A - 花火の近さ

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 266 点

問題文

夏祭りの夜、高橋君と青木君はそれぞれ異なる場所から花火を眺めています。花火大会では N 発の花火が打ち上げられます。

i 発目の花火が開いた瞬間、高橋君は二次元平面上の座標 (X_i, Y_i) に、青木君は座標 (P_i, Q_i) にいます。花火ごとに二人の位置は異なる場合があります。

ある花火が開いた瞬間における高橋君と青木君のユークリッド距離が R 以下であるとき、その花火を「一緒に観た」と表現します。ここで、i 発目の花火における二人のユークリッド距離は \sqrt{(X_i - P_i)^2 + (Y_i - Q_i)^2} です。

N 発の花火のうち、二人が一緒に観た花火の数を求めてください。

制約

  • 1 \leq N \leq 10^5
  • 1 \leq R \leq 10^9
  • -10^9 \leq X_i, Y_i, P_i, Q_i \leq 10^9
  • 入力はすべて整数

入力

N R
X_1 Y_1 P_1 Q_1
X_2 Y_2 P_2 Q_2
\vdots
X_N Y_N P_N Q_N
  • 1 行目には、花火の数 N と、一緒に観たと判定する距離の閾値 R が、スペース区切りで与えられる。
  • 1 + i 行目 (1 \leq i \leq N) には、i 発目の花火が開いた瞬間の高橋君の座標 (X_i, Y_i) と青木君の座標 (P_i, Q_i) が、スペース区切りで与えられる。

出力

二人が一緒に観た花火の数を 1 行で出力してください。


入力例 1

3 5
0 0 3 4
0 0 6 0
1 1 1 1

出力例 1

2

入力例 2

2 1
0 0 10 10
5 5 0 0

出力例 2

0

入力例 3

6 10
0 0 3 4
0 0 8 6
0 0 11 0
5 5 5 5
-3 4 3 -4
100 100 0 0

出力例 3

4

入力例 4

10 1000000000
0 0 600000000 800000000
0 0 600000001 800000000
1000000000 1000000000 -1000000000 -1000000000
0 0 0 0
-500000000 -500000000 -500000000 -500000000
999999999 0 0 0
0 0 0 1000000000
100 200 300 400
-1000000000 0 1000000000 0
500000000 500000000 500000001 500000001

出力例 4

7

入力例 5

1 1
0 0 1 0

出力例 5

1

Score : 266 pts

Problem Statement

On the night of a summer festival, Takahashi and Aoki are watching fireworks from different locations. During the fireworks show, N fireworks are launched.

At the moment the i-th firework bursts, Takahashi is at coordinates (X_i, Y_i) and Aoki is at coordinates (P_i, Q_i) on a two-dimensional plane. Their positions may differ for each firework.

When the Euclidean distance between Takahashi and Aoki at the moment a firework bursts is at most R, we say they "watched it together." Here, the Euclidean distance between the two for the i-th firework is \sqrt{(X_i - P_i)^2 + (Y_i - Q_i)^2}.

Among the N fireworks, find the number of fireworks that the two watched together.

Constraints

  • 1 \leq N \leq 10^5
  • 1 \leq R \leq 10^9
  • -10^9 \leq X_i, Y_i, P_i, Q_i \leq 10^9
  • All inputs are integers

Input

N R
X_1 Y_1 P_1 Q_1
X_2 Y_2 P_2 Q_2
\vdots
X_N Y_N P_N Q_N
  • The first line contains the number of fireworks N and the distance threshold R for determining whether they watched together, separated by a space.
  • The (1 + i)-th line (1 \leq i \leq N) contains Takahashi's coordinates (X_i, Y_i) and Aoki's coordinates (P_i, Q_i) at the moment the i-th firework bursts, separated by spaces.

Output

Print the number of fireworks the two watched together in one line.


Sample Input 1

3 5
0 0 3 4
0 0 6 0
1 1 1 1

Sample Output 1

2

Sample Input 2

2 1
0 0 10 10
5 5 0 0

Sample Output 2

0

Sample Input 3

6 10
0 0 3 4
0 0 8 6
0 0 11 0
5 5 5 5
-3 4 3 -4
100 100 0 0

Sample Output 3

4

Sample Input 4

