This page is still under construction.

Parts of this page are still being built. What you see may change.

Robot

Time limit3sMemory limit512 MB

Summary
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 (x,y)(x, y). The starting cell has coordinate (0,0)(0, 0). If we start from this cell, walk xx steps to the right, and then walk yy steps upwards, we arrive at cell (x,y)(x, y). Note that xx and yy could be negative, which means walking in the opposite direction.

A robot starts from cell (0,0)(0,0) and then executes a sequence of commands c1c2…cnc_1 c_2 \ldots c_n, where each ci∈{L,R,D,U}c_i \in \{\mathtt{L}, \mathtt{R}, \mathtt{D}, \mathtt{U}\} means walking one step in the direction of Left, Right, Down, Up, respectively. For example, if the sequence of commands is LRLD\mathtt{LRLD}, then the cells traveled are (0,0)→(−1,0)→(0,0)→(−1,0)→(−1,−1)(0, 0) \to (-1, 0) \to (0, 0) \to (-1, 0) \to (-1, -1). We call such a sequence the travel history of the robot (in this example, the history contains five elements).

For every cell (x,y)(x, y) in the travel history, if it is the ii-th time the robot visits this cell, then the robot earns a score of f(x,y,i)=i⋅((∣x∣+1)xor(∣y∣+1))+i.f(x, y, i) = i \cdot \left((|x| + 1) \mathrm{xor} (|y| + 1)\right) + i\text{.} The total score is the sum of the score of every cell in the travel history. In this example, the total score is f(0,0,1)+f(−1,0,1)+f(0,0,2)+f(−1,0,2)+f(−1,−1,1)=1+4+2+8+1=16f(0, 0, 1) + f(-1, 0, 1) + f(0, 0, 2) + f(-1, 0, 2) + f(-1, -1, 1) = 1 + 4 + 2 + 8 + 1 = 16.

For every ii from 11 to nn, answer the following: if we remove cic_i from the sequence of commands, what is the total score earned by the robot after executing the remaining sequence c1c2…ci−1ci+1…cnc_1 c_2 \ldots c_{i - 1} c_{i + 1} \ldots c_n?

Input

The first line contains an integer nn (2≤n≤3⋅1052 \le n \le 3 \cdot 10^{5}).

The second line contains a string c1c2…cnc_1 c_2 \ldots c_n of length nn, denoting the sequence of commands.

Output

Output nn lines. The ii-th line must contain the total score if we remove command cic_i.

Examples1

  1. Example 1

    Input
    5
    LRLDD
    
    Expected output
    14
    11
    14
    16
    16