A - 温度センサーの点検

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

配点 : 233

問題文

高橋君は工場に設置された温度センサーの点検を担当しています。工場には N 個の温度センサーが一列に並んでおり、それぞれのセンサーには 1 から N までの番号が、並んでいる順に付けられています。番号が 1 だけ異なるセンサー同士が互いに隣接しています。

i 番目のセンサーが計測した温度は A_i です。

点検では、各センサーについて「局所温度指標」M_i を計算します。センサー i の局所温度指標 M_i は、センサー i 自身とそれに隣接するすべてのセンサーの計測値の合計であり、以下のように定義されます:

  • 2 \leq i \leq N-1 のとき: M_i = A_{i-1} + A_i + A_{i+1}
  • i = 1 のとき: M_1 = A_1 + A_2
  • i = N のとき: M_N = A_{N-1} + A_N

なお、N = 2 のときは 2 番目の条件に該当するセンサーはなく、1 番目と 3 番目の条件のみが適用されます。

高橋君は、すべてのセンサーの局所温度指標の中で最大のものを報告する必要があります。

N 個のセンサーの計測値が与えられたとき、局所温度指標の最大値 \displaystyle \max_{1 \leq i \leq N} M_i を求めてください。

制約

  • 2 \leq N \leq 2 \times 10^5
  • -10^9 \leq A_i \leq 10^9
  • 入力はすべて整数

入力

N
A_1 A_2 \ldots A_N
  • 1 行目には、センサーの個数を表す整数 N が与えられる。
  • 2 行目には、各センサーの計測値を表す N 個の整数 A_1, A_2, \ldots, A_N が空白区切りで与えられる。

出力

局所温度指標の最大値を 1 行に出力せよ。


入力例 1

5
3 1 4 1 5

出力例 1

10

入力例 2

2
100 -50

出力例 2

50

入力例 3

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

出力例 3

50

Score : 233 pts

Problem Statement

Takahashi is in charge of inspecting temperature sensors installed in a factory. The factory has N temperature sensors arranged in a row, and each sensor is numbered from 1 to N in the order they are arranged. Sensors whose numbers differ by exactly 1 are adjacent to each other.

The temperature measured by the i-th sensor is A_i.

During the inspection, a "local temperature index" M_i is calculated for each sensor. The local temperature index M_i of sensor i is the sum of the measurements of sensor i itself and all sensors adjacent to it, defined as follows:

  • When 2 \leq i \leq N-1: M_i = A_{i-1} + A_i + A_{i+1}
  • When i = 1: M_1 = A_1 + A_2
  • When i = N: M_N = A_{N-1} + A_N

Note that when N = 2, no sensor falls under the second condition, and only the first and third conditions apply.

Takahashi needs to report the maximum value among the local temperature indices of all sensors.

Given the measurements of N sensors, find the maximum value of the local temperature indices \displaystyle \max_{1 \leq i \leq N} M_i.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • -10^9 \leq A_i \leq 10^9
  • All inputs are integers

Input

N
A_1 A_2 \ldots A_N
  • The first line contains an integer N representing the number of sensors.
  • The second line contains N integers A_1, A_2, \ldots, A_N separated by spaces, representing the measurements of each sensor.

Output

Print the maximum value of the local temperature indices on a single line.


Sample Input 1

5
3 1 4 1 5

Sample Output 1

10

Sample Input 2

2
100 -50

Sample Output 2

50

Sample Input 3

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

Sample Output 3

50
B - シャンパンタワー

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

配点 : 333

問題文

高橋君は、パーティーの準備としてシャンパンタワーを作ることになりました。シャンパンタワーといっても、今回は N 個のグラスを上から下へ一列に並べたシンプルな構造です。上から順に 1 段目、2 段目、\ldotsN 段目とします。

上から i 段目のグラスの容量は C_i ミリリットルです。

最初、すべてのグラスは空です。高橋君は Q 回の操作を順番に行います。各操作は以下の 2 種類のいずれかです:

  • 操作 1(注ぐ)1 段目のグラスに V ミリリットルのシャンパンを注ぐ。注がれたシャンパンは 1 段目のグラスの現在のシャンパン量に加えられる。その結果、i 段目(1 \leq i \leq N-1)のグラスに入っているシャンパンの量が容量 C_i を超えている(容量より真に大きい)場合、超過分はすべて即座に i + 1 段目のグラスに流れ落ちる。この判定は 1 段目から順に各段について連鎖的に行われ、すべての段の処理が瞬時に完了する。最下段(N 段目)のグラスから溢れたシャンパンは失われ、どこにも溜まらない。操作完了時には各グラスのシャンパン量が容量以下に確定している。
  • 操作 2(問い合わせ)k 段目のグラスに現在入っているシャンパンの量(ミリリットル)を出力する。

各操作 2 に対して、答えを出力してください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq C_i \leq 10^91 \leq i \leq N
  • 操作 1 において、1 \leq V \leq 10^9
  • 操作 2 において、1 \leq k \leq N
  • 操作 21 回以上与えられる
  • 入力はすべて整数である

入力

N Q
C_1 C_2 \ldots C_N
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
  • 1 行目には、グラスの段数を表す整数 N と、操作の回数を表す整数 Q が、スペース区切りで与えられる。
  • 2 行目には、上から i 段目のグラスの容量を表す整数 C_1, C_2, \ldots, C_N が、スペース区切りで与えられる。
  • 続く Q 行にわたって、各操作が 1 行ずつ与えられる。
  • 操作 1 の場合:1 V と与えられる。1 段目のグラスに V ミリリットルのシャンパンを注ぐことを意味する。V は正の整数である。
  • 操作 2 の場合:2 k と与えられる。k 段目のグラスに現在入っているシャンパンの量を問い合わせることを意味する。k1 以上 N 以下の整数である。

出力

操作 2 が与えられるたびに、指定された k 段目のグラスに現在入っているシャンパンの量(ミリリットル)を 1 行に 1 つずつ出力せよ。なお、入力がすべて整数であることから、答えは必ず整数となる。


入力例 1

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

出力例 1

0
4
5
2
0

入力例 2

4 8
2 2 2 2
1 1
2 1
1 10
2 1
2 2
2 3
2 4
2 4

出力例 2

1
2
2
2
2
2

入力例 3

8 15
3 7 2 10 5 1 8 6
2 5
1 4
2 1
2 2
1 20
2 1
2 2
2 3
2 4
1 6
2 4
2 5
1 15
2 7
2 8

出力例 3

0
3
1
3
7
2
10
10
5
8
6

入力例 4

25 40
100 1 50 200 3 400 5 600 7 800 9 1000 11 1200 13 1400 15 1600 17 1800 19 2000 21 2200 23
1 75
2 1
2 2
1 1000
2 1
2 3
2 4
1 5000
2 5
2 8
2 10
1 12345
2 12
2 15
2 20
1 999999999
2 1
2 2
2 3
2 10
2 25
1 1
2 25
1 2500
2 6
2 7
2 11
2 13
1 777
2 14
2 16
2 18
1 424242
2 19
2 21
2 22
2 23
2 24
1 314159265
2 25

出力例 4

75
0
100
50
200
3
600
800
1000
13
1800
100
1
50
800
23
23
400
5
9
11
1200
1400
1600
17
19
2000
21
2200
23

入力例 5

1 7
1000000000
2 1
1 1
2 1
1 999999999
2 1
1 1000000000
2 1

出力例 5

0
1
1000000000
1000000000

Score : 333 pts

Problem Statement

Takahashi is preparing a champagne tower for a party. However, this time it is a simple structure with N glasses arranged in a single column from top to bottom. The glasses are numbered from the top as level 1, level 2, \ldots, level N.

The capacity of the glass at level i from the top is C_i milliliters.

Initially, all glasses are empty. Takahashi performs Q operations in order. Each operation is one of the following two types:

  • Operation 1 (pour): Pour V milliliters of champagne into the glass at level 1. The poured champagne is added to the current amount of champagne in the level 1 glass. As a result, if the amount of champagne in the glass at level i (1 \leq i \leq N-1) exceeds its capacity C_i (is strictly greater than the capacity), all the excess immediately flows down to the glass at level i + 1. This check is performed sequentially from level 1 in a cascading manner, and all processing is completed instantaneously. Champagne that overflows from the bottom glass (level N) is lost and does not accumulate anywhere. Upon completion of the operation, the amount of champagne in each glass is guaranteed to be at most its capacity.
  • Operation 2 (query): Output the amount of champagne (in milliliters) currently in the glass at level k.

For each operation 2, output the answer.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq Q \leq 2 \times 10^5
  • 1 \leq C_i \leq 10^9 (1 \leq i \leq N)
  • For operation 1: 1 \leq V \leq 10^9
  • For operation 2: 1 \leq k \leq N
  • Operation 2 is given at least once
  • All input values are integers

Input

N Q
C_1 C_2 \ldots C_N
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q
  • The first line contains an integer N representing the number of glass levels and an integer Q representing the number of operations, separated by a space.
  • The second line contains integers C_1, C_2, \ldots, C_N representing the capacity of the glass at level i from the top, separated by spaces.
  • The following Q lines each contain one operation.
  • For operation 1: Given as 1 V. This means pouring V milliliters of champagne into the glass at level 1. V is a positive integer.
  • For operation 2: Given as 2 k. This means querying the amount of champagne currently in the glass at level k. k is an integer between 1 and N, inclusive.

Output

Each time operation 2 is given, output the amount of champagne (in milliliters) currently in the specified glass at level k, one per line. Since all input values are integers, the answer is always an integer.


Sample Input 1

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

Sample Output 1

0
4
5
2
0

Sample Input 2

4 8
2 2 2 2
1 1
2 1
1 10
2 1
2 2
2 3
2 4
2 4

Sample Output 2

1
2
2
2
2
2

Sample Input 3

8 15
3 7 2 10 5 1 8 6
2 5
1 4
2 1
2 2
1 20
2 1
2 2
2 3
2 4
1 6
2 4
2 5
1 15
2 7
2 8

Sample Output 3

0
3
1
3
7
2
10
10
5
8
6

Sample Input 4

25 40
100 1 50 200 3 400 5 600 7 800 9 1000 11 1200 13 1400 15 1600 17 1800 19 2000 21 2200 23
1 75
2 1
2 2
1 1000
2 1
2 3
2 4
1 5000
2 5
2 8
2 10
1 12345
2 12
2 15
2 20
1 999999999
2 1
2 2
2 3
2 10
2 25
1 1
2 25
1 2500
2 6
2 7
2 11
2 13
1 777
2 14
2 16
2 18
1 424242
2 19
2 21
2 22
2 23
2 24
1 314159265
2 25

Sample Output 4

75
0
100
50
200
3
600
800
1000
13
1800
100
1
50
800
23
23
400
5
9
11
1200
1400
1600
17
19
2000
21
2200
23

Sample Input 5

1 7
1000000000
2 1
1 1
2 1
1 999999999
2 1
1 1000000000
2 1

Sample Output 5

0
1
1000000000
1000000000
C - 会議室の混雑

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

配点 : 366

問題文

高橋君は、ある会社の会議室管理システムを開発しています。

この会社には 1 つの大きな会議室があり、N 件の会議の予約が入っています。i 番目の会議は時刻 S_i に開始し、時刻 E_i に終了します。つまり、i 番目の会議は時刻 S_i 以上 E_i 未満の間、会議室を使用しています。

会議室の定員の関係上、同時に K 件以上の会議が重なると問題が発生します。高橋君は、予約のスケジュールに問題がないかを確認したいと思っています。

K 件以上の会議が同時に行われている瞬間が存在するならば Yes を、存在しないならば No を出力してください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 2 \leq K \leq N + 1
  • 0 \leq S_i < E_i \leq 10^9
  • 入力はすべて整数

入力

N K
S_1 E_1
S_2 E_2
:
S_N E_N
  • 1 行目には、会議の件数を表す N 、同時開催の上限を表す K が、スペース区切りで与えられる。
  • 2 行目から N + 1 行目では、各会議の情報が与えられる。
  • 1 + i 行目では、i 番目の会議の開始時刻 S_i と終了時刻 E_i が、スペース区切りで与えられる。

出力

K 件以上の会議が同時に行われている瞬間が存在するならば Yes を、存在しないならば No1 行で出力せよ。


入力例 1

3 2
1 5
3 7
6 9

出力例 1

Yes

入力例 2

5 3
0 10
11 20
5 15
21 30
25 35

出力例 2

No

入力例 3

10 4
100 500
200 600
250 400
300 350
700 1000
800 900
850 950
10 50
60 90
500000000 1000000000

出力例 3

Yes

Score : 366 pts

Problem Statement

Takahashi is developing a meeting room management system for a company.

This company has one large meeting room, and N meetings have been reserved. The i-th meeting starts at time S_i and ends at time E_i. In other words, the i-th meeting occupies the meeting room during the time interval from S_i (inclusive) to E_i (exclusive).

Due to the capacity of the meeting room, a problem occurs if K or more meetings overlap at the same time. Takahashi wants to check whether the reservation schedule has any issues.

If there exists a moment when K or more meetings are being held simultaneously, output Yes; otherwise, output No.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 2 \leq K \leq N + 1
  • 0 \leq S_i < E_i \leq 10^9
  • All inputs are integers

Input

N K
S_1 E_1
S_2 E_2
:
S_N E_N
  • The first line contains N, the number of meetings, and K, the upper limit for simultaneous meetings, separated by a space.
  • From the 2nd line to the (N + 1)-th line, the information for each meeting is given.
  • The (1 + i)-th line contains the start time S_i and end time E_i of the i-th meeting, separated by a space.

Output

If there exists a moment when K or more meetings are being held simultaneously, output Yes; otherwise, output No on a single line.


Sample Input 1

3 2
1 5
3 7
6 9

Sample Output 1

Yes

Sample Input 2

5 3
0 10
11 20
5 15
21 30
25 35

Sample Output 2

No

Sample Input 3

10 4
100 500
200 600
250 400
300 350
700 1000
800 900
850 950
10 50
60 90
500000000 1000000000

Sample Output 3

Yes
D - 果物狩りフェスティバル

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

配点 : 400

問題文

高橋君は果物狩りフェスティバルに参加しています。フェスティバルの農園には N 本の果樹があり、それぞれの木には果物が 1 つずつ実っています。i 番目の木 (1 \leq i \leq N) の果物のおいしさは V_i で、その果物は高さ D_i の位置に実っています。

高橋君には合計 M 回の収穫チャンスが与えられています。j 回目 (1 \leq j \leq M) の収穫チャンスでは、高さ L_j の脚立が 1 つ割り当てられており、高橋君はこの脚立を使うことで高さ L_j 以下の位置にある果物に手が届きます。

収穫チャンスは j = 1, 2, \ldots, M の順番に 1 回ずつ行われます。各収穫チャンスにおいて、高橋君は以下のいずれか一方を行います。

  • まだ収穫されていない果物のうち、D_i \leq L_j を満たすものを 1 つ選んで収穫する。
  • 何も収穫せずにパスする。

同じ果物を複数回収穫することはできません。すなわち、ある収穫チャンスで収穫された果物は、以降の収穫チャンスでは選べなくなります。

高橋君が M 回の収穫チャンスを通じて収穫できる果物のおいしさの合計の最大値を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq 2 \times 10^5
  • 1 \leq D_i \leq 10^9
  • 1 \leq V_i \leq 10^9
  • 1 \leq L_j \leq 10^9
  • 入力はすべて整数である

入力

N M
D_1 V_1
D_2 V_2
\vdots
D_N V_N
L_1 L_2 \ldots L_M
  • 1 行目には、果樹の本数を表す整数 N と収穫チャンスの回数を表す整数 M が、スペース区切りで与えられる。
  • 2 行目から N + 1 行目では、各果樹の情報が与えられる。
  • 1 + i 行目には、i 番目の木の果物の高さ D_i とおいしさ V_i が、スペース区切りで与えられる。
  • N + 2 行目には、各収穫チャンスで割り当てられる脚立の高さ L_1, L_2, \ldots, L_M が、スペース区切りで与えられる。

出力

