{"raw_statement":[{"iden":"problem statement","content":"Snuke has $2N$ dogs, numbered $1$ through $2N$.\nThe cuteness of Dog $i$ is $a_i$. The color of Dog $i$ is $c_i$, which is `R`, `G`, or `B`; `R` stands for red, `G` stands for green, and `B` stands for blue.\nSnuke has $N$ kennels, and wants to put two dogs in each kennel. Note that this means each dog will be in exactly one kennel.\nWhen he puts two dogs in the same kennel, it will cause some _dissatisfaction_ in that kennel. The level of dissatisfaction is represented as an integer. When Dogs $i$ and $j$ are in the same kennel, the dissatisfaction will be $0$ if $c_i = c_j$ and $|a_i - a_j|$ otherwise.\nFind the minimum possible total dissatisfaction when putting two dogs in each of the $N$ kennels."},{"iden":"constraints","content":"*   $1 \\leq N \\leq 10^{5}$\n*   $1 \\leq a_i \\leq 10^{15}$\n*   $a_i$ is an integer.\n*   $c_i$ is `R`, `G`, or `B`."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$\n$a_{1}$ $c_{1}$\n$\\vdots$\n$a_{2N}$ $c_{2N}$"},{"iden":"sample input 1","content":"1\n1 R\n2 G"},{"iden":"sample output 1","content":"1\n\n*   Dog $1$ has the cuteness of $1$, and Dog $2$ has the cuteness of $2$.\n*   Since $c_1 \\neq c_2$, the dissatisfaction will be $1$."},{"iden":"sample input 2","content":"1\n1 B\n2 B"},{"iden":"sample output 2","content":"0\n\n*   Dog $1$ has the cuteness of $1$, and Dog $2$ has the cuteness of $2$.\n*   Since $c_1 = c_2$, the dissatisfaction will be $0$."},{"iden":"sample input 3","content":"10\n585 B\n293 B\n788 B\n222 B\n772 G\n841 B\n115 R\n603 G\n450 B\n325 R\n851 B\n205 G\n134 G\n651 R\n565 R\n548 B\n391 G\n19 G\n808 B\n475 B"},{"iden":"sample output 3","content":"0"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}