A - Tires

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

配点 : 100 点

問題文

末尾が er または ist であるような文字列 S が与えられます。
S の末尾が er である場合は er を、 ist である場合は ist を出力してください。

制約

  • 2 \le |S| \le 20
  • S は英小文字のみからなる。
  • S の末尾は er または ist である。

入力

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

S

出力

答えを出力せよ。


入力例 1

atcoder

出力例 1

er

S="atcoder" の末尾は er です。


入力例 2

tourist

出力例 2

ist

入力例 3

er

出力例 3

er

Score : 100 points

Problem Statement

You are given a string S ending with er or ist.
If S ends with er, print er; if it ends with ist, print ist.

Constraints

  • 2 \le |S| \le 20
  • S consists of lowercase English letters.
  • S ends with er or ist.

Input

Input is given from Standard Input in the following format:

S

Output

Print the answer.


Sample Input 1

atcoder

Sample Output 1

er

S="atcoder" ends with er.


Sample Input 2

tourist

Sample Output 2

ist

Sample Input 3

er

Sample Output 3

er
B - OS Versions

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

配点 : 100 点

問題文

ある OS のバージョンは古い順に "Ocelot", "Serval", "Lynx" です。
バージョン X がバージョン Y 以降のバージョンであるか判定してください。
なお、バージョン X 自身もバージョン X 以降のバージョンであるものとします。

制約

  • X,Y は "Ocelot", "Serval", "Lynx" のいずれか (引用符を含まない)

入力

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

X Y

出力

バージョン X がバージョン Y 以降のバージョンであれば Yes 、そうでなければ No と出力せよ。


入力例 1

Serval Ocelot

出力例 1

Yes

バージョン Serval はバージョン Ocelot 以降のバージョンです。そのため、 Yes と出力します。


入力例 2

Serval Lynx

出力例 2

No

バージョン Serval はバージョン Lynx 以降のバージョンではありません。そのため、 No と出力します。


入力例 3

Ocelot Ocelot

出力例 3

Yes

バージョン Ocelot 自身もバージョン Ocelot 以降のバージョンです。そのため、 Yes と出力します。

Score : 100 points

Problem Statement

The versions of a certain OS in chronological order are "Ocelot", "Serval", "Lynx".
Determine whether version X is the same as or newer than version Y.

Constraints

  • Each of X and Y is one of "Ocelot", "Serval", "Lynx" (without quotation marks).

Input

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

X Y

Output

If version X is the same as or newer than version Y, print Yes; otherwise, print No.


Sample Input 1

Serval Ocelot

Sample Output 1

Yes

Version Serval is the same as or newer than version Ocelot. Therefore, print Yes.


Sample Input 2

Serval Lynx

Sample Output 2

No

Version Serval is not the same as nor newer than version Lynx. Therefore, print No.


Sample Input 3

Ocelot Ocelot

Sample Output 3

Yes

Version Ocelot itself is the same as or newer than version Ocelot. Therefore, print Yes.

C - Personnel Change

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

配点 : 200 点

問題文

高橋君の勤めている会社には N 人の社員がおり、各社員には 1,2,\dots,N の社員番号が割り当てられています。 社内には M 個の部門があり、部門 1,2,\dots,M と呼ばれています。

社員番号 i の社員は、今期は部門 A_i に所属しており、来期は部門 B_i に所属します。

部門 1,2,\dots,M それぞれに対して、来期の所属人数から今期の所属人数を引いた値を求めてください。

制約

  • 1 \leq N \leq 100
  • 1 \leq M \leq 100
  • 1 \leq A_i \leq M
  • 1 \leq B_i \leq M
  • 入力はすべて整数

入力

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

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

出力

M 行出力せよ。j 行目には部門 j についての答えを出力せよ。


入力例 1

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

出力例 1

1
-1
-1
1
  • 部門 1 について、今期は社員番号 1 の 1 人が所属し、来期は社員番号 2,3 の 2 人が所属します。
  • 部門 2 について、今期は社員番号 2,4,5 の 3 人が所属し、来期は社員番号 1,4 の 2 人が所属します。
  • 部門 3 について、今期は社員番号 3 の 1 人が所属し、来期は誰も所属しません。
  • 部門 4 について、今期は誰も所属せず、来期は社員番号 5 の 1 人が所属します。

