A - When?

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

AtCoder Beginner Contest は通常、日本標準時で 21 時ちょうどに始まり 100 分間にわたって行われます。

0 以上 100 以下の整数 K が与えられます。21 時ちょうどから K 分後の時刻を HH:MM の形式で出力してください。ただし、HH24 時間制での時間を、MM は分を表します。時間または分が 1 桁のときは、先頭に 0 を追加して 2 桁の整数として表してください。

制約

  • K0 以上 100 以下の整数

入力

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

K

出力

21 時ちょうどから K 分後の時刻を問題文中の形式に従って出力せよ。


入力例 1

63

出力例 1

22:03

21 時ちょうどから 63 分後の時刻は 223 分なので、22:03 と出力します。

以下のような出力は不正解となります。

  • 10:03
  • 22:3

入力例 2

45

出力例 2

21:45

入力例 3

100

出力例 3

22:40

Score : 100 points

Problem Statement

AtCoder Beginner Contest usually starts at 21:00 JST and lasts for 100 minutes.

You are given an integer K between 0 and 100 (inclusive). Print the time K minutes after 21:00 in the HH:MM format, where HH denotes the hour on the 24-hour clock and MM denotes the minute. If the hour or the minute has just one digit, append a 0 to the beginning to represent it as a 2-digit integer.

Constraints

  • K is an integer between 0 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

K

Output

Print the time K minutes after 21:00 in the format specified in the Problem Statement.


Sample Input 1

63

Sample Output 1

22:03

63 minutes after 21:00, it will be 22:03, so 22:03 should be printed.

The following outputs would be judged incorrect:

  • 10:03
  • 22:3

Sample Input 2

45

Sample Output 2

21:45

Sample Input 3

100

Sample Output 3

22:40
B - Number Box

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

正整数 N が与えられます。

NN 列のマス目があり、上から i 行目、左から j 列目のマスには数字 A_{i,j} が書かれています。

このマス目は上下および左右がつながっているものとします。つまり以下が全て成り立ちます。

  • (1,i) の上のマスは (N,i) であり、(N,i) の下のマスは (1,i) である。(1\le i\le N)
  • (i,1) の左のマスは (i,N) であり、(i,N) の右のマスは (i,1) である。(1\le i\le N)

高橋君は、上下左右および斜めの 8 方向のうちいずれかを初めに選びます。そして、好きなマスから決めた方向に 1 マス移動することを N-1 回繰り返します。

高橋君は N 個のマス上を移動することになりますが、高橋君が通ったマスに書かれている数字を左から通った順番に並べた整数としてあり得る最大のものを求めてください。

制約

  • 1 \le N \le 10
  • 1 \le A_{i,j} \le 9
  • 入力はすべて整数。

入力

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

N
A_{1,1}A_{1,2}\dots A_{1,N}
A_{2,1}A_{2,2}\dots A_{2,N}
\vdots
A_{N,1}A_{N,2}\dots A_{N,N}

出力

答えを出力せよ。


入力例 1

4
1161
1119
7111
1811

出力例 1

9786

高橋君が上から 2 行目、左から 4 列目のマスから出発し、右下に進むことで、通ったマスに書かれた数字を並べ 9786 を作ることができます。 9786 より大きい値を作ることはできないため、9786 が解です。


入力例 2

10
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111

出力例 2

1111111111

32bit整数型に答えが収まるとは限らないことに注意してください。

Score : 200 points

Problem Statement

You are given a positive integer N.

We have a grid with N rows and N columns, where the square at the i-th row from the top and j-th column from the left has a digit A_{i,j} written on it.

Assume that the upper and lower edges of this grid are connected, as well as the left and right edges. In other words, all of the following holds.

  • (N,i) is just above (1,i), and (1,i) is just below (N,i). (1\le i\le N).
  • (i,N) is just to the left of (i,1), and (i,1) is just to the right of (i,N). (1\le i\le N).

Takahashi will first choose one of the following eight directions: up, down, left, right, and the four diagonal directions. Then, he will start on a square of his choice and repeat moving one square in the chosen direction N-1 times.

In this process, Takahashi visits N squares. Find the greatest possible value of the integer that is obtained by arranging the digits written on the squares visited by Takahashi from left to right in the order visited by him.

Constraints

  • 1 \le N \le 10
  • 1 \le A_{i,j} \le 9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_{1,1}A_{1,2}\dots A_{1,N}
A_{2,1}A_{2,2}\dots A_{2,N}
\vdots
A_{N,1}A_{N,2}\dots A_{N,N}

Output

Print the answer.


Sample Input 1

4
1161
1119
7111
1811

Sample Output 1

9786

If Takahashi starts on the square at the 2-nd row from the top and 4-th column from the left and goes down and to the right, the integer obtained by arranging the digits written on the visited squares will be 9786. It is impossible to make a value greater than 9786, so the answer is 9786.


Sample Input 2

10
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111

Sample Output 2

1111111111

Note that the answer may not fit into a 32-bit integer.

C - Rotation

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300

問題文

正整数 N,Q と、長さ N の英小文字からなる文字列 S が与えられます。

以下で説明されるクエリを Q 個処理してください。クエリは次の 2 種類のいずれかです。

  • 1 x: 「S の末尾の文字を削除し、先頭に挿入する」という操作を x 回連続で行う。
  • 2 x: Sx 番目の文字を出力する。

制約

  • 2 \le N \le 5 \times 10^5
  • 1 \le Q \le 5 \times 10^5
  • 1 \le x \le N
  • |S|=N
  • S は英小文字からなる。
  • 2 x の形式のクエリが 1 個以上与えられる。
  • N,Q,x はすべて整数。

入力

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

N Q
S
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q

それぞれのクエリは以下の形式で与えられる。ここで、t1 または 2 である。

t x

出力

2 x の形式の各クエリについて、答えを一行に出力せよ。


入力例 1

3 3
abc
2 2
1 1
2 2

出力例 1

b
a

1 個目のクエリのとき、Sabc なので 2 文字目の b を出力します。 2 個目のクエリのとき、Sabc から cab に変わります。 3 個目のクエリのとき、Scab なので 2 文字目の a を出力します。


入力例 2

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

出力例 2

c
u
c
u

Score : 300 points

Problem Statement

You are given positive integers N and Q, and a string S of length N consisting of lowercase English letters.

Process Q queries. Each query is of one of the following two types.

  • 1 x: Perform the following x times in a row: delete the last character of S and append it to the beginning.
  • 2 x: Print the x-th character of S.

Constraints

  • 2 \le N \le 5 \times 10^5
  • 1 \le Q \le 5 \times 10^5
  • 1 \le x \le N
  • |S|=N
  • S consists of lowercase English letters.
  • At least one query in the format 2 x.
  • N, Q, x are all integers.

Input

Input is given from Standard Input in the following format:

N Q
S
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q

Each query is in the following format, where t is 1 or 2:

t x

Output

For each query in the format 2 x, print the answer in a single line.


Sample Input 1

3 3
abc
2 2
1 1
2 2

Sample Output 1

b
a

In the 1-st query, S is abc, so the 2-nd character b should be printed. In the 2-nd query, S is changed from abc to cab. In the 3-rd query, S is cab, so the 2-nd character a should be printed.


Sample Input 2

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

Sample Output 2

c
u
c
u
D - Trophy

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

N 個のステージからなるゲームがあり、i \, (1 \leq i \leq N) 番目のステージは A_i 分間のストーリー映像と B_i 分間のゲームプレイによって構成されます。

初めて i 番目のステージをクリアするためにはストーリー映像の視聴とゲームプレイを両方行う必要がありますが、二回目以降はストーリー映像をスキップすることができるので、ゲームプレイのみでクリアすることができます。

初めから遊べるのは 1 番目のステージのみですが、i \, (1 \leq i \leq N - 1) 番目のステージをクリアすることにより、i+1 番目のステージも遊べるようになります。

合計 X 回ステージをクリアするために必要な時間の最小値を求めてください。ただし、同じステージを複数回クリアしたとしても、全てクリア回数に数えられます。

制約

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq A_i, B_i \leq 10^9 \, (1 \leq i \leq N)
  • 1 \leq X \leq 10^9
  • 入力は全て整数

入力

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

N X
A_1 B_1
\vdots
A_N B_N

出力

答えを出力せよ。


入力例 1

3 4
3 4
2 3
4 2

出力例 1

18

例えば、次のようにして 18 分で 4 回クリアすることができます。

  • ステージ 1 をクリアする。A_1 + B_1 = 7 分かかる。
  • ステージ 2 をクリアする。A_2 + B_2 = 5 分かかる。
  • ステージ 2 を再びクリアする。B_2 = 3 分かかる。
  • ステージ 2 を再びクリアする。B_2 = 3 分かかる。

17 分以内に 4 回クリアすることはできません。


入力例 2

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

出力例 2

1000000076

Score : 400 points

Problem Statement

We have a video game consisting of N stages. The i-th stage (1 \leq i \leq N) is composed of a movie lasting A_i minutes and gameplay lasting B_i minutes.

To clear the i-th stage for the first time, one must watch the movie and do the gameplay for that stage. For the second and subsequent times, one may skip the movie and do just the gameplay.

In the beginning, only the 1-st stage is unlocked, and clearing the i-th stage (1 \leq i \leq N - 1) unlocks the (i+1)-th stage.

Find the shortest time needed to clear a stage X times in total. Here, if the same stage is cleared multiple times, all of them count.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • 1 \leq A_i, B_i \leq 10^9 \, (1 \leq i \leq N)
  • 1 \leq X \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N X
A_1 B_1
\vdots
A_N B_N

Output

Print the answer.


Sample Input 1

3 4
3 4
2 3
4 2

Sample Output 1

18

Here is one way to clear a stage 4 times in 18 minutes:

  • Clear Stage 1. It takes A_1 + B_1 = 7 minutes.
  • Clear Stage 2. It takes A_2 + B_2 = 5 minutes.
  • Clear Stage 2 again. It takes B_2= 3 minutes.
  • Clear Stage 2 again. It takes B_2= 3 minutes.

It is impossible to clear a stage 4 times within 17 minutes.


Sample Input 2

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

Sample Output 2

1000000076
E - Packing Potatoes

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

ベルトコンベアに載って 10^{100} 個のじゃがいもが 1 個ずつ流れてきます。流れてくるじゃがいもの重さは長さ N の数列 W = (W_0, \dots, W_{N-1}) で表され、i \, (1 \leq i \leq 10^{100}) 番目に流れてくるじゃがいもの重さは W_{(i-1) \bmod N} です。ここで、(i-1) \bmod Ni - 1N で割った余りを表します。

高橋君は、まず空の箱を用意し、次のルールに従ってじゃがいもを順番に箱に詰めていきます。

  • じゃがいもを箱に入れる。箱に入っているじゃがいもの重さの総和が X 以上になったら、その箱には蓋をし、新たに空の箱を用意する。

Q 個のクエリが与えられます。i \, (1 \leq i \leq Q) 番目のクエリでは、正整数 K_i が与えられるので、K_i 番目に蓋をされた箱に入っているじゃがいもの個数を求めてください。問題の制約下で、蓋をされた箱が K_i 個以上存在することが証明できます。

制約

  • 1 \leq N, Q \leq 2 \times 10^5
  • 1 \leq X \leq 10^9
  • 1 \leq W_i \leq 10^9 \, (0 \leq i \leq N - 1)
  • 1 \leq K_i \leq 10^{12} \, (1 \leq i \leq Q)
  • 入力は全て整数

入力

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

N Q X
W_0 W_1 \ldots W_{N-1}
K_1
\vdots
K_Q

出力

Q 行出力せよ。i \, (1 \leq i \leq Q) 行目には、i 番目のクエリへの答えを出力せよ。


入力例 1

3 2 5
3 4 1
1
2

出力例 1

2
3

2 つの箱に蓋をするまでの高橋くんの行動は以下の通りです。

  • 空の箱を用意する。
  • 1 番目のじゃがいもを箱に入れる。箱に入っているじゃがいもの重さの総和は 3 である。
  • 2 番目のじゃがいもを箱に入れる。箱に入っているじゃがいもの重さの総和は 3 + 4 = 7 であり、X = 5 以上になったのでこの箱には蓋をする。
  • 新たに空の箱を用意する。
  • 3 番目のじゃがいもを箱に入れる。箱に入っているじゃがいもの重さの総和は 1 である。
  • 4 番目のじゃがいもを箱に入れる。箱に入っているじゃがいもの重さの総和は 1 + 3 = 4 である。
  • 5 番目のじゃがいもを箱に入れる。箱に入っているじゃがいもの重さの総和は 1 + 3 + 4 = 8 であり、X = 5 以上になったのでこの箱には蓋をする。

1 番目に蓋をされた箱には 2 つのじゃがいもが入っており、2 番目に蓋をされた箱には 3 つのじゃがいもが入っています。


入力例 2

10 5 20
5 8 5 9 8 7 4 4 8 2
1
1000
1000000
1000000000
1000000000000

出力例 2

4
5
5
5
5

Score : 500 points

Problem Statement

10^{100} potatoes are coming from a conveyor belt one by one. The weights of the potatoes are described by a sequence W = (W_0, \dots, W_{N-1}) of length N: the weight of the i-th potato coming is W_{(i-1) \bmod N}, where (i-1) \bmod N denotes the remainder when i - 1 is divided by N.

Takahashi will prepare an empty box and then pack the potatoes in order, as follows.

  • Pack the incoming potato into the box. If the total weight of the potatoes in the box is now X or greater, seal that box and prepare a new empty box.

You are given Q queries. In the i-th query (1 \leq i \leq Q), given a positive integer K_i, find the number of potatoes in the K_i-th box to be sealed. It can be proved that, under the Constraints of the problem, there will be at least K_i sealed boxes.

Constraints

  • 1 \leq N, Q \leq 2 \times 10^5
  • 1 \leq X \leq 10^9
  • 1 \leq W_i \leq 10^9 \, (0 \leq i \leq N - 1)
  • 1 \leq K_i \leq 10^{12} \, (1 \leq i \leq Q)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N Q X
W_0 W_1 \ldots W_{N-1}
K_1
\vdots
K_Q

Output

Print Q lines. The i-th line (1 \leq i \leq Q) should contain the answer to the i-th query.


Sample Input 1

3 2 5
3 4 1
1
2

Sample Output 1

2
3

Before sealing the 2-nd box, Takahashi will do the following:

  • Prepare an empty box.
  • Pack the 1-st potato into the box. Now, the total weight of potatoes in the box is 3.
  • Pack the 2-nd potato into the box. Now, the total weight of potatoes in the box is 3 + 4 = 7, which is not less than X = 5, so seal this box.
  • Prepare a new empty box.
  • Pack the 3-rd potato into the box. Now, the total weight of potatoes in the box is 1.
  • Pack the 4-th potato into the box. Now, the total weight of potatoes in the box is 1 + 3 = 4.
  • Pack the 5-th potato into the box. Now, the total weight of potatoes in the box is 1 + 3 + 4 = 8, which is not less than X = 5, so seal this box.

The 1-st box sealed contains 2 potatoes, and the 2-nd box sealed contains 3 potatoes.


Sample Input 2

10 5 20
5 8 5 9 8 7 4 4 8 2
1
1000
1000000
1000000000
1000000000000

Sample Output 2

4
5
5
5
5
F - Main Street

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 500

問題文

xy 平面上にある AtCoder 王国の道路は、全ての整数 n に対する直線 x=n および直線 y=n からなります。 そのうち、全ての整数 n に対する直線 x=Bn および直線 y=Bn は大通りです。

高橋君は (x,y) にいるときに、(x,y-1),(x,y+1),(x+1,y),(x-1,y) のいずれかに移動することができます。 また、1 回の移動につき、大通りに沿って移動する場合は 1 秒、それ以外の場合は K 秒かかります。

(S_x,S_y) にいる高橋君が (G_x,G_y) に移動するのに最短で何秒かかるかを求めてください。

この問題は T ケース与えられます。

制約

  • 1 \le T \le 2 \times 10^5
  • 1 \le B,K \le 10^9
  • 0 \le S_x,S_y,G_x,G_y \le 10^9
  • 入力はすべて整数。

入力

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

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

それぞれのテストケースは以下の形式で与えられる。

B K S_x S_y G_x G_y

出力

T 行出力せよ。i 行目には i 個目のテストケースの解を出力せよ。


入力例 1

4
3 4 2 2 4 4
5 6 2 3 2 3
1 1000000000 0 0 1000000000 1000000000
1000000000 1000000000 500000000 500000000 1000000000 1000000000

出力例 1

10
0
2000000000
500000000500000000

1 個目のテストケースについて、(2,2) から (2,3)4 秒かけて移動し、(2,3) から (4,3)2 秒かけて移動し、(4,3) から (4,4)4 秒かけて移動することで 10 秒で (2,2) から (4,4) に移動することができます。10 秒より早く移動することはできないため、解は 10 です。
2 個目のテストケースについて、初めから (G_x,G_y) にいるため解は 0 です。


入力例 2

10
928184439 674654465 203937094 186855052 851783856 805293696
55480262 448852233 823161539 786348805 550018803 322680316
891870741 235679524 32164572 497841190 620600021 96487871
321502816 428964257 499656016 521484999 717623189 824784374
144040837 680268887 76238777 371138006 350230937 78690135
768922620 799628518 403830696 60449731 218880692 88319939
482031503 121412614 472330444 284479575 949635609 427232765
389524418 132987043 656496997 678732442 23028233 488463974
857778764 629964237 714551548 739330018 579247790 874251485
461612428 535402609 555160129 833592114 44418273 287363785

出力例 2

177606591118701316
6205925075792263
30320747646118343
84136273267803188
83764071874751489
118960470930399064
2929499649126153
16403238161749820
84995699148879437
71771264361119335

Score : 500 points

Problem Statement

The roads in the Kingdom of AtCoder, which lies on the xy-plane, are the lines x=n and y=n for all integers n. Among them, the lines x=Bn and y=Bn for all integers n are main roads.

When Takahashi is at (x,y), he can move to (x,y-1), (x,y+1), (x+1,y), or (x-1,y). Each move takes 1 second along a main road and K seconds otherwise.

Find the minimum number of seconds Takahashi needs to get from (S_x, S_y) to (G_x, G_y).

You will have T test cases to solve.

Constraints

  • 1 \le T \le 2 \times 10^5
  • 1 \le B,K \le 10^9
  • 0 \le S_x,S_y,G_x,G_y \le 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

Each test case is in the following format:

B K S_x S_y G_x G_y

Output

Print T lines. The i-th line should contain the answer to the i-th test case.


Sample Input 1

4
3 4 2 2 4 4
5 6 2 3 2 3
1 1000000000 0 0 1000000000 1000000000
1000000000 1000000000 500000000 500000000 1000000000 1000000000

Sample Output 1

10
0
2000000000
500000000500000000

For the 1-st test case, he can go from (2,2) to (2,3) in 4 seconds, from (2,3) to (4,3) in 2 seconds, and from (4,3) to (4,4) in 4 seconds to get from (2,2) to (4,4) in 10 seconds. It is impossible to get there in less than 10 seconds, so the answer is 10.
For the 2-nd test case, he is already at (G_x, G_y) in the beginning, so the answer is 0.


Sample Input 2

10
928184439 674654465 203937094 186855052 851783856 805293696
55480262 448852233 823161539 786348805 550018803 322680316
891870741 235679524 32164572 497841190 620600021 96487871
321502816 428964257 499656016 521484999 717623189 824784374
144040837 680268887 76238777 371138006 350230937 78690135
768922620 799628518 403830696 60449731 218880692 88319939
482031503 121412614 472330444 284479575 949635609 427232765
389524418 132987043 656496997 678732442 23028233 488463974
857778764 629964237 714551548 739330018 579247790 874251485
461612428 535402609 555160129 833592114 44418273 287363785

Sample Output 2

177606591118701316
6205925075792263
30320747646118343
84136273267803188
83764071874751489
118960470930399064
2929499649126153
16403238161749820
84995699148879437
71771264361119335
G - Triangle

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 600

問題文

N 頂点単純無向グラフ G が与えられます。

GNN 列の隣接行列 A によって与えられます。つまり、A_{i,j}1 である場合は頂点 i,j 間に辺があることを、0 である場合には辺がないことを意味します。

1 \le i < j < k \le N を満たす整数の組 (i,j,k) のうち、頂点 i,j 間にも頂点 j,k 間にも頂点 i,k 間にも辺があるようなものの個数を求めてください。

制約

  • 3 \le N \le 3000
  • A は単純無向グラフ G の隣接行列である。
  • 入力はすべて整数。

入力

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

N
A_{1,1}A_{1,2}\dots A_{1,N}
A_{2,1}A_{2,2}\dots A_{2,N}
\vdots
A_{N,1}A_{N,2}\dots A_{N,N}

出力

答えを出力せよ。


入力例 1

4
0011
0011
1101
1110

出力例 1

2

(i,j,k)=(1,3,4),(2,3,4) が条件を満たします。

(i,j,k)=(1,2,3) は、頂点 1,2 間に辺がないため条件を満たしません。

よって、解は 2 です。


入力例 2

10
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000

出力例 2

0

Score : 600 points

Problem Statement

You are given a simple undirected graph G with N vertices.

G is given as the N \times N adjacency matrix A. That is, there is an edge between Vertices i and j if A_{i,j} is 1, and there is not if A_{i,j} is 0.

Find the number of triples of integers (i,j,k) satisfying 1 \le i < j < k \le N such that there is an edge between Vertices i and j, an edge between Vertices j and k, and an edge between Vertices i and k.

Constraints

  • 3 \le N \le 3000
  • A is the adjacency matrix of a simple undirected graph G.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_{1,1}A_{1,2}\dots A_{1,N}
A_{2,1}A_{2,2}\dots A_{2,N}
\vdots
A_{N,1}A_{N,2}\dots A_{N,N}

Output

Print the answer.


Sample Input 1

4
0011
0011
1101
1110

Sample Output 1

2

(i,j,k)=(1,3,4),(2,3,4) satisfy the condition.

(i,j,k)=(1,2,3) does not satisfy the condition, because there is no edge between Vertices 1 and 2.

Thus, the answer is 2.


Sample Input 2

10
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000
0000000000

Sample Output 2

0
Ex - Odd Steps

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 600

問題文

以下の条件を全て満たす数列 X の総数を 998244353 で割った余りを求めてください。

  • X の全ての項は正の奇数である。
  • X の各項の総和は S に等しい。
  • X の累積和には A_1, \dots, A_N のいずれも現れない。厳密には、各 i \, (1 \leq i \leq |X|) に対して Y_i = X_1 + \dots + X_i と定めたとき、1 \leq i \leq |X|, 1 \leq j \leq N を満たす全ての整数 i, j に対して Y_i \neq A_j が成り立つ。

制約

  • 1 \leq N \leq 10^5
  • 1 \leq A_1 \lt A_2 \lt \dots \lt A_N \lt S \leq 10^{18}
  • 入力は全て整数

入力

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

N S
A_1 \ldots A_N

出力

答えを出力せよ。


入力例 1

3 7
2 4 5

出力例 1

3

以下の 3 通りが条件を満たします。

  • (1, 5, 1)
  • (3, 3, 1)
  • (7)

入力例 2

5 60
10 20 30 40 50

出力例 2

37634180

入力例 3

10 1000000000000000000
1 2 4 8 16 32 64 128 256 512

出力例 3

75326268

Score : 600 points

Problem Statement

Find the number, modulo 998244353, of sequences X that satisfy all of the following conditions.

  • Every term in X is a positive odd number.
  • The sum of the terms in X is S.
  • The prefix sums of X contain none of A_1, \dots, A_N. Formally, if we define Y_i = X_1 + \dots + X_i for each i, then Y_i \neq A_j holds for all integers i and j such that 1 \leq i \leq |X| and 1 \leq j \leq N.

Constraints

  • 1 \leq N \leq 10^5
  • 1 \leq A_1 \lt A_2 \lt \dots \lt A_N \lt S \leq 10^{18}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N S
A_1 \ldots A_N

Output

Print the answer.


Sample Input 1

3 7
2 4 5

Sample Output 1

3

The following three sequences satisfy the conditions.

  • (1, 5, 1)
  • (3, 3, 1)
  • (7)

Sample Input 2

5 60
10 20 30 40 50

Sample Output 2

37634180

Sample Input 3

10 1000000000000000000
1 2 4 8 16 32 64 128 256 512

Sample Output 3

75326268