A - 484558

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

配点 : 100 点

問題文

0123456789 に加えて 10,11,12,13,14,15 に対応する数字として ABCDEF を使う 16 進表記では、0 以上 255 以下の整数は 1 桁または 2 桁になります。
例えば、0 や 12 は 16 進表記では 0 や C と 1 桁になり、99 や 255 は 16 進表記では 63 や FF と 2 桁になります。

0 以上 255 以下の整数 N を、必要に応じて先頭に 0 を加えることでちょうど 2 桁の 16 進表記に変換してください。

注記

英大文字と英小文字は区別されます。特に、16 進表記の数字として ABCDEF の代わりに abcdef を使うことは出来ません。

制約

  • 0 \leq N \leq 255
  • N は整数

入力

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

N

出力

答えを出力せよ。


入力例 1

99

出力例 1

63

99 は 16 進表記で 63 です。


入力例 2

12

出力例 2

0C

12 は 16 進表記で C です。
要求されているのはちょうど 2 桁の 16 進表記に変換することなので、C の先頭に 0 を加えた 0C が答えです。


入力例 3

0

出力例 3

00

入力例 4

255

出力例 4

FF

Score : 100 points

Problem Statement

In the hexadecimal system, where the digits ABCDEF corresponding to 10,11,12,13,14, and 15 are used in addition to 0123456789, every integer between 0 and 255 is represented as a 1- or 2-digit numeral.
For example, 0 and 12 are represented as 1-digit hexadecimal numerals 0 and C; 99 and 255 are represented as 2-digit hexadecimals 63 and FF.

Given an integer N between 0 and 255, convert it to an exactly two-digit hexadecimal numeral, prepending leading 0s if necessary.

Notes

The judge is case-sensitive. Specifically, you cannot use abcdef as hexadecimal digits instead of ABCDEF.

Constraints

  • 0 \leq N \leq 255
  • N is an integer.

Input

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

N

Output

Print the answer.


Sample Input 1

99

Sample Output 1

63

99 is represented as 63 in hexadecimal.


Sample Input 2

12

Sample Output 2

0C

12 is represented as C in hexadecimal.
Since we ask you to convert it to a two-digit hexadecimal numeral, the answer is 0C, where 0 is prepended to C.


Sample Input 3

0

Sample Output 3

00

Sample Input 4

255

Sample Output 4

FF
B - "atcoder".substr()

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

配点 : 100 点

問題文

文字列 atcoder の L 文字目から R 文字目までを出力してください。

制約

  • L,R は整数
  • 1 \le L \le R \le 7

入力

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

L R

出力

答えを出力せよ。


入力例 1

3 6

出力例 1

code

atcoder の 3 文字目から 6 文字目までを出力すると code となります。


入力例 2

4 4

出力例 2

o

入力例 3

1 7

出力例 3

atcoder

Score : 100 points

Problem Statement

Print the L-th through R-th characters of the string atcoder.

Constraints

  • L and R are integers.
  • 1 \le L \le R \le 7

Input

Input is given from Standard Input in the following format:

L R

Output

Print the answer.


Sample Input 1

3 6

Sample Output 1

code

The 3-rd through 6-th characters of atcoder are code.


Sample Input 2

4 4

Sample Output 2

o

Sample Input 3

1 7

Sample Output 3

atcoder
C - Center Alignment

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

配点 : 200 点

問題文

英小文字からなる N 個の奇数長の文字列 S_1,S_2,\dots,S_N が与えられます。

S_1,S_2,\dots,S_N のうち最も長いものの長さを m とします。 以下の条件を満たす文字列 T_1,T_2,\dots,T_N を求めてください。

  • 条件:T_i はある非負整数 k について k 個の .、S_i、k 個の . をこの順に結合してできる、長さ m の文字列である。

制約

  • N は 1 以上 100 以下の整数
  • S_i は英小文字からなる長さ 1 以上 99 以下の奇数長の文字列

入力

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

N
S_1
S_2
\vdots
S_N

出力

N 行出力せよ。i\ (1 \leq i \leq N) 行目には T_i を出力せよ。


入力例 1

4
apple
blueberry
coconut
dragonfruit

出力例 1

...apple...
.blueberry.
..coconut..
dragonfruit

m=11 であり、T_1,T_2,T_3,T_4 はそれぞれ k=3,1,2,0 について問題文中の条件を満たしています。


入力例 2

6
abc
d
efghi
jkl
mnopq
r

出力例 2

.abc.
..d..
efghi
.jkl.
mnopq
..r..

Score : 200 points

Problem Statement

You are given N strings S_1,S_2,\dots,S_N of odd lengths consisting of lowercase English letters.

Let m be the length of the longest string among S_1,S_2,\dots,S_N. Find strings T_1,T_2,\dots,T_N satisfying the following condition.

  • Condition: T_i is a string of length m formed by concatenating k copies of ., S_i, and k copies of . in this order, for some non-negative integer k.

Constraints

  • N is an integer between 1 and 100, inclusive.
  • S_i is a string of odd length between 1 and 99, inclusive, consisting of lowercase English letters.

Input

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

N
S_1
S_2
\vdots
S_N

Output

Output N lines. The i-th line (1 \leq i \leq N) should contain T_i.


Sample Input 1

4
apple
blueberry
coconut
dragonfruit

Sample Output 1

...apple...
.blueberry.
..coconut..
dragonfruit

m=11, and T_1,T_2,T_3,T_4 satisfy the condition in the problem statement for k=3,1,2,0, respectively.


Sample Input 2

6
abc
d
efghi
jkl
mnopq
r

Sample Output 2

.abc.
..d..
efghi
.jkl.
mnopq
..r..
D - Not All

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

配点 : 200 点

問題文

長さ N の整数列 A=(A_1,A_2,\dots,A_N) および正整数 M が与えられます。

A の末尾の要素を削除するという操作を 0 回以上 N 回以下行うことで、以下の条件が満たされないようにしたいです。

  • 条件:A には 1 以上 M 以下の整数がすべて含まれている。

必要な操作回数の最小値を求めてください。

なお、本問題の制約下において、操作を 0 回以上 N 回以下行うことで上述の条件が満たされないようにすることが必ず可能であることが証明できます。

制約

  • 1\leq M \leq N \leq 100
  • 1\leq A_i \leq M
  • 入力は全て整数

入力

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

N M
A_1 A_2 \dots A_N

出力

条件が満たされなくなるために必要な操作回数の最小値を出力せよ。


入力例 1

5 3
3 2 3 1 2

出力例 1

2

最初、A=(3,2,3,1,2) です。このとき、A には 1 以上 3 以下の整数がすべて含まれるため条件を満たします。

A の末尾の要素を削除する操作を 1 回行うと、A=(3,2,3,1) となります。このとき、A には 1 以上 3 以下の整数がすべて含まれるため条件を満たします。

A の末尾の要素を削除する操作をもう 1 回行うと、A=(3,2,3) となります。このとき、A には 1 が含まれないため条件を満たしません。

よって、条件が満たされなくなるために必要な操作回数の最小値は 2 です。


入力例 2

4 3
1 3 1 3

出力例 2

0

A には最初から 2 が含まれず条件を満たさないため、操作を 1 回も行う必要がありません。


入力例 3

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

出力例 3

6

Score : 200 points

Problem Statement

You are given an integer sequence A = (A_1, A_2, \dots, A_N) of length N and a positive integer M.

Your goal is to make the following condition false by performing this operation between 0 and N times (inclusive): remove the last element of A.

  • Condition: A contains every integer from 1 through M.

Find the minimum number of operations required.

Under the constraints of this problem, it can be proved that it is always possible to make the condition false by performing the operation between 0 and N times.

Constraints

  • 1 \le M \le N \le 100
  • 1 \le A_i \le M
  • 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_N

Output

Output the minimum number of operations required to make the condition false.


Sample Input 1

5 3
3 2 3 1 2

Sample Output 1

2

Initially, A = (3,2,3,1,2). Since A contains every integer from 1 through 3, the condition holds.

If you perform the operation once, A = (3,2,3,1). The condition still holds.

If you perform the operation once more, A = (3,2,3). The integer 1 is missing, so the condition no longer holds.

Therefore, the minimum required number of operations is 2.


Sample Input 2

4 3
1 3 1 3

Sample Output 2

0

Since A initially lacks the integer 2, the condition is already false, so no operation is needed.


Sample Input 3

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

Sample Output 3

6
E - Select Mul

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

配点 : 300 点

問題文

整数 N が与えられます。N の各桁の数字を取り出して並べ(並べる順序は好きに変えてよい)、2 つの正整数に分離することを考えましょう。

例えば、123 という整数に対しては以下の 6 通りの分離の仕方が考えられます。

  • 12 と 3
  • 21 と 3
  • 13 と 2
  • 31 と 2
  • 23 と 1
  • 32 と 1

