A - Multiple Check

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

高橋君は N 個の整数 A_1, A_2, \ldots, A_N を持っています。

正の整数 K が与えられるので、A_1, A_2, \ldots, A_N のそれぞれについて K で割り切れるかを調べ、K で割り切れるものの個数を求めてください。

ここで、整数 aK で割り切れるとは、a = K \times q を満たす整数 q が存在することをいいます。例えば、-63 で割り切れ、0 は任意の正の整数で割り切れます。

制約

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

入力

N K
A_1 A_2 \cdots A_N

1 行目には、整数の個数 N と割る数 K がスペース区切りで与えられる。

2 行目には、N 個の整数 A_1, A_2, \ldots, A_N がスペース区切りで与えられる。

出力

K で割り切れる整数の個数を 1 行で出力してください。


入力例 1

5 3
1 3 6 -4 0

出力例 1

3

入力例 2

6 5
1 2 3 4 6 7

出力例 2

0

入力例 3

12 7
14 -21 28 5 0 49 56 -1 70 100 -98 13

出力例 3

8

入力例 4

30 12
12 24 36 48 60 72 84 96 108 120 -12 -24 -36 -48 -60 -72 1 11 13 25 37 49 61 73 85 97 0 144 -120 1000000000

出力例 4

19

入力例 5

1 1000000000
-1000000000

出力例 5

1

Score : 200 pts

Problem Statement

Takahashi has N integers A_1, A_2, \ldots, A_N.

Given a positive integer K, determine for each of A_1, A_2, \ldots, A_N whether it is divisible by K, and find the number of integers that are divisible by K.

Here, an integer a is divisible by K means that there exists an integer q such that a = K \times q. For example, -6 is divisible by 3, and 0 is divisible by any positive integer.

Constraints

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

Input

N K
A_1 A_2 \cdots A_N

The first line contains the number of integers N and the divisor K, separated by a space.

The second line contains N integers A_1, A_2, \ldots, A_N, separated by spaces.

Output

Print the number of integers that are divisible by K on a single line.


Sample Input 1

5 3
1 3 6 -4 0

Sample Output 1

3

Sample Input 2

6 5
1 2 3 4 6 7

Sample Output 2

0

Sample Input 3

12 7
14 -21 28 5 0 49 56 -1 70 100 -98 13

Sample Output 3

8

Sample Input 4

30 12
12 24 36 48 60 72 84 96 108 120 -12 -24 -36 -48 -60 -72 1 11 13 25 37 49 61 73 85 97 0 144 -120 1000000000

Sample Output 4

19

Sample Input 5

1 1000000000
-1000000000

Sample Output 5

1
B - Fruit Harvest Season

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

高橋君は果樹園を経営しています。今年の収穫シーズンは N 日間あり、各日の天気はすでに確定しています。天気は各日について「晴れ」「曇り」「雨」のいずれかであり、i 日目の天気を W_i で表します。W_iS のとき晴れ、C のとき曇り、R のとき雨を意味します。

果物の収穫作業は晴れの日にしか行うことができません。高橋君はアルバイトを雇うために、N 日間の中から連続する K 日間をちょうど 1 つ選んで勤務期間とする契約を結びます。すなわち、ある整数 d1 \leq d \leq N - K + 1)を選び、第 d 日目から第 d + K - 1 日目までをアルバイトの勤務期間とします。

高橋君は、選んだ K 日間に含まれる晴れの日の数ができるだけ多くなるように期間を選びたいです。

N 日間の天気が与えられたとき、連続する K 日間の選び方すべてのうち、その区間に含まれる晴れの日数の最大値を求めてください。

制約

  • 1 \leq K \leq N \leq 10^6
  • N, K は整数である。
  • W_i1 \leq i \leq N)は S, C, R のいずれかである。

入力

N K
W_1 W_2 \ldots W_N
  • 1 行目には、収穫シーズンの日数を表す整数 N と、アルバイトを雇う連続日数を表す整数 K が、スペース区切りで与えられる。
  • 2 行目には、各日の天気を表す W_1, W_2, \ldots, W_N が、スペース区切りで与えられる。
  • W_ii 日目の天気を表し、 S は晴れ、 C は曇り、 R は雨を意味する。

出力

連続する K 日間の選び方すべてのうち、その区間に含まれる晴れの日数の最大値を 1 行で出力してください。


入力例 1

7 3
S C S S R S C

出力例 1

2

入力例 2

5 3
R C R C R

出力例 2

0

入力例 3

15 5
S S C R S S S C R R S S S S C

出力例 3

4

入力例 4

30 7
S C S S R S S S C R S S S S R C S S S R S C S S S S C R S S

出力例 4

5

入力例 5

1 1
S

出力例 5

1

Score : 300 pts

Problem Statement

Takahashi runs an orchard. This year's harvest season lasts N days, and the weather for each day has already been determined. The weather for each day is one of "sunny," "cloudy," or "rainy," and the weather on day i is represented by W_i. W_i is S for sunny, C for cloudy, and R for rainy.

Fruit harvesting can only be done on sunny days. To hire a part-time worker, Takahashi will sign a contract that selects exactly one period of K consecutive days from the N days as the work period. That is, he chooses an integer d (1 \leq d \leq N - K + 1) and sets the work period from day d to day d + K - 1.

Takahashi wants to choose the period so that the number of sunny days included in the chosen K days is as large as possible.

Given the weather for all N days, find the maximum number of sunny days contained in any selection of K consecutive days.

Constraints

  • 1 \leq K \leq N \leq 10^6
  • N, K are integers.
  • W_i (1 \leq i \leq N) is one of S, C, R.

Input

N K
W_1 W_2 \ldots W_N
  • The first line contains an integer N representing the number of days in the harvest season and an integer K representing the number of consecutive days to hire the part-time worker, separated by a space.
  • The second line contains W_1, W_2, \ldots, W_N representing the weather for each day, separated by spaces.
  • W_i represents the weather on day i, where S means sunny, C means cloudy, and R means rainy.

Output

Print in one line the maximum number of sunny days contained in any selection of K consecutive days.


Sample Input 1

7 3
S C S S R S C

Sample Output 1

2

Sample Input 2

5 3
R C R C R

Sample Output 2

0

Sample Input 3

15 5
S S C R S S S C R R S S S S C

Sample Output 3

4

Sample Input 4

30 7
S C S S R S S S C R S S S S R C S S S R S C S S S S C R S S

Sample Output 4

5

Sample Input 5

1 1
S

Sample Output 5

1
C - Assortment of Sweets

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 366

問題文

高橋君は、お菓子屋さんで N 個のお菓子が一列に並んでいるのを見つけました。左から i 番目のお菓子の重さは W_i グラムです。

高橋君は、並んでいるお菓子の中から連続する 1 個以上のお菓子を選び、まとめて 1 つの袋に詰めて持ち帰ろうとしています。

お店には M 枚の袋が用意されており、j 番目の袋の耐荷重は C_j グラムです。袋に入れるお菓子の重さの合計が袋の耐荷重を超えると袋が破れてしまうため、お菓子の重さの合計は選んだ袋の耐荷重以下でなければなりません。

高橋君はできるだけ多くのお菓子を入れたいので、耐荷重が最も大きい袋を使おうとしましたが、あいにくその袋は売り切れていました。それどころか、耐荷重が大きい袋から順に売れてしまっていて、最終的に残っていたのは耐荷重が最も小さい袋だけでした。仕方がないので、高橋君はその袋を使うことにしました。

すなわち、高橋君が使う袋の耐荷重は C_{\min} = \min(C_1, C_2, \ldots, C_M) グラムです。

高橋君が袋を破らずにお菓子を持ち帰れるような、連続するお菓子の選び方が何通りあるか求めてください。具体的には、1 \leq l \leq r \leq N を満たす整数の組 (l, r) であって、

W_l + W_{l+1} + \cdots + W_r \leq \min(C_1, C_2, \ldots, C_M)

を満たすものの個数を求めてください。

制約

  • 1 \leq N \leq 5 \times 10^5
  • 1 \leq M \leq 5 \times 10^5
  • 1 \leq W_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq C_j \leq 10^{18} (1 \leq j \leq M)
  • 入力はすべて整数

入力

N M
W_1 W_2 \ldots W_N
C_1 C_2 \ldots C_M
  • 1 行目には、お菓子の個数を表す整数 N と、袋の枚数を表す整数 M が、スペース区切りで与えられる。
  • 2 行目には、各お菓子の重さを表す整数 W_1, W_2, \ldots, W_N が、スペース区切りで与えられる。
  • 3 行目には、各袋の耐荷重を表す整数 C_1, C_2, \ldots, C_M が、スペース区切りで与えられる。

出力

条件を満たす整数の組 (l, r) の個数を 1 行で出力せよ。


入力例 1

5 3
1 2 3 4 5
10 20 30

出力例 1

12

入力例 2

3 2
5 5 5
3 10

出力例 2

0

入力例 3

10 5
1 1 1 1 1 1 1 1 1 1
5 8 3 7 6

出力例 3

27

入力例 4

20 10
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4
100 50 30 80 25 60 45 70 35 55

出力例 4

83

入力例 5

1 1
1
1

出力例 5

1

Score : 366 pts

Problem Statement

Takahashi found N sweets lined up in a row at a candy shop. The weight of the i-th sweet from the left is W_i grams.

Takahashi wants to choose one or more consecutive sweets from the lineup, put them all into a single bag, and take them home.

The shop has M bags available, and the j-th bag has a weight capacity of C_j grams. Since a bag will tear if the total weight of the sweets inside exceeds its capacity, the total weight of the sweets must not exceed the capacity of the chosen bag.

Takahashi wanted to use the bag with the largest capacity so he could fit as many sweets as possible, but unfortunately that bag was sold out. In fact, the bags had been sold starting from the one with the largest capacity, and the only bag remaining was the one with the smallest capacity. Having no other choice, Takahashi decided to use that bag.

In other words, the capacity of the bag Takahashi uses is C_{\min} = \min(C_1, C_2, \ldots, C_M) grams.

Find the number of ways to choose consecutive sweets such that Takahashi can take them home without tearing the bag. Specifically, find the number of pairs of integers (l, r) satisfying 1 \leq l \leq r \leq N such that

W_l + W_{l+1} + \cdots + W_r \leq \min(C_1, C_2, \ldots, C_M)

Constraints

  • 1 \leq N \leq 5 \times 10^5
  • 1 \leq M \leq 5 \times 10^5
  • 1 \leq W_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq C_j \leq 10^{18} (1 \leq j \leq M)
  • All inputs are integers

Input

N M
W_1 W_2 \ldots W_N
C_1 C_2 \ldots C_M
  • The first line contains an integer N representing the number of sweets and an integer M representing the number of bags, separated by a space.
  • The second line contains integers W_1, W_2, \ldots, W_N representing the weight of each sweet, separated by spaces.
  • The third line contains integers C_1, C_2, \ldots, C_M representing the capacity of each bag, separated by spaces.

Output

Output the number of pairs of integers (l, r) satisfying the condition, on a single line.


Sample Input 1

5 3
1 2 3 4 5
10 20 30

Sample Output 1

12

Sample Input 2

3 2
5 5 5
3 10

Sample Output 2

0

Sample Input 3

10 5
1 1 1 1 1 1 1 1 1 1
5 8 3 7 6

Sample Output 3

27

Sample Input 4

20 10
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4
100 50 30 80 25 60 45 70 35 55

Sample Output 4

83

Sample Input 5

1 1
1
1

Sample Output 5

1
D - Watering the Flower Bed

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

高橋君は花壇の管理を担当しています。花壇には N 株の花が一列に植えられており、左から順に花 1 , 花 2 , \ldots , 花 N と番号が付けられています。

各花には「乾燥度」と呼ばれる非負整数の値があり、花 i の初期乾燥度は F_i です。乾燥度が高い花ほど枯れやすいため、水やりが必要になります。

高橋君は M 回の水やり作業を順に行います。j 番目の作業( j = 1, 2, \ldots, M )では、花 L_j から花 R_j までのすべての花に水を与え、それらの花の乾燥度をそれぞれ D_j だけ減少させます。

