We need to find maximum candies collected traveling from (1,1) to (2,N) with moves right or down. The grid is 2 rows by N columns. Starting top-left, ending bottom-right. Only allowed moves: right (increase column) or down (from row1 to row2 at same column). However, note that since there are only 2 rows, down move only possible when in row1 (i=1) to row2 (i=2) at same column. After moving down, you are in row2, then you can only move right (since moving down from row2 is not possible? Actually there is no lower row, so only right). Also you cannot move up. So path is essentially: start at (1,1). Then you will go right some number of columns staying in row1, then at some column k (1<=k<=N) you move down to row2, then continue right to column N. But note: You could also move down at column 1 immediately, then go right all the way. Or you could never move down? But you must end at (2,N), so you must eventually move down. So all paths are characterized by the column at which you move down from row1 to row2. The path is: from (1,1) go right through columns 1..k on row1, then down to (2,k), then go right through columns k..N on row2. But careful: When you go down at column k, you'll collect A[1][k] before moving down? Actually you are at (1,k) then you move down to (2,k). So you will have visited (1,k) and then (2,k). The candies collected are sum of all squares visited. Since you traverse along a path, you collect each square exactly once (if you pass through it; but note you might pass through a column twice? Not in these moves: you go right along row1 from column 1 to k inclusive, then down to row2 at column k, then right along row2 from column k to N inclusive. So you will visit each square (1,j) for j=1..k, and (2,j) for j=k..N. So the total candies = sum_{j=1}^{k} A[1][j] + sum_{j=k}^{N} A[2][j].
But note: is it allowed to move down later than N? No, you must end at (2,N). Could you move down multiple times? Only two rows, so you can only move down once, because after moving down you are at row2, you cannot go back up. So yes, exactly one down move. So the problem reduces to: find k (1 ≤ k ≤ N) that maximizes S(k) = sum_{j=1}^{k} A[1][j] + sum_{j=k}^{N} A[2][j].
We can precompute prefix sums for row1 and suffix sums for row2. Then compute max over k.
But wait: Could there be a path that goes down, then right, then down? No because only two rows. Also could there be a path that goes right, down, right, down? That would require moving down from row2 to row3, impossible. So indeed all paths are of that form.
Thus solution is straightforward: O(N). But the constraints N up to 100, A up to 100, so trivial.
We must ensure we consider k from 1 to N inclusive. But note: starting at (1,1) and ending at (2,N). At k=1, you move down immediately at column1: sum row1 col1 + sum row2 col1..N. At k=N, you go all the way to (1,N) then down to (2,N): sum row1 col1..N + row2 colN.
Thus answer is max over k.
Check examples:
Example1:
N=5
row1: 3 2 2 4 1
row2: 1 2 2 2 1
Compute sums:
k=1: row1[1]=3 + row2 sum (1+2+2+2+1=8) = 11
k=2: row1 sum first2=3+2=5 + row2 sum from2: 2+2+2+1=7 =12
k=3: row1 first3=3+2+2=7 + row2 from3:2+2+1=5 =12? Actually row2 from3 to5: A[2,3]=2, A[2,4]=2, A[2,5]=1 => sum=5, total=12.
k=4: row1 first4=3+2+2+4=11 + row2 from4:2+1=3 => total=14
k=5: row1 first5=3+2+2+4+1=12 + row2 from5:1=1 => total=13
Max is 14, matches.
Example2:
N=4 all ones.
k=1: row1[1]=1 + row2 sum 1+1+1+1=4 ->5
k=2: row1 first2=2 + row2 from2:1+1+1=3 ->5
k=3: row1 first3=3 + row2 from3:1+1=2 ->5
k=4: row1 first4=4 + row2 from4:1=1 ->5
All 5, matches.
Example3:
N=7:
row1:3 3 4 5 4 5 3
row2:5 3 4 4 2 3 2
Compute? Let's compute quickly:
Row1 prefix:
p1[0]=0
p1[1]=3
p1[2]=6
p1[3]=10
p1[4]=15
p1[5]=19
p1[6]=24
p1[7]=27
Row2 suffix:
s2[1]= sum from1 to7 = 5+3+4+4+2+3+2=23? Let's sum:5+3=8, +4=12, +4=16, +2=18, +3=21, +2=23.
s2[2]= from2 to7 = 3+4+4+2+3+2=18
s2[3]= from3 to7 = 4+4+2+3+2=15
s2[4]= from4 to7 = 4+2+3+2=11
s2[5]= from5 to7 = 2+3+2=7
s2[6]= from6 to7 = 3+2=5
s2[7]= from7 =2
s2[8]=0.
Then S(k)=p1[k]+s2[k].
k=1:3+23=26
k=2:6+18=24
k=3:10+15=25
k=4:15+11=26
k=5:19+7=26
k=6:24+5=29
k=7:27+2=29
max 29 matches.
Example4: N=1, row1:2 row2:3. The only path: start at (1,1) -> (2,1) maybe? Since we need to end at (2,1). Moves: we are at (1,1). To get to (2,1) we need to move down (since right not possible because N=1). So total = A[1][1] + A[2][1] = 2+3=5 matches.
Thus solution is correct.
Now we can code.
Implementation details: read N, read two lines of integers. Compute prefix sum for row1, compute suffix sum for row2 (or compute total row2 sum and subtract prefix). Then loop k=1..N compute prefix1[k] + suffix2[k]. Keep max. Print max.
Edge cases: N=1 works.
Complexity O(N).
That's it.
But the problem statement: "You will travel to the bottom-right square, (2, N), by repeatedly moving right or down." In a 2xN grid, moving down is allowed only from top to bottom. So indeed.
Double-check: Is moving down allowed only when at row1? Yes. So the path shape is as described.
Thus solution is trivial.
Now code in Python:
def solve():
import sys
data = sys.stdin.read().strip().split()
if not data: return
it = iter(data)
N = int(next(it))
A1 = [int(next(it)) for _ in range(N)]
A2 = [int(next(it)) for _ in range(N)]
prefix1 = [0](N+1)
for i in range(1,N+1):
prefix1[i] = prefix1[i-1] + A1[i-1]
suffix2 = [0](N+2)
# suffix2[k] = sum from index k to N (1-indexed)
for i in range(N,0,-1):
suffix2[i] = suffix2[i+1] + A2[i-1]
best = 0
for k in range(1,N+1):
total = prefix1[k] + suffix2[k]
if total > best:
best = total
print(best)
Alternatively, compute prefix and then keep a running sum of row1 and compute row2 suffix on the fly: total2 = sum(A2); then for k from 1 to N, total = prefix1[k] + total2; then subtract A2[k-1] from total2 for next iteration? Actually careful: suffix from k = sum from k to N of A2. So we can compute suffix2 as total2 - sum_{j=1}^{k-1} A2[j]. So we can keep a variable sum2 = sum(A2) and then for k=1..N: total = prefix1[k] + sum2; then sum2 -= A2[k-1]. This works too.
But simple is fine.
Now produce final answer.
But note: The problem is from AtCoder ABC129 C? Actually it's from typical DP but simpler. But anyway.
We should output the maximum.
We'll include the solution explanation.
Thus final answer: We'll present code.
I'll now write final response. ```python
import sys
def main() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
it = iter(data)
N = int(next(it))
A1 = [int(next(it)) for _ in range(N)]
A2 = [int(next(it)) for _ in range(N)]
# prefix sums of the first row
pref = [0] * (N + 1)
for i in range(1, N + 1):
pref[i] = pref[i - 1] + A1[i - 1]
# suffix sums of the second row
suff = [0] * (N + 2) # 1-indexed, suff[N+1] = 0
for i in range(N, 0, -1):
suff[i] = suff[i + 1] + A2[i - 1]
best = 0
for k in range(1, N + 1):
candies = pref[k] + suff[k]
if candies > best:
best = candies
print(best)
if name == "main":
main()