TopCoder

User's AC Ratio

NaN% (0/0)

Submission's AC Ratio

NaN% (0/0)

Tags

Description

Wind's birthday is approaching. In order to buy a really really fantastic gift for her, Jiajia has to take a boring yet money-making job - a text checker.



This job is very humdrum. Jiajia will be given a string of text what is English letters and he must count the maximum number of letters that can be matched, starting from two position of the current text simultanously. The matching proceeds from left to right, one character by one.



Even worse, sometimes the boss will insert some characters before, after or within the text. Jiajia wants to write a program to do his job automatically, this program should be fast enough, because there are only few days to Wind's birthday.

Input Format

There are multiple test cases in the input file. For each test case:


The first line of input file contains initial text.



The second line contains then number of commands n. And the following n lines describe each command. There are two formats of commands:



I ch p: Insert a character ch before the p-th. if p is larger than the current length of text, then insert at end of the text.



Q i j: Ask the length of matching started from the i-th and j-th character of the initial text, which doesn't include the inserted characters.



You can assume that the length of initial text will not exceed 50000, the number of I command will not exceed 200, the number of Q command will not exceed 20000.

Output Format

Print one line for each Q command, contain the max length of matching.

Sample Input 1

abaab
5
Q 1 2
Q 1 3
I a 2
Q 1 2
Q 1 3
abaab
5
Q 1 2
Q 1 3
I a 2
Q 1 2
Q 1 3

Sample Output 1

0
1
0
3
0
1
0
3

Hints

Problem Source

Migrated from old NTUJ.

POJ 2758

Subtasks

No. Testdata Range Score

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 10000 65536 2000