Under construction

Still being built. Things may change

Fish Game

Time limit1sMemory limit1024 MB

Summary
Otto and Dave alternate moves on a 2xN grid, each taking the fish in every cell they enter; find what each takes under optimal play.
Level

Medium7 of 10

Topics
Game theory, Prefix sum, Greedy
Solved
No attempts yet

Problem

Otto received curry with conger eel in Hanchosu, and in return he built Dave a fish farm of size 2×N2\times N!

  • Dave: Oh...! What is this place?
  • Otto: You have been struggling to catch fish every day, haven't you?
  • Otto: So I built this fish farm in a single day yesterday!
  • Dave: ... In a single day?
  • Otto: First, I put Ai,jA_{i,j} fish in each cell (i,j)(i, j) except (1,1)(1, 1) and (2,N)(2, N).
  • Otto: But I cannot just give them to you. Play a game with me, and I will give you as many fish as you earn!

So Dave and Otto began a game. Otto stands at (1,1)(1,1), and Dave stands at (2,N)(2,N). Every cell except (1,1)(1,1) and (2,N)(2,N) contains fish. Dave and Otto repeat the following turns 1010010^{100} times.

  • Otto moves to an adjacent cell.
  • Otto harvests all fish in that cell and takes them. The fish do not regrow after Otto leaves the cell.
  • Dave moves to an adjacent cell.
  • Dave harvests all fish in that cell and takes them. The fish do not regrow after Dave leaves the cell.
  • Dave and Otto may be in the same cell at the same time.

Both Dave and Otto try to take as many fish as possible. Find the number of fish Otto takes and the number of fish Dave takes.

Input

The first line contains the size of the fish farm NN.

The second line contains A1,1,A1,2,⋯ ,A1,NA_{1,1}, A_{1,2}, \cdots, A_{1,N}, separated by spaces.

The third line contains A2,1,A2,2,⋯ ,A2,NA_{2,1}, A_{2,2}, \cdots, A_{2,N}, separated by spaces.

Output

When both play optimally, print the number of fish Otto takes and the number of fish Dave takes, separated by a space.

Constraints

  • 2≤N≤500 0002 \leq N \leq 500\,000
  • A1,1=A2,N=0A_{1,1} = A_{2,N} = 0
  • When (i,j)≠(1,1),(2,N)(i, j) \neq (1, 1), (2, N), 1≤Ai,j≤1 000 0001 \leq A_{i,j} \leq 1\,000\,000
  • All given numbers are integers.

Examples2

  1. Example 1

    Input
    5
    0 2 3 3 7
    1 3 1 2 0
    
    Expected output
    10 12
    
  2. Example 2

    Input
    2
    0 100
    10 0
    
    Expected output
    100 10