具体的には、花 iL_j \leq i \leq R_j )の乾燥度が現在 v であるとき、この作業により \max(v - D_j,\ 0) に更新されます。すなわち、乾燥度は 0 未満にはなりません。

すべての水やり作業が終わった後、乾燥度が閾値 T 以下になった花は「元気な状態」と見なされ、きれいに咲き続けることができます。一方、乾燥度が T より大きいままの花は依然として枯れるリスクが高い状態です。

青木君は高橋君の水やり計画を見て「元気にできない花がたくさんあるだろう」と言いますが、高橋君は自分の計画に自信を持っています。

高橋君の計画が実行された後、元気な状態になっている花(すなわち最終的な乾燥度が T 以下である花)の株数を求めてください。

制約

  • 1 \leq N \leq 5 \times 10^5
  • 0 \leq M \leq 2 \times 10^5
  • 0 \leq T \leq 10^9
  • 0 \leq F_i \leq 10^91 \leq i \leq N
  • 1 \leq L_j \leq R_j \leq N1 \leq j \leq M
  • 1 \leq D_j \leq 10^91 \leq j \leq M
  • 入力はすべて整数である。

入力

N M T
F_1 F_2 \ldots F_N
L_1 R_1 D_1
L_2 R_2 D_2
\vdots
L_M R_M D_M
  • 1 行目には、花の株数 N 、水やり作業の回数 M 、元気な状態と見なす乾燥度の閾値 T が、スペース区切りで与えられる。
  • 2 行目には、各花の初期乾燥度 F_1, F_2, \ldots, F_N が、スペース区切りで与えられる。
  • 続く M 行にわたって、各水やり作業の情報が与えられる。
  • そのうち j 行目(入力全体の 2 + j 行目)には、 j 番目の作業の対象区間の左端 L_j 、右端 R_j 、乾燥度の減少量 D_j が、スペース区切りで与えられる。

出力

すべての水やり作業後に元気な状態(最終的な乾燥度が T 以下)である花の株数を 1 行で出力せよ。


入力例 1

5 3 4
7 2 10 5 8
1 3 3
3 5 4
2 4 2

出力例 1

5

入力例 2

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

出力例 2

2

入力例 3

10 6 5
0 12 7 20 5 9 14 3 18 6
1 5 4
4 10 6
2 7 3
8 9 10
1 10 1
6 6 5

出力例 3

9

入力例 4

30 18 100
150 80 220 0 95 310 500 120 75 640 130 90 1000 45 260 330 10 700 85 400 55 600 140 20 900 110 70 350 480 5
1 10 50
5 15 80
12 30 60
3 3 200
18 25 300
1 30 20
7 14 100
20 30 150
2 28 10
16 16 5
1 1 1000
10 22 40
23 27 500
4 19 30
8 8 70
29 30 10
6 24 90
13 17 200

出力例 4

24

入力例 5

1 0 1000000000
1000000000

出力例 5

1

Score : 400 pts

Problem Statement

Takahashi is in charge of managing a flower bed. The flower bed has N flowers planted in a row, numbered flower 1, flower 2, \ldots, flower N from left to right.

Each flower has a non-negative integer value called "dryness level," and the initial dryness level of flower i is F_i. Flowers with higher dryness levels are more likely to wilt, so they need watering.

Takahashi performs M watering operations in order. In the j-th operation (j = 1, 2, \ldots, M), he waters all flowers from flower L_j to flower R_j, decreasing each of their dryness levels by D_j.

Specifically, if flower i (L_j \leq i \leq R_j) currently has a dryness level of v, this operation updates it to \max(v - D_j,\ 0). In other words, the dryness level never goes below 0.

After all watering operations are completed, flowers whose dryness level is at most the threshold T are considered to be in a "healthy state" and can continue to bloom beautifully. On the other hand, flowers whose dryness level remains greater than T are still at high risk of wilting.

Aoki looks at Takahashi's watering plan and says, "There will probably be many flowers you can't make healthy," but Takahashi is confident in his plan.

After Takahashi's plan is executed, find the number of flowers that are in a healthy state (i.e., flowers whose final dryness level is at most T).

Constraints

  • 1 \leq N \leq 5 \times 10^5
  • 0 \leq M \leq 2 \times 10^5
  • 0 \leq T \leq 10^9
  • 0 \leq F_i \leq 10^9 (1 \leq i \leq N)
  • 1 \leq L_j \leq R_j \leq N (1 \leq j \leq M)
  • 1 \leq D_j \leq 10^9 (1 \leq j \leq M)
  • All input values are integers.

Input

N M T
F_1 F_2 \ldots F_N
L_1 R_1 D_1
L_2 R_2 D_2
\vdots
L_M R_M D_M
  • The first line contains the number of flowers N, the number of watering operations M, and the dryness level threshold T for being considered healthy, separated by spaces.
  • The second line contains the initial dryness levels F_1, F_2, \ldots, F_N of each flower, separated by spaces.
  • The following M lines contain the information for each watering operation.
  • The j-th of these lines (the (2 + j)-th line of the entire input) contains the left endpoint L_j, right endpoint R_j of the target interval, and the dryness level decrease D_j for the j-th operation, separated by spaces.

Output

Output in one line the number of flowers that are in a healthy state (final dryness level is at most T) after all watering operations are completed.


Sample Input 1

5 3 4
7 2 10 5 8
1 3 3
3 5 4
2 4 2

Sample Output 1

5

Sample Input 2

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

Sample Output 2

2

Sample Input 3

10 6 5
0 12 7 20 5 9 14 3 18 6
1 5 4
4 10 6
2 7 3
8 9 10
1 10 1
6 6 5

Sample Output 3

9

Sample Input 4

30 18 100
150 80 220 0 95 310 500 120 75 640 130 90 1000 45 260 330 10 700 85 400 55 600 140 20 900 110 70 350 480 5
1 10 50
5 15 80
12 30 60
3 3 200
18 25 300
1 30 20
7 14 100
20 30 150
2 28 10
16 16 5
1 1 1000
10 22 40
23 27 500
4 19 30
8 8 70
29 30 10
6 24 90
13 17 200

Sample Output 4

24

Sample Input 5

1 0 1000000000
1000000000

Sample Output 5

1
E - Message Delivery

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 433

問題文

N 人の人がおり、それぞれ 1 から N までの番号が付いています。各人 i は初期値として非負整数 V_i を持っています。

高橋君は「伝達ネットワーク」を設計します。伝達ネットワークとは、各人 i に対して送り先 A_i1 以上 N 以下の整数、A_i = i も許される)を定めた配列 A = (A_1, A_2, \ldots, A_N) のことです。

伝達ネットワークが定まると、「伝達操作」を行うことができます。1回の伝達操作は以下のように行われます:

  • すべての人が同時に、自分の持つ値を送り先に送る。すなわち、人 i は自分の操作前の値を人 A_i に送る。
  • 操作後、各人 j の新しい値は、j に値を送ったすべての人の操作前の値のビットごとの排他的論理和(XOR)となる。すなわち、人 j の新しい値は A_k = j を満たすすべての k について V_k(操作前の値)の XOR である。A_k = j を満たす k が存在しない場合、人 j の値は 0 になる。

高橋君と青木君は、以下の手順でゲームを行います:

  1. 高橋君が配列 A(各 A_i1 以上 N 以下の整数)を決める。
  2. 青木君が配列 A の内容を確認した上で、ちょうど 1 人を選び、その人の初期値を任意の非負整数に書き換える。(必ず 1 人を選ばなければならないが、元と同じ値に書き換えることは許される。つまり実質的に書き換えない場合と同じ状態にすることも可能である。)
  3. 伝達操作をちょうど K 回行う。
  4. すべての人の値の総和を計算する。

高橋君はこの総和を最大化したいと考え、青木君はこの総和を最小化したいと考えています。

両者が最適に行動したとき、K 回の伝達操作後のすべての人の値の総和を求めてください。

注記

ビットごとの排他的論理和(XOR)とは、二つの非負整数を二進法で表したとき、各桁について一方のみが 1 であれば 1、そうでなければ 0 とする演算です。複数の値の XOR は、これを順に適用して得られます(結合的であるため順序によらず結果は同じです)。値が 1 つだけの場合の XOR はその値自身、値が 0 個の場合の XOR は 0 と定めます。

