Inaho is a scientist. He discovered the fourth dimension recently. In fact, he also discovered the fifth, the sixth, the seventh, the eighth, the ninth, and the tenth dimension! Today, as he was travelling on the infinite plane of uniform density, he fell into an
Fortunately, he knows the way out is the direction with the least density. However, the densities are constantly changing, so he needs to react quickly. Inaho does not know the initial densities, but in a desperate attempt to escape, he assumes them to be
He will tell you
Input Specification
The first line will contain two space-separated integers
The second line will contain
The next
, which represents a change at position to . , which represents summing the total density between and inclusive.
Subtasks
For 2 of the 25 available marks,
For an additional 2 of the 25 available marks,
For an additional 2 of the 25 available marks,
For an additional 2 of the 25 available marks,
NOTE: This problem is practically impossible to solve with Python (even with PyPy). To allow a correct Python solution to pass would require a time limit of 30 seconds, which is unrealistic. It is recommended to use C++.
Output Specification
For each summation statement, output the answer on a separate line.
Sample Input 1
2 7
5 5
1 1 1 2
2 1 1 1 1
1 2 4 12
1 1 1 3
1 5 5 6
2 1 1 4 4
2 2 3 5 5
Sample Output 1
2
15
18
Sample Input 2
10 9
3 3 3 3 3 3 3 3 3 5
1 1 1 1 1 1 1 1 1 2 1 13
1 3 3 3 3 3 3 3 3 3 5 19
1 1 1 3 2 2 2 2 2 2 2 3
2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1 1 24
2 1 1 1 1 1 1 1 1 2 1 3 3 3 3 3 3 3 3 3 5
2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 5
1 1 1 1 1 1 1 1 1 2 1 12
2 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3
Sample Output 2
13
35
19
39
Comments