なお、ここで分離されたあとの 2 整数に leading zero が含まれていてはなりません。例えば、101 という整数を 1 と 01 の 2 つに分離することはできません。また上述の「正整数に分離する」という条件より、101 を 11 と 0 の 2 つに分離することもできません。

適切に N を分離したとき、分離後の 2 数の積の最大値はいくらになりますか?

制約

  • N は 1 以上 10^9 以下の整数
  • N には 0 でない桁が 2 つ以上含まれる

入力

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

N

出力

分離後の 2 数の積の最大値を出力せよ。


入力例 1

123

出力例 1

63

問題文中にある通り、以下の 6 通りの分離の仕方が考えられます。

  • 12 と 3
  • 21 と 3
  • 13 と 2
  • 31 と 2
  • 23 と 1
  • 32 と 1

積はそれぞれ 36, 63, 26, 62, 23, 32 であり、この中の最大値は 63 です。


入力例 2

1010

出力例 2

100

考えられる分離の仕方は以下の 2 通りです。

  • 100 と 1
  • 10 と 10

いずれの場合にも積は 100 となります。


入力例 3

998244353

出力例 3

939337176

Score : 300 points

Problem Statement

You are given an integer N. Consider permuting the digits in N and separate them into two positive integers.

For example, for the integer 123, there are six ways to separate it, as follows:

  • 12 and 3,
  • 21 and 3,
  • 13 and 2,
  • 31 and 2,
  • 23 and 1,
  • 32 and 1.

Here, the two integers after separation must not contain leading zeros. For example, it is not allowed to separate the integer 101 into 1 and 01. Additionally, since the resulting integers must be positive, it is not allowed to separate 101 into 11 and 0, either.

What is the maximum possible product of the two resulting integers, obtained by the optimal separation?

Constraints

  • N is an integer between 1 and 10^9 (inclusive).
  • N contains two or more digits that are not 0.

Input

Input is given from Standard Input in the following format:

N

Output

Print the maximum possible product of the two integers after separation.


Sample Input 1

123

Sample Output 1

63

As described in Problem Statement, there are six ways to separate it:

  • 12 and 3,
  • 21 and 3,
  • 13 and 2,
  • 31 and 2,
  • 23 and 1,
  • 32 and 1.

The products of these pairs, in this order, are 36, 63, 26, 62, 23, 32, with 63 being the maximum.


Sample Input 2

1010

Sample Output 2

100

There are two ways to separate it:

  • 100 and 1,
  • 10 and 10.

In either case, the product is 100.


Sample Input 3

998244353

Sample Output 3

939337176
F - Rotate Colored Subsequence

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

配点 : 300 点

問題文

英小文字からなる長さ N の文字列 S が与えられます。 S の各文字は色 1 、色 2 、\ldots 、色 M の M 色のうちのいずれかで塗られており、 i = 1, 2, \ldots, N について、S の i 文字目は色 C_i で塗られています。

各 i = 1, 2, \ldots, M について、この順番に下記の操作を行います。

  • S の色 i で塗られた文字からなる部分を、右に 1 つ巡回シフトする。 すなわち、S の 色 i で塗られた文字の位置が先頭のものから順に p_1, p_2, p_3, \ldots, p_k 文字目であるとき、 S の p_1, p_2, p_3, \ldots, p_k 文字目を、それぞれ、S の p_k, p_1,p_2, \ldots, p_{k-1} 文字目で同時に置き換える。

上記の操作をすべて行った後の、最終的な S を出力してください。

なお、M 色あるどの色についても、その色で塗られた S の文字が必ず 1 つ以上存在することが、制約として保証されます。

制約

  • 1 \leq M \leq N \leq 2 \times 10^5
  • 1 \leq C_i \leq M
  • N, M, C_i はすべて整数
  • S は英小文字からなる長さ N の文字列
  • 任意の整数 1 \leq i \leq M に対して、ある整数 1 \leq j \leq N が存在して C_j = i が成り立つ

入力

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

N M
S
C_1 C_2 \ldots C_N

出力

答えを出力せよ。


入力例 1

8 3
apzbqrcs
1 2 3 1 2 2 1 2

出力例 1

cszapqbr

はじめ、S = apzbqrcs です。

  • i = 1 に対する操作では、S の 1, 4, 7 文字目からなる部分を右に 1 つ巡回シフトします。その結果、S = cpzaqrbs となります。
  • i = 2 に対する操作では、S の 2, 5, 6, 8 文字目からなる部分を右に 1 つ巡回シフトします。その結果、S = cszapqbr となります。
  • i = 3 に対する操作では、S の 3 文字目からなる部分を右に 1 つ巡回シフトします。その結果、S = cszapqbr となります(操作の前後で S は変わりません)。

