#K69937. Max Unique Characters Collection

    ID: 33197 Type: Default 1000ms 256MiB

Max Unique Characters Collection

Max Unique Characters Collection

Polycarp is playing with a circular string and he collects characters as he moves along the circle. He starts at any index, and while traversing the string in a circular manner, he collects a character the first time he sees it. However, if he revisits a character that he has already collected, he is allowed to skip exactly one such duplicate occurrence. If he encounters a second duplicate in a row (without collecting a new character in between), he must stop collecting. Your task is to determine the maximum number of unique characters Polycarp can collect by choosing the optimal starting position.

Formally, for a given string (s) of length (n) (considered circularly), for each starting index (i), simulate the process:
[ \text{Let } visited = \emptyset, \ count = 0, \ skip = 0, \ j = i. ]
Then, while true, if (s[j]) is not in (visited), add it and reset (skip) to zero. Otherwise, increment (skip) by one. If (skip > 1) break the process. Continue with (j = (j+1) \mod n), stopping if (j = i).
The answer is the maximum count among all possible starting indices.

inputFormat

The input is read from standard input. The first line contains an integer (T), denoting the number of test cases. Each of the following (T) lines contains a non-empty string (s) consisting of lowercase English letters representing the circular string.

outputFormat

For each test case, output a single line containing one integer: the maximum number of unique characters that Polycarp can collect.## sample

1
abcde
5

</p>