10 1000000000
0 0 600000000 800000000
0 0 600000001 800000000
1000000000 1000000000 -1000000000 -1000000000
0 0 0 0
-500000000 -500000000 -500000000 -500000000
999999999 0 0 0
0 0 0 1000000000
100 200 300 400
-1000000000 0 1000000000 0
500000000 500000000 500000001 500000001

Sample Output 4

7

Sample Input 5

1 1
0 0 1 0

Sample Output 5

1
B - 荷物の配送スケジュール

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 300 点

問題文

高橋君は配送センターで働くスタッフです。配送センターには N 件の届け先があり、それぞれ 1 から N の番号が付けられています。届け先 i には A_i 個の荷物を届ける必要があります。

高橋君は 1 日に 1 つの届け先のみを訪問し、その届け先に最大 K 個の荷物を届けることができます。1 日に届けきれない荷物がある場合は、別の日に同じ届け先を再度訪問して届けます。したがって、届け先 i への配送を完了するには \lceil A_i / K \rceil 日かかり、すべての届け先への配送を完了するために必要な日数は \sum_{i=1}^{N} \lceil A_i / K \rceil 日です。

青木君は配送センターの管理者であり、配送にかかる日数を少しでも短縮したいと考えています。そこで青木君は、配送を開始する前に、1 日あたりの配送能力を増やすことを検討しています。具体的には、青木君は 0 以上 M 以下の整数 x を 1 つ選び、1 日あたりの配送能力を K から K + x に変更することができます。この変更は配送開始前に一度だけ行い、配送中は変えることができません。なお x = 0 を選び、能力を変更しないことも可能です。

青木君が最適に x を選んだとき、高橋君がすべての荷物の配送を完了するために必要な最小の日数を求めてください。

すなわち、0 \le x \le M を満たす整数 x に対して全体の配送日数は

\sum_{i=1}^{N} \left\lceil \frac{A_i}{K + x} \right\rceil

となります。この値を最小にする x を選んだときの全体の配送日数を出力してください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq 10^9
  • 0 \leq M \leq 10^9
  • 1 \leq A_i \leq 10^9
  • 入力はすべて整数である。

入力

N K M
A_1 A_2 \ldots A_N
  • 1 行目には、届け先の数を表す整数 N、1 日あたりの配送可能個数を表す整数 K、配送能力を増やせる上限を表す整数 M が、スペース区切りで与えられる。
  • 2 行目には、各届け先への荷物の個数を表す整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。

出力

高橋君がすべての荷物の配送を完了するために必要な最小の日数を 1 行で出力せよ。


入力例 1

3 3 2
7 3 5

出力例 1

4

入力例 2

2 5 0
12 8

出力例 2

5

入力例 3

5 10 100
100 200 50 75 300

出力例 3

8

入力例 4

10 100 1000000000
1000000000 999999999 500000000 123456789 987654321 100000000 1 999999999 500000001 750000000

出力例 4

10

入力例 5

1 1 0
1

出力例 5

1

Score : 300 pts

Problem Statement

Takahashi is a staff member working at a delivery center. The delivery center has N destinations, each numbered from 1 to N. He needs to deliver A_i packages to destination i.

Takahashi can visit only one destination per day and deliver at most K packages to that destination. If there are packages that cannot be delivered in a single day, he visits the same destination again on another day to deliver them. Therefore, completing the delivery to destination i takes \lceil A_i / K \rceil days, and the total number of days required to complete deliveries to all destinations is \sum_{i=1}^{N} \lceil A_i / K \rceil days.

Aoki is the manager of the delivery center and wants to reduce the number of delivery days as much as possible. To this end, Aoki is considering increasing the daily delivery capacity before deliveries begin. Specifically, Aoki can choose an integer x with 0 \leq x \leq M and change the daily delivery capacity from K to K + x. This change is made only once before deliveries start and cannot be altered during the delivery process. Note that choosing x = 0, i.e., not changing the capacity, is also allowed.

Find the minimum number of days required for Takahashi to complete all deliveries when Aoki chooses x optimally.

In other words, for an integer x satisfying 0 \le x \le M, the total number of delivery days is

\sum_{i=1}^{N} \left\lceil \frac{A_i}{K + x} \right\rceil

Output the total number of delivery days when x is chosen to minimize this value.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq 10^9
  • 0 \leq M \leq 10^9
  • 1 \leq A_i \leq 10^9
  • All input values are integers.

Input