入力例 2

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

出力例 2

0
4
-5
1
0

Score : 200 points

Problem Statement

The company where Takahashi works has N employees, each assigned an employee number from 1, 2, \dots, N. There are M departments in the company, called departments 1, 2, \dots, M.

Employee i belongs to department A_i this term and will belong to department B_i next term.

For each of departments 1, 2, \dots, M, find the number of members next term minus the number of members this term.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq M \leq 100
  • 1 \leq A_i \leq M
  • 1 \leq B_i \leq M
  • All input values are integers.

Input

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

N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N

Output

Output M lines. The j-th line should contain the answer for department j.


Sample Input 1

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

Sample Output 1

1
-1
-1
1
  • For department 1: this term, one employee (employee number 1) belongs; next term, two employees (employee numbers 2, 3) belong.
  • For department 2: this term, three employees (employee numbers 2, 4, 5) belong; next term, two employees (employee numbers 1, 4) belong.
  • For department 3: this term, one employee (employee number 3) belongs; next term, no one belongs.
  • For department 4: this term, no one belongs; next term, one employee (employee number 5) belongs.

Sample Input 2

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

Sample Output 2

0
4
-5
1
0
D - Integer Division

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

配点 : 200 点

問題文

-10^{18} 以上 10^{18} 以下の整数 X が与えられるので、\left\lfloor \dfrac{X}{10} \right\rfloor を出力してください。

注記

実数 x に対して、「x 以下の整数の中で最大の整数」を \left\lfloor x \right\rfloor と表します。たとえば \left\lfloor 4.7 \right\rfloor = 4, \left\lfloor -2.4 \right\rfloor = -3, \left\lfloor 5 \right\rfloor = 5 のようになります。(詳しくは入出力例にある説明を参考にしてください。)

制約

  • -10^{18} \leq X \leq 10^{18}
  • 入力はすべて整数である。

入力

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

X

出力

\left\lfloor \frac{X}{10} \right\rfloor を出力せよ。整数として出力する必要があることに注意せよ。


入力例 1

47

出力例 1

4

\frac{47}{10} = 4.7 以下の整数は、すべての負の整数および 0, 1, 2, 3, 4 です。この中で一番大きい整数は 4 なので、\left\lfloor \frac{47}{10} \right\rfloor = 4 となります。


入力例 2

-24

出力例 2

-3

\frac{-24}{10} = -2.4 以下の整数の中で一番大きい整数は -3 なので、 \left\lfloor \frac{-24}{10} \right\rfloor = -3 となります。
-2 は -2.4 よりも大きいので、条件を満たさないことに注意してください。


入力例 3

50

出力例 3

5

\frac{50}{10} = 5 以下の整数の中で一番大きい整数は 5 自身です。よって \left\lfloor \frac{50}{10} \right\rfloor = 5 となります。


入力例 4

-30

出力例 4

-3

上の例と同様に \left\lfloor \frac{-30}{10} \right\rfloor = -3 となります。


入力例 5

987654321987654321

出力例 5

98765432198765432

答えは 98765432198765432 となります。すべての桁が正しく合っているか確認しましょう。

なお、もしも自分で書いたプログラムが想定通りの挙動をしない場合は、使用しているプログラミング言語の仕様を調べてみることを推奨します。
また、自分の書いたコードがどのように動作するかを確認したい場合は問題文上部の「コードテスト」をご利用ください。

Score : 200 points

Problem Statement

Given an integer X between -10^{18} and 10^{18} (inclusive), print \left\lfloor \dfrac{X}{10} \right\rfloor.

Notes

For a real number x, \left\lfloor x \right\rfloor denotes "the maximum integer not exceeding x". For example, we have \left\lfloor 4.7 \right\rfloor = 4, \left\lfloor -2.4 \right\rfloor = -3, and \left\lfloor 5 \right\rfloor = 5. (For more details, please refer to the description in the Sample Input and Output.)

