CF1913B.Swap and Delete

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Swap and Delete

You are given a binary string ss (a string consisting only of 0-s and 1-s).

You can perform two types of operations on ss:

  1. delete one character from ss. This operation costs 11 coin;
  2. swap any pair of characters in ss. This operation is free (costs 00 coins).

You can perform these operations any number of times and in any order.

Let's name a string you've got after performing operations above as tt. The string tt is good if for each ii from 11 to t|t| tisit_i \neq s_i (t|t| is the length of the string tt). The empty string is always good. Note that you are comparing the resulting string tt with the initial string ss.

What is the minimum total cost to make the string tt good?

Input

The first line contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases. Then tt test cases follow.

The only line of each test case contains a binary string ss (1s21051 \le |s| \le 2 \cdot 10^5; si{s_i \in \{0, 1}\}) — the initial string, consisting of characters 0 and/or 1.

Additional constraint on the input: the total length of all strings ss doesn't exceed 21052 \cdot 10^5.

Output

For each test case, print one integer — the minimum total cost to make string tt good.

Note

In the first test case, you have to delete a character from ss to get the empty string tt. Only then tt becomes good. One deletion costs 11 coin.

In the second test case, you can, for example, delete the second character from ss to get the string 01, and then swap the first and second characters to get the string tt == 10. String tt is good, since t1s1t_1 \neq s_1 and t2s2t_2 \neq s_2. The total cost is 11 coin.

In the third test case, you can, for example, swap s1s_1 with s2s_2, swap s3s_3 with s4s_4, swap s5s_5 with s7s_7, s6s_6 with s8s_8 and s9s_9 with s10s_{10}. You'll get tt == 1010001110. All swap operations are free, so the total cost is 00.

Samples

4
0
011
0101110001
111100
1
1
0
4

在线编程 IDE

建议全屏模式获得最佳体验