N K M
A_1 A_2 \ldots A_N
  • The first line contains three space-separated integers: N representing the number of destinations, K representing the number of packages that can be delivered per day, and M representing the upper limit of the capacity increase.
  • The second line contains N space-separated integers A_1, A_2, \ldots, A_N representing the number of packages for each destination.

Output

Output in a single line the minimum number of days required for Takahashi to complete all deliveries.


Sample Input 1

3 3 2
7 3 5

Sample Output 1

4

Sample Input 2

2 5 0
12 8

Sample Output 2

5

Sample Input 3

5 10 100
100 200 50 75 300

Sample Output 3

8

Sample Input 4

10 100 1000000000
1000000000 999999999 500000000 123456789 987654321 100000000 1 999999999 500000001 750000000

Sample Output 4

10

Sample Input 5

1 1 0
1

Sample Output 5

1
C - 山の見える展望台

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 366 点

問題文

高橋君は登山が趣味で、各地の展望台から見える山々の情報をまとめています。

ある山岳地帯には N 座の山があり、 i 番目の山は標高 Y_i メートル、その山の美しさの評価値は P_i です。

高橋君は Q 回の調査を行います。各調査では、基準となる標高 L_j が決められており、標高が L_j 以上であるすべての山の美しさの評価値の合計を求めたいと考えています。

各調査に対する答えを求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq Y_i \leq 10^9
  • 1 \leq P_i \leq 10^9
  • 1 \leq L_j \leq 10^9
  • 入力はすべて整数である

入力

N Q
Y_1 P_1
Y_2 P_2
:
Y_N P_N
L_1
L_2
:
L_Q
  • 1 行目には、山の数を表す N 、調査の回数を表す Q が、スペース区切りで与えられる。
  • 2 行目から N + 1 行目では、各山の情報が与えられる。
  • 1 + i 行目では、 i 番目の山の標高 Y_i と美しさの評価値 P_i が、スペース区切りで与えられる。
  • N + 2 行目から N + 1 + Q 行目では、各調査の基準標高が与えられる。
  • N + 1 + j 行目では、 j 番目の調査の基準標高 L_j が与えられる。

出力

Q 行にわたって、各調査の答えを出力せよ。 j 行目には、 j 番目の調査に対して、標高が L_j 以上であるすべての山の美しさの評価値の合計を出力せよ。該当する山が存在しない場合は 0 を出力せよ。


入力例 1

3 2
100 5
200 10
300 15
150
100

出力例 1

25
30

入力例 2

3 3
100 3
200 7
300 11
500
300
1

出力例 2

0
11
21

入力例 3

8 5
50 2
120 8
300 15
500 20
700 25
1000 30
1500 50
2000 100
600
1000
2000
2001
1

出力例 3

205
180
100
0
250

入力例 4

15 10
80 12
150 25
300 18
450 30
600 45
800 55
1200 60
1800 70
2500 85
3000 100
4000 120
5500 200
7000 150
8500 300
10000 500
1
500
1000
2000
3000
5000
7000
9000
10000
10001

出力例 4

1770
1685
1585
1455
1370
1150
950
500
500
0

入力例 5

1 1
1000000000 1000000000
1000000000

出力例 5

1000000000

Score : 366 pts

Problem Statement

Takahashi's hobby is mountain climbing, and he is compiling information about the mountains visible from observatories in various locations.

In a certain mountainous region, there are N mountains. The i-th mountain has an elevation of Y_i meters and a beauty rating of P_i.

Takahashi conducts Q surveys. In each survey, a reference elevation L_j is specified, and he wants to find the total beauty rating of all mountains whose elevation is at least L_j.

Find the answer for each survey.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq Y_i \leq 10^9
  • 1 \leq P_i \leq 10^9
  • 1 \leq L_j \leq 10^9
  • All input values are integers

Input

N Q
Y_1 P_1
Y_2 P_2
:
Y_N P_N
L_1
L_2
:
L_Q
  • The first line contains N, the number of mountains, and Q, the number of surveys, separated by a space.
  • From the 2nd line to the (N + 1)-th line, information about each mountain is given.
  • The (1 + i)-th line contains the elevation Y_i and the beauty rating P_i of the i-th mountain, separated by a space.
  • From the (N + 2)-th line to the (N + 1 + Q)-th line, the reference elevation for each survey is given.
  • The (N + 1 + j)-th line contains the reference elevation L_j for the j-th survey.

