A group of bunnies found a garden with carrots, arranged in a row. Both the bunnies and the carrots are numbered with integers from to . The bunnies have made preliminary evaluation for the sweetness of the carrots, which are expressed with the integers (some carrots may be spoiled and can have negative number for sweetness). The soil under only one carrot is fertilized and this changes the sweetness of this carrot by an integer . More precisely, the real sweetness of carrot is .
Unfortunately, and are unknown to rabbits. However, they have assumptions about the pair of values .
Bunny number makes jumps of length , i.e. collects the carrots in positions that are multiples of .
For each assumption , they look for the maximum amount of the total real sweetness of the carrots that can be collected by a bunny. Help them by writing program that finds the sum of the values of for all assumptions.
Input
From the first line of the standard input, your program reads an integer - the number of carrots (and bunnies). From the next line read integers - the preliminary evaluation of the sweetness of the carrots. From the next line read an integer - the number of assumptions. From each of the next lines, read two integers and - carrot's index and its' sweetness change for the corresponding assumption.
Output
On one line of the standard output, print a number equal to , where is the maximum sum of carrots' sweetness under the -th assumption.
Constraints
- for each carrot's index
- for any change in sweetness
Subtask 1 (0 points)
- Sample test
Subtask 2 (13 points)
Subtask 3 (21 points)
Subtask 4 (25 points)
- Only non-negative changes in any sweetness .
Subtask 5 (30 points)
Subtask 6 (11 points)
- No additional constraints
Example
stdin
6
2 -5 3 2 -1 4
2
3 -4
2 3
stdout
12
Explanation
According to the first assumption, carrots have sweetness 2, -5, -1, 2, -1, 4.
Bunny 1 collects total sweetness 2 + (-5) + (-1) + 2 + (-1) + 4 = 1.
Bunny 2 collects total sweetness (-5) + 2 + 4 = 1.
Bunny 3 collects total sweetness (-1) + 4 = 3.
Bunny 4 collects total sweetness 2.
Bunny 5 collects total sweetness of -1.
Bunny 6 collects total sweetness 4.
Therefore t1 = 4.
According to the second assumption, carrots have sweetness 2, -2, 3, 2, -1, 4.
Bunnies collect sweetness 8, 4, 7, 2, -1, 4, respectively.
Therefore t2 = 8.
The final answer is 4 + 8 = 12.