よって、最終的な S である cszapqbr を出力します。


入力例 2

2 1
aa
1 1

出力例 2

aa

Score : 300 points

Problem Statement

You are given a string S of length N consisting of lowercase English letters. Each character of S is painted in one of the M colors: color 1, color 2, ..., color M; for each i = 1, 2, \ldots, N, the i-th character of S is painted in color C_i.

For each i = 1, 2, \ldots, M in this order, let us perform the following operation.

  • Perform a right circular shift by 1 on the part of S painted in color i. That is, if the p_1-th, p_2-th, p_3-th, \ldots, p_k-th characters are painted in color i from left to right, then simultaneously replace the p_1-th, p_2-th, p_3-th, \ldots, p_k-th characters of S with the p_k-th, p_1-th, p_2-th, \ldots, p_{k-1}-th characters of S, respectively.

Print the final S after the above operations.

The constraints guarantee that at least one character of S is painted in each of the M colors.

Constraints

  • 1 \leq M \leq N \leq 2 \times 10^5
  • 1 \leq C_i \leq M
  • N, M, and C_i are all integers.
  • S is a string of length N consisting of lowercase English letters.
  • For each integer 1 \leq i \leq M, there is an integer 1 \leq j \leq N such that C_j = i.

Input

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

N M
S
C_1 C_2 \ldots C_N

Output

Print the answer.


Sample Input 1

8 3
apzbqrcs
1 2 3 1 2 2 1 2

Sample Output 1

cszapqbr

Initially, S = apzbqrcs.

  • For i = 1, perform a right circular shift by 1 on the part of S formed by the 1-st, 4-th, 7-th characters, resulting in S = cpzaqrbs.
  • For i = 2, perform a right circular shift by 1 on the part of S formed by the 2-nd, 5-th, 6-th, 8-th characters, resulting in S = cszapqbr.
  • For i = 3, perform a right circular shift by 1 on the part of S formed by the 3-rd character, resulting in S = cszapqbr (here, S is not changed).

Thus, you should print cszapqbr, the final S.


Sample Input 2

2 1
aa
1 1

Sample Output 2

aa
G - Pop and Insert

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

配点 : 400 点

問題文

0 および 1 からなる長さ N の文字列 S が与えられます。

あなたは S に対して以下の操作を好きな回数(0 回でもよい)行うことができます。

  • 先頭または末尾の 1 文字を削除し、その文字を反転して(0 ならば 1 に、1 ならば 0 に変えて)、好きな位置に挿入し直す。 より厳密には、r(0)= 1,r(1)= 0 として、以下のいずれかを行う。(ここで、S_i は S の i 文字目を表す。)
    • 好きな i\ (1\leq i\leq N) を選んで、S を S_2\dots S_i\,r(S_1)\,S_{i+1}\dots S_N に変更する。
    • 好きな i\ (0\leq i\leq N-1) を選んで、S を S_1\dots S_i\,r(S_N)\,S_{i+1}\dots S_{N-1} に変更する。

S の全ての文字を同じ文字にするために必要な操作回数の最小値を求めてください。 なお、そのような操作列が必ず存在することは証明可能です。

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

制約

  • 1\leq T\leq 2\times 10^5
  • 2\leq N \leq 5\times 10^5
  • T,N は整数
  • S は 0 および 1 からなる長さ N の文字列
  • 全てのテストケースにおける N の総和は 5\times 10^5 以下

入力

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

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

\text{case}_i は i 番目のテストケースを表す。各テストケースは以下の形式で与えられる。

N
S

出力

T 行出力せよ。i 行目 (1\leq i\leq T) には i 番目のテストケースに対する答えを出力せよ。


入力例 1

3
5
01001
3
000
15
110010111100101

出力例 1

4
0
16

1 番目のテストケースについて、例えば以下のように 4 回の操作をすることで S の全ての文字を 0 にすることができます。 3 回以下の操作で S の全ての文字を同じ文字にすることはできないので、答えは 4 です。

  • 先頭の文字 0 を削除し、1 を(削除した後の S における)1 文字目と 2 文字目の間に挿入する。S= 11001 になる。
  • 先頭の文字 1 を削除し、0 を(削除した後の S における)2 文字目と 3 文字目の間に挿入する。S= 10001 になる。
  • 末尾の文字 1 を削除し、0 を(削除した後の S における)末尾に挿入する。S= 10000 になる。
  • 先頭の文字 1 を削除し、0 を(削除した後の S における)先頭に挿入する。S= 00000 になる。