Constraints

  • -10^{18} \leq X \leq 10^{18}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

X

Output

Print \left\lfloor \frac{X}{10} \right\rfloor. Note that it should be output as an integer.


Sample Input 1

47

Sample Output 1

4

The integers that do not exceed \frac{47}{10} = 4.7 are all the negative integers, 0, 1, 2, 3, and 4. The maximum integer among them is 4, so we have \left\lfloor \frac{47}{10} \right\rfloor = 4.


Sample Input 2

-24

Sample Output 2

-3

Since the maximum integer not exceeding \frac{-24}{10} = -2.4 is -3, we have \left\lfloor \frac{-24}{10} \right\rfloor = -3.
Note that -2 does not satisfy the condition, as -2 exceeds -2.4.


Sample Input 3

50

Sample Output 3

5

The maximum integer that does not exceed \frac{50}{10} = 5 is 5 itself. Thus, we have \left\lfloor \frac{50}{10} \right\rfloor = 5.


Sample Input 4

-30

Sample Output 4

-3

Just like the previous example, \left\lfloor \frac{-30}{10} \right\rfloor = -3.


Sample Input 5

987654321987654321

Sample Output 5

98765432198765432

The answer is 98765432198765432. Make sure that all the digits match.

If your program does not behave as intended, we recommend you checking the specification of the programming language you use.
If you want to check how your code works, you may use "Custom Test" above the Problem Statement.

E - Festival

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

配点 : 250 点

問題文

AtCoder 王国では、これから N 日間のお祭りが開催されます。そのうち、A_1 日目、A_2 日目、\dots、A_M 日目の M 日では花火が上がります。ここで、お祭りの最終日には花火が上がることが保証されます。(つまり、A_M=N が保証されます。)

i=1,2,\dots,N に対して、以下の問題を解いてください。

  • i 日目以降で初めて花火が上がるのは、i 日目から数えて何日後か?ただし、i 日目に花火が上がる場合 0 日後とする。

制約

  • 1 \le M \le N \le 2 \times 10^5
  • 1 \le A_1 < A_2 < \dots < A_M = N
  • 入力は全て整数

入力

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

N M
A_1 A_2 \dots A_M

出力

N 行出力せよ。

i(1 \le i \le N) 行目には、i 日目以降で初めて花火が上がるのは、i 日目から数えて何日後かを整数として出力せよ。


入力例 1

3 2
2 3

出力例 1

1
0
0

AtCoder 王国ではお祭りを 3 日間開催し、2,3 日目に花火が上がります。

  • 1 日目以降で初めて花火が上がるのは 2 日目なので、1 日目から数えて 1 日後です。
  • 2 日目以降で初めて花火が上がるのは 2 日目なので、2 日目から数えて 0 日後です。
  • 3 日目以降で初めて花火が上がるのは 3 日目なので、3 日目から数えて 0 日後です。

入力例 2

8 5
1 3 4 7 8

出力例 2

0
1
0
0
2
1
0
0

Score : 250 points

Problem Statement

The AtCoder Kingdom holds a festival for N days. On M of these days, namely on the A_1-th, A_2-th, \dots, A_M-th days, fireworks will be launched. It is guaranteed that fireworks will be launched on the last day of the festival. (In other words, A_M=N is guaranteed.)

For each i=1,2,\dots,N, solve the following problem.

  • How many days later from the i-th day will fireworks be launched for the first time on or after the i-th day? If fireworks are launched on the i-th day, it is considered to be 0 days later.

Constraints

  • 1 \le M \le N \le 2 \times 10^5
  • 1 \le A_1 < A_2 < \dots < A_M = N
  • All input values are integers.

Input

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

N M
A_1 A_2 \dots A_M

Output

Print N lines.

The i-th line (1 \le i \le N) should contain an integer representing the number of days from the i-th day until fireworks are launched for the first time on or after the i-th day.


Sample Input 1

3 2
2 3

Sample Output 1

1
0
0

The kingdom holds a festival for 3 days, and fireworks are launched on the 2-nd and 3-rd days.

  • From the 1-st day, the first time fireworks are launched is the 2-nd day of the festival, which is 1 day later.
  • From the 2-nd day, the first time fireworks are launched is the 2-nd day of the festival, which is 0 days later.
  • From the 3-rd day, the first time fireworks are launched is the 3-rd day of the festival, which is 0 days later.

Sample Input 2

8 5
1 3 4 7 8

Sample Output 2

0
1
0
0
2
1
0
0
F - Medicine

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

配点 : 350 点

問題文

高橋君は医者のすぬけ君から N 種類の薬を処方されました。i 種類目の薬は(処方された日を含めて) a_i 日間、毎日 b_i 錠ずつ飲む必要があります。また、高橋君はこれ以外の薬を飲む必要がありません。

薬を処方された日を 1 日目とします。1 日目以降で、初めて高橋君がその日に飲む必要がある薬が K 錠以下になるのは何日目かを求めてください。

制約

  • 1 \leq N \leq 3 \times 10^5
  • 0 \leq K \leq 10^9
  • 1 \leq a_i,b_i \leq 10^9
  • 入力はすべて整数

入力

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

N K
a_1 b_1
\vdots
a_N b_N

出力

1 日目以降で、初めて高橋君がその日に飲む必要がある薬が K 錠以下になるのが X 日目の時、 X を出力せよ。


入力例 1

4 8
6 3
2 5
1 9
4 2

出力例 1

3

1 日目には、高橋君は 1,2,3,4 種類目の薬をそれぞれ 3,5,9,2 錠飲む必要があります。よってこの日は 19 錠飲む必要があり、K(=8) 錠以下ではありません。
2 日目には、高橋君は 1,2,4 種類目の薬をそれぞれ 3,5,2 錠飲む必要があります。よってこの日は 10 錠飲む必要があり、K(=8) 錠以下ではありません。
3 日目には、高橋君は 1,4 種類目の薬をそれぞれ 3,2 錠飲む必要があります。よってこの日は 5 錠飲む必要があり、初めて K(=8) 錠以下になります。

以上より、3 が答えです。


入力例 2

4 100
6 3
2 5
1 9
4 2

出力例 2

1

入力例 3

15 158260522
877914575 2436426
24979445 61648772
623690081 33933447
476190629 62703497
211047202 71407775
628894325 31963982
822804784 50968417
430302156 82631932
161735902 80895728
923078537 7723857
189330739 10286918
802329211 4539679
303238506 17063340
492686568 73361868
125660016 50287940

出力例 3

492686569

Score : 350 points

Problem Statement

Snuke the doctor prescribed N kinds of medicine for Takahashi. For the next a_i days (including the day of the prescription), he has to take b_i pills of the i-th medicine. He does not have to take any other medicine.

Let the day of the prescription be day 1. On or after day 1, when is the first day on which he has to take K pills or less?

Constraints

  • 1 \leq N \leq 3 \times 10^5
  • 0 \leq K \leq 10^9
  • 1 \leq a_i,b_i \leq 10^9
  • All input values are integers.

Input

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

N K
a_1 b_1
\vdots
a_N b_N

Output

If Takahashi has to take K pills or less on day X for the first time on or after day 1, print X.


Sample Input 1

4 8
6 3
2 5
1 9
4 2

Sample Output 1

3

On day 1, he has to take 3,5,9, and 2 pills of the 1-st, 2-nd, 3-rd, and 4-th medicine, respectively. In total, he has to take 19 pills on this day, which is not K(=8) pills or less.
On day 2, he has to take 3,5, and 2 pills of the 1-st, 2-nd, and 4-th medicine, respectively. In total, he has to take 10 pills on this day, which is not K(=8) pills or less.
On day 3, he has to take 3 and 2 pills of the 1-st and 4-th medicine, respectively. In total, he has to take 5 pills on this day, which is K(=8) pills or less for the first time.

Thus, the answer is 3.


Sample Input 2

4 100
6 3
2 5
1 9
4 2

Sample Output 2

1

Sample Input 3

