| <p>You are writing a new revolutionary archiver. The archive is essentially a | |
| pair of non-decreasing sequences of integers of equal length <strong>K</strong>: <strong>0≤x<sub>1</sub>≤...≤x<sub>k</sub></strong> and | |
| <strong>0≤y<sub>1</sub>≤...≤y<sub>k</sub></strong>.</p> | |
| <p> | |
| The decompression algorithm proceeds as follows: | |
| <ol> | |
| <li>Sequence <strong>(0,0), (x<sub>1</sub>,y<sub>1</sub>), ... (x<sub>k</sub>,y<sub>k</sub>), (x<sub>k</sub>, 0), (0, 0)</strong> defines a polygon <strong>P</strong></li> | |
| <li>Starting from the point <strong>(0,0)</strong>, increase either <strong>x</strong> or <strong>y</strong> coordinate by 1 without | |
| moving outside of <strong>P</strong>. If both moves are available, you should increase y. | |
| After each step write <strong>0</strong> to output if incremented <strong>x</strong> or <strong>1</strong> otherwise.</li> | |
| <li>Repeat step 2 until you end up in point <strong>(x<sub>k</sub>,y<sub>k</sub>)</strong>.</li> | |
| </ol> | |
| </p> | |
| <p>Example: decompression of sequence <strong>(3,4), (7,6), (7,8)</strong> will produce string <strong>010101100100111</strong>.</p> | |
| <p>Your task is to write a compression rate calculator, that is given | |
| binary string s find the smallest value of <strong>K</strong> for which there exists archive | |
| that decompresses to s.</p> | |
| <h2>Input</h2> | |
| <p> | |
| The first line contains a single integer <strong>T</strong>, <strong>T</strong> ≤ 20. <strong>T</strong> test cases follow, where each test case consists of one binary string with length <strong>≤ 1,000,000</strong>. | |
| </p> | |
| <h2>Output</h2> | |
| <p>Output a single line containing the smallest possible <strong>K</strong>.</p> | |