401927: GYM100584 D Balanced strings
Description
We call a string balanced if all its characters (those which occur in it at least once) occur in it an equal number of times. For example, aaaaa, badcx, bbaaab are balanced strings. However, abacb isn't a balanced string.
Given a string, find its longest (continuous) balanced substring.
The substring we're looking for doesn't have to contain all characters which occur in the original string. For example, the correct answer for cbababac is the substring bababa.
InputThe input consists of a single string of lowercase letters of English alphabet. The string has length N and the characters are indexed from 0 to N - 1.
OutputPrint a single line containing two space-separated integers: indices of the character by which the substring we're looking for starts and the one by which it ends. If there are multiple optimal solutions, find the one that starts the earliest.
ExamplesInputbaabOutput
0 3Input
baaabOutput
1 3Input
cbababacOutput
1 6Input
cbabadbabaeOutput
1 4Note
There are 10 sets of tests, in which the following restrictions hold:
Set(s) no. | Length of input | Set of letters used |
1 | 1 ≤ N ≤ 20 | [ab] |
2 | 1 ≤ N ≤ 1000 | [ab] |
3-4 | 1 ≤ N ≤ 1000 | [abcdefgh] |
5 | 1 ≤ N ≤ 105 | [ab] |
6 | 1 ≤ N ≤ 105 | [abc] (the optimal solution doesn't use all three) |
7 | 1 ≤ N ≤ 105 | [abc] |
8-10 | 1 ≤ N ≤ 5·104 | [abcde] |