{"raw_statement":[{"iden":"problem statement","content":"There are $2N$ balls, $N$ white and $N$ black, arranged in a row. The integers from $1$ through $N$ are written on the white balls, one on each ball, and they are also written on the black balls, one on each ball. The integer written on the $i$\\-th ball from the left ($1$ $≤$ $i$ $≤$ $2N$) is $a_i$, and the color of this ball is represented by a letter $c_i$. $c_i$ $=$ `W` represents the ball is white; $c_i$ $=$ `B` represents the ball is black.\nTakahashi the human wants to achieve the following objective:\n\n*   For every pair of integers $(i,j)$ such that $1$ $≤$ $i$ $<$ $j$ $≤$ $N$, the white ball with $i$ written on it is to the left of the white ball with $j$ written on it.\n*   For every pair of integers $(i,j)$ such that $1$ $≤$ $i$ $<$ $j$ $≤$ $N$, the black ball with $i$ written on it is to the left of the black ball with $j$ written on it.\n\nIn order to achieve this, he can perform the following operation:\n\n*   Swap two adjacent balls.\n\nFind the minimum number of operations required to achieve the objective."},{"iden":"constraints","content":"*   $1$ $≤$ $N$ $≤$ $2000$\n*   $1$ $≤$ $a_i$ $≤$ $N$\n*   $c_i$ $=$ `W` or $c_i$ $=$ `B`.\n*   If $i$ $≠$ $j$, $(a_i,c_i)$ $≠$ $(a_j,c_j)$."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$\n$c_1$ $a_1$\n$c_2$ $a_2$\n$:$\n$c_{2N}$ $a_{2N}$"},{"iden":"sample input 1","content":"3\nB 1\nW 2\nB 3\nW 1\nW 3\nB 2"},{"iden":"sample output 1","content":"4\n\nThe objective can be achieved in four operations, for example, as follows:\n\n*   Swap the black $3$ and white $1$.\n*   Swap the white $1$ and white $2$.\n*   Swap the black $3$ and white $3$.\n*   Swap the black $3$ and black $2$."},{"iden":"sample input 2","content":"4\nB 4\nW 4\nB 3\nW 3\nB 2\nW 2\nB 1\nW 1"},{"iden":"sample output 2","content":"18"},{"iden":"sample input 3","content":"9\nW 3\nB 1\nB 4\nW 1\nB 5\nW 9\nW 2\nB 6\nW 5\nB 3\nW 8\nB 9\nW 7\nB 2\nB 8\nW 4\nW 6\nB 7"},{"iden":"sample output 3","content":"41"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}