Output

Output Q lines, each containing the answer to the corresponding survey. On the j-th line, output the total beauty rating of all mountains whose elevation is at least L_j. If no such mountain exists, output 0.


Sample Input 1

3 2
100 5
200 10
300 15
150
100

Sample Output 1

25
30

Sample Input 2

3 3
100 3
200 7
300 11
500
300
1

Sample Output 2

0
11
21

Sample Input 3

8 5
50 2
120 8
300 15
500 20
700 25
1000 30
1500 50
2000 100
600
1000
2000
2001
1

Sample Output 3

205
180
100
0
250

Sample Input 4

15 10
80 12
150 25
300 18
450 30
600 45
800 55
1200 60
1800 70
2500 85
3000 100
4000 120
5500 200
7000 150
8500 300
10000 500
1
500
1000
2000
3000
5000
7000
9000
10000
10001

Sample Output 4

1770
1685
1585
1455
1370
1150
950
500
500
0

Sample Input 5

1 1
1000000000 1000000000
1000000000

Sample Output 5

1000000000
D - アルバイトのシフト割り当て

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 400 点

問題文

高橋君は、アルバイト N 人を抱える店舗の店長です。今度の休日に M 個の業務をこなす必要があり、各業務にちょうど 1 人のアルバイトを割り当てなければなりません。

アルバイトにはそれぞれ 1 から N までの番号が付けられており、アルバイト i のスキル値は A_i です。また、業務にはそれぞれ 1 から M までの番号が付けられており、業務 j の要求スキル値は D_j です。

アルバイト i が業務 j を担当した場合、その満足度は A_i - D_j で計算されます。満足度が負になるとそのアルバイトは不満を感じてしまうため、高橋君はすべての担当者の満足度が 0 以上(すなわち不満を感じない状態)となるように割り当てたいと考えています。

具体的には、N 人のアルバイトの中から M 人を選び、選んだ M 人と M 個の業務を一対一に対応させて割り当てます。すなわち、業務 j の担当者を f(j) と表したとき、以下の条件をすべて満たす割り当て f を考えます。

  • すべての業務 j (1 \leq j \leq M) にちょうど 1 人のアルバイトが担当者として割り当てられている。
  • 異なる業務には異なるアルバイトが割り当てられている。すなわち、j \neq j' ならば f(j) \neq f(j') である。(業務を担当しないアルバイトがいてもよい。)
  • 業務を担当するすべてのアルバイトについて、満足度が 0 以上である。すなわち、すべての業務 j (1 \leq j \leq M) に対して A_{f(j)} \geq D_j が成り立つ。

このような条件を満たす割り当てが存在する場合、担当者 M 人の満足度の合計 \displaystyle\sum_{j=1}^{M}(A_{f(j)} - D_j) の最大値を求めてください。条件を満たす割り当てが存在しない場合は -1 を出力してください。

制約

  • 1 \leq M \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq D_j \leq 10^9 (1 \leq j \leq M)
  • 入力はすべて整数である。

入力

N M
A_1 A_2 \ldots A_N
D_1 D_2 \ldots D_M
  • 1 行目には、アルバイトの人数を表す整数 N と、業務の個数を表す整数 M が、スペース区切りで与えられる。
  • 2 行目には、各アルバイトのスキル値を表す整数 A_1, A_2, \ldots, A_N が、スペース区切りで与えられる。
  • 3 行目には、各業務の要求スキル値を表す整数 D_1, D_2, \ldots, D_M が、スペース区切りで与えられる。

出力

条件を満たす割り当てが存在する場合は、満足度の合計の最大値を整数で 1 行に出力せよ。存在しない場合は -1 を 1 行に出力せよ。


入力例 1

4 3
5 3 7 1
2 4 6

出力例 1

3

入力例 2

3 3
1 2 3
4 5 6

出力例 2

-1

入力例 3

7 5
10 25 8 30 15 5 20
3 12 7 18 25

出力例 3

35

Score : 400 pts

Problem Statement

Takahashi is the manager of a store with N part-time workers. He needs to complete M tasks on an upcoming holiday, and must assign exactly 1 part-time worker to each task.

The part-time workers are numbered from 1 to N, and the skill level of worker i is A_i. The tasks are numbered from 1 to M, and the required skill level of task j is D_j.