2 番目のテストケースについて、はじめから S の全ての文字が同じ文字であるため、操作は 1 回も必要ありません。

Score : 400 points

Problem Statement

You are given a string S of length N consisting of 0 and 1.

You can perform the following operation on S any number of times (possibly zero):

  • Delete the first or last character, flip it (change 0 to 1 or 1 to 0), and insert it back at any position. More formally, let r(0)= 1 and r(1)= 0, and perform one of the following: (Here, S_i denotes the i-th character of S.)
    • Choose any i\ (1\leq i\leq N) and change S to S_2\dots S_i\,r(S_1)\,S_{i+1}\dots S_N.
    • Choose any i\ (0\leq i\leq N-1) and change S to S_1\dots S_i\,r(S_N)\,S_{i+1}\dots S_{N-1}.

Find the minimum number of operations required to make all characters of S the same. It can be proved that such a sequence of operations always exists.

You are given T test cases, so solve each of them.

Constraints

  • 1\leq T\leq 2\times 10^5
  • 2\leq N \leq 5\times 10^5
  • T and N are integers.
  • S is a string of length N consisting of 0 and 1.
  • The sum of N over all test cases is at most 5\times 10^5.

Input

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

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

\text{case}_i represents the i-th test case. Each test case is given in the following format:

N
S

Output

Output T lines. The i-th line (1\leq i\leq T) should contain the answer for the i-th test case.


Sample Input 1

3
5
01001
3
000
15
110010111100101

Sample Output 1

4
0
16

For the first test case, for example, you can make all characters of S into 0 with four operations as follows. It is impossible to make all characters of S the same with three or fewer operations, so the answer is 4.

  • Delete the first character 0, and insert 1 between the 1st and 2nd characters (in S after deletion). S becomes 11001.
  • Delete the first character 1, and insert 0 between the 2nd and 3rd characters (in S after deletion). S becomes 10001.
  • Delete the last character 1, and insert 0 at the end (in S after deletion). S becomes 10000.
  • Delete the first character 1, and insert 0 at the beginning (in S after deletion). S becomes 00000.

For the second test case, all characters of S are the same from the beginning, so no operation is needed.

H - Subarray Sum Divisibility

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

配点 : 475 点

問題文

長さ N の整数列 A = (A_1, A_2, \ldots, A_N) が与えられます。

あなたの目的は、以下の操作を繰り返し行うことにより、A のすべての長さ L の連続部分列についてその総和が M の倍数であるようにすることです。

  • 1 \leq i \leq N なる整数 i を選び、A_i の値を 1 増やす。

目的を達成するまでの操作回数として考えられる最小値を求めてください。

制約

  • 1 \leq N, M \leq 500
  • 1 \leq L \leq N
  • 0 \leq A_i < M
  • 入力される値はすべて整数

入力

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

N M L
A_1 A_2 \ldots A_N

出力

答えを出力せよ。


入力例 1

4 5 3
4 2 1 3

出力例 1

4

i = 2 を選ぶ操作を 1 回、i = 3 を選ぶ操作を 2 回、i = 4 を選ぶ操作を 1 回行うことで合計 4 回の操作で A = (4, 3, 3, 4) となり、すべての長さ 3 の連続部分列の総和が 5 の倍数となります。


入力例 2

7 10 4
7 0 9 1 6 4 2

出力例 2

10

Score : 475 points

Problem Statement

You are given a length-N integer sequence A = (A_1, A_2, \ldots, A_N).

Your goal is to perform the following operation repeatedly so that for every length-L contiguous subarray of A, the sum is a multiple of M.

  • Choose an integer i such that 1 \leq i \leq N, and increase the value of A_i by 1.

Find the minimum possible number of operations before achieving the goal.

Constraints

  • 1 \leq N, M \leq 500
  • 1 \leq L \leq N
  • 0 \leq A_i < M
  • All input values are integers.

Input

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

N M L
A_1 A_2 \ldots A_N

Output

Output the answer.


Sample Input 1

4 5 3
4 2 1 3

Sample Output 1

4

By performing the operation once choosing i = 2, twice choosing i = 3, and once choosing i = 4, you get A = (4, 3, 3, 4) with a total of four operations, where every length-3 contiguous subarray sums to a multiple of 5.


Sample Input 2

7 10 4
7 0 9 1 6 4 2

Sample Output 2

10
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