CF BUDDY
← Problems·

1820B · JoJo's Incredible Adventures

1100 · math, strings, two pointers

Problem: Did you think there was going to be a JoJo legend here? But no, that was me, Dio!

Given a binary string ss of length nn, consisting of characters 0 and 1. Let's build a square table of size n×nn \times n, consisting of 0 and 1 characters as follows.

In the first row of the table write the original string ss. In the second row of the table write cyclic shift of the string ss by one to the right. In the third row of the table, write the cyclic shift of line ss by two to the right. And so on. Thus, the row with number kk will contain a cyclic shift of string ss by kk to the right. The rows are numbered from 00 to n1n - 1 top-to-bottom.

In the resulting table we need to find the rectangle consisting only of ones that has the largest area.

We call a rectangle the set of all cells (i,j)(i, j) in the table, such that x1ix2x_1 \le i \le x_2 and y1jy2y_1 \le j \le y_2 for some integers 0x1x2<n0 \le x_1 \le x_2 < n and 0y1y2<n0 \le y_1 \le y_2 < n.

Recall that the cyclic shift of string ss by kk to the right is the string snk+1sns1s2snks_{n-k+1} \ldots s_n s_1 s_2 \ldots s_{n-k}. For example, the cyclic shift of the string "01011" by 00 to the right is the string itself "01011", its cyclic shift by 33 to the right is the string "01101".

Input Format: Each test consists of multiple test cases. The first line contains a single integer tt (1t21041 \le t \le 2 \cdot 10^4) — the number of test cases. The description of test cases follows.

The first and the only line of each test case contains a single binary string ss (1s21051 \le \lvert s \rvert \le 2 \cdot 10^5), consisting of characters 0 and 1.

It is guaranteed that the sum of string lengths s|s| over all test cases does not exceed 21052 \cdot 10^5.

Output Format: For each test case, output a single integer — the maximum area of a rectangle consisting only of ones. If there is no such rectangle, output 00.

Note: In the first test case, there is a table 1×11 \times 1 consisting of a single character 0, so there are no rectangles consisting of ones, and the answer is 00.

In the second test case, there is a table 1×11 \times 1, consisting of a single character 1, so the answer is 11.

In the third test case, there is a table:

101110011

In the fourth test case, there is a table:

011110001111100111110011111001111100

In the fifth test case, there is a table:

101010010101101010010101101010010101

Rectangles with maximum area are shown in bold.

Sample Cases

Case 1

Input

5
0
1
101
011110
101010

Output

0
1
2
6
1

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback