Stone Placement Game
Time limit1sMemory limit1024 MB
On a circle of valued cells, find each player's optimal score when they alternately place stones next to their own stones.
Problem
A game board has cells arranged in a circle, and Cheolsu and Younghee play a game on it. The -th cell has a non-negative integer written on it. Each cell can hold at most one stone.
Cheolsu has black stones, and Younghee has white stones. First, the two players place stones on some predetermined cells. After that, Cheolsu starts, and they take turns. On a turn, a player looks at the empty cells adjacent to the cells holding their own stones. If there is at least one such cell, the player picks one and places a stone there. If there is none, the turn passes to the opponent. If neither player can place a stone, the game ends.
Each player wants to maximize the sum of the values of the cells holding their own stones. Given the stone placement before the turns begin, find each player's score when both play optimally.
Input
The first line contains ().
The second line contains , separated by spaces, which describe the initial stone placement (). means cell holds a black stone, means it holds a white stone, and means it is empty.
The third line contains , separated by spaces ().
Output
Print the scores of Cheolsu and Younghee, separated by a space, on the first line.