When worker i is assigned to task j, their satisfaction is calculated as A_i - D_j. Since a worker becomes dissatisfied if their satisfaction is negative, Takahashi wants to make an assignment such that every assigned worker's satisfaction is 0 or more (i.e., no one is dissatisfied).

Specifically, he selects M workers out of the N part-time workers and assigns the selected M workers to the M tasks in a one-to-one correspondence. That is, letting f(j) denote the worker assigned to task j, he considers an assignment f that satisfies all of the following conditions:

  • Exactly 1 part-time worker is assigned to each task j (1 \leq j \leq M).
  • Different tasks are assigned different workers. That is, if j \neq j', then f(j) \neq f(j'). (Some workers may not be assigned to any task.)
  • For every worker assigned to a task, their satisfaction is 0 or more. That is, for every task j (1 \leq j \leq M), A_{f(j)} \geq D_j holds.

If an assignment satisfying these conditions exists, find the maximum value of the total satisfaction of the M assigned workers, \displaystyle\sum_{j=1}^{M}(A_{f(j)} - D_j). If no valid assignment exists, output -1.

Constraints

  • 1 \leq M \leq N \leq 2 \times 10^5
  • 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq D_j \leq 10^9 (1 \leq j \leq M)
  • All input values are integers.

Input

N M
A_1 A_2 \ldots A_N
D_1 D_2 \ldots D_M
  • The first line contains an integer N representing the number of part-time workers and an integer M representing the number of tasks, separated by a space.
  • The second line contains integers A_1, A_2, \ldots, A_N representing the skill levels of each worker, separated by spaces.
  • The third line contains integers D_1, D_2, \ldots, D_M representing the required skill levels of each task, separated by spaces.

Output

If a valid assignment exists, output the maximum value of the total satisfaction as an integer on a single line. If no valid assignment exists, output -1 on a single line.


Sample Input 1

4 3
5 3 7 1
2 4 6

Sample Output 1

3

Sample Input 2

3 3
1 2 3
4 5 6

Sample Output 2

-1

Sample Input 3

7 5
10 25 8 30 15 5 20
3 12 7 18 25

Sample Output 3

35
E - 倍数ボーナス

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 466 点

問題文

高橋君は N 人の社員を管理する部門長です。各社員には 1 から N までの社員番号が付けられており、社員 i の初期評価ポイントは S_i です。

社員 i の現在の評価ポイントを T_i とします。はじめ、T_i = S_i(1 \leq i \leq N)です。

この会社には独特の評価制度があります。ある社員 k(1 \leq k \leq N)がチームリーダーとして成果を上げると、社員番号が k の倍数(k, 2k, 3k, \ldots)であり N 以下であるすべての社員の評価ポイントに、成果に応じたボーナスポイントが加算されます。k 自身も k の倍数であるため、対象に含まれます。

高橋君はこの評価システムに対して Q 回の操作を行います。各操作は以下の 2 種類のいずれかです。

  • 操作 1:正の整数 k(1 \leq k \leq N)と正の整数 v が与えられる。社員番号が k の倍数であり N 以下であるすべての社員 j(すなわち j = k, 2k, 3k, \ldots かつ j \leq N)の評価ポイント T_j に v を加算する。
  • 操作 2:正の整数 x(1 \leq x \leq N)が与えられる。社員 1 から社員 x までの現在の評価ポイントの合計値 \displaystyle\sum_{i=1}^{x} T_i を出力する。

すべての操作 2 に対して、正しい答えを出力してください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq 10^5
  • 1 \leq S_i \leq 10^9
  • 操作 1 において、1 \leq k \leq N
  • 操作 1 において、1 \leq v \leq 10^9
  • 操作 2 において、1 \leq x \leq N
  • 操作 2 は 1 回以上与えられる
  • 入力はすべて整数である
  • 出力すべき値は 2^{63} - 1 以下であることが保証される(符号付き 64 ビット整数に収まる)

入力

N Q
S_1 S_2 \ldots S_N
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q
  • 1 行目には、社員の数 N と操作の回数 Q がスペース区切りで与えられる。
  • 2 行目には、各社員の初期評価ポイント S_1, S_2, \ldots, S_N がスペース区切りで与えられる。
  • 続く Q 行にわたって、各操作が 1 行ずつ与えられる。
  • 操作 1 の場合:1 k v の形式で与えられる。
  • 操作 2 の場合:2 x の形式で与えられる。

