A - Distinct Strings

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

配点 : 100 点

問題文

英小文字のみからなる長さ 3 の文字列 S が与えられます。

S の各文字を並び替えて得られる文字列は、何種類ありますか?

制約

  • S は英小文字のみからなる長さ 3 の文字列

入力

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

S

出力

S の各文字を並び替えて得られる文字列の種類数を出力せよ。


入力例 1

aba

出力例 1

3

S= aba の各文字を並び替えて得られる文字列は、aab, aba, baa の 3 通りです。


入力例 2

ccc

出力例 2

1

S= ccc の各文字を並び替えて得られる文字列は、ccc の 1 通りのみです。


入力例 3

xyz

出力例 3

6

S= xyz の各文字を並び替えて得られる文字列は、xyz, xzy, yxz, yzx, zxy, zyx の 6 通りです。

Score : 100 points

Problem Statement

You are given a string S of length 3 consisting of lowercase English letters.

How many different strings can be obtained by permuting the characters in S?

Constraints

  • S is a string S of length 3 consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of different strings that can be obtained by permuting the characters in S.


Sample Input 1

aba

Sample Output 1

3

By permuting the characters in S= aba, three different strings can be obtained: aab, aba, baa.


Sample Input 2

ccc

Sample Output 2

1

By permuting the characters in S= ccc, just one string can be obtained: ccc.


Sample Input 3

xyz

Sample Output 3

6

By permuting the characters in S= xyz, six different strings can be obtained: xyz, xzy, yxz, yzx, zxy, zyx.

B - Lacked Number

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

配点 : 100 点

問題文

数字のみからなる、長さがちょうど 9 の文字列 S が与えられます。
S には 0 から 9 までのうち、ちょうど 1 つの数字を除いた 9 種類の数字が一度ずつ登場します。

S に登場しない唯一の数字を出力してください。

制約

  • S は数字のみからなる長さ 9 の文字列である。
  • S の文字はすべて相異なる。

入力

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

S

出力

S に登場しない唯一の数字を出力せよ。


入力例 1

023456789

出力例 1

1

文字列 023456789 には 1 のみが登場していません。 よって、1 を出力します。


入力例 2

459230781

出力例 2

6

文字列 459230781 には 6 のみが登場していません。 よって、6 を出力します。

文字列に数字が現れる順番は昇順とは限らないので注意してください。

Score : 100 points

Problem Statement

You are given a string S of length exactly 9 consisting of digits. One but all digits from 0 to 9 appear exactly once in S.

Print the only digit missing in S.

Constraints

  • S is a string of length 9 consisting of digits.
  • All characters in S are distinct.

Input

Input is given from Standard Input in the following format:

S

Output

Print the only digit missing in S.


Sample Input 1

023456789

Sample Output 1

1

The string 023456789 only lacks 1. Thus, 1 should be printed.


Sample Input 2

459230781

Sample Output 2

6

The string 459230781 only lacks 6. Thus, 6 should be printed.

Note that the digits in the string may not appear in increasing order.

C - Longest Segment

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

配点 : 200 点

問題文

二次元平面上に N 個の点があります。i 個目の点の座標は (x_i,y_i) です。

この中から 2 個の点を選ぶとき、それらを結ぶ線分の長さの最大値を求めてください。

制約

  • 2 \leq N \leq 100
  • -1000 \leq x_i,y_i \leq 1000
  • (x_i,y_i) \neq (x_j,y_j)\ (i \neq j)
  • 入力はすべて整数

入力

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

N
x_1 y_1
x_2 y_2
\hspace{0.4cm} \vdots
x_N y_N

出力

2 点を結ぶ線分の長さの最大値を出力せよ。

想定解との絶対誤差または相対誤差が 10^{-6} 以下であれば正解とみなされる。


入力例 1

3
0 0
0 1
1 1

出力例 1

1.4142135624

1 個目の点と 3 個目の点を選んだときそれらを結ぶ線分の長さは \sqrt 2 = 1.41421356237\dots となり、これが最大です。


入力例 2

5
315 271
-2 -621
-205 -511
-952 482
165 463

出力例 2

1455.7159750446

Score : 200 points

Problem Statement

There are N points in a two-dimensional plane. The coordinates of the i-th point are (x_i,y_i).

Find the maximum length of a segment connecting two of these points.