制約

  • 1 \leq N \leq 12
  • 1 \leq K \leq 10^{18}
  • 0 \leq V_i \leq 10^{9}
  • 入力はすべて整数である。

入力

N K
V_1 V_2 \ldots V_N
  • 1 行目には、人数を表す整数 N と、伝達操作の回数を表す整数 K が、スペース区切りで与えられる。
  • 2 行目には、各人の初期値を表す整数 V_1, V_2, \ldots, V_N が、スペース区切りで与えられる。

出力

両者が最適に行動したときの、K 回の伝達操作後のすべての人の値の総和を 1 行で出力せよ。


入力例 1

3 2
1 2 3

出力例 1

3

入力例 2

4 1
0 5 7 10

出力例 2

12

入力例 3

8 17
12 34 56 78 90 123 456 789

出力例 3

849

入力例 4

12 123456789012345678
1000000000 999999937 123456789 987654321 0 1 2 3 255 1024 65535 314159265

出力例 4

2425337132

入力例 5

1 1000000000000000000
1000000000

出力例 5

0

Score : 433 pts

Problem Statement

There are N people, numbered 1 to N. Each person i initially has a non-negative integer value V_i.

Takahashi will design a "transmission network". A transmission network is defined by an array A = (A_1, A_2, \ldots, A_N) of length N, where each A_i is an integer between 1 and N (inclusive), representing the destination for person i (it is allowed that A_i = i).

Once the transmission network is determined, "transmission operations" can be performed. One transmission operation is carried out as follows:

  • All people simultaneously send their current values to their destinations. That is, person i sends their pre-operation value to person A_i.
  • After the operation, the new value of each person j becomes the bitwise exclusive OR (XOR) of the pre-operation values of all people who sent their values to j. That is, the new value of person j is the XOR of V_k (the pre-operation value) for all k such that A_k = j. If there is no k satisfying A_k = j, the value of person j becomes 0.

Takahashi and Aoki play a game using the following procedure:

  1. Takahashi decides the array A (where each A_i is an integer between 1 and N inclusive).
  2. Aoki inspects the contents of the array A, chooses exactly one person, and rewrites their initial value to an arbitrary non-negative integer. (Aoki must choose exactly one person, but rewriting to the same value as the original is allowed. In other words, he can choose to leave the value practically unchanged.)
  3. The transmission operation is performed exactly K times.
  4. The sum of the values of all people is calculated.

Takahashi wants to maximize this sum, and Aoki wants to minimize this sum.

Find the sum of the values of all people after K transmission operations when both players play optimally.

Notes

The bitwise exclusive OR (XOR) of non-negative integers is an operation where, when two non-negative integers are represented in binary, the result has a 1 in each digit if and only if exactly one of the two numbers has a 1 in that digit, and 0 otherwise. The XOR of multiple values is obtained by applying this operation sequentially (since it is associative, the order does not affect the result). The XOR of a single value is the value itself, and the XOR of zero values is defined as 0.

Constraints

  • 1 \leq N \leq 12
  • 1 \leq K \leq 10^{18}
  • 0 \leq V_i \leq 10^{9}
  • All input values are integers.

Input

N K
V_1 V_2 \ldots V_N
  • The first line contains an integer N representing the number of people, and an integer K representing the number of transmission operations, separated by a space.
  • The second line contains integers V_1, V_2, \ldots, V_N representing the initial values of each person, separated by a space.

Output

Print the sum of the values of all people after K transmission operations when both players play optimally in a single line.


Sample Input 1

3 2
1 2 3

Sample Output 1

3

Sample Input 2

4 1
0 5 7 10

Sample Output 2

12

Sample Input 3

8 17
12 34 56 78 90 123 456 789

Sample Output 3

849

Sample Input 4

12 123456789012345678
1000000000 999999937 123456789 987654321 0 1 2 3 255 1024 65535 314159265

Sample Output 4

2425337132

Sample Input 5

1 1000000000000000000
1000000000

Sample Output 5

0