Robot
Time limit3sMemory limit512 MB
For each command in a robot's move string, compute the total score the robot would earn if that single command were deleted, where each visit to a cell scores based on visit count and cell coordinates.
- Level
Hard8 of 10
- Topics
- Simulation, Prefix sum, Math, Implementation
- Solved
- No attempts yet
Problem
There is an infinitely large 2-dimensional chessboard, in which every cell has a unique integer coordinate . The starting cell has coordinate . If we start from this cell, walk steps to the right, and then walk steps upwards, we arrive at cell . Note that and could be negative, which means walking in the opposite direction.
A robot starts from cell and then executes a sequence of commands , where each means walking one step in the direction of Left, Right, Down, Up, respectively. For example, if the sequence of commands is , then the cells traveled are . We call such a sequence the travel history of the robot (in this example, the history contains five elements).
For every cell in the travel history, if it is the -th time the robot visits this cell, then the robot earns a score of The total score is the sum of the score of every cell in the travel history. In this example, the total score is .
For every from to , answer the following: if we remove from the sequence of commands, what is the total score earned by the robot after executing the remaining sequence ?
Input
The first line contains an integer ().
The second line contains a string of length , denoting the sequence of commands.
Output
Output lines. The -th line must contain the total score if we remove command .