Vadim is a very talented and passionate young man about computer science. Filled with the Christmas spirit, he decides to spend his winter vacation participating in as many contests as possible on his favorite platform, . There, the scoring system is a bit different. If the contest has problems, with the -th problem worth points, then when he solves problem , points are added to his total score, and points are subtracted from the scores of the unsolved problems. The platform rules allow for there to be problems with negative scores at any given time (which Vadim will need to solve).
Task
Vadim receives problems, knowing the values and for each. Over the next days, he chooses an interval and wonders what the maximum score he can achieve is if he participates in a contest consisting of problems . Help Vadim answer these questions, or else you will end up on Santa's naughty list.
Input data
The first line contains and . The next 2 lines will each contain values ( and ), and the last lines contain the questions posed by Vadim.
Output data
Each of the next lines will contain the answers to Vadim's questions.
Constraints and clarifications
- This link might be helpful in solving the problem.
- The values in array are pairwise distinct!!
# | Points | Constraints |
---|---|---|
1 | 11 | |
2 | 9 | |
3 | 12 | |
4 | 10 | For each question, the optimal order in which Vadim solves the problems is given, in other words, starting from problem and ending with . |
5 | 20 | |
6 | 38 | No additional constraints |
Example 1
stdin
4 3
12 5 4 10
6 7 1 2
1 3
2 4
3 4
stdout
13
15
13
Example 2
stdin
5 5
2 4 6 5 9
4 9 5 2 8
2 5
1 2
2 3
2 2
3 3
stdout
0
2
5