{"problem":{"name":"Avoid Boring Matches","description":{"content":"There is a tournament with $2^N$ participants, numbered $1$ to $2^N$. The tournament proceeds as follows: *   First, each participant is given a red or blue hat. You are given the color of the hat fo","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"arc169_e"},"statements":[{"statement_type":"Markdown","content":"There is a tournament with $2^N$ participants, numbered $1$ to $2^N$.\nThe tournament proceeds as follows:\n\n*   First, each participant is given a red or blue hat. You are given the color of the hat for each participant as the string $S$. Specifically, participant $i$ is given a red hat if the $i$\\-th character ($1 \\leq i \\leq 2^N$) of $S$ is `R`, and a blue hat if it is `B`.\n    \n*   Then, the following operation is repeated until there is only one participant remaining:\n    *   Let $2k$ be the current number of participants. Divide the participants into $k$ pairs. You can freely choose how to pair them. Then, a match is held for each pair; the winner remains, and the loser leaves the tournament. The participants are numbered in descending order of strength, so the participant with the **smaller** number always wins.\n\nA match between two participants wearing red hats is called a **boring** match. Your goal is to arrange the pairings so that no boring matches occur during the tournament.\nWhether the goal is achievable or not depends on the string $S$. Hence, you have decided to tamper with $S$ before the start of the tournament. Specifically, you can perform the following operation zero or more times:\n\n*   Choose two adjacent characters in $S$ and swap them.\n\nDetermine whether it is possible to achieve the goal after operations. If it is, find the minimum number of operations required.\n\n## Constraints\n\n*   $1 \\leq N \\leq 18$\n*   $S$ is a string of length $2^N$ consisting of `R` and `B`.\n*   All input values are integers.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$\n$S$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"arc169_e","tags":[],"sample_group":[["2\nRRBB","1\n\nWithout performing any operations, you cannot achieve the goal.\nIf you swap the second and third characters of $S$, making $S=$`RBRB`, you can achieve the goal as follows:\n\n*   Give red, blue, red, and blue hats to participants $1$, $2$, $3$, and $4$, respectively.\n*   Divide the four participants into two pairs $(1,4),(2,3)$. No boring matches occur here. After the matches, participants $1$ and $2$ remain.\n*   Divide the two participants into one pair $(1,2)$. No boring matches occur here. After the match, participant $1$ remains.\n\nTherefore, the answer is $1$."],["1\nRR","\\-1"],["4\nRBBRRBRBBRBBBRBR","0"],["5\nRBRRBRRRBRRRRRRRRRBBBBBBBBBBBBBB","11"]],"created_at":"2026-03-03 11:01:14"}}