Codeforces Round 1049 (Div. 2)
A
Shift Sort
Codeforces
800
原题
←B →
翻译中…

You are given a binary string$^{\text{∗}}$ $s$ of length $n$ and you are allowed to perform the following operation any number of times (including zero):

翻译中…
  • Choose $3$ indices $1 \le i \lt j \lt k \le n$ and right shift or left shift the values on $s_i$, $s_j$, $s_k$ cyclically.
翻译中…

For the binary string 110110, if we choose $i=1$, $j=2$, $k=3$ and perform a right shift cyclically, the string becomes 011110; if we choose $i=4$, $j=5$, $k=6$ and perform a left shift cyclically, the string becomes 110101.

翻译中…

Determine the minimum number of operations required to sort the given binary string.

翻译中…

$^{\text{∗}}$A binary string is a string that consists only of the characters 0 and 1.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($3 \le n \le 100$) — the length of the string.

翻译中…

The second line contains a binary string $s$ of length $n$.

翻译中…

Output

翻译中…

For each test case, output a single integer — the minimum number of operations required to sort the given binary string.

翻译中…

Note

翻译中…

For the first test case, the given string is already sorted. So, no operations are needed.

翻译中…

For the second test case, we can choose $i = 1$, $j = 2$, $k = 4$ and perform a right shift cyclically. The string becomes equal to 0011, which is sorted.

翻译中…

样例

Input #1
4
3
001
4
0110
6
110100
6
101011
Output #1
0
1
2
1
InputCopy OutputCopy
题目信息
题号
2140A
时间限制
1 s
内存限制
256 MB
标签
贪心
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。