15 158260522
877914575 2436426
24979445 61648772
623690081 33933447
476190629 62703497
211047202 71407775
628894325 31963982
822804784 50968417
430302156 82631932
161735902 80895728
923078537 7723857
189330739 10286918
802329211 4539679
303238506 17063340
492686568 73361868
125660016 50287940

Sample Output 3

492686569
G - Colorful Bracket Sequence

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

配点 : 400 点

問題文

6 種類の文字、(, ), [, ], <, > からなる文字列 S が与えられます。

ここで、文字列 T は、以下の条件を満たすときカラフル括弧列と呼ばれます。

以下の操作を何回か(0 回でも良い)繰り返すことで、T を空文字列にできる。

  • T の(連続する)部分文字列であって、(), [], <> のいずれかであるようなものが存在するとき、そのうちの 1 つを選んで削除する。
  • 削除された部分文字列が T の先頭または末尾であるとき、残りの文字列を新たに T とする。
  • そうでないとき、削除された前後の文字列を 1 つに連結し、新たに T とする。

S がカラフル括弧列であるか判定してください。

制約

  • S は長さ 1 以上 2\times 10^5 以下の文字列
  • S は (, ), [, ], <, > のみからなる。

入力

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

S

出力

S がカラフル括弧列ならば Yes を、そうでないならば No を出力せよ。


入力例 1

([])<>()

出力例 1

Yes

S=([])<>() に対して、次のように操作を繰り返すことで空文字列にすることができます。

  • ([])<>() の 2 文字目から 3 文字目までをとった部分文字列 [] を削除し、前後を連結する。文字列は新たに ()<>() となる。
  • ()<>() の 1 文字目から 2 文字目までをとった部分文字列 () を削除する。文字列は新たに <>() となる。
  • <>() の 1 文字目から 2 文字目までをとった部分文字列 <> を削除する。文字列は新たに () となる。
  • () の 1 文字目から 2 文字目までをとった部分文字列 () を削除する。文字列は空文字列となる。

よって、S=([])<>() はカラフル括弧列であるため、Yes を出力します。


入力例 2

([<)]>

出力例 2

No

S=([<)]> は (), [], <> を部分列として含まないため、1 回目の操作を行うことができず、特に S はカラフル括弧列ではありません。よって、No を出力します。


入力例 3

())

出力例 3

No

S に対して操作を繰り返し、空文字列とすることはできません。
よって、S はカラフル括弧列ではないため、No を出力します。

Score : 400 points

Problem Statement

You are given a string S consisting of six types of characters: (, ), [, ], <, >.

A string T is called a colorful bracket sequence if it satisfies the following condition:

It is possible to turn T into an empty string by repeating the following operation any number of times (possibly zero):

  • If there exists a contiguous substring of T that is one of (), [], or <>, choose one such substring and delete it.
  • If the deleted substring was at the beginning or end of T, the remainder becomes the new T.
  • Otherwise, concatenate the part before the deleted substring and the part after the deleted substring, and that becomes the new T.

Determine whether S is a colorful bracket sequence.

Constraints

  • S is a string of length between 1 and 2\times 10^5, inclusive.
  • S consists of (, ), [, ], <, >.

Input

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

S

Output

If S is a colorful bracket sequence, print Yes; otherwise, print No.


Sample Input 1

([])<>()

Sample Output 1

Yes

For S=([])<>(), it is possible to turn it into an empty string by repeating the operation as follows:

  • Delete the substring [] from the 2nd to the 3rd character in ([])<>(), then concatenate the parts before and after it. The string becomes ()<>().
  • Delete the substring () from the 1st to the 2nd character in ()<>(). The string becomes <>().
  • Delete the substring <> from the 1st to the 2nd character in <>(). The string becomes ().
  • Delete the substring () from the 1st to the 2nd character in (). The string becomes empty.

Thus, S=([])<>() is a colorful bracket sequence, so print Yes.


Sample Input 2

([<)]>

Sample Output 2

No

Since S=([<)]> does not contain (), [], or <> as a contiguous substring, we cannot perform the 1st operation, and in particular S is not a colorful bracket sequence. Therefore, print No.


Sample Input 3

())

Sample Output 3

No

