A - Obesity

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

配点 : 100

問題文

以下の式で計算される値を \mathrm{BMI}[\mathrm{kg}/\mathrm{m}^2] と言います。

  • \text{体重}[\mathrm{kg}] \div \text{身長}[\mathrm{m}] \div \text{身長}[\mathrm{m}]

日本では、\mathrm{BMI}25 \; \mathrm{kg}/\mathrm{m}^2 以上の人は肥満とされます。
身長 H[\mathrm{cm}]、体重 W[\mathrm{kg}] の人が日本で肥満とされるかどうかを判定してください。

制約

  • 1 \leq H \leq 300
  • 1 \leq W \leq 300
  • 入力される値はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

H W  

出力

身長 H[\mathrm{cm}]、体重 W[\mathrm{kg}] の人が日本で肥満とされるならば Yes を、そうでないならば No1 行で出力せよ。


入力例 1

180 60

出力例 1

No

身長が 180 \; \mathrm{cm}=1.8 \; \mathrm{m} なので、\mathrm{BMI}60 \; \mathrm{kg} \div 1.8 \; \mathrm{m} \div 1.8 \; \mathrm{m}=18.5\dots \; \mathrm{kg}/\mathrm{m}^2 となり、この人は肥満とはされません。


入力例 2

182 188

出力例 2

Yes

入力例 3

180 81

出力例 3

Yes

Score : 100 points

Problem Statement

The value calculated by the following formula is called \mathrm{BMI}[\mathrm{kg}/\mathrm{m}^2]. (\div denotes division.)

  • \text{Weight}[\mathrm{kg}] \div \text{Height}[\mathrm{m}] \div \text{Height}[\mathrm{m}]

In Japan, a person whose \mathrm{BMI} is 25 \; \mathrm{kg}/\mathrm{m}^2 or more is considered obese.
Determine whether a person with height H[\mathrm{cm}] and weight W[\mathrm{kg}] is considered obese in Japan.

Constraints

  • 1 \leq H \leq 300
  • 1 \leq W \leq 300
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

H W  

Output

Output Yes on one line if a person with height H[\mathrm{cm}] and weight W[\mathrm{kg}] is considered obese in Japan, and No otherwise.


Sample Input 1

180 60

Sample Output 1

No

Since the height is 180 \; \mathrm{cm}=1.8 \; \mathrm{m}, the \mathrm{BMI} is 60 \; \mathrm{kg} \div 1.8 \; \mathrm{m} \div 1.8 \; \mathrm{m}=18.5\dots \; \mathrm{kg}/\mathrm{m}^2, so this person is not considered obese.


Sample Input 2

182 188

Sample Output 2

Yes

Sample Input 3

180 81

Sample Output 3

Yes
B - Keep the Change

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

配点 : 200

問題文

高橋君は N 軒の店で買い物をしました。はじめ、高橋君は 10000 円持っていました。
i 軒目の店では A_i 円の商品を買って B_i 円支払いました。ここで A_i \leq B_i が成り立ちます。そして、S_i = keep の時、高橋君はお釣りを受け取らず、S_i = take の場合、お釣りを受け取りました。
高橋君が全ての店でお釣りを受け取っていた場合に比べて損した金額を求めてください。厳密に述べると、

  • 高橋君の最終的な所持金を X 円、
  • 高橋君が全ての店でお釣りを受け取っていた場合の最終的な所持金を Y

とした時、Y - X を求めてください。

制約

  • 1 \leq N \leq 100
  • 1 \leq A_i \leq B_i \leq 100
  • S_ikeep または take
  • N, A_i, B_i は全て整数

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 B_1 S_1
A_2 B_2 S_2
\vdots
A_N B_N S_N

出力

高橋君が全ての店でお釣りを受け取っていた場合に比べて損した金額を出力せよ。


入力例 1

3
1 2 keep
3 6 take
5 9 keep

出力例 1

5

高橋君の行動を説明すると次の通りです。

  • 1 番目の店で 1 円の商品を買い、2 円支払い、お釣りを受け取らなかった。
  • 2 番目の店で 3 円の商品を買い、6 円支払い、お釣りを受け取った。
  • 3 番目の店で 5 円の商品を買い、9 円支払い、お釣りを受け取らなかった。

入力例 2

8
36 49 take
38 73 keep
27 85 take
65 71 take
52 86 keep
48 60 keep
37 98 keep
5 38 keep

出力例 2

175

Score : 200 points

Problem Statement

Takahashi made purchases at N stores. Initially, he had 10000 yen.
At the i-th store, he bought an item worth A_i yen and paid B_i yen. Here, A_i \leq B_i holds. If S_i = keep, he did not receive the change, and if S_i = take, he received the change.
Find the amount of money he lost compared to the case where he received the change at every store. To be precise,

  • let X yen be Takahashi's final amount of money, and
  • let Y yen be Takahashi's final amount of money in the case where he received the change at every store.

Find Y - X.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq A_i \leq B_i \leq 100
  • S_i is keep or take.
  • N, A_i, B_i are all integers.

Input

The input is given from Standard Input in the following format:

N
A_1 B_1 S_1
A_2 B_2 S_2
\vdots
A_N B_N S_N

Output

Output the amount of money Takahashi lost compared to the case where he received the change at every store.


Sample Input 1

3
1 2 keep
3 6 take
5 9 keep

Sample Output 1

5

Takahashi's actions are as follows.

  • At the first store, he bought an item worth 1 yen, paid 2 yen, and did not receive the change.
  • At the second store, he bought an item worth 3 yen, paid 6 yen, and received the change.
  • At the third store, he bought an item worth 5 yen, paid 9 yen, and did not receive the change.

Sample Input 2

8
36 49 take
38 73 keep
27 85 take
65 71 take
52 86 keep
48 60 keep
37 98 keep
5 38 keep

Sample Output 2

175
C - Adjacent Sums (easy)

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

配点 : 300

問題文

※ C 問題の問題文は E 問題と同じです。赤字で示された制約のみが異なります。

0 以上 M-1 以下の整数からなる整数列 A=(A_1,A_2,\dots,A_N),B=(B_1,B_2,\dots,B_{N-1}) が与えられます。 A,B の長さはそれぞれ N,N-1 です。
A に対して以下の操作を好きな回数行うことができます。

  • 1 以上 N 以下の整数 i1 つ選び、A_i1 を加える。

以下の条件を満たすようにするために必要な操作回数の最小値を求めてください。
なお、問題の制約下では、必ず条件を満たすようにできることが証明できます。

  • i=1,2,\dots,N-1 について、A_i+A_{i+1}M で割った余りは B_i に等しい。

制約

  • 2 \leq N \leq 2 \times 10^5
  • M=2
  • 0 \leq A_i \leq M-1
  • 0 \leq B_i \leq M-1
  • 入力される値はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N M  
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_{N-1}

出力

答えを 1 行で出力せよ。


入力例 1

3 2
1 1 1
1 1

出力例 1

1

1 回目の操作で i=2 を選ぶと、A=(1,2,1) となります。
A_1+A_2=1+2=3,\;A_2+A_3=2+1=3 なので、条件を満たします。
また、A=(1,1,1) は条件を満たさないため、答えは 1 です。


入力例 2

2 2
1 1
0

出力例 2

0

入力例 3

10 2
0 0 0 1 1 0 1 0 1 0
0 1 0 1 0 1 0 1 0

出力例 3

4

Score : 300 points

Problem Statement

The problem statement of Problem C is the same as Problem E. Only the constraint shown in red differ.

You are given integer sequences A=(A_1,A_2,\dots,A_N),B=(B_1,B_2,\dots,B_{N-1}) consisting of integers between 0 and M-1, inclusive. The lengths of A and B are N and N-1, respectively.
You can perform the following operation on A any number of times.

  • Choose an integer i with 1 \leq i \leq N, and add 1 to A_i.

Find the minimum number of operations required to satisfy the following condition.
It can be proved that the condition can always be satisfied under the constraints of this problem.

  • For i=1,2,\dots,N-1, the remainder when A_i+A_{i+1} is divided by M equals B_i.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • M=2
  • 0 \leq A_i \leq M-1
  • 0 \leq B_i \leq M-1
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N M  
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_{N-1}

Output

Output the answer on one line.


Sample Input 1

3 2
1 1 1
1 1

Sample Output 1

1

If we choose i=2 for the first operation, we get A=(1,2,1).
Since A_1+A_2=1+2=3 and A_2+A_3=2+1=3, the condition is satisfied.
A=(1,1,1) does not satisfy the condition, so the answer is 1.


Sample Input 2

2 2
1 1
0

Sample Output 2

0

Sample Input 3

10 2
0 0 0 1 1 0 1 0 1 0
0 1 0 1 0 1 0 1 0

Sample Output 3

4
D - Concentric Circles

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

配点 : 425

問題文

xy 平面上に以下の条件を全て満たす 2 個の円 C_1, C_2 は存在しますか? ただし C_1, C_2 は同一である可能性があります。

  • 異なる 2(P_x, P_y), (Q_x, Q_y)C_1 の円周上にある。
  • 異なる 2(R_x, R_y), (S_x, S_y)C_2 の円周上にある。
  • C_1C_2 は中心が一致する。

T 個のテストケースが与えられるので、それぞれについて答えを求めてください。

制約

  • 1 \leq T \leq 5 \times 10^4
  • -10^9 \leq P_x,P_y,Q_x,Q_y,R_x,R_y,S_x,S_y \leq 10^9
  • (P_x, P_y) \neq (Q_x, Q_y)
  • (R_x, R_y) \neq (S_x, S_y)
  • 入力される値は全て整数

入力

入力は以下の形式で標準入力から与えられる。

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

各テストケース \mathrm{case}_t は以下の形式で与えられる。

P_x P_y Q_x Q_y R_x R_y S_x S_y

出力

T 行出力せよ。t 行目には t 番目のテストケースの答えを出力せよ。
各テストケースでは、条件を全て満たす 2 個の円 C_1, C_2 が存在する場合は Yes を、存在しない場合は No を出力せよ。


入力例 1

3
2 0 1 1 -1 0 1 2
1 0 -1 0 0 1 0 -1
4 0 3 1 2 0 1 1

出力例 1

Yes
Yes
No

1 番目のテストケースを考えます。以下の図に示す通り、中心が (1,0) で半径が 1 の円を C_1、中心が (1,0) で半径が 2 の円を C_2 とすると条件を満たします。

2 番目のテストケースでは、C_1C_2 をともに中心が (0,0) で半径が 1 の円とすると条件を満たします。

image

Score : 425 points

Problem Statement

Do there exist two circles C_1 and C_2 on the xy-plane satisfying all of the following conditions? Here, C_1 and C_2 may coincide.

  • The two distinct points (P_x, P_y) and (Q_x, Q_y) lie on the circumference of C_1.
  • The two distinct points (R_x, R_y) and (S_x, S_y) lie on the circumference of C_2.
  • C_1 and C_2 have the same center.

You are given T test cases; solve each of them.

Constraints

  • 1 \leq T \leq 5 \times 10^4
  • -10^9 \leq P_x,P_y,Q_x,Q_y,R_x,R_y,S_x,S_y \leq 10^9
  • (P_x, P_y) \neq (Q_x, Q_y)
  • (R_x, R_y) \neq (S_x, S_y)
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

Each test case \mathrm{case}_t is given in the following format:

P_x P_y Q_x Q_y R_x R_y S_x S_y

Output

Output T lines. The t-th line should contain the answer to the t-th test case.
For each test case, output Yes if there exist two circles C_1 and C_2 satisfying all of the conditions, and No otherwise.


Sample Input 1

3
2 0 1 1 -1 0 1 2
1 0 -1 0 0 1 0 -1
4 0 3 1 2 0 1 1

Sample Output 1

Yes
Yes
No

Consider the first test case. As shown in the figure below, if we let C_1 be the circle with center (1,0) and radius 1, and C_2 be the circle with center (1,0) and radius 2, the conditions are satisfied.

For the second test case, letting both C_1 and C_2 be the circle with center (0,0) and radius 1 satisfies the conditions.

image

E - Adjacent Sums (hard)

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

配点 : 450

問題文

※ E 問題の問題文は C 問題と同じです。赤字で示された制約のみが異なります。

0 以上 M-1 以下の整数からなる整数列 A=(A_1,A_2,\dots,A_N),B=(B_1,B_2,\dots,B_{N-1}) が与えられます。 A,B の長さはそれぞれ N,N-1 です。
A に対して以下の操作を好きな回数行うことができます。

  • 1 以上 N 以下の整数 i1 つ選び、A_i1 を加える。

以下の条件を満たすようにするために必要な操作回数の最小値を求めてください。
なお、問題の制約下では、必ず条件を満たすようにできることが証明できます。

  • i=1,2,\dots,N-1 について、A_i+A_{i+1}M で割った余りは B_i に等しい。

制約

  • 2 \leq N \leq 2 \times 10^5
  • 3 \leq M \leq 10^9
  • 0 \leq A_i \leq M-1
  • 0 \leq B_i \leq M-1
  • 入力される値はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N M  
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_{N-1}

出力

答えを 1 行で出力せよ。


入力例 1

3 10
4 6 7
5 5

出力例 1

5

1 回目の操作で i=2 を選ぶと、A=(4,7,7) となります。
2 回目の操作で i=1 を選ぶと、A=(5,7,7) となります。
3 回目の操作で i=1 を選ぶと、A=(6,7,7) となります。
4 回目の操作で i=2 を選ぶと、A=(6,8,7) となります。
5 回目の操作で i=1 を選ぶと、A=(7,8,7) となります。
A_1+A_2=7+8=15,\;A_2+A_3=8+7=15 なので、条件を満たします。
また、4 回以下の操作で条件を満たすようにはできないため、答えは 5 です。


入力例 2

2 3
1 2
2

出力例 2

2

入力例 3

10 10
0 1 2 3 4 5 6 7 8 9
9 8 7 6 5 4 3 2 1

出力例 3

40

Score : 450 points

Problem Statement

The problem statement of Problem E is the same as Problem C. Only the constraint shown in red differ.

You are given integer sequences A=(A_1,A_2,\dots,A_N) and B=(B_1,B_2,\dots,B_{N-1}) consisting of integers between 0 and M-1, inclusive. The lengths of A and B are N and N-1, respectively.
You can perform the following operation on A any number of times.

  • Choose an integer i with 1 \leq i \leq N, and add 1 to A_i.

Find the minimum number of operations required to satisfy the following condition.
It can be proved that the condition can always be satisfied under the constraints of this problem.

  • For i=1,2,\dots,N-1, the remainder when A_i+A_{i+1} is divided by M equals B_i.

Constraints

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

Input

The input is given from Standard Input in the following format:

N M  
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_{N-1}

Output

Output the answer on one line.


Sample Input 1

3 10
4 6 7
5 5

Sample Output 1

5

If we choose i=2 for the first operation, we get A=(4,7,7).
If we choose i=1 for the second operation, we get A=(5,7,7).
If we choose i=1 for the third operation, we get A=(6,7,7).
If we choose i=2 for the fourth operation, we get A=(6,8,7).
If we choose i=1 for the fifth operation, we get A=(7,8,7).
Since A_1+A_2=7+8=15 and A_2+A_3=8+7=15, the condition is satisfied.
The condition cannot be satisfied with four or fewer operations, so the answer is 5.


Sample Input 2

2 3
1 2
2

Sample Output 2

2

Sample Input 3

10 10
0 1 2 3 4 5 6 7 8 9
9 8 7 6 5 4 3 2 1

Sample Output 3

40
F - Email Scheduling Optimization

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

配点 : 525

問題文

長さ N の正整数列 A=(A_1,A_2,\dots,A_N),\;B=(B_1,B_2,\dots,B_N) が与えられます。
Q 個のクエリが与えられます。
各クエリは以下の 2 種類のいずれかです。

  • 1 i x : A_ix に変更する。
  • 2 i x : B_ix に変更する。

各クエリを処理するたびに、以下の問題の答えを求めてください。

高橋君は N 個の会社にメールを送り、それぞれの会社から返信をもらう必要があります。
j 個目の会社に送るメールを書くには A_j 分の時間を要し、送ってから B_j 分後に返信が届きます。
高橋君は時刻 0 からメールを書き始めます。
高橋君は N 通のメールを好きな順番で書くことができますが、2 通以上のメールを同時に書くことはできません。
高橋君がすべての返信を受け取り終える時刻としてあり得る最小値を求めてください。
ただし、メールを送るのにかかる時間は無視できるものとします。

制約

  • 1 \leq N \leq 10^5
  • 1 \leq Q \leq 10^5
  • 1 \leq A_j,B_j \leq 10^9
  • 各クエリにおいて、1 \leq i \leq N
  • 各クエリにおいて、1 \leq x \leq 10^9
  • 入力される値はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N Q  
A_1 A_2 \ldots A_N  
B_1 B_2 \ldots B_N  
\mathrm{query}_1  
\mathrm{query}_2  
\vdots  
\mathrm{query}_Q  

各クエリ \mathrm{query}_q では、クエリの種類(12)と ix がこの順に空白区切りで与えられる。
すなわち、各クエリは以下の 2 つの形式のいずれかである。

1 i x  
2 i x  

出力

答えを合計 Q 行で出力せよ。 q 行目には、q 番目のクエリを処理した後の問題の答えを出力せよ。


入力例 1

3 3
4 6 7
4 6 7
1 2 1
2 3 7
2 3 1

出力例 1

16
16
13

最初のクエリを行った後、A=(4,1,7), \; B=(4,6,7) です。
時刻 0 に会社 3 に送るメールを書き始め、時刻 7 に書き終えて会社 3 にメールを送ると、時刻 14 に返信を受け取ります。
時刻 7 に会社 2 に送るメールを書き始め、時刻 8 に書き終えて会社 2 にメールを送ると、時刻 14 に返信を受け取ります。
時刻 8 に会社 1 に送るメールを書き始め、時刻 12 に書き終えて会社 1 にメールを送ると、時刻 16 に返信を受け取ります。

Score : 525 points

Problem Statement

You are given length-N sequences of positive integers A=(A_1,A_2,\dots,A_N) and B=(B_1,B_2,\dots,B_N).
You are given Q queries.
Each query is of one of the following two types.

  • 1 i x : Change A_i to x.
  • 2 i x : Change B_i to x.

After processing each query, solve the following problem.

Takahashi needs to send an email to each of N companies and receive a reply from each of them.
Writing the email to send to the j-th company takes A_j minutes, and the reply arrives B_j minutes after it is sent.
He starts writing emails at time 0.
He can write the N emails in any order he likes, but he cannot write two or more emails simultaneously.
Find the minimum possible time at which he finishes receiving all of the replies.
Assume that the time taken to send emails is negligible.

Constraints

  • 1 \leq N \leq 10^5
  • 1 \leq Q \leq 10^5
  • 1 \leq A_j,B_j \leq 10^9
  • In each query, 1 \leq i \leq N.
  • In each query, 1 \leq x \leq 10^9.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N Q  
A_1 A_2 \ldots A_N  
B_1 B_2 \ldots B_N  
\mathrm{query}_1  
\mathrm{query}_2  
\vdots  
\mathrm{query}_Q  

For each query \mathrm{query}_q, the type of the query (1 or 2), i, and x are given in this order, separated by spaces.
That is, each query is given in one of the following two formats:

1 i x  
2 i x  

Output

Output the answers in a total of Q lines. The q-th line should contain the answer to the problem after processing the q-th query.


Sample Input 1

3 3
4 6 7
4 6 7
1 2 1
2 3 7
2 3 1

Sample Output 1

16
16
13

After processing the first query, A=(4,1,7) and B=(4,6,7).
If Takahashi starts writing the email to send to company 3 at time 0, finishes writing it at time 7, and sends it to company 3, he receives the reply at time 14.
If he starts writing the email to send to company 2 at time 7, finishes writing it at time 8, and sends it to company 2, he receives the reply at time 14.
If he starts writing the email to send to company 1 at time 8, finishes writing it at time 12, and sends it to company 1, he receives the reply at time 16.

G - Many Sweets Problem

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

配点 : 625

問題文

長さ N の正整数列 A=(A_1,A_2,\dots,A_N) があります。次のクエリを Q 回処理してください。

  • c x l r k : A_c の値を x に更新する。その後、次の小問題を解いて答えを出力する。

r-l+1 個のお菓子があります。i 個目のお菓子の美味しさは A_{l+i-1} です。
あなたは食べたお菓子の美味しさの総和が k 以上になるまでお菓子を食べることにしました。
上手く食べるお菓子を選んだ時、食べるお菓子の個数を最小で何個にすることができますか?答えを出力してください。
ただし、どのようにお菓子を食べても美味しさの総和が k 以上にならない時は -1 を出力してください。

制約

  • 1 \leq N \leq 10^5
  • 1 \leq Q \leq 10^5
  • 1 \leq A_i \leq 10^9
  • 1 \leq c \leq N
  • 1 \leq x \leq 10^9
  • 1 \leq l \leq r \leq N
  • 1 \leq k \leq 10^{15}
  • 入力される値は全て整数

入力

入力は以下の形式で標準入力から与えられる。

N Q
A_1 A_2 \dots A_N
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q

各クエリ \mathrm{query}_q は以下の形式で与えられる。

c x l r k

出力

Q 行出力せよ。q 行目には q 番目のクエリの答えを出力せよ。


入力例 1

7 5
8 2 4 1 7 3 6
1 1 4 7 9
5 2 1 3 8
6 4 1 5 9
6 5 3 5 1
7 9 4 6 4

出力例 1

2
-1
4
1
1

1 番目のクエリについて説明します。
まず、A_11 に更新します。A=(1,2,4,1,7,3,6) になります。そして小問題を解きます。
小問題ではお菓子は 4 個あり、美味しさは順に 1,7,3,6 です。
食べたお菓子の美味しさの総和が k=9 以上になるように食べるお菓子の個数を最小化するには、2 番目のお菓子と 4 番目のお菓子を食べるのが最適です。よって小問題の答えは 2 になります。


入力例 2

15 10
993115119 576136368 21553212 219853538 853822501 687675302 281611653 844033520 423210108 339630584 780395612 207907746 285523486 359061085 14767613
6 13801767 1 3 667406485
7 672229269 5 7 855399219
11 2367096 1 10 4016308479
6 5951398 8 8 413598120
6 196639646 5 11 2483790193
14 105322777 6 7 610670157
7 416730828 2 14 1236755516
9 838827476 5 14 4350335977
1 894919681 3 7 1132967029
6 932707551 6 15 1694677398

出力例 2

1
2
6
1
4
1
2
-1
2
2

Score : 625 points

Problem Statement

There is a length-N sequence of positive integers A=(A_1,A_2,\dots,A_N). Process the following query Q times.

  • c x l r k : Update the value of A_c to x. Then, solve the following sub-problem and output the answer.

There are r-l+1 sweets. The deliciousness of the i-th sweet is A_{l+i-1}.
You decide to eat sweets until the total deliciousness of the sweets eaten becomes k or more.
What is the minimum possible number of sweets you eat, if you optimally choose which sweets to eat? Output the answer.
If the total deliciousness cannot become k or more no matter how you choose the sweets to eat, output -1 instead.

Constraints

  • 1 \leq N \leq 10^5
  • 1 \leq Q \leq 10^5
  • 1 \leq A_i \leq 10^9
  • 1 \leq c \leq N
  • 1 \leq x \leq 10^9
  • 1 \leq l \leq r \leq N
  • 1 \leq k \leq 10^{15}
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N Q
A_1 A_2 \dots A_N
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q

Each query \mathrm{query}_q is given in the following format:

c x l r k

Output

Output Q lines. The q-th line should contain the answer to the q-th query.


Sample Input 1

7 5
8 2 4 1 7 3 6
1 1 4 7 9
5 2 1 3 8
6 4 1 5 9
6 5 3 5 1
7 9 4 6 4

Sample Output 1

2
-1
4
1
1

We explain the first query.
First, update A_1 to 1. Then, A=(1,2,4,1,7,3,6). Now, solve the sub-problem.
In the sub-problem, there are four sweets, with deliciousness 1,7,3,6 in order.
To minimize the number of sweets eaten so that the total deliciousness becomes k=9 or more, it is optimal to eat the second and fourth sweets. Thus, the answer to the sub-problem is 2.


Sample Input 2

15 10
993115119 576136368 21553212 219853538 853822501 687675302 281611653 844033520 423210108 339630584 780395612 207907746 285523486 359061085 14767613
6 13801767 1 3 667406485
7 672229269 5 7 855399219
11 2367096 1 10 4016308479
6 5951398 8 8 413598120
6 196639646 5 11 2483790193
14 105322777 6 7 610670157
7 416730828 2 14 1236755516
9 838827476 5 14 4350335977
1 894919681 3 7 1132967029
6 932707551 6 15 1694677398

Sample Output 2

1
2
6
1
4
1
2
-1
2
2