五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

CF 1633B - Minority

2023-06-21 18:13 作者:您是打尖兒還是住店呢  | 我要投稿

You are given a string s, consisting only of characters '0' and '1'.

You have to choose a contiguous substring of s and remove all occurrences of the character, which is a strict minority in it, from the substring.

That is, if the amount of '0's in the substring is strictly smaller than the amount of '1's, remove all occurrences of '0' from the substring. If the amount of '1's is strictly smaller than the amount of '0's, remove all occurrences of '1'. If the amounts are the same, do nothing.

You have to apply the operation exactly once. What is the maximum amount of characters that can be removed?

Input

The first line contains a single integer t (1≤t≤104) — the number of testcases.

The only line of each testcase contains a non-empty string s, consisting only of characters '0' and '1'. The length of s doesn't exceed 2?105.

The total length of strings s over all testcases doesn't exceed 2?105.

Output

For each testcase, print a single integer — the maximum amount of characters that can be removed after applying the operation exactly once.

Example

input

4

01

1010101010111

00110001000

1

output

0

5

3

0

Note

In the first testcase, you can choose substrings "0", "1" or "01". In "0" the amount of '0' is 1

, the amount of '1' is 0. '1' is a strict minority, thus all occurrences of it are removed from the substring. However, since there were 0 of them, nothing changes. Same for "1". And in "01" neither of '0' or '1' is a strict minority. Thus, nothing changes. So there is no way to remove any characters.

In the second testcase, you can choose substring "10101010101". It contains 5 characters '0' and 6 characters '1'. '0' is a strict minority. Thus, you can remove all its occurrences. There exist other substrings that produce the same answer.

In the third testcase, you can choose substring "011000100". It contains 6 characters '0' and 3 characters '1'. '1' is a strict minority. Thus, you can remove all its occurrences.

放2個(gè)參數(shù)依次記錄當(dāng)前0和1的數(shù)量,每次去比較兩個(gè)數(shù)誰小,保存,依次遍歷完即可,但是要在兩個(gè)數(shù)不相等的情況下,這里踩了一個(gè)坑。


CF 1633B - Minority的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
阳高县| 丹东市| 南和县| 六盘水市| 永宁县| 信宜市| 夹江县| 凤山市| 峨眉山市| 东源县| 章丘市| 郯城县| 深州市| 南昌县| 大理市| 仪征市| 安康市| 繁峙县| 清水县| 房山区| 重庆市| 旌德县| 凉山| 郯城县| 武穴市| 西宁市| 顺昌县| 乐都县| 辽中县| 增城市| 扶余县| 海南省| 巴塘县| 微山县| 洛川县| 吴江市| 黄陵县| 澜沧| 鸡泽县| 长沙县| 惠安县|