codeforces#P1371F. Raging Thunder
Raging Thunder
Description
You are a warrior fighting against the machine god Thor.
Thor challenge you to solve the following problem:
There are conveyors arranged in a line numbered with integers from to from left to right. Each conveyor has a symbol "<" or ">". The initial state of the conveyor is equal to the -th character of the string . There are holes numbered with integers from to . The hole is on the left side of the conveyor , and for all the hole is on the right side of the conveyor .
When a ball is on the conveyor , the ball moves by the next rules:
If the symbol "<" is on the conveyor , then:
- If , the ball falls into the hole .
- If the symbol "<" is on the conveyor , the ball moves to the conveyor .
- If the symbol ">" is on the conveyor , the ball falls into the hole .
If the symbol ">" is on the conveyor , then:
- If , the ball falls into the hole .
- If the symbol ">" is on the conveyor , the ball moves to the conveyor .
- If the symbol "<" is on the conveyor , the ball falls into the hole .
You should answer next queries, each query is defined by the pair of integers ():
- First, for all conveyors , the symbol "<" changes to ">" and vice versa. These changes remain for the next queries.
- After that, put one ball on each conveyor . Then, each ball falls into some hole. Find the maximum number of balls in one hole. After the query all balls disappear and don't considered in the next queries.
The first line contains two integers , ().
The second line contains a string of length . It consists of characters "<" and ">".
Next lines contain the descriptions of the queries, -th of them contains two integers , , describing the -th query.
Print lines, in the -th of them print the answer to the -th query.
Input
The first line contains two integers , ().
The second line contains a string of length . It consists of characters "<" and ">".
Next lines contain the descriptions of the queries, -th of them contains two integers , , describing the -th query.
Output
Print lines, in the -th of them print the answer to the -th query.
Samples
Note
- In the first query, the conveyors change to ">><<<". After that, put a ball on each conveyor . All three balls fall into the hole . So the answer is .
- In the second query, the conveyors change to ">>>>>". After that, put a ball on each conveyor . All three balls fall into the hole . So the answer is .
- In the third query, the conveyors change to "<<<<<". After that, put a ball on each conveyor . All five balls fall into the hole . So the answer is .
- In the fourth query, the conveyors change to ">>><<". After that, put a ball on each conveyor . All three balls fall into the hole . So the answer is .
- In the fifth query, the conveyors change to "><<><". After that, put a ball on each conveyor . Two balls fall into the hole , and one ball falls into the hole . So, the answer is .
- In the sixth query, the conveyors change to "<>><>". After that, put a ball on each conveyor . Three balls fall into the hole , one ball falls into the hole and one ball falls into the hole . So, the answer is .