After several weeks of training, you've finally managed to increase your typing speed to a staggering 40 WPM. Accordingly, you've also found another modified version of TypeRacer to intensify your training. In this game, you start off with a string
To do this, you are provided with an empty screen at the start of the round. In one keystroke, you may add a lowercase character to the end of the current string on the screen, or you may press enter to submit the current string on the screen, simultaneously clearing the screen of all characters. The round is completed when you have submitted every distinct non-empty substring of the substring of
Of course, the game wants you to complete the rounds in the order which they are given (supposedly there is extra merit in doing so), so you will not be given the parameters
Constraints
Subtask 1 [5%]
Subtask 2 [15%]
Subtask 3 [30%]
All characters of
Subtask 4 [50%]
No additional constraints.
Input Specification
The first line contains the string
The second line contains the integer
The next
Output Specification
Output
Sample Input
araaraoneesan
5
4 6
6 5
29 26
61 50
31 19
Sample Input (Unencrypted)
araaraoneesan
5
4 6
8 11
1 6
6 9
1 13
Sample Output
14
28
59
30
522
Explanation
For your convenience, an unencrypted version of the sample input is provided above.
The first round is played on the substring of ara
. One possible strategy is as follows:
- Type
a
and press enter to submit in keystrokes. - Type
ra
and press enter to submit in keystrokes. - Type
ara
and press enter to submit in keystrokes. - Type
r
and press enter to submit in keystrokes. - Type
ar
and press enter to submit in keystrokes.
Thus, this round was completed with a
twice, since every distinct substring only needs to be submitted once.
Comments