##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
| # | Title | Points | Solved | Admin | |
|---|---|---|---|---|---|
You are given an array of length , indexed from to . Every element of the array is either or . The array is represented by a string , where is + if , and - if .
An experiment can start at any position . Before every experiment, the array is restored to its initial state.
In the -th experiment, Mammali starts at position . While he is inside the array, suppose that his current position is and let . He performs the following actions:
In other words, the move uses the value of the position before its sign is reversed.
If Mammali reaches position , he exits from the left. If he reaches position , he exits from the right.
You are given queries. In the -th query, Mammali separately performs one experiment from every starting position such that . Determine how many of these experiments end with Mammali exiting from the left.
Queries do not change the array, and every experiment is independent of all other experiments.
+ or -The first line contains two integers and .
The second line contains the string .
Each of the next lines contains two integers and , describing a query.
Starting from position , the states after successive moves are:
Thus, Mammali exits from the left.
Starting from position , the states after successive moves are:
Thus, Mammali exits from the right. The other two experiments can be followed in the same way.
In fact, starts and exit left, while starts and exit right. Therefore, the four query answers are , , , and .
Starting from position , the states after successive moves are:
Thus, Mammali exits from the left.
Starting from position , the states after successive moves are:
Thus, Mammali exits from the right. The other experiments can be followed in the same way.
The experiments starting at positions , , and exit left. The experiments starting at positions and exit right. Hence, all five positions contain three left exits, positions through contain two, and positions through contain none.