欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1633B.Minority
Minority
You are given a string , consisting only of characters '0' and '1'.
You have to choose a contiguous substring of 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 () — the number of testcases.
The only line of each testcase contains a non-empty string , consisting only of characters '0' and '1'. The length of doesn't exceed .
The total length of strings over all testcases doesn't exceed .
Output
For each testcase, print a single integer — the maximum amount of characters that can be removed after applying the operation exactly once.
Note
In the first testcase, you can choose substrings "0", "1" or "01". In "0" the amount of '0' is , the amount of '1' is . '1' is a strict minority, thus all occurrences of it are removed from the substring. However, since there were 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 characters '0' and 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 characters '0' and characters '1'. '1' is a strict minority. Thus, you can remove all its occurrences.
Samples
4
01
1010101010111
00110001000
1
0
5
3
0
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |