A - o-padding

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 100

問題文

整数 N および、英小文字からなる長さが N 未満 の文字列 S が与えられます。

長さが N になるまで S の先頭に英小文字 o を追加し続けることで得られる文字列を出力してください。

制約

  • 2\leq N \leq 100
  • N は整数
  • S は長さ 1 以上 N 未満の英小文字からなる文字列

入力

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

N
S

出力

答えを出力せよ。


入力例 1

5
abc

出力例 1

ooabc

N=5S の長さは 3 であるため、S の先頭に o5-3=2 個追加した文字列が答えとなります。


入力例 2

2
o

出力例 2

oo

入力例 3

12
vgxgpuam

出力例 3

oooovgxgpuam

Score : 100 points

Problem Statement

You are given an integer N and a string S consisting of lowercase English letters with length less than N.

Print the string obtained by repeatedly adding the lowercase English letter o to the beginning of S until its length becomes N.

Constraints

  • 2\leq N \leq 100
  • N is an integer.
  • S is a string consisting of lowercase English letters with length between 1 and N - 1, inclusive.

Input

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

N
S

Output

Print the answer.


Sample Input 1

5
abc

Sample Output 1

ooabc

Since N=5 and the length of S is 3, the answer is the string obtained by adding 5-3=2 os to the beginning of S.


Sample Input 2

2
o

Sample Output 2

oo

Sample Input 3

12
vgxgpuam

Sample Output 3

oooovgxgpuam
B - Magic Square

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 200

問題文

3 以上の奇数 N が与えられます。

NN 列のマス目があり、はじめどのマスも空白です。 今から、以下の手順に従ってこのマス目の各マスに整数を書き込みます。 なお、上から i+1 行目、左から j+1 列目 (0\leq i<N, 0\leq j<N) のマスを (i,j) と表記することとします。

  1. マス (0,\frac{N-1}{2})1 を書き込む。
  2. 次の操作を N^2-1 回繰り返す。
    • 前回整数を書き込んだマスを (r,c)、書き込んだ整数を k としたとき、マス ((r-1) \bmod N, (c+1) \bmod N) が空白ならばそのマスに、そうでなければマス ((r+1) \bmod N,c)k+1 を書き込む。 ここで、x \bmod NxN で割ったあまりを表す。

この手順においてそれぞれのマスに書き込まれる整数を求めてください。 なお、どのマスもちょうど 1 回だけ整数を書き込まれることが証明できます。

制約

  • 3\leq N \leq 99
  • N は奇数

入力

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

N

出力

マス (i,j) に書き込まれる整数を a_{i,j} として、以下の形式で出力せよ。

a_{0,0} a_{0,1} \dots a_{0,N-1}
\vdots
a_{N-1,0} a_{N-1,1} \dots a_{N-1,N-1}

入力例 1

3

出力例 1

8 1 6
3 5 7
4 9 2

以下のように各マスに整数が書き込まれていきます。

  1. マス (0,\frac{3-1}{2})=(0,1)1 を書き込む。
  2. マス ((0-1) \bmod 3, (1+1) \bmod 3)=(2,2) は空白なので、そこに 2 を書き込む。
  3. マス ((2-1) \bmod 3, (2+1) \bmod 3)=(1,0) は空白なので、そこに 3 を書き込む。
  4. マス ((1-1) \bmod 3, (0+1) \bmod 3)=(0,1) は空白ではないので、マス ((1+1) \bmod 3,0)=(2,0)4 を書き込む。
  5. \vdots

入力例 2

5

出力例 2

17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9

Score : 200 points

Problem Statement

You are given an odd number N that is at least 3.

There is a grid with N rows and N columns, where all cells are initially empty. Now, you will write integers in each cell of this grid according to the following procedure. Let (i,j) denote the cell at the (i+1)-th row from the top and (j+1)-th column from the left (0\leq i<N, 0\leq j<N).

  1. Write 1 in cell (0,\frac{N-1}{2}).
  2. Repeat the following operation N^2-1 times:
    • Let (r,c) be the cell where an integer was written last time, and k be the integer written. If cell ((r-1) \bmod N, (c+1) \bmod N) is empty, write k+1 in that cell; otherwise, write k+1 in cell ((r+1) \bmod N,c). Here, x \bmod N denotes the remainder when x is divided by N.

Find the integer that will be written in each cell in this procedure. It can be proved that each cell will have an integer written in it exactly once.

Constraints

  • 3\leq N \leq 99
  • N is an odd number.

Input

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

N

Output

Let a_{i,j} be the integer written in cell (i,j), and print it in the following format:

a_{0,0} a_{0,1} \dots a_{0,N-1}
\vdots
a_{N-1,0} a_{N-1,1} \dots a_{N-1,N-1}

Sample Input 1

3

Sample Output 1

8 1 6
3 5 7
4 9 2

Integers are written in each cell as follows:

  1. Write 1 in cell (0,\frac{3-1}{2})=(0,1).
  2. Cell ((0-1) \bmod 3, (1+1) \bmod 3)=(2,2) is empty, so write 2 there.
  3. Cell ((2-1) \bmod 3, (2+1) \bmod 3)=(1,0) is empty, so write 3 there.
  4. Cell ((1-1) \bmod 3, (0+1) \bmod 3)=(0,1) is not empty, so write 4 in cell ((1+1) \bmod 3,0)=(2,0).
  5. \vdots

Sample Input 2

5

Sample Output 2

17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
C - 2x2 Placing

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 300

問題文

NN 列のマス目があります。 上から i 行目、左から j 列目のマスを (i,j) と表記します。 はじめ、マス目の上には何も置かれていません。

今から M 回の操作を行います。 i 回目 (1\leq i\leq M) の操作は以下の通りです。

  • マス (R_i,C_i) を左上とする 2 \times 2 の領域を占めるブロックを、既に置かれている他のブロックと位置が重ならない場合、またその場合に限り、マス目の上に置く。 より厳密には、マス集合 S=\lbrace (R_i,C_i),(R_i+1,C_i),(R_i,C_i+1),(R_i+1,C_i+1)\rbrace に対し、既にマス目の上に置かれているブロックであって S に含まれるいずれかのマスを占めるものが存在するならば何も行わず、 存在しないならば S に含まれる 4 マス全体を占めるブロックを置く。

全ての操作を行った後、マス目の上に何個のブロックが置かれているか求めてください。

制約

  • 2\leq N \leq 10^9
  • 1\leq M \leq 2\times 10^5
  • 1\leq R_i,C_i \leq N-1
  • 入力は全て整数

入力

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

N M
R_1 C_1
R_2 C_2
\vdots
R_M C_M

出力

答えを出力せよ。


入力例 1

4 3
1 1
2 2
2 3

出力例 1

2

以下の図は操作のようすを示したものであり、黒く塗られた領域がブロックを、赤枠で囲まれた領域が次にブロックを置きたい場所を表しています。

  • 1 回目の操作:マス (1,1) を左上とする 2 \times 2 の領域には何も置かれていないため、そこにブロックを置きます。
  • 2 回目の操作:マス (2,2) を左上とする 2 \times 2 の領域のうち、マス (2,2) 上に既に他のブロックが存在するため、何も行いません。
  • 3 回目の操作:マス (2,3) を左上とする 2 \times 2 の領域には何も置かれていないため、そこにブロックを置きます。

よって、全ての操作を行った後、マス目の上に 2 個のブロックが置かれています。


入力例 2

1000000000 4
1 1
1 101
101 1
101 101

出力例 2

4

全ての操作においてブロックを置くことができます。


入力例 3

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

出力例 3

8

(R_i,C_i)=(R_j,C_j) を満たす i,j\ (i\neq j) が存在することもあります。

Score : 300 points

Problem Statement

There is a grid with N rows and N columns. Let (i,j) denote the cell at the i-th row from the top and j-th column from the left. Initially, nothing is placed on the grid.

You will now perform M operations. The i-th operation (1\leq i\leq M) is as follows:

  • Place a block that occupies a 2 \times 2 region with cell (R_i,C_i) as the top-left corner on the grid if and only if its position does not overlap with any other blocks already placed. More precisely, for the set of cells S=\lbrace (R_i,C_i),(R_i+1,C_i),(R_i,C_i+1),(R_i+1,C_i+1)\rbrace, if there exists a block already placed on the grid that occupies any cell in S, do nothing; otherwise, place a block that occupies all four cells in S.

After performing all operations, find how many blocks are placed on the grid.

Constraints

  • 2\leq N \leq 10^9
  • 1\leq M \leq 2\times 10^5
  • 1\leq R_i,C_i \leq N-1
  • All input values are integers.

Input

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

N M
R_1 C_1
R_2 C_2
\vdots
R_M C_M

Output

Print the answer.


Sample Input 1

4 3
1 1
2 2
2 3

Sample Output 1

2

The following diagram shows the operations, where black-filled regions represent blocks and red-framed regions represent where the next block is to be placed.

  • Operation 1: Nothing is placed in the 2 \times 2 region with cell (1,1) as the top-left corner, so place a block there.
  • Operation 2: Among the 2 \times 2 region with cell (2,2) as the top-left corner, there is already another block on cell (2,2), so do nothing.
  • Operation 3: Nothing is placed in the 2 \times 2 region with cell (2,3) as the top-left corner, so place a block there.

Thus, after performing all operations, two blocks are placed on the grid.


Sample Input 2

1000000000 4
1 1
1 101
101 1
101 101

Sample Output 2

4

Blocks can be placed in all operations.


Sample Input 3

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

Sample Output 3

8

There may exist i,j\ (i\neq j) such that (R_i,C_i)=(R_j,C_j).

D - Teleport Maze

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 400

問題文

HW 列のマス目からなる迷路があります。 上から i 行目、左から j 列目のマスを (i,j) と表記します。 マス (i,j) がどのようなマスであるかは文字 S_{i,j} として与えられ、各文字の意味は以下の通りです。

  • . : 空きマス
  • # : 障害物マス
  • 英小文字(a - z): ワープマス

迷路内では、以下の二種類の行動を好きな順序で何回でも行うことができます。

  • 歩行:現在いるマスから上下左右の四方向のいずれかに 1 マス分進んだマスへ移動する。ただし、障害物マスへ移動することや、マス目の外に移動することはできない。
  • ワープ:ワープマスにいるとき、そのワープマスと同じ文字が書かれたワープマスのうちいずれか好きなマスへと移動する。

マス (1,1) からマス (H,W) へ移動することが可能かどうか判定し、可能ならばそれに必要な最小の合計行動回数を求めてください。

制約

  • 1\leq H,W \leq 1000
  • H\times W \geq 2
  • H,W は整数
  • S_{i,j}., #, または英小文字のいずれか
  • S_{1,1}\neq #
  • S_{H,W}\neq #

入力

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

H W
S_{1,1}S_{1,2}\dots S_{1,W}
\vdots
S_{H,1}S_{H,2}\dots S_{H,W}

出力

マス (1,1) からマス (H,W) へ移動することが可能ならばそれに必要な最小の合計行動回数を、不可能ならば -1 を出力せよ。


入力例 1

3 4
..a.
####
ba#b

出力例 1

5

以下のように行動することで、マス (1,1) からマス (3,4) へ移動することができます。

  1. マス (1,1) からマス (1,2) へ歩行によって移動する。
  2. マス (1,2) からマス (1,3) へ歩行によって移動する。
  3. マス (1,3) からマス (3,2) へワープによって移動する。
  4. マス (3,2) からマス (3,1) へ歩行によって移動する。
  5. マス (3,1) からマス (3,4) へワープによって移動する。

このときの合計行動回数は 5 回であり、これが最小です。


入力例 2

3 4
..a.
####
b.#b

出力例 2

-1

マス (1,1) からマス (3,4) へ移動することは不可能です。


入力例 3

4 4
xxxx
xxxx
xxxx
xxxx

出力例 3

1

入力例 4

7 11
u..#y..#...
k..#.z.#.k.
iju#...#x..
###########
..x#.t.#..n
abc#y..#...
..z#..t#.y.

出力例 4

12

Score : 400 points

Problem Statement

There is a maze consisting of a grid with H rows and W columns. Let (i,j) denote the cell at the i-th row from the top and j-th column from the left. The type of cell (i,j) is given as a character S_{i,j}, where each character has the following meaning:

  • . : Empty cell
  • # : Obstacle cell
  • Lowercase English letter (a - z): Warp cell

In the maze, you can perform the following two types of actions any number of times in any order:

  • Walk: Move from the current cell to a cell that is one cell away in one of the four directions (up, down, left, right). However, you cannot move to an obstacle cell or outside the grid.
  • Warp: When you are at a warp cell, move to any warp cell with the same character written on it.

Determine whether it is possible to move from cell (1,1) to cell (H,W), and if possible, find the minimum total number of actions required.

Constraints

  • 1\leq H,W \leq 1000
  • H\times W \geq 2
  • H and W are integers.
  • S_{i,j} is ., #, or a lowercase English letter.
  • S_{1,1}\neq #
  • S_{H,W}\neq #

Input

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

H W
S_{1,1}S_{1,2}\dots S_{1,W}
\vdots
S_{H,1}S_{H,2}\dots S_{H,W}

Output

If it is possible to move from cell (1,1) to cell (H,W), print the minimum total number of actions required; otherwise, print -1.


Sample Input 1

3 4
..a.
####
ba#b

Sample Output 1

5

You can move from cell (1,1) to cell (3,4) by performing actions as follows:

  1. Move from cell (1,1) to cell (1,2) by walking.
  2. Move from cell (1,2) to cell (1,3) by walking.
  3. Move from cell (1,3) to cell (3,2) by warping.
  4. Move from cell (3,2) to cell (3,1) by walking.
  5. Move from cell (3,1) to cell (3,4) by warping.

The total number of actions is 5, which is the minimum.


Sample Input 2

3 4
..a.
####
b.#b

Sample Output 2

-1

It is impossible to move from cell (1,1) to cell (3,4).


Sample Input 3

4 4
xxxx
xxxx
xxxx
xxxx

Sample Output 3

1

Sample Input 4

7 11
u..#y..#...
k..#.z.#.k.
iju#...#x..
###########
..x#.t.#..n
abc#y..#...
..z#..t#.y.

Sample Output 4

12
E - Minimum Swap

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 475

問題文

(1,2,\ldots,N) を並べ替えた整数列 P=(P _ 1,P _ 2,\ldots,P _ N) が与えられます。 ここで、P(1,2,\ldots,N) と等しくないことが保証されます。

あなたは、次の操作を 0 回以上行って P を列 (1,2,\ldots,N) と一致させたいです。

  • 1\le i\lt j\le N を満たす整数の組 (i,j) をひとつ選ぶ。P _ iP _ j の値を入れ替える。

P を列 (1,2,\ldots,N) と一致させるために必要な最小の操作回数を K 回とします。

K 回の操作で P を列 (1,2,\ldots,N) と一致させるような操作列の \mathbf{1} 回目の操作としてあり得る操作の数を求めてください。 ただし、2 つの操作は選んだ整数の組 (i,j) が異なるとき、またそのときに限り区別します。

制約

  • 2\le N\le3\times10 ^ 5
  • 1\le P _ i\le N\ (1\le i\le N)
  • P _ i\ne P _ j\ (1\le i\lt j\le N)
  • i\ne P _ i を満たす 1\le i\le N が存在する
  • 入力はすべて整数

入力

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

N
P _ 1 P _ 2 \ldots P _ N

出力

答えを出力せよ。


入力例 1

5
3 1 4 2 5

出力例 1

6

例えば、次のようにして 3 回の操作で目標を達成することができます。

  • (i,j)=(1,2) を選ぶ。P=(1,3,4,2,5) となる。
  • (i,j)=(2,4) を選ぶ。P=(1,2,4,3,5) となる。
  • (i,j)=(3,4) を選ぶ。P=(1,2,3,4,5) となる。

2 回以下の操作で目標を達成することはできないので、K=3 です。

上の説明の通り、最初の操作で (1,2) を選ぶと 3 回の操作で目標を達成できます。 その他にも、最初の操作で (1,3),(1,4),(2,3),(2,4),(3,4) のいずれかを選んだ場合にはそのあとの 2 回の操作を適切に行うことで P=(1,2,3,4,5) とすることができます。

よって、6 を出力してください。


入力例 2

2
2 1

出力例 2

1

入力例 3

20
15 5 13 17 9 11 20 4 14 16 6 3 8 19 12 7 10 18 2 1

出力例 3

77

Score : 475 points

Problem Statement

You are given an integer sequence P=(P _ 1,P _ 2,\ldots,P _ N) that is a permutation of (1,2,\ldots,N). Here, it is guaranteed that P is not equal to (1,2,\ldots,N).

