|
<p> |
|
Uriel is an android programmed for a singular purpose — to obtain jam. He's found himself in a row of cells, some of which hopefully contain raspberry jam for him to gather |
|
in the form of special jars called "jammers". |
|
</p> |
|
|
|
<p> |
|
There are |<strong>C</strong>| cells in the row, and their contents are described by a string <strong>C</strong>, with the <em>i</em>th character of <strong>C</strong> |
|
corresponding to the <em>i</em>th cell. Each character is one of the following: |
|
</p> |
|
|
|
<ul> |
|
<li> - "<code>.</code>": Empty cell </li> |
|
<li> - "<code>*</code>": Cell initially containing a jammer </li> |
|
<li> - "<code>#</code>": Cell containing a laser barrier </li> |
|
</ul> |
|
|
|
<p> |
|
By default, each laser barrier is "active". However, whenever a laser barrier has at least one jammer in an adjacent cell to its left or right, that laser barrier becomes jammed by the jammer's jam, |
|
and becomes "inactive" instead. A laser barrier may switch back and forth between being inactive and active if jammers next to it are added or removed. |
|
A single jammer may be responsible for jamming multiple laser barriers at once. |
|
</p> |
|
|
|
<p> |
|
Uriel begins in the first cell (which is guaranteed to be empty). He has the ability to carry around any number of jammers at once, though he initially has 0 of them. |
|
At each point in time, he may choose to perform one of the following actions: |
|
</p> |
|
|
|
<ul> |
|
<li> - Pick up a jammer from his current cell. He may only do so if the cell contains a jammer. That cell will then become empty.</li> |
|
<li> - Place one of his jammers into his current cell. He may only do so if he's holding at least one jammer, and if the cell is currently completely empty |
|
(it doesn't contain another jammer, and doesn't contain a laser barrier, even if it's inactive).</li> |
|
<li> - Walk left or right into an adjacent cell, without leaving the row of cells. He may only do so if that cell doesn't currently contain an active laser barrier.</li> |
|
</ul> |
|
|
|
<p> |
|
Uriel isn't interested in consuming any jam, he just wants to hold onto it — onto as much of it as he can. |
|
As such, he'd like to determine the maximum number of jammers which he can ever end up holding at a single time, after performing any number of moves of his choice. |
|
</p> |
|
|
|
|
|
<h3>Input</h3> |
|
|
|
<p> |
|
Input begins with an integer <strong>T</strong>, the number of rows of cells. |
|
For each row of cells, there is a single line containing the string <strong>C</strong> as described above. |
|
</p> |
|
|
|
|
|
<h3>Output</h3> |
|
|
|
<p> |
|
For the <em>i</em>th row of cells, output a line containing "Case #<em>i</em>: " followed by the maximum number of jammers which Uriel can end up holding at once. |
|
</p> |
|
|
|
|
|
<h3>Constraints</h3> |
|
|
|
<p> |
|
1 ≤ <strong>T</strong> ≤ 100 <br /> |
|
1 ≤ |<strong>C</strong>| ≤ 400,000 <br /> |
|
</p> |
|
|
|
|
|
<h3>Explanation of Sample</h3> |
|
|
|
<p> |
|
In the first case, there are no laser barriers, so Uriel can simply walk to the right while picking up each jammer he comes across, allowing him to end up with 5 jammers by the end. |
|
</p> |
|
|
|
<p> |
|
In the second case, Uriel is immediately left with no valid moves, as there's an active laser barrier to his right and he's not holding any jammers. |
|
</p> |
|
|
|
<p> |
|
In the third case, the first laser barrier which Uriel encounters is already inactive due to the jammer to its right, meaning that he can walk through it. |
|
The second laser barrier is initially active, but Uriel can jam it by putting down a jammer to its left. After collecting the rightmost jammer, Uriel can return to pick up the jammer that he previously put down to end up with all 5 jammers simultaneously in his possession. |
|
</p> |
|
|
|
|
|
|