高橋君が収穫できる果物のおいしさの合計の最大値を 1 行で出力せよ。


入力例 1

4 3
2 10
5 30
3 20
1 5
3 2 5

出力例 1

60

入力例 2

3 4
10 100
1 20
2 50
1 1 2 1

出力例 2

70

入力例 3

10 8
8 40
3 100
5 60
10 200
1 15
7 90
4 55
6 70
2 80
9 120
4 6 3 10 5 8 1 7

出力例 3

670

入力例 4

30 25
12 500
3 1000000000
25 450
7 300
18 760
2 50
30 900
15 610
9 400
22 850
5 120
11 530
28 990
14 600
1 10
20 800
6 250
24 870
17 700
10 480
13 560
27 950
4 200
19 780
8 350
21 820
16 650
29 980
23 860
26 930
5 10 15 20 25 30 1 6 12 18 24 30 3 9 14 22 27 2 7 13 19 26 28 4 11

出力例 4

1000014280

入力例 5

1 1
1000000000 1000000000
1

出力例 5

0

Score : 400 pts

Problem Statement

Takahashi is participating in a fruit picking festival. The festival's orchard has N fruit trees, each bearing exactly one fruit. The fruit on the i-th tree (1 \leq i \leq N) has a deliciousness of V_i and grows at height D_i.

Takahashi is given a total of M harvesting chances. In the j-th (1 \leq j \leq M) harvesting chance, he is assigned a stepladder of height L_j, which allows him to reach any fruit at height L_j or below.

The harvesting chances occur one at a time in the order j = 1, 2, \ldots, M. During each harvesting chance, Takahashi performs one of the following:

  • Choose and harvest one fruit that has not yet been harvested and satisfies D_i \leq L_j.
  • Pass without harvesting anything.

The same fruit cannot be harvested more than once. That is, a fruit harvested during one harvesting chance cannot be chosen in any subsequent harvesting chance.

Find the maximum total deliciousness of fruits that Takahashi can harvest over the M harvesting chances.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq M \leq 2 \times 10^5
  • 1 \leq D_i \leq 10^9
  • 1 \leq V_i \leq 10^9
  • 1 \leq L_j \leq 10^9
  • All input values are integers.

Input

N M
D_1 V_1
D_2 V_2
\vdots
D_N V_N
L_1 L_2 \ldots L_M
  • The first line contains an integer N representing the number of fruit trees and an integer M representing the number of harvesting chances, separated by a space.
  • From the 2nd line to the (N + 1)-th line, information about each fruit tree is given.
  • The (1 + i)-th line contains the height D_i and deliciousness V_i of the fruit on the i-th tree, separated by a space.
  • The (N + 2)-th line contains the heights L_1, L_2, \ldots, L_M of the stepladders assigned for each harvesting chance, separated by spaces.

Output

Output in one line the maximum total deliciousness of fruits that Takahashi can harvest.


Sample Input 1

4 3
2 10
5 30
3 20
1 5
3 2 5

Sample Output 1

60

Sample Input 2

3 4
10 100
1 20
2 50
1 1 2 1

Sample Output 2

70

Sample Input 3

10 8
8 40
3 100
5 60
10 200
1 15
7 90
4 55
6 70
2 80
9 120
4 6 3 10 5 8 1 7

Sample Output 3

670

Sample Input 4

30 25
12 500
3 1000000000
25 450
7 300
18 760
2 50
30 900
15 610
9 400
22 850
5 120
11 530
28 990
14 600
1 10
20 800
6 250
24 870
17 700
10 480
13 560
27 950
4 200
19 780
8 350
21 820
16 650
29 980
23 860
26 930
5 10 15 20 25 30 1 6 12 18 24 30 3 9 14 22 27 2 7 13 19 26 28 4 11

Sample Output 4

1000014280

Sample Input 5

1 1
1000000000 1000000000
1

Sample Output 5

0
E - 商品の逆元ポイント

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

配点 : 433

問題文

高橋君はお店で買い物をしています。

お店には N 個の商品が並んでおり、各商品には 1 から N までの番号が付けられています。商品 i の価格は A_i です。価格が同じ商品が複数存在することもありますが、番号が異なれば異なる商品として区別します。