You want to perform the following operation zero or more times to make P match the sequence (1,2,\ldots,N):

  • Choose a pair of integers (i,j) satisfying 1\le i\lt j\le N. Swap the values of P _ i and P _ j.

Let K be the minimum number of operations required to make P match the sequence (1,2,\ldots,N).

Find the number of operations that can be the first operation in a sequence of operations that makes P match the sequence (1,2,\ldots,N) in K operations. Two operations are distinguished if and only if the chosen pairs of integers (i,j) are different.

Constraints

  • 2\le N\le3\times10 ^ 5
  • 1\le P _ i\le N\ (1\le i\le N)
  • P _ i\ne P _ j\ (1\le i\lt j\le N)
  • There exists 1\le i\le N such that i\ne P _ i.
  • All input values are integers.

Input

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

N
P _ 1 P _ 2 \ldots P _ N

Output

Print the answer.


Sample Input 1

5
3 1 4 2 5

Sample Output 1

6

For example, the goal can be achieved in three operations as follows:

  • Choose (i,j)=(1,2). P becomes (1,3,4,2,5).
  • Choose (i,j)=(2,4). P becomes (1,2,4,3,5).
  • Choose (i,j)=(3,4). P becomes (1,2,3,4,5).

The goal cannot be achieved in two or fewer operations, so K=3.

As explained above, choosing (1,2) for the first operation allows the goal to be achieved in three operations. Additionally, if one of (1,3),(1,4),(2,3),(2,4),(3,4) is chosen for the first operation, then by performing the next two operations appropriately, P can be made equal to (1,2,3,4,5).

Therefore, print 6.


Sample Input 2

2
2 1

Sample Output 2

1

Sample Input 3

20
15 5 13 17 9 11 20 4 14 16 6 3 8 19 12 7 10 18 2 1

Sample Output 3

77
F - Starry Landscape Photo

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 500

問題文

AtCoder 星から見える夜空には N 個の星があり、これらの N 個の星は東から西へ一直線上に並んでいます。 東から i 番目 (1\le i\le N) の星は、これらの星の中で B _ i 番目に明るい星です。

高橋くんは、次のような手順で夜空の写真を撮ることにしました。

  1. 1\le l\le r\le N を満たす整数の組 (l,r) を選び、東から l 番目、l+1 番目、\ldotsr 番目の星が全てフレームに収まり、他の星がフレームに入らないようにカメラを設置する。
  2. 1\le b\le N を満たす整数 b を選び、N 個の星のうち明るさが 1 番目から b 番目に入る(かつフレームに収まっている)星がすべて写り、そうでない星が写らないようにシャッターを開放する。

ただし、星が 1 つも写らないように写真を撮ることはできません。

このようにして撮影された夜空の写真に写っている星の集合としてありえるものが何通りあるか求めてください。

制約

  • 1\le N\le5\times10 ^ 5
  • 1\le B _ i\le N\ (1\le i\le N)
  • B _ i\ne B _ j\ (1\le i\lt j\le N)
  • 入力はすべて整数

入力

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

N
B _ 1 B _ 2 \ldots B _ N

出力

答えを出力せよ。


入力例 1

4
3 1 4 2

出力例 1

12

例えば (l,r)=(2,4),b=3 とすると、東から 2 番目の星と東から 4 番目の星の 2 つの星が写った写真を撮ることができます。

これを含め、以下の 12 通りの星の集合が写った写真を撮ることができます。 それぞれの写真ではより東にある星がより左側に並んでおり、i 番目に明るい星に整数 i が書かれています。

これ以外の集合を撮ることはできないため、12 を出力してください。


入力例 2

7
1 2 3 4 5 6 7

出力例 2

28

入力例 3

20
15 5 13 17 9 11 20 4 14 16 6 3 8 19 12 7 10 18 2 1

出力例 3

627

Score : 500 points

Problem Statement

In the night sky seen from planet AtCoder, there are N stars, and these N stars are arranged in a line from east to west. The i-th star from the east (1\le i\le N) is the B _ i-th brightest among these stars.

Takahashi decided to take a picture of the night sky using the following procedure:

  1. Choose a pair of integers (l,r) satisfying 1\le l\le r\le N, and set up the camera so that the l-th, (l+1)-th, \ldots, r-th stars from the east all fit in the frame, and no other stars enter the frame.
  2. Choose an integer b satisfying 1\le b\le N, and open the shutter so that all stars among the N stars whose brightness ranks from 1st through b-th (and that fit in the frame) are captured, and no other stars are captured.