Constraints

  • 2 \leq N \leq 100
  • -1000 \leq x_i,y_i \leq 1000
  • (x_i,y_i) \neq (x_j,y_j)\ (i \neq j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
x_2 y_2
\hspace{0.4cm} \vdots
x_N y_N

Output

Print the maximum length of a segment connecting two of the points.

Your answer will be considered correct when the absolute or relative error from the judge's answer is at most 10^{-6}.


Sample Input 1

3
0 0
0 1
1 1

Sample Output 1

1.4142135624

For the 1-st and 3-rd points, the length of the segment connecting them is \sqrt 2 = 1.41421356237\dots, which is the maximum length.


Sample Input 2

5
315 271
-2 -621
-205 -511
-952 482
165 463

Sample Output 2

1455.7159750446
D - Prefix?

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

配点 : 200 点

問題文

英小文字のみからなる 2 つの文字列 S, T が与えられます。 S が T の接頭辞かどうかを判定してください。

接頭辞とは 長さ N の文字列 T_1T_2\ldots T_N の接頭辞とは、 0 \leq i \leq N を満たすある整数 i によって、T の先頭 i 文字目までの文字列 T_1T_2\ldots T_i として表される文字列です。例えば、T = abc のとき、T の接頭辞は、空文字列、a 、ab 、abc の 4 つです。

制約

  • S と T はそれぞれ英小文字のみからなる長さが 1 以上 100 以下の文字列

入力

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

S
T

出力

S が T の接頭辞である場合は Yes を、そうでない場合は No を出力せよ。 ジャッジは英小文字と英大文字を厳密に区別することに注意せよ。


入力例 1

atco
atcoder

出力例 1

Yes

atco は atcoder の接頭辞です。よって、Yes を出力します。


入力例 2

code
atcoder

出力例 2

No

code は atcoder の接頭辞ではありません。よって、No を出力します。


入力例 3

abc
abc

出力例 3

Yes

文字列全体もその文字列の接頭辞であることに注意してください。


入力例 4

aaaa
aa

出力例 4

No

Score : 200 points

Problem Statement

You are given two strings S and T consisting of lowercase English letters. Determine if S is a prefix of T.

What is a prefix? A prefix of a string T_1T_2\ldots T_N of length N is a string expressed as the first i characters of T, T_1T_2\ldots T_i, where i is an integer such that 0 \leq i \leq N. For example, when T = abc, there are four prefixes of T: an empty string, a, ab, and abc.

Constraints

  • S and T are strings of lengths between 1 and 100 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T

Output

Print Yes if S is a prefix of T; print No otherwise. Note that the judge is case-sensitive.


Sample Input 1

atco
atcoder

Sample Output 1

Yes

atco is a prefix of atcoder. Thus, Yes should be printed.


Sample Input 2

code
atcoder

Sample Output 2

No

code is not a prefix of atcoder. Thus, No should be printed.


Sample Input 3

abc
abc

Sample Output 3

Yes

Note that a string is also a prefix of itself.


Sample Input 4

aaaa
aa

Sample Output 4

No
E - Happy New Year!

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

配点 : 300 点

問題文

10 進法で表記したときに 0,2 のみからなる正整数のうち、 K 番目に小さいものを求めてください。

制約

  • K は 1 以上 10^{18} 以下の整数

入力

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

K

出力

答えを整数として出力せよ。
ただし、たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要がある。たとえば、 2.34e+22 のような指数表記や、 0523 のような先頭に不要な 0 を付けたような表記は許されない。


入力例 1

3

出力例 1

22

10 進法で表記した時に 0,2 のみからなる正整数を小さい方から並べると、 2,20,22,\dots となります。
このうち K=3 番目である 22 を出力してください。


入力例 2

11

出力例 2

2022

入力例 3

923423423420220108

出力例 3

220022020000202020002022022000002020002222002200002022002200

たとえ答えが大きな整数であっても、求める答えを正確に整数として出力する必要があることに注意してください。

Score : 300 points

Problem Statement

Among the positive integers that consist of 0's and 2's when written in base 10, find the K-th smallest integer.

Constraints

  • K is an integer between 1 and 10^{18} (inclusive).

Input

Input is given from Standard Input in the following format:

K

Output

Print the answer as an integer.
Here, the exact value must be printed as an integer, even if it is big. Exponential notations such as 2.34e+22, for example, or unnecessary leading zeros such as 0523 are not allowed.


Sample Input 1

3

Sample Output 1

22

The positive integers that consist of 0's and 2's when written in base 10 are 2,20,22,\dots in ascending order.
The (K=) 3-rd of them, which is 22, should be printed.


Sample Input 2

11

Sample Output 2

2022

Sample Input 3

923423423420220108

Sample Output 3

220022020000202020002022022000002020002222002200002022002200

Note that the exact value of the answer must be printed as an integer, even if it is big.

F - abc285_brutmhyhiizp

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

配点 : 300 点

問題文

別世界の AtCoder で開催されている AtCoder Big Contest では、 10^{16} 問の問題が一度に出題されます。
問題の ID は 1 問目から順に A, B, ..., Z, AA, AB, ..., ZZ, AAA, ... と付けられています。

つまり、 ID は以下の順番で付けられています。

  • 長さ 1 の英大文字からなる文字列を辞書順に並べたもの
  • 長さ 2 の英大文字からなる文字列を辞書順に並べたもの
  • 長さ 3 の英大文字からなる文字列を辞書順に並べたもの
  • ...

このコンテストに含まれる問題の ID である文字列 S が与えられるので、それが何問目か答えてください。

制約

  • S は AtCoder Big Contest に含まれる問題の ID として正しい

入力

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

S

出力

答えを整数として出力せよ。


入力例 1

AB

出力例 1

28

ID が AB である問題は、 AtCoder Big Contest の 28 問目です。


入力例 2

C

出力例 2

3

ID が C である問題は、 AtCoder Big Contest の 3 問目です。


入力例 3

BRUTMHYHIIZP

出力例 3

10000000000000000

ID が BRUTMHYHIIZP である問題は、 AtCoder Big Contest の 10^{16} 問目、すなわち最終問題です。

Score : 300 points

Problem Statement

In a parallel universe, AtCoder holds AtCoder Big Contest, where 10^{16} problems are given at once.
The IDs of the problems are as follows, from the 1-st problem in order: A, B, ..., Z, AA, AB, ..., ZZ, AAA, ...

In other words, the IDs are given in the following order:

  • the strings of length 1 consisting of uppercase English letters, in lexicographical order;
  • the strings of length 2 consisting of uppercase English letters, in lexicographical order;
  • the strings of length 3 consisting of uppercase English letters, in lexicographical order;
  • ...

Given a string S that is an ID of a problem given in this contest, find the index of the problem. (See also Samples.)

Constraints

  • S is a valid ID of a problem given in AtCoder Big Contest.

Input

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

S

Output

Print the answer as an integer.


Sample Input 1

AB

Sample Output 1

28

The problem whose ID is AB is the 28-th problem of AtCoder Big Contest, so 28 should be printed.


Sample Input 2

C

Sample Output 2

3

The problem whose ID is C is the 3-rd problem of AtCoder Big Contest, so 3 should be printed.


Sample Input 3

BRUTMHYHIIZP

Sample Output 3

10000000000000000

The problem whose ID is BRUTMHYHIIZP is the 10^{16}-th (last) problem of AtCoder Big Contest, so 10^{16} should be printed as an integer.

G - A Piece of Cake

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

配点 : 400 点

問題文

xy -平面上にいくつかのイチゴが載った長方形のケーキがあります。 ケーキは、長方形領域 \lbrace (x, y) : 0 \leq x \leq W, 0 \leq y \leq H \rbrace をちょうど占めます。

ケーキには N 個のイチゴが載っており、i = 1, 2, \ldots, N について、i 番目のイチゴの座標は (p_i, q_i) です。 2 個以上のイチゴが同一の座標にあることはありません。

高橋君は、このケーキを包丁で下記の通りにいくつかのピースに切り分けます。

  • まず、ケーキを通る y 軸に並行な A 本の異なる直線、直線 x = a_1 、直線 x = a_2 、\ldots 、直線 x = a_A のそれぞれにそってケーキを切る。
  • 次に、ケーキを通る x 軸に並行な B 本の異なる直線、直線 y = b_1 、直線 y = b_2 、\ldots 、直線 y = b_B のそれぞれにそってケーキを切る。

その結果、ケーキは (A+1)(B+1) 個の長方形のピースに分割されます。 高橋君はそれらのうちのいずれか 1 個だけを選んで食べます。 高橋君が選んだピースに載っているイチゴの個数としてあり得る最小値と最大値をそれぞれ出力してください。

ここで、最終的にピースの縁となる位置にはイチゴが存在しないことが保証されます。 より形式的な説明は下記の制約を参照してください。

制約

  • 3 \leq W, H \leq 10^9
  • 1 \leq N \leq 2 \times 10^5
  • 0 \lt p_i \lt W
  • 0 \lt q_i \lt H
  • i \neq j \implies (p_i, q_i) \neq (p_j, q_j)
  • 1 \leq A, B \leq 2 \times 10^5
  • 0 \lt a_1 \lt a_2 \lt \cdots \lt a_A \lt W
  • 0 \lt b_1 \lt b_2 \lt \cdots \lt b_B \lt H
  • p_i \not \in \lbrace a_1, a_2, \ldots, a_A \rbrace
  • q_i \not \in \lbrace b_1, b_2, \ldots, b_B \rbrace
  • 入力はすべて整数

入力

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

W H
N
p_1 q_1
p_2 q_2
\vdots
p_N q_N
A
a_1 a_2 \ldots a_A
B
b_1 b_2 \ldots b_B

出力

高橋君が選んだピースに載っているイチゴの個数としてあり得る最小値 m と最大値 M をそれぞれ、下記の形式の通り空白区切りで出力せよ。

m M

入力例 1

7 6
5
6 1
3 1
4 2
1 5
6 2
2
2 5
2
3 4

出力例 1

0 2

全 9 個のピースの内訳は、イチゴが 0 個載ったものが 6 個、イチゴが 1 個載ったものが 1 個、イチゴが 2 個載ったものが 2 個です。 よって、それらのうちのいずれか 1 個だけを選んで食べるとき、選んだピースに載っているイチゴの個数としてあり得る最小値は 0 、最大値は 2 です。


入力例 2

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

出力例 2

1 1

どのピースにもイチゴが 1 個載っています。

Score : 400 points

Problem Statement

There is a rectangular cake with some strawberries on the xy-plane. The cake occupies the rectangular area \lbrace (x, y) : 0 \leq x \leq W, 0 \leq y \leq H \rbrace.

There are N strawberries on the cake, and the coordinates of the i-th strawberry are (p_i, q_i) for i = 1, 2, \ldots, N. No two strawberries have the same coordinates.

Takahashi will cut the cake into several pieces with a knife, as follows.

  • First, cut the cake along A different lines parallel to the y-axis: lines x = a_1, x = a_2, \ldots, x = a_A.
  • Next, cut the cake along B different lines parallel to the x-axis: lines y = b_1, y = b_2, \ldots, y = b_B.

As a result, the cake will be divided into (A+1)(B+1) rectangular pieces. Takahashi will choose just one of these pieces to eat. Print the minimum and maximum possible numbers of strawberries on the chosen piece.

Here, it is guaranteed that there are no strawberries along the edges of the final pieces. For a more formal description, refer to the constraints below.

Constraints

  • 3 \leq W, H \leq 10^9
  • 1 \leq N \leq 2 \times 10^5
  • 0 \lt p_i \lt W
  • 0 \lt q_i \lt H
  • i \neq j \implies (p_i, q_i) \neq (p_j, q_j)
  • 1 \leq A, B \leq 2 \times 10^5
  • 0 \lt a_1 \lt a_2 \lt \cdots \lt a_A \lt W
  • 0 \lt b_1 \lt b_2 \lt \cdots \lt b_B \lt H
  • p_i \not \in \lbrace a_1, a_2, \ldots, a_A \rbrace
  • q_i \not \in \lbrace b_1, b_2, \ldots, b_B \rbrace
  • All input values are integers.

Input

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

W H
N
p_1 q_1
p_2 q_2
\vdots
p_N q_N
A
a_1 a_2 \ldots a_A
B
b_1 b_2 \ldots b_B

Output

Print the minimum possible number of strawberries m and the maximum possible number M on the chosen piece in the following format, separated by a space.

m M

Sample Input 1

7 6
5
6 1
3 1
4 2
1 5
6 2
2
2 5
2
3 4

Sample Output 1

0 2

There are nine pieces in total: six with zero strawberries, one with one strawberry, and two with two strawberries. Therefore, when choosing just one of these pieces to eat, the minimum possible number of strawberries on the chosen piece is 0, and the maximum possible number is 2.


Sample Input 2

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

Sample Output 2

1 1

Each piece has one strawberry on it.

H - Prerequisites

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

配点 : 425 点

問題文

1 から N までの番号がついた N 冊の本があります。
本 i には C_i 冊の前提となる本があり、そのうち j 冊目は本 P_{i,j} で、本 i を読む前にこの C_i 冊をすべて読む必要があります。
ただし、適切な順序を選ぶことですべての本を読むことができます。

あなたは本 1 を読むために必要な最小の数の本を読もうとしています。
本 1 以外に読まなければならない本の番号を読むべき順に出力してください。ただし、この条件下で読むべき本の集合は一意に定まります。
条件を満たす読む順番が複数考えられる場合は、そのいずれを出力しても構いません。

制約

  • 2 \leq N \leq 2 \times 10^5
  • 0 \leq C_i < N
  • \sum_{i=1}^{N} C_i \leq 2 \times 10^5
  • C_1 \geq 1
  • 1 \leq P_{i,j} \leq N
  • 1 \leq j < k \leq C_i のとき P_{i,j} \neq P_{i,k}
  • すべての本を読むことが可能である

入力

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

N
C_1 P_{1,1} \ldots P_{1,C_1}
C_2 P_{2,1} \ldots P_{2,C_2}
\vdots
C_N P_{N,1} \ldots P_{N,C_N}

出力

本 1 を読むために読む必要のある最小の数の本を読むとき、それらの番号を読むべき順に空白区切りで出力せよ。


入力例 1

6
3 2 3 4
2 3 5
0
1 5
0
0

出力例 1

5 3 4 2

本 1 を読むために本 2,3,4、本 2 を読むために本 3,5、本 4 を読むために本 5 を読む必要があります。本 3,5,6 を読むために他の本を読む必要はありません。

このとき、例えば本 5,3,4,2 の順に読むことで本 1 を読むことができます。3 冊以下の本を読んだ状態で本 1 が読めるようになることはないため、これは答えの一つです。他にも本 3,5,4,2 の順などで読むことでも 4 冊の本を読んだ状態で本 1 を読むことができるようになります。


入力例 2

6
1 2
1 3
1 4
1 5
1 6
0

出力例 2

6 5 4 3 2

入力例 3

8
1 5
1 6
1 7
1 8
0
0
0
0

出力例 3

5

Score : 425 points

Problem Statement

We have N books numbered 1 to N.
Book i assumes that you have read C_i books, the j-th of which is book P_{i,j}: you must read all these C_i books before reading book i.
Here, you can read all the books in some order.

You are trying to read the minimum number of books required to read book 1.
Print the numbers of the books you must read excluding book 1 in the order they should be read. Under this condition, the set of books to read is uniquely determined.
If there are multiple reading orders that satisfy the condition, you may print any of them.

Constraints

  • 2 \leq N \leq 2 \times 10^5
  • 0 \leq C_i < N
  • \sum_{i=1}^{N} C_i \leq 2 \times 10^5
  • C_1 \geq 1
  • 1 \leq P_{i,j} \leq N
  • P_{i,j} \neq P_{i,k} for 1 \leq j < k \leq C_i.
  • It is possible to read all the books.

Input

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

N
C_1 P_{1,1} \ldots P_{1,C_1}
C_2 P_{2,1} \ldots P_{2,C_2}
\vdots
C_N P_{N,1} \ldots P_{N,C_N}

Output

Print the numbers of the books you must read to read book 1 in the order they should be read, with spaces in between.


Sample Input 1

6
3 2 3 4
2 3 5
0
1 5
0
0

Sample Output 1

5 3 4 2

To read book 1, you must read books 2,3,4; to read book 2, you must read books 3,5; to read book 4, you must read book 5. To read books 3,5,6, you do not have to read any other books.

For example, if you read books 5,3,4,2 in this order, you can read book 1. This is a correct answer, because you will never be able to read book 1 with three or fewer books read. As another example, reading books 3,5,4,2 in this order also allows you to read book 1 with 4 books read.


Sample Input 2

6
1 2
1 3
1 4
1 5
1 6
0

Sample Output 2

6 5 4 3 2

Sample Input 3

8
1 5
1 6
1 7
1 8
0
0
0
0

Sample Output 3

5
I - #(subset sum = K) with Add and Erase

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

配点 : 525 点

問題文

箱を用意します。最初、箱は空です。
この箱に対して、以下の 2 種類の操作を合計 Q 個、入力で与えられた順に施します。

+ x

タイプ 1 : 箱の中に整数 x の書かれたボールを 1 つ追加する。

- x

タイプ 2 : 箱の中にある、整数 x の書かれたボールを 1 つ取り除く。
但し、取り除く前の時点で箱の中に整数 x が書かれたボールが含まれることが保証されます。


各操作後の箱に関して、以下の問題を解いてください。

箱からボールをいくつか取り出して、ボールに書かれた整数の総和を K とする方法の総数を 998244353 で割った余りを求めてください。
但し、箱の中に入っている全てのボールは区別可能です。

制約

  • 入力は全て整数
  • 1 \le Q \le 5000
  • 1 \le K \le 5000
  • タイプ 1 の操作に関して、 1 \le x \le 5000
  • 全ての操作は問題文中の条件を満たす。

入力

入力は以下の形式で標準入力から与えられる。
但し、 \rm{Query}_{i} は i 個目の操作を表す。

Q K
\rm{Query}_{1}
\rm{Query}_{2}
\vdots
\rm{Query}_{Q}

出力

全体で Q 行出力せよ。
そのうち i 行目には、 i 個目までの操作を終えた時点での答えを出力せよ。


入力例 1

15 10
+ 5
+ 2
+ 3
- 2
+ 5
+ 10
- 3
+ 1
+ 3
+ 3
- 5
+ 1
+ 7
+ 4
- 3

出力例 1

0
0
1
0
1
2
2
2
2
2
1
3
5
8
5

この入力には、操作が 15 個含まれます。

最後の操作の後、箱の中に入ったボールは (5,10,1,3,1,7,4) となります。
総和を 10 にする方法は以下の 5 通りです。

  • 5+1+3+1 ( 1,3,4,5 番目のボールを取り出す )
  • 5+1+4 ( 1,3,7 番目のボールを取り出す )
  • 5+1+4 ( 1,5,7 番目のボールを取り出す )
  • 10 ( 2 番目のボールを取り出す )
  • 3+7 ( 4,6 番目のボールを取り出す )

Score : 525 points

Problem Statement

We have a box, which is initially empty.
Let us perform a total of Q operations of the following two types in the order they are given in the input.

+ x

Type 1: Put into the box a ball with the integer x written on it.

- x

Type 2: Remove from the box a ball with the integer x written on it.
It is guaranteed that the box contains a ball with the integer x written on it before the operation.


For the box after each operation, solve the following problem.

Find the number, modulo 998244353, to pick up some number of balls from the box so that the integers written on them sum to K.
All balls in the box are distinguishable.

Constraints

  • All input values are integers.
  • 1 \le Q \le 5000
  • 1 \le K \le 5000
  • For each type-1 operation, 1 \le x \le 5000.
  • All the operations satisfy the condition in the problem statement.

Input

The input is given from Standard Input in the following format, where \mathrm{Query}_i represents the i-th operation:

Q K
\rm{Query}_{1}
\rm{Query}_{2}
\vdots
\rm{Query}_{Q}

Output

Print Q lines.
The i-th line should contain the answer when the first i operations have been done.


Sample Input 1

15 10
+ 5
+ 2
+ 3
- 2
+ 5
+ 10
- 3
+ 1
+ 3
+ 3
- 5
+ 1
+ 7
+ 4
- 3

Sample Output 1

0
0
1
0
1
2
2
2
2
2
1
3
5
8
5

This input contains 15 operations.

After the last operation, the box contains the balls (5,10,1,3,1,7,4).
There are five ways to pick up balls for a sum of 10:

  • 5+1+3+1 (the 1-st, 3-rd, 4-th, 5-th balls)
  • 5+1+4 (the 1-st, 3-rd, 7-th balls)
  • 5+1+4 (the 1-st, 5-th, 7-th balls)
  • 10 (the 2-nd ball)
  • 3+7 (the 4-th, 6-th balls)