高橋君はこの中から K 個の商品を選んで購入します。同じ商品を複数回選ぶことはできず、選ぶ順序も区別しません(すなわち、N 個から K 個を選ぶ組み合わせとして選びます)。選んだ K 個の商品の価格のP とします。

このお店では特別なポイント制度があり、購入した商品の組み合わせに対して、素数 M を用いた以下のルールでポイントが付与されます。

  • PM の倍数でない場合:P \cdot Q \equiv 1 \pmod{M} かつ 0 \leq Q < M を満たす整数 Q がただ 1 つ存在します(M が素数であることから保証されます)。この QM を法とした P乗法逆元と呼び、Q がポイントとして付与されます。
  • PM の倍数である場合:乗法逆元が存在しないため、付与されるポイントは 0 とします。

N 個の商品から K 個を選ぶ \binom{N}{K} 通りすべての選び方について、それぞれ付与されるポイントを求め、その総和を M で割った余りを出力してください。

制約

  • 1 \leq K \leq N \leq 5000
  • 2 \leq M \leq 10^9
  • M は素数である
  • 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • 入力はすべて整数である

入力

N K M
A_1 A_2 \ldots A_N
  • 1 行目には、商品の個数を表す整数 N、選ぶ個数を表す整数 K、素数 M が、スペース区切りで与えられる。
  • 2 行目には、各商品の価格を表す整数 A_1, A_2, \ldots, A_N がスペース区切りで与えられる。

出力

すべての選び方における付与ポイントの総和を M で割った余りを 1 行で出力せよ。出力は 0 以上 M - 1 以下の整数となる。


入力例 1

4 2 7
1 2 3 4

出力例 1

0

入力例 2

5 3 5
5 1 2 10 3

出力例 2

1

入力例 3

12 5 101
3 202 7 15 101 48 7 99 100 250 13 1

出力例 3

12

入力例 4

30 15 998244353
1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 998244353 999999937 123456789 987654321 314159265

出力例 4

354173354

入力例 5

1 1 2
2

出力例 5

0

Score : 433 pts

Problem Statement

Takahashi is shopping at a store.

The store has N products lined up, each numbered from 1 to N. The price of product i is A_i. Multiple products may have the same price, but products with different numbers are distinguished as different products.

Takahashi will select and purchase K products from these. He cannot select the same product more than once, and the order of selection does not matter (that is, he selects as a combination of K items from N). Let P be the product of the prices of the K selected items.

This store has a special point system where points are awarded for the combination of purchased products according to the following rules using a prime number M:

  • If P is not a multiple of M: There exists exactly one integer Q satisfying P \cdot Q \equiv 1 \pmod{M} and 0 \leq Q < M (this is guaranteed since M is prime). This Q is called the multiplicative inverse of P modulo M, and Q points are awarded.
  • If P is a multiple of M: Since the multiplicative inverse does not exist, the awarded points are 0.

For all \binom{N}{K} ways of choosing K products from N products, determine the points awarded for each selection, and output the remainder when the total sum is divided by M.

Constraints

  • 1 \leq K \leq N \leq 5000
  • 2 \leq M \leq 10^9
  • M is a prime number
  • 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • All input values are integers

Input

N K M
A_1 A_2 \ldots A_N
  • The first line contains the integer N representing the number of products, the integer K representing the number to select, and the prime M, separated by spaces.
  • The second line contains the integers A_1, A_2, \ldots, A_N representing the prices of each product, separated by spaces.

Output

Output in one line the remainder when the total sum of awarded points over all selections is divided by M. The output will be an integer between 0 and M - 1, inclusive.


Sample Input 1

4 2 7
1 2 3 4

Sample Output 1

0

Sample Input 2

5 3 5
5 1 2 10 3

Sample Output 2

1

Sample Input 3

12 5 101
3 202 7 15 101 48 7 99 100 250 13 1

Sample Output 3

12

Sample Input 4

30 15 998244353
1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 998244353 999999937 123456789 987654321 314159265

Sample Output 4

354173354

Sample Input 5

1 1 2
2

Sample Output 5

0