However, he may not take a picture with no stars captured.

Find the number of different sets of stars that can be captured in pictures taken in this way.

Constraints

  • 1\le N\le5\times10 ^ 5
  • 1\le B _ i\le N\ (1\le i\le N)
  • B _ i\ne B _ j\ (1\le i\lt j\le N)
  • All input values are integers.

Input

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

N
B _ 1 B _ 2 \ldots B _ N

Output

Print the answer.


Sample Input 1

4
3 1 4 2

Sample Output 1

12

For example, with (l,r)=(2,4),b=3, you can take a picture with two stars: the 2nd star from the east and the 4th star from the east.

Including this, you can take pictures with the following 12 different sets of stars. In each picture, stars further east are arranged further left, and the i-th brightest star is labeled with integer i.

No other sets can be captured, so print 12.


Sample Input 2

7
1 2 3 4 5 6 7

Sample Output 2

28

Sample Input 3

20
15 5 13 17 9 11 20 4 14 16 6 3 8 19 12 7 10 18 2 1

Sample Output 3

627
G - Linear Inequation

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 600

問題文

長さ N の正整数列 A=(A _ 1,A _ 2,\ldots,A _ N) および正整数 M が与えられます。

次の条件を満たす長さ N の非負整数列 x=(x _ 1,x _ 2,\ldots,x _ N) がいくつあるか求めてください。

  • \displaystyle\sum _ {i=1} ^ NA _ ix _ i\le M

答えは非常に大きくなる場合があるので、答えを 998244353 で割った余りを求めてください。

制約

  • 1\le N\le100
  • 1\le A _ i\le100\ (1\le i\le N)
  • 1\le M\le10 ^ {18}
  • 入力はすべて整数

入力

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

N M
A _ 1 A _ 2 \ldots A _ N

出力

条件を満たす非負整数列の個数を 998244353 で割った余りを出力せよ。


入力例 1

4 6
5 4 3 2

出力例 1

10

条件を満たす x(0,0,0,0),(0,0,0,1),(0,0,0,2),(0,0,0,3),(0,0,1,0),(0,0,1,1),(0,0,2,0),(0,1,0,0),(0,1,0,1),(1,0,0,0)10 個です。

よって、10 を出力してください。


入力例 2

6 89
4 7 5 10 7 6

出力例 2

38469

入力例 3

1 1000000007
1

出力例 3

1755655

条件を満たす x1000000008 個あります。

これを 998244353 で割った余りである 1755655 を出力してください。


入力例 4

20 738894495848985641
40 58 13 24 65 11 63 29 98 75 40 77 15 50 83 85 35 46 38 37

出力例 4

31156940

Score : 600 points

Problem Statement

You are given a length-N sequence of positive integers A=(A _ 1,A _ 2,\ldots,A _ N) and a positive integer M.

Find the number of length-N sequences of non-negative integers x=(x _ 1,x _ 2,\ldots,x _ N) that satisfy the following condition:

  • \displaystyle\sum _ {i=1} ^ NA _ ix _ i\le M

The number can be very large, so find it modulo 998244353.

Constraints

  • 1\le N\le100
  • 1\le A _ i\le100\ (1\le i\le N)
  • 1\le M\le10 ^ {18}
  • 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

Output

Print the number, modulo 998244353, of non-negative integer sequences that satisfy the condition.


Sample Input 1

4 6
5 4 3 2

Sample Output 1

10

The sequences x that satisfy the condition are the following 10: (0,0,0,0),(0,0,0,1),(0,0,0,2),(0,0,0,3),(0,0,1,0),(0,0,1,1),(0,0,2,0),(0,1,0,0),(0,1,0,1),(1,0,0,0).

Thus, print 10.


Sample Input 2

6 89
4 7 5 10 7 6

Sample Output 2

38469

Sample Input 3

1 1000000007
1

Sample Output 3

1755655

There are 1000000008 sequences x that satisfy the condition.

Print this modulo 998244353, which is 1755655.


Sample Input 4

20 738894495848985641
40 58 13 24 65 11 63 29 98 75 40 77 15 50 83 85 35 46 38 37

Sample Output 4

31156940