It is impossible to turn S into an empty string by repeating the operations.
Therefore, S is not a colorful bracket sequence, so print No.

H - Yet Another Sigma Problem

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

配点 : 500 点

問題文

文字列 x,y に対して f(x,y) を以下で定義します。

  • x,y の最長共通接頭辞の長さを f(x,y) とする。

英小文字からなる N 個の文字列 (S_1,\ldots,S_N) が与えられます。次の式の値を求めてください。

\displaystyle \sum_{i=1}^{N-1}\sum_{j=i+1}^N f(S_i,S_j)


制約

  • 2\leq N\leq 3\times 10^5
  • S_i は英小文字からなる文字列
  • 1\leq |S_i|
  • |S_1|+|S_2|+\ldots+|S_N|\leq 3\times 10^5
  • 入力される数値は全て整数

入力

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

N 
S_1 \ldots S_N

出力

答えを出力せよ。


入力例 1

3
ab abc arc

出力例 1

4
  • f(S_1,S_2)=2
  • f(S_1,S_3)=1
  • f(S_2,S_3)=1

なので、答えは f(S_1,S_2)+f(S_1,S_3)+f(S_2,S_3) = 4 です。


入力例 2

11
ab bb aaa bba baba babb aaaba aabbb a a b

出力例 2

32

Score: 500 points

Problem Statement

For strings x and y, define f(x, y) as follows:

  • f(x, y) is the length of the longest common prefix of x and y.

You are given N strings (S_1, \ldots, S_N) consisting of lowercase English letters. Find the value of the following expression:

\displaystyle \sum_{i=1}^{N-1}\sum_{j=i+1}^N f(S_i,S_j).


Constraints

  • 2 \leq N \leq 3\times 10^5
  • S_i is a string consisting of lowercase English letters.
  • 1 \leq |S_i|
  • |S_1|+|S_2|+\ldots+|S_N|\leq 3\times 10^5
  • All input numbers are integers.

Input

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

N 
S_1 \ldots S_N

Output

Print the answer.


Sample Input 1

3
ab abc arc

Sample Output 1

4
  • f(S_1,S_2)=2
  • f(S_1,S_3)=1
  • f(S_2,S_3)=1

Thus, the answer is f(S_1,S_2) + f(S_1,S_3) + f(S_2,S_3) = 4.


Sample Input 2

11
ab bb aaa bba baba babb aaaba aabbb a a b

Sample Output 2

32
I - Score of Permutations

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

配点 : 500 点

問題文

(1,2, \dots, N) を並び替えた長さ N の順列 P = (p_1, p_2, \dots, p_N) に対して、 P のスコア S(P) を次のように定めます。

  • N 人の人とすぬけ君がいて、N 人の人には 1,2,\dots,N の番号がついています。はじめ、人 i (1 \leq i \leq N) はボール i を持っています。
    すぬけ君が叫ぶたびに、i \neq p_i であるようなすべての人 i は人 p_i に持っているボールを同時に渡します。
    すぬけ君は、1 回以上叫んだ後にすべての人 i がボール i を持っている状態になると叫ぶのをやめます。
    すぬけ君が叫ぶのをやめるまでに叫んだ回数が順列のスコアとなります。ここでスコアは有限の値を取ることが保証されます。

P としてあり得るものは N! 通りありますが、それらのスコアを K 乗した値の総和を 998244353 で割ったあまりを計算してください。

  • 厳密に言い換えると、(1,2, \dots, N) を並び替えた長さ N の順列全体の集合を S_N として

    \displaystyle \left(\sum_{P \in S_N} S(P)^K \right) \bmod {998244353}

    を計算してください。

制約

  • 2 \leq N \leq 50
  • 1 \leq K \leq 10^4
  • 入力はすべて整数である。

入力

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

N K

出力

\displaystyle \left(\sum_{P \in S_N} S(P)^K \right) \bmod {998244353} を出力せよ。


入力例 1

2 2

出力例 1

5

N = 2 のとき P としてあり得る順列は (1,2),(2,1) の 2 つです。

