시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.2 초 1024 MB958612.245%

문제

A group of n bunnies found a garden with n carrots, arranged in a row. Both the bunnies and the carrots are numbered with integers from 1 to n. The bunnies have made preliminary evaluation for the sweetness of the carrots, which are expressed with the integers a1, ..., an (some carrots may be spoiled and can have negative number for sweetness). The soil under only one carrot p is fertilized and this changes the sweetness of this carrot by an integer s. More precisely, the real sweetness of carrot p is ap + s.

Unfortunately, p and s are unknown to rabbits. However, they have massumptions about the pair of values (p, s).

Bunny number k makes jumps of length k, i.e. collects the carrots in positions that are multiples of k.

For each assumption j, they look for the maximum amount tj of the total real sweetness of the carrots that can be collected by a bunny. Help them by writing program maxs that finds the sum of the values of tj for all assumptions.

입력

From the first line of the standard input, your program reads an integer n - the number of carrots (and bunnies). From the next line read n integers a1, ..., an - the preliminary evaluation of the sweetness of the carrots. From the next line read an integer m-the number of assumptions. From each of the next mlines, read two integers p and s – carrot's index and its’ sweetness change for the corresponding assumption.

출력

On one line of the standard output, print a number equal to t1 + ... + tm, where tj is the maximum sum of carrots' sweetness under the j-th assumption.

제한

  • 1 ≤ n ≤ 5×104
  • 1 ≤ m ≤ 5×105
  • −108 ≤ ai ≤ 108
  • 1 ≤ p ≤ n for each carrot's index p
  • −1013 ≤ s ≤ 1013 for any change in sweetness s

서브태스크

번호배점제한
113

n ≤ 5×103, m ≤ 5×103

221

n ≤ 1.5×104, m ≤ 3.5×103

325

n ≤ 5×104, m ≤ 2×105, Only non-negative changes in any sweetness s.

430

n ≤ 5×104, m ≤ 2×105

511

n ≤ 5×104, m ≤ 5×105

예제 입력 1

6
2 -5 3 2 -1 4
2
3 -4
2 3

예제 출력 1

12

힌트

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.

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.