Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
A, B, C からなる文字列 S が与えられます。S は A, B, C を全て含むことが保証されます。
S を左から 1 文字ずつ見ていったときに、はじめて次の条件を満たした状態になるのは、左から何文字目まで見たときですか?
A,B,Cが全て 1 回以上出現している。
制約
- 3 \leq N \leq 100
- S は
A,B,Cからなる長さ N の文字列 - S は
A,B,Cを全て含む
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
答えを出力せよ。
入力例 1
5 ACABB
出力例 1
4
左から 4 文字目までに A は 2 回, B は 1 回, C は 1 回出現していて、条件を満たします。
3 文字目以前では条件を満たさないので答えは 4 です。
入力例 2
4 CABC
出力例 2
3
左から 3 文字目までに A, B, C は 1 回ずつ出現していて、条件を満たします。
入力例 3
30 AABABBBABABBABABCABACAABCBACCA
出力例 3
17
Score : 100 points
Problem Statement
You are given a string S consisting of A, B, and C. S is guaranteed to contain all of A, B, and C.
If the characters of S are checked one by one from the left, how many characters will have been checked when the following condition is satisfied for the first time?
- All of
A,B, andChave appeared at least once.
Constraints
- 3 \leq N \leq 100
- S is a string of length N consisting of
A,B, andC. - S contains all of
A,B, andC.
Input
The input is given from Standard Input in the following format:
N S
Output
Print the answer.
Sample Input 1
5 ACABB
Sample Output 1
4
In the first four characters from the left, A, B, and C appear twice, once, and once, respectively, satisfying the condition.
The condition is not satisfied by checking three or fewer characters, so the answer is 4.
Sample Input 2
4 CABC
Sample Output 2
3
In the first three characters from the left, each of A, B, and C appears once, satisfying the condition.
Sample Input 3
30 AABABBBABABBABABCABACAABCBACCA
Sample Output 3
17
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
正整数 N および、英小文字からなる長さ N の文字列 S,T が与えられます。
S と T のハミング距離を求めてください。 すなわち、1 以上 N 以下の整数 i であって、S の i 文字目と T の i 文字目が異なるようなものの個数を求めてください。
制約
- 1\leq N \leq 100
- N は整数
- S,T はそれぞれ英小文字からなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S T
出力
答えを出力せよ。
入力例 1
6 abcarc agcahc
出力例 1
2
S と T は 2,5 文字目が異なり、それ以外が等しいです。よって答えは 2 です。
入力例 2
7 atcoder contest
出力例 2
7
入力例 3
8 chokudai chokudai
出力例 3
0
入力例 4
10 vexknuampx vzxikuamlx
出力例 4
4
Score : 100 points
Problem Statement
You are given a positive integer N and two strings S and T, each of length N and consisting of lowercase English letters.
Find the Hamming distance between S and T. That is, find the number of integers i such that 1 \leq i \leq N and the i-th character of S is different from the i-th character of T.
Constraints
- 1\leq N \leq 100
- N is an integer.
- Each of S and T is a string of length N consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
N S T
Output
Print the answer.
Sample Input 1
6 abcarc agcahc
Sample Output 1
2
S and T differ in the 2nd and 5th characters, but not in other characters. Thus, the answer is 2.
Sample Input 2
7 atcoder contest
Sample Output 2
7
Sample Input 3
8 chokudai chokudai
Sample Output 3
0
Sample Input 4
10 vexknuampx vzxikuamlx
Sample Output 4
4
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
入学試験の受験者が N 人います。
試験の結果、 i 番の受験生は数学で A_i 点、英語で B_i 点を取りました。
試験の合格者は次のように決められます。
- 数学の点が高い方から X 人を合格とする。
- 次に、この時点でまだ合格となっていない受験者のうち、英語の点が高い方から Y 人を合格とする。
- 次に、この時点でまだ合格となっていない受験者のうち、数学と英語の合計点が高い方から Z 人を合格とする。
- ここまでで合格となっていない受験者は、不合格とする。
ただし、 1. から 3. までのどの段階についても、同点であった場合は受験生の番号の小さい方を優先します。入出力例も参照してください。
以上の手順で合格者を決める時、合格となった受験生の番号を小さい方から順に改行区切りで出力してください。
制約
- 入力は全て整数
- 1 \le N \le 1000
- 0 \le X,Y,Z \le N
- 1 \le X+Y+Z \le N
- 0 \le A_i,B_i \le 100
入力
入力は以下の形式で標準入力から与えられる。
N X Y Z A_1 A_2 \dots A_N B_1 B_2 \dots B_N
出力
合格となった受験生の番号を小さい方から順に改行区切りで出力せよ。
入力例 1
6 1 0 2 80 60 80 60 70 70 40 20 50 90 90 80
出力例 1
1 4 5
- まず、数学の点が高い方から 1 人が合格となります。
- 数学の最高点は 80 点で 1 番の受験生と 3 番の受験生が並んでいますが、受験生の番号が小さい方が優先され 1 番の受験生が合格となります。
- 次に、まだ合格となっていない受験者のうち、英語の点が高い方から 0 人が合格となります。
- 明らかに、ここで合格者が増えることはありません。
- 次に、まだ合格となっていない受験者のうち、数学と英語の合計点が高い方から 2 人が合格となります。
- まず、まだ合格となっていない受験者の中で、合計点が 160 点と最も高い 5 番の受験生が合格となります。
- 次に、まだ合格となっていない受験者の中で、合計点が 150 点の 4 番の受験生と 6 番の受験生が並んでいます。受験生の番号の小さい方が優先され、 4 番の受験生が合格となります。
以上より、合格となる受験生の番号は 1,4,5 なので、小さい方から出力してください。
入力例 2
5 2 1 2 0 100 0 100 0 0 0 100 100 0
出力例 2
1 2 3 4 5
全員が合格となることもあります。
入力例 3
15 4 3 2 30 65 20 95 100 45 70 85 20 35 95 50 40 15 85 0 25 45 35 65 70 80 90 40 55 20 20 45 75 100
出力例 3
2 4 5 6 7 8 11 14 15
Score : 200 points
Problem Statement
N examinees took an entrance exam.
The examinee numbered i scored A_i points in math and B_i points in English.
The admissions are determined as follows.
- X examinees with the highest math scores are admitted.
- Then, among the examinees who are not admitted yet, Y examinees with the highest English scores are admitted.
- Then, among the examinees who are not admitted yet, Z examinees with the highest total scores in math and English are admitted.
- Those examinees who are not admitted yet are rejected.
Here, in each of the steps 1. to 3., ties are broken by examinees' numbers: an examinee with the smaller examinee's number is prioritized. See also Sample Input and Output.
Print the examinees' numbers of the admitted examinees determined by the steps above in ascending order, separated by newlines.
Constraints
- All values in input are integers.
- 1 \le N \le 1000
- 0 \le X,Y,Z \le N
- 1 \le X+Y+Z \le N
- 0 \le A_i,B_i \le 100
Input
Input is given from Standard Input in the following format:
N X Y Z A_1 A_2 \dots A_N B_1 B_2 \dots B_N
Output
Print the examinees' number of the admitted examinees in ascending order, separated by newlines.
Sample Input 1
6 1 0 2 80 60 80 60 70 70 40 20 50 90 90 80
Sample Output 1
1 4 5
- First, 1 examinee with the highest math score is admitted.
- Examinee 1 is tied with Examinee 3, scoring the highest 80 points in math, and the tie is broken by the examinees' numbers, so Examinee 1 is admitted.
- Then, among the examinees who are not admitted yet, 0 examinees with the highest English scores are admitted.
- Obviously, it does not affect the admissions.
- Then, among the examinees who are not admitted yet, 2 examinees with the highest total scores in math and English are admitted.
- First, among the examinees who are not admitted yet, Examinee 5 is admitted, scoring the highest total score of 160 points.
- Next, among the examinees who are not admitted yet, Examinee 4 is tied with Examinee 6, scoring a total score of 150 points. The tie is broken by the examinees' numbers, and Examinee 4 is admitted.
Therefore, the examinees' numbers of the admitted examinees are 1, 4, and 5. Print them in ascending order.
Sample Input 2
5 2 1 2 0 100 0 100 0 0 0 100 100 0
Sample Output 2
1 2 3 4 5
All examinees may be admitted.
Sample Input 3
15 4 3 2 30 65 20 95 100 45 70 85 20 35 95 50 40 15 85 0 25 45 35 65 70 80 90 40 55 20 20 45 75 100
Sample Output 3
2 4 5 6 7 8 11 14 15
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
整数 N,M と長さ N の数字列 S 、長さ M の数字列 T が与えられます。ここで、数字列とは 0 から 9 までの数字のみから構成される文字列のことを表します。
あなたは以下の操作を 0 回以上好きな回数行うことができます:
- T から 1 文字選び、選んだ数字を 1 増やす。ただし、選んだ数字が
9である場合は0にする。
T を S の部分文字列(連続する部分列)にするために必要な操作回数の最小値を求めてください。
制約
- 1\le M\le N\le 100
- N,M は整数
- S は長さ N の数字列
- T は長さ M の数字列
入力
入力は以下の形式で標準入力から与えられる。
N M S T
出力
T を S の部分文字列にするために必要な操作回数の最小値を出力せよ。
入力例 1
4 2 2025 91
出力例 1
2
以下のように 2 回操作することで T を S の部分文字列にすることができます。
- T の 2 文字目に対して操作する。 T=
91から T=92になる。 - T の 1 文字目に対して操作する。 T=
92から T=02になる。
02 は S の 2 文字目から 3 文字目までの部分文字列となっています。
2 回未満の操作で T を S の部分文字列にすることはできないため、 2 を出力してください。
入力例 2
3 2 438 38
出力例 2
0
はじめから 38 は 438 の部分文字列です。したがって、0 を出力してください。
入力例 3
5 5 00000 11111
出力例 3
45
入力例 4
8 3 20251227 438
出力例 4
13
Score : 200 points
Problem Statement
You are given integers N and M, a digit string S of length N, and a digit string T of length M. Here, a digit string is a string consisting of digits from 0 to 9.
You can perform the following operation zero or more times:
- Choose one character from T and increase the chosen digit by 1. However, if the chosen digit is
9, change it to0.
Find the minimum number of operations required to make T a substring (contiguous subsequence) of S.
Constraints
- 1\le M\le N\le 100
- N and M are integers.
- S is a digit string of length N.
- T is a digit string of length M.
Input
The input is given from Standard Input in the following format:
N M S T
Output
Output the minimum number of operations required to make T a substring of S.
Sample Input 1
4 2 2025 91
Sample Output 1
2
You can make T a substring of S with two operations as follows:
- Perform the operation on the 2nd character of T. T=
91becomes T=92. - Perform the operation on the 1st character of T. T=
92becomes T=02.
02 is a substring from the 2nd character to the 3rd character of S.
It is impossible to make T a substring of S with less than two operations, so output 2.
Sample Input 2
3 2 438 38
Sample Output 2
0
38 is a substring of 438 from the beginning. Thus, output 0.
Sample Input 3
5 5 00000 11111
Sample Output 3
45
Sample Input 4
8 3 20251227 438
Sample Output 4
13
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
非負整数 N が与えられるので、以下の条件を満たす非負整数 x を昇順に全て出力してください。
- x を 2 進数として表記した時に 1 となる位の集合が、 N を 2 進数として表記した時に 1 となる位の集合の部分集合となる。
- すなわち、全ての非負整数 k について、「 x の 2^k の位が 1 ならば、 N の 2^k の位は 1 」が成り立つ。
制約
- N は整数
- 0 \le N < 2^{60}
- N を 2 進数として表記した時、 1 となる位は 15 個以下である
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを 1 行に 1 つずつ、10 進法の整数として昇順に出力せよ。
入力例 1
11
出力例 1
0 1 2 3 8 9 10 11
N = 11_{(10)} を 2 進数で表記すると、 1011_{(2)} となります。
条件を満たす非負整数 x は以下の通りです。
- 0000_{(2)}=0_{(10)}
- 0001_{(2)}=1_{(10)}
- 0010_{(2)}=2_{(10)}
- 0011_{(2)}=3_{(10)}
- 1000_{(2)}=8_{(10)}
- 1001_{(2)}=9_{(10)}
- 1010_{(2)}=10_{(10)}
- 1011_{(2)}=11_{(10)}
入力例 2
0
出力例 2
0
入力例 3
576461302059761664
出力例 3
0 524288 549755813888 549756338176 576460752303423488 576460752303947776 576461302059237376 576461302059761664
入力は 32bit 符号付き整数に収まらない可能性があります。
Score : 300 points
Problem Statement
You are given a non-negative integer N. Print all non-negative integers x that satisfy the following condition in ascending order.
- The set of the digit positions containing 1 in the binary representation of x is a subset of the set of the digit positions containing 1 in the binary representation of N.
- That is, the following holds for every non-negative integer k: if the digit in the "2^ks" place of x is 1, the digit in the 2^ks place of N is 1.
Constraints
- N is an integer.
- 0 \le N < 2^{60}
- In the binary representation of N, at most 15 digit positions contain 1.
Input
The input is given from Standard Input in the following format:
N
Output
Print the answer as decimal integers in ascending order, each in its own line.
Sample Input 1
11
Sample Output 1
0 1 2 3 8 9 10 11
The binary representation of N = 11_{(10)} is 1011_{(2)}.
The non-negative integers x that satisfy the condition are:
- 0000_{(2)}=0_{(10)}
- 0001_{(2)}=1_{(10)}
- 0010_{(2)}=2_{(10)}
- 0011_{(2)}=3_{(10)}
- 1000_{(2)}=8_{(10)}
- 1001_{(2)}=9_{(10)}
- 1010_{(2)}=10_{(10)}
- 1011_{(2)}=11_{(10)}
Sample Input 2
0
Sample Output 2
0
Sample Input 3
576461302059761664
Sample Output 3
0 524288 549755813888 549756338176 576460752303423488 576460752303947776 576461302059237376 576461302059761664
The input may not fit into a 32-bit signed integer.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 350 点
問題文
N 個の整数の組 (L_1,R_1),(L_2,R_2),\ldots,(L_N,R_N) が与えられます。
以下の条件を満たす長さ N の整数列 X=(X_1,X_2,\ldots,X_N) が存在するか判定し、存在するならば一つ出力してください。
- 各 i=1,2,\ldots,N に対して L_i\leq X_i\leq R_i
- \displaystyle \sum_{i=1}^N X_i=0
制約
- 1\leq N\leq 2\times 10^5
- -10^9\leq L_i\leq R_i\leq 10^9
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
N L_1 R_1 L_2 R_2 \vdots L_N R_N
出力
存在しない場合は No を出力せよ。存在する場合は条件を満たす整数列 X を以下の形式で出力せよ。
Yes X_1 X_2 \ldots X_N
答えが複数存在する場合、どれを出力しても正解とみなされる。
入力例 1
3 3 5 -4 1 -2 3
出力例 1
Yes 4 -3 -1
数列 X=(4,-3,-1) は問題の条件をすべて満たします。ほかにも (3,-3,0) や (5,-4,-1) などが条件を満たします。
入力例 2
3 1 2 1 2 1 2
出力例 2
No
条件を満たす整数列 X は存在しません。
入力例 3
6 -87 12 -60 -54 2 38 -76 6 87 96 -17 38
出力例 3
Yes -66 -57 31 -6 89 9
Score : 350 points
Problem Statement
You are given N pairs of integers (L_1, R_1), (L_2, R_2), \ldots, (L_N, R_N).
Determine whether there exists a sequence of N integers X = (X_1, X_2, \ldots, X_N) that satisfies the following conditions, and print one such sequence if it exists.
- L_i \leq X_i \leq R_i for each i = 1, 2, \ldots, N.
- \displaystyle \sum_{i=1}^N X_i = 0.
Constraints
- 1 \leq N \leq 2 \times 10^5
- -10^9 \leq L_i \leq R_i \leq 10^9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N L_1 R_1 L_2 R_2 \vdots L_N R_N
Output
If no solution exists, print No. Otherwise, print an integer sequence X that satisfies the conditions in the following format:
Yes X_1 X_2 \ldots X_N
If multiple solutions exist, any of them will be considered correct.
Sample Input 1
3 3 5 -4 1 -2 3
Sample Output 1
Yes 4 -3 -1
The sequence X = (4, -3, -1) satisfies all the conditions. Other valid sequences include (3, -3, 0) and (5, -4, -1).
Sample Input 2
3 1 2 1 2 1 2
Sample Output 2
No
No sequence X satisfies the conditions.
Sample Input 3
6 -87 12 -60 -54 2 38 -76 6 87 96 -17 38
Sample Output 3
Yes -66 -57 31 -6 89 9
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
長さ N の数列 A=(A_1,A_2,\ldots,A_N) が与えられます。
以下の 2 条件をともに満たすような整数の組 (i,j,k) の個数を求めてください。
- 1\leq i \lt j \lt k \leq N
- A_i,A_j,A_k は相異なる
制約
- 3 \leq N \leq 2\times 10^5
- 1 \leq A_i \leq 2\times 10^5
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
4 3 1 4 1
出力例 1
2
条件を満たす整数の組 (i,j,k) は (1,2,3),(1,3,4) の 2 つです。
入力例 2
10 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990
出力例 2
120
入力例 3
15 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9
出力例 3
355
Score : 400 points
Problem Statement
You are given a sequence of length N: A=(A_1,A_2,\ldots,A_N).
Find the number of triples (i,j,k) that satisfy both of the following conditions.
- 1\leq i \lt j \lt k \leq N
- A_i, A_j, and A_k are distinct.
Constraints
- 3 \leq N \leq 2\times 10^5
- 1 \leq A_i \leq 2\times 10^5
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print the answer.
Sample Input 1
4 3 1 4 1
Sample Output 1
2
The two triples (i,j,k) satisfying the conditions are (1,2,3) and (1,3,4).
Sample Input 2
10 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990
Sample Output 2
120
Sample Input 3
15 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9
Sample Output 3
355
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
正の整数 N が与えられます。 \displaystyle\sum_{i=1}^N \left[ \frac{N}{i} \right] の値を求めてください。
ただし、実数 x に対して [x] で x 以下の最大の整数を表します。
制約
- 1 \leq N \leq 10^{12}
- N は整数である。
入力
入力は以下の形式で標準入力から与えられる。
N
出力
答えを出力せよ。
入力例 1
3
出力例 1
5
\left[ \frac{3}{1} \right]+\left[ \frac{3}{2} \right]+\left[ \frac{3}{3} \right]=3+1+1=5 です。
入力例 2
10000000000
出力例 2
231802823220
入力や出力が 32 bit 整数型に収まらないことがあることに注意してください。
Score : 500 points
Problem Statement
Given is a positive integer N. Find the value \displaystyle\sum_{i=1}^N \left[ \frac{N}{i} \right].
Here, for a real number x, [x] denotes the largest integer not exceeding x.
Constraints
- 1 \leq N \leq 10^{12}
- N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.
Sample Input 1
3
Sample Output 1
5
We have \left[ \frac{3}{1} \right]+\left[ \frac{3}{2} \right]+\left[ \frac{3}{3} \right]=3+1+1=5.
Sample Input 2
10000000000
Sample Output 2
231802823220
Note that the input and output may not fit into a 32-bit integer type.
Time Limit: 2 sec / Memory Limit: 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