順列 (1,2) のスコアは次のように決まります。

  • はじめ人 1 はボール 1 を、人 2 はボール 2 を持っています。
    すぬけ君が 1 回目に叫んだ後に、人 1 はボール 1 を、人 2 はボール 2 を持っています。
    このとき、すべての人が自身の番号と同じ番号が書かれたボールを持っているので、すぬけ君は叫ぶのをやめます。
    よってスコアは 1 となります。

順列 (2,1) のスコアは次のように決まります。

  • はじめ人 1 はボール 1 を、人 2 はボール 2 を持っています。
    すぬけ君が 1 回目に叫んだ後に、人 1 はボール 2 を、人 2 はボール 1 を持っています。
    すぬけ君が 2 回目に叫んだ後に、人 1 はボール 1 を、人 2 はボール 2 を持っています。
    このとき、すべての人が自身の番号と同じ番号が書かれたボールを持っているので、すぬけ君は叫ぶのをやめます。
    よってスコアは 2 となります。

よって 1^2 + 2^2 = 5 がこの問題の答えになります。


入力例 2

3 3

出力例 2

79

すべての順列とスコアの組を列挙すると以下のようになります。

  • 順列 : (1,2,3), スコア : 1
  • 順列 : (1,3,2), スコア : 2
  • 順列 : (2,1,3), スコア : 2
  • 順列 : (2,3,1), スコア : 3
  • 順列 : (3,1,2), スコア : 3
  • 順列 : (3,2,1), スコア : 2

よって 1^3 + 2^3 + 2^3 + 3^3 + 3^3 + 2^3 = 79 を出力します。


入力例 3

50 10000

出力例 3

77436607

Score : 500 points

Problem Statement

For a permutation P = (p_1, p_2, \dots, p_N) of (1,2, \dots, N), let us define the score S(P) of P as follows.

  • There are N people, numbered 1,2,\dots,N. Additionally, Snuke is there. Initially, Person i (1 \leq i \leq N) has Ball i.
    Each time Snuke screams, every Person i such that i \neq p_i gives their ball to Person p_i simultaneously.
    If, after screaming at least once, every Person i has Ball i, Snuke stops screaming.
    The score is the number of times Snuke screams until he stops. Here, it is guaranteed that the score will be a finite value.

There are N! permutations P of (1,2, \dots, N). Find the sum, modulo 998244353, of the scores of those permutations, each raised to the K-th power.

  • Formally, let S_N be the set of the permutations of (1,2, \dots, N). Compute the following: \displaystyle \left(\sum_{P \in S_N} S(P)^K \right) \bmod {998244353}.

Constraints

  • 2 \leq N \leq 50
  • 1 \leq K \leq 10^4
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print \displaystyle \left(\sum_{P \in S_N} S(P)^K \right) \bmod {998244353}.


Sample Input 1

2 2

Sample Output 1

5

When N = 2, there are two possible permutations P: (1,2),(2,1).

The score of the permutation (1,2) is found as follows.

  • Initially, Person 1 has Ball 1, and Person 2 has Ball 2.
    After Snuke's first scream, Person 1 has Ball 1, and Person 2 has Ball 2.
    Here, every Person i has Ball i, so he stops screaming.
    Thus, the score is 1.

The score of the permutation (2,1) is found as follows.

  • Initially, Person 1 has Ball 1, and Person 2 has Ball 2.
    After Snuke's first scream, Person 1 has Ball 2, and Person 2 has Ball 1.
    After Snuke's second scream, Person 1 has Ball 1, and Person 2 has Ball 2.
    Here, every Person i has Ball i, so he stops screaming.
    Thus, the score is 2.

Therefore, the answer in this case is 1^2 + 2^2 = 5.


Sample Input 2

3 3

Sample Output 2

79

All permutations and their scores are listed below.

  • (1,2,3): The score is 1.
  • (1,3,2): The score is 2.
  • (2,1,3): The score is 2.
  • (2,3,1): The score is 3.
  • (3,1,2): The score is 3.
  • (3,2,1): The score is 2.

Thus, we should print 1^3 + 2^3 + 2^3 + 3^3 + 3^3 + 2^3 = 79.


Sample Input 3

50 10000

Sample Output 3

77436607