Codeforces Round 944 (Div. 4) |
---|

Finished |

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

dp

greedy

implementation

sortings

strings

*1100

No tag edit access

The problem statement has recently been changed. View the changes.

×
D. Binary Cut

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputYou are given a binary string$$$^{\dagger}$$$. Please find the minimum number of pieces you need to cut it into, so that the resulting pieces can be rearranged into a sorted binary string.

Note that:

- each character must lie in exactly one of the pieces;
- the pieces must be contiguous substrings of the original string;
- you must use all the pieces in the rearrangement.

$$$^{\dagger}$$$ A binary string is a string consisting of characters $$$\texttt{0}$$$ and $$$\texttt{1}$$$. A sorted binary string is a binary string such that all characters $$$\texttt{0}$$$ come before all characters $$$\texttt{1}$$$.

Input

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 500$$$) — the number of test cases.

The only line of each test case contains a single string $$$s$$$ ($$$1 \leq |s| \leq 500$$$) consisting of characters $$$\texttt{0}$$$ and $$$\texttt{1}$$$, where $$$|s|$$$ denotes the length of the string $$$s$$$.

Output

For each test case, output a single integer — the minimum number of pieces needed to be able to rearrange the string into a sorted binary string.

Example

Input

6110100000000011000011110110

Output

3 1 1 2 1 2

Note

The first test case is pictured in the statement. It can be proven that you can't use fewer than $$$3$$$ pieces.

In the second and third test cases, the binary string is already sorted, so only $$$1$$$ piece is needed.

In the fourth test case, you need to make a single cut between the two characters and rearrange them to make the string $$$\texttt{01}$$$.

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jun/25/2024 15:48:18 (i2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|