#P16857. [GKS 2021 #F] Trash Bins

[GKS 2021 #F] Trash Bins

Problem Description

In the city where you live, Kickstartland, there is 11 particularly long street with NN houses on it. This street has length NN, and the NN houses are evenly placed along it, that is, the 11st house is at position 11, the 22nd house is at position 22, and so on. The distance between any pair of houses ii and jj is ij|i-j|, where x|x| denotes the absolute value of xx.

Some of these houses have trash bins in front of them. That means that the owners of such houses do not have to walk when they want to take their trash out. However, for the owners of houses that do not have trash bins in front of them, they have to walk towards some house that has a trash bin in front of it, either to the left or to the right of their own house.

To save time, every house owner always takes their trash out to the trash bin that is closest to their houses. If there are 22 trash bins that are both the closest to a house, then the house owner can walk to any of them.

Given the number of houses NN, and the description of which of these houses have trash bins in front of them, find out what is the sum of the distances that each house owner has to walk to take their trashes out. You can assume that at least 11 house has a trash bin in front of it.

Input Format

The 11st line of the input gives the number of test cases, TT. TT test cases follow. Each test case consists of 22 lines.

The 11st line of each test case contains an integer NN, denoting the number of houses on the street.

The 22nd line of each test case contains a string SS of length NN, representing which houses have trash bins in front of them. If the ii-th character in string SS is equal to 11, then it means that the ii-th house has a trash bin in front of it. Otherwise, if it is equal to 00, then it means that the ii-th house does not have a trash bin in front of it.

Output Format

For each test case, output one line containing Case #xx: yy, where xx is the test case number (starting from 11) and yy is the sum of the distances that each house owner has to walk to take their trashes out.

2
3
111
6
100100
Case #1: 0
Case #2: 5

Hint

For the 11st test case, every house has a trash bin in front of it, and therefore none of the house owners will have to walk to take their trashes out.

For the 22nd test case, the 11st and the 44th house owners have trash bins in front of their houses, and therefore will not have to walk. The 22nd house owner will walk towards the 11st house, and the distance will be equal to 11. The 33rd, 55th, and 66th house owners will walk towards the 44th house, and the distances will be equal to 11, 11, and 22, respectively.

Limits

1T1001 \le T \le 100.

The length of SS is equal to NN.

Each character of SS is either 00 or 11.

There is at least one character 11 in SS.

Test Set 11

1N1001 \le N \le 100.

Test Set 22

1N5×1051 \le N \le 5 \times 10^5.