出力

操作 2 が与えられるたびに、社員 1 から社員 x までの評価ポイントの合計値を 1 行に出力せよ。


入力例 1

5 6
1 2 3 4 5
2 3
1 2 10
2 5
1 1 1
2 1
2 4

出力例 1

6
35
2
34

入力例 2

4 7
5 1 4 2
1 4 7
2 4
1 3 2
2 2
1 1 5
2 3
2 1

出力例 2

19
6
27
10

入力例 3

12 10
3 1 4 1 5 9 2 6 5 3 5 8
2 6
1 3 4
2 12
1 5 7
2 10
1 2 1
1 12 100
2 12
2 1
2 11

出力例 3

23
68
65
188
3
75

入力例 4

20 14
10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200
2 20
1 4 25
1 6 10
2 12
1 1 3
2 5
1 10 100
2 20
1 7 8
1 20 50
2 19
2 20
1 3 6
2 18

出力例 4

2100
875
190
2515
2203
2581
2046

入力例 5

1 4
1000000000
2 1
1 1 1000000000
2 1
2 1

出力例 5

1000000000
2000000000
2000000000

Score : 466 pts

Problem Statement

Takahashi is a department manager who manages N employees. Each employee is assigned an employee number from 1 to N, and the initial evaluation points of employee i are S_i.

Let T_i denote the current evaluation points of employee i. Initially, T_i = S_i (1 \leq i \leq N).

This company has a unique evaluation system. When a certain employee k (1 \leq k \leq N) achieves results as a team leader, bonus points corresponding to the achievement are added to the evaluation points of all employees whose employee numbers are multiples of k (k, 2k, 3k, \ldots) and are at most N. Since k itself is a multiple of k, it is included in the targets.

Takahashi performs Q operations on this evaluation system. Each operation is one of the following two types:

  • Operation 1: Given a positive integer k (1 \leq k \leq N) and a positive integer v. Add v to the evaluation points T_j of all employees j whose employee numbers are multiples of k and are at most N (i.e., j = k, 2k, 3k, \ldots and j \leq N).
  • Operation 2: Given a positive integer x (1 \leq x \leq N). Output the sum of the current evaluation points from employee 1 to employee x: \displaystyle\sum_{i=1}^{x} T_i.

For all operations of type 2, output the correct answer.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq 10^5
  • 1 \leq S_i \leq 10^9
  • In operation 1, 1 \leq k \leq N
  • In operation 1, 1 \leq v \leq 10^9
  • In operation 2, 1 \leq x \leq N
  • Operation 2 is given at least once
  • All input values are integers
  • It is guaranteed that the values to be output are at most 2^{63} - 1 (they fit in a signed 64-bit integer)

Input

N Q
S_1 S_2 \ldots S_N
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q
  • The first line contains the number of employees N and the number of operations Q, separated by a space.
  • The second line contains the initial evaluation points S_1, S_2, \ldots, S_N of each employee, separated by spaces.
  • The following Q lines each contain one operation.
  • For operation 1: given in the format 1 k v.
  • For operation 2: given in the format 2 x.

Output

Each time operation 2 is given, output the sum of evaluation points from employee 1 to employee x on one line.


Sample Input 1

5 6
1 2 3 4 5
2 3
1 2 10
2 5
1 1 1
2 1
2 4

Sample Output 1

6
35
2
34

Sample Input 2

4 7
5 1 4 2
1 4 7
2 4
1 3 2
2 2
1 1 5
2 3
2 1

Sample Output 2

19
6
27
10

Sample Input 3

12 10
3 1 4 1 5 9 2 6 5 3 5 8
2 6
1 3 4
2 12
1 5 7
2 10
1 2 1
1 12 100
2 12
2 1
2 11

Sample Output 3

23
68
65
188
3
75

Sample Input 4

20 14
10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200
2 20
1 4 25
1 6 10
2 12
1 1 3
2 5
1 10 100
2 20
1 7 8
1 20 50
2 19
2 20
1 3 6
2 18

Sample Output 4

2100
875
190
2515
2203
2581
2046

Sample Input 5

1 4
1000000000
2 1
1 1 1000000000
2 1
2 1

Sample Output 5

1000000000
2000000000
2000000000