Xiao Ming's divisibility

TimeLimit:1000MS  MemoryLimit:128MB
64-bit integer IO format:%lld
未提交 | 登录后收藏
Problem Description

Xiaohong gave Xiaoming a string s containing only 0 and 1. Xiaohong wants to know the maximum interval [l, r] so that the number of '0' inside is a multiple of '1', or the number  of '1' is a multiple of the number of '0'.

For the clumsy little red, she didn't want to know what the l of this largest interval is and what is r, she just wants to know the value of r-l+1.

For Xiao Ming, who has always loved Xiaohong, he must help Xiaohong find this value, but Xiao Ming is also very clumsy, so he found you.

Since S is too long, it can't be calculated by Xiao Ming, so please help he with programming to solve this problem. 

这题太简单了就不翻译了

Input

An integer T indicates the number of questions Xiao Hong gave to Xiao Ming. (1<=T<=20)

Each question contains a string s (1<=|s|<=1000)

Guarantee all problems ∑|s|<=5000.


Output

Each question outputs a line of integers indicating the value of the maximum interval r-l+1. If there is no interval [l, r], then 0 is output.


SampleInput
3
01
101
1011010
SampleOutput
2
3
6
Submit
题目统计信息详细
总AC数12
通过人数12
尝试人数12
总提交量29
AC率41.38%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: