A - 2UP3DOWN

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

配点 : 100

問題文

高橋君が 100 階建てのビルにいます。

高橋君は 2 階分までの上り、または、3 階分までの下りであれば移動には階段を使い、そうでないときエレベーターを使います。

高橋君が X 階から Y 階への移動に使うのは階段ですか?

制約

  • 1 \leq X,Y \leq 100
  • X \neq Y
  • 入力は全ては整数である

入力

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

X Y

出力

移動に使うのが階段ならば Yes、エレベーターならば No を出力せよ。


入力例 1

1 4

出力例 1

No

1 階から 4 階への移動は 3 階分の上りなのでエレベーターを使います。


入力例 2

99 96

出力例 2

Yes

99 階から 96 階への移動は 3 階分の下りなので階段を使います。


入力例 3

100 1

出力例 3

No

Score : 100 points

Problem Statement

Takahashi is in a building with 100 floors.

He uses the stairs for moving up two floors or less or moving down three floors or less, and uses the elevator otherwise.

Does he use the stairs to move from floor X to floor Y?

Constraints

  • 1 \leq X,Y \leq 100
  • X \neq Y
  • All input values are integers.

Input

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

X Y

Output

If Takahashi uses the stairs for the move, print Yes; if he uses the elevator, print No.


Sample Input 1

1 4

Sample Output 1

No

The move from floor 1 to floor 4 involves going up three floors, so Takahashi uses the elevator.


Sample Input 2

99 96

Sample Output 2

Yes

The move from floor 99 to floor 96 involves going down three floors, so Takahashi uses the stairs.


Sample Input 3

100 1

Sample Output 3

No
B - Not Overflow

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

配点 : 100

問題文

整数 N が与えられます。 N-2^{31} 以上かつ 2^{31} 未満ならば Yes を、そうでないならば No を出力してください。

制約

  • -2^{63} \leq N < 2^{63}
  • N は整数である。

入力

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

N

出力

N-2^{31} 以上かつ 2^{31} 未満ならば Yes を、そうでないならば No を出力せよ。


入力例 1

10

出力例 1

Yes

10-2^{31} 以上かつ 2^{31} 未満であるので、Yes を出力します。


入力例 2

-9876543210

出力例 2

No

-9876543210-2^{31} 未満であるので、No を出力します。


入力例 3

483597848400000

出力例 3

No

4835978484000002^{31} 以上であるので、No を出力します。

Score : 100 points

Problem Statement

You are given an integer N. If N is between -2^{31} and 2^{31}-1 (inclusive), print Yes; otherwise, print No.

Constraints

  • -2^{63} \leq N < 2^{63}
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

If N is between -2^{31} and 2^{31}-1 (inclusive), print Yes; otherwise, print No.


Sample Input 1

10

Sample Output 1

Yes

10 is between -2^{31} and 2^{31}-1, so Yes should be printed.


Sample Input 2

-9876543210

Sample Output 2

No

-9876543210 is less than -2^{31}, so No should be printed.


Sample Input 3

483597848400000

Sample Output 3

No

483597848400000 is greater than 2^{31}-1, so No should be printed.

C - Which is ahead?

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

配点 : 200

問題文

N 人が 1 列に並んでおり、前から i 番目に並んでいる人は人 P_i です。

Q 個のクエリを処理して下さい。i 番目のクエリは以下のものです。

  • 整数 A_i,B_i が与えられる。人 A_i と人 B_i のうち、より前に並んでいる人の番号を出力せよ。

制約

  • 入力は全て整数
  • 1\leq N\leq 100
  • 1\leq P_i\leq N
  • P_i \neq P_j\ (i\neq j)
  • 1\leq Q \leq 100
  • 1\leq A_i<B_i\leq N

入力

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

N
P_1 \ldots P_N
Q
A_1 B_1
\vdots
A_Q B_Q

出力

Q 行出力せよ。i 行目には、i 番目のクエリの答えを出力せよ。


入力例 1

3
2 1 3
3
2 3
1 2
1 3

出力例 1

2
2
1

1 番目のクエリでは、人 2 は前から 1 番目、人 3 は前から 3 番目なので、人 2 がより前にいます。

2 番目のクエリでは、人 1 は前から 2 番目、人 2 は前から 1 番目なので、人 2 がより前にいます。

3 番目のクエリでは、人 1 は前から 2 番目、人 3 は前から 3 番目なので、人 1 がより前にいます。


入力例 2

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

出力例 2

3
2
3
3
3
2
3
3
7
1
2
3
3

Score: 200 points

Problem Statement

There are N people standing in a line. The person standing at the i-th position from the front is person P_i.

Process Q queries. The i-th query is as follows:

  • You are given integers A_i and B_i. Between person A_i and person B_i, print the person number of the person standing further to the front.

Constraints

  • All inputs are integers.
  • 1 \leq N \leq 100
  • 1 \leq P_i \leq N
  • P_i \neq P_j\ (i \neq j)
  • 1 \leq Q \leq 100
  • 1 \leq A_i < B_i \leq N

Input

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

N
P_1 \ldots P_N
Q
A_1 B_1
\vdots
A_Q B_Q

Output

Print Q lines. The i-th line should contain the response for the i-th query.


Sample Input 1

3
2 1 3
3
2 3
1 2
1 3

Sample Output 1

2
2
1

In the first query, person 2 is at the first position from the front, and person 3 is at the third position, so person 2 is further to the front.

In the second query, person 1 is at the second position from the front, and person 2 is at the first position, so person 2 is further to the front.

In the third query, person 1 is at the second position from the front, and person 3 is at the third position, so person 1 is further to the front.


Sample Input 2

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

Sample Output 2

3
2
3
3
3
2
3
3
7
1
2
3
3
D - Japanese Cursed Doll

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

配点 : 200

問題文

N 人の人がおり、i 人目 (1\leq i\leq N) の現在の髪の長さは L_i です。
すべての人は 1 日経つごとに髪の長さが 1 ずつ増えます。

髪の長さが T 以上の人が初めて P 人以上になるのは現在から何日後か出力してください。
ただし、現在の時点ですでに髪の長さが T 以上の人が P 人以上にいる場合は 0 を出力してください。

制約

  • 1\leq N\leq 100
  • 1\leq L_i\leq 100
  • 1\leq T\leq 100
  • 1\leq P\leq N
  • 入力はすべて整数

入力

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

N T P
L_1 L_2 \ldots L_N

出力

髪の長さが T 以上の人が初めて P 人以上になるのは現在から何日後か出力せよ。 ただし、現在の時点ですでに条件をみたしている場合は 0 を出力せよ。


入力例 1

5 10 3
3 11 1 6 2

出力例 1

7

5 人の人がおり、現在の時点で髪の長さはそれぞれ 3,11,1,6,2 であるため、髪の長さが 10 以上の人は 1 人です。

現在から 7 日後にはそれぞれの人の髪の長さは順に 10,18,8,13,9 となり、髪の長さが 10 以上の人は 3 人となります。
現在から 6 日後の時点では髪の長さが 10 以上の人は 2 人であるため条件をみたしておらず、よって 7 を出力します。


入力例 2

2 5 2
10 10

出力例 2

0

現在の時点ですでに髪の長さが 5 以上の人が 2 人いるため条件をみたしており、0 を出力します。


入力例 3

3 10 1
1 2 3

出力例 3

7

Score : 200 points

Problem Statement

There are N people, and the current hair length of the i-th person (1 \leq i \leq N) is L_i.
Each person's hair grows by 1 per day.

Print the number of days after which the number of people whose hair length is at least T becomes P or more for the first time.
If there are already P or more people whose hair length is at least T now, print 0.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq L_i \leq 100
  • 1 \leq T \leq 100
  • 1 \leq P \leq N
  • All input values are integers.

Input

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

N T P
L_1 L_2 \ldots L_N

Output

Print the number of days after which the number of people whose hair length is at least T becomes P or more for the first time. If this condition is already satisfied now, print 0.


Sample Input 1

5 10 3
3 11 1 6 2

Sample Output 1

7

There are five people, and their current hair lengths are 3, 11, 1, 6, 2, so there is one person whose hair length is at least 10.

After seven days, the hair lengths of the people will be 10, 18, 8, 13, 9, respectively, and there will be three people whose hair length is at least 10.
After six days, there are only two people whose hair length is at least 10, not satisfying the condition, so print 7.


Sample Input 2

2 5 2
10 10

Sample Output 2

0

Since there are already two people whose hair length is at least 5 now, satisfying the condition, so print 0.


Sample Input 3

3 10 1
1 2 3

Sample Output 3

7
E - Perfect Bus

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

配点 : 250

問題文

一台のバスが走っています。バスの乗客の数は常に非負整数です。

このバスにはある時点で 0 人以上の乗客が乗っており、その時点から現在までに N 回停車しました。このうち i 回目の停車では乗客が差し引き A_i 人増えました。A_i は負の値であることもあり、その場合は乗客が差し引き -A_i 人減ったことを意味しています。また、停車時以外には乗客の乗り降りはありませんでした。

与えられた情報に矛盾しない現在のバスの乗客の数として考えられる最小値を求めてください。

制約

  • 1 \leq N \leq 2 \times 10^5
  • -10^9 \leq A_i \leq 10^9
  • 入力される数値はすべて整数

入力

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

N
A_1 A_2 \ldots A_N

出力

答えを出力せよ。


入力例 1

4
3 -5 7 -4

出力例 1

3

はじめに乗っている乗客の人数が 2 人であるとき、現在の乗客の人数は 2 + 3 + (-5) + 7 + (-4) = 3 人であり、さらにバスの乗客の人数は常に非負整数となります。


入力例 2

5
0 0 0 0 0

出力例 2

0

入力例 3

4
-1 1000000000 1000000000 1000000000

出力例 3

3000000000

Score: 250 points

Problem Statement

A bus is in operation. The number of passengers on the bus is always a non-negative integer.

At some point in time, the bus had zero or more passengers, and it has stopped N times since then. At the i-th stop, the number of passengers increased by A_i. Here, A_i can be negative, meaning the number of passengers decreased by -A_i. Also, no passengers got on or off the bus other than at the stops.

Find the minimum possible current number of passengers on the bus that is consistent with the given information.

Constraints

  • 1 \leq N \leq 2 \times 10^5
  • -10^9 \leq A_i \leq 10^9
  • All input values are integers.

Input

The 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 -5 7 -4

Sample Output 1

3

If the initial number of passengers was 2, the current number of passengers would be 2 + 3 + (-5) + 7 + (-4) = 3, and the number of passengers on the bus would have always been a non-negative integer.


Sample Input 2

5
0 0 0 0 0

Sample Output 2

0

Sample Input 3

4
-1 1000000000 1000000000 1000000000

Sample Output 3

3000000000
F - NewFolder(1)

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

配点 : 300

問題文

2 つの文字列 A,B に対して、A の末尾に B を連結した文字列を A+B と表します。

N 個の文字列 S_1,\ldots,S_N が与えられます。i=1,\ldots,N の順に、次の指示に従って加工して出力してください。

  • S_1,\ldots,S_{i-1} の中に S_i と同じ文字列が存在しないならば、S_i を出力する。
  • S_1,\ldots,S_{i-1} の中に S_i と同じ文字列が X(X>0) 存在するならば、X を文字列として扱って S_i+ ( +X+ ) を出力する。

制約

  • 1 \leq N \leq 2\times 10^5
  • S_i は英小文字のみからなる長さ 1 以上 10 以下の文字列

入力

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

N
S_1
S_2
\vdots
S_N

出力

問題文中の指示にしたがって、N 行出力せよ。


入力例 1

5
newfile
newfile
newfolder
newfile
newfolder

出力例 1

newfile
newfile(1)
newfolder
newfile(2)
newfolder(1)

入力例 2

11
a
a
a
a
a
a
a
a
a
a
a

出力例 2

a
a(1)
a(2)
a(3)
a(4)
a(5)
a(6)
a(7)
a(8)
a(9)
a(10)

Score : 300 points

Problem Statement

For two strings A and B, let A+B denote the concatenation of A and B in this order.

You are given N strings S_1,\ldots,S_N. Modify and print them as follows, in the order i=1, \ldots, N:

  • if none of S_1,\ldots,S_{i-1} is equal to S_i, print S_i;
  • if X (X>0) of S_1,\ldots,S_{i-1} are equal to S_i, print S_i+ ( +X+ ), treating X as a string.

Constraints

  • 1 \leq N \leq 2\times 10^5
  • S_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
S_1
S_2
\vdots
S_N

Output

Print N lines as specified in the Problem Statement.


Sample Input 1

5
newfile
newfile
newfolder
newfile
newfolder

Sample Output 1

newfile
newfile(1)
newfolder
newfile(2)
newfolder(1)

Sample Input 2

11
a
a
a
a
a
a
a
a
a
a
a

Sample Output 2

a
a(1)
a(2)
a(3)
a(4)
a(5)
a(6)
a(7)
a(8)
a(9)
a(10)
G - Sum of Maximum Weights

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

配点 : 400

問題文

N 頂点の木があり、頂点は 1, 2, \dots, N と番号付けられています。
i \, (1 \leq i \leq N - 1) 番目の辺は頂点 u_i と頂点 v_i を結び、重みは w_i です。

異なる頂点 u, v に対し、頂点 u から頂点 v までの最短パスに含まれる辺の重みの最大値を f(u, v) とおきます。

\displaystyle \sum_{i = 1}^{N - 1} \sum_{j = i + 1}^N f(i, j) を求めてください。

制約

  • 2 \leq N \leq 10^5
  • 1 \leq u_i, v_i \leq N
  • 1 \leq w_i \leq 10^7
  • 与えられるグラフは木である。
  • 入力は全て整数である。

入力

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

N
u_1 v_1 w_1
\vdots
u_{N - 1} v_{N - 1} w_{N - 1}

出力

答えを出力せよ。


入力例 1

3
1 2 10
2 3 20

出力例 1

50

f(1, 2) = 10, f(2, 3) = 20, f(1, 3) = 20 であるので、これらの和である 50 を出力します。


入力例 2

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

出力例 2

76

Score : 400 points

Problem Statement

We have a tree with N vertices numbered 1, 2, \dots, N.
The i-th edge (1 \leq i \leq N - 1) connects Vertex u_i and Vertex v_i and has a weight w_i.

For different vertices u and v, let f(u, v) be the greatest weight of an edge contained in the shortest path from Vertex u to Vertex v.

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

Constraints

  • 2 \leq N \leq 10^5
  • 1 \leq u_i, v_i \leq N
  • 1 \leq w_i \leq 10^7
  • The given graph is a tree.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
u_1 v_1 w_1
\vdots
u_{N - 1} v_{N - 1} w_{N - 1}

Output

Print the answer.


Sample Input 1

3
1 2 10
2 3 20

Sample Output 1

50

We have f(1, 2) = 10, f(2, 3) = 20, and f(1, 3) = 20, so we should print their sum, or 50.


Sample Input 2

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

Sample Output 2

76
H - Nearest Black Vertex

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

配点 : 500

問題文

N 個の頂点と M 本の辺からなる、単純(自己ループおよび多重辺を含まない)かつ連結な無向グラフが与えられます。
i = 1, 2, \ldots, M について、i 番目の辺は頂点 u_i と頂点 v_i を結ぶ無向辺です。

各頂点を白または黒で塗る方法であって、下記の 2 つの条件をともに満たすものが存在するかを判定し、存在する場合はその一例を示してください。

  • 1 個以上の頂点が黒で塗られている。
  • すべての i = 1, 2, \ldots, K について、下記の条件が成り立つ。
    • 頂点 p_i と「黒で塗られた頂点のうち頂点 p_i からの距離が最小であるもの」の距離がちょうど d_i である。

ここで、頂点 u と頂点 v の距離は、uv を結ぶパスの辺の本数としてあり得る最小値として定義されます。

制約

  • 1 \leq N \leq 2000
  • N-1 \leq M \leq \min\lbrace N(N-1)/2, 2000 \rbrace
  • 1 \leq u_i, v_i \leq N
  • 0 \leq K \leq N
  • 1 \leq p_1 \lt p_2 \lt \cdots \lt p_K \leq N
  • 0 \leq d_i \leq N
  • 与えられるグラフは単純かつ連結
  • 入力はすべて整数

入力

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

N M
u_1 v_1
u_2 v_2
\vdots
u_M v_M
K
p_1 d_1
p_2 d_2
\vdots
p_K d_K

出力

問題文中の条件を満たすように各頂点を白または黒で塗る方法が存在しない場合は、No を出力せよ。
存在する場合は、下記の形式の通り、1 行目に Yes と出力し、2 行目に各頂点を塗る方法を表す文字列 S を出力せよ。 ここで、S は長さ N の文字列であり、i = 1, 2, \ldots, N について Si 文字目は、頂点 i を黒で塗るとき 1 、白で塗るとき 0 である。

Yes
S

答えが複数ある場合、どれを出力しても正解とみなされる。


入力例 1

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

出力例 1

Yes
10100

例えば、頂点 1, 3 を黒に、頂点 2, 4, 5 を白に塗るという方法が、問題文中の条件を満たします。
実際、i = 1, 2, 3, 4, 5 について、頂点 i と「黒で塗られた頂点のうち頂点 i からの距離が最小であるもの」の距離を A_i で表すと、 (A_1, A_2, A_3, A_4, A_5) = (0, 1, 0, 1, 2) であり、特に、A_1 = 0, A_5 = 2 が成り立ちます。


入力例 2

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

出力例 2

No

問題文中の条件を満たすように各頂点を白または黒で塗る方法が存在しないため、No を出力します。


入力例 3

1 0
0

出力例 3

Yes
1

Score : 500 points

Problem Statement

You are given a simple connected undirected graph with N vertices and M edges (a simple graph contains no self-loop and no multi-edges).
For i = 1, 2, \ldots, M, the i-th edge connects vertex u_i and vertex v_i bidirectionally.

Determine whether there is a way to paint each vertex black or white to satisfy both of the following conditions, and show one such way if it exists.

  • At least one vertex is painted black.
  • For every i = 1, 2, \ldots, K, the following holds:
    • the minimum distance between vertex p_i and a vertex painted black is exactly d_i.

Here, the distance between vertex u and vertex v is the minimum number of edges in a path connecting u and v.

Constraints

  • 1 \leq N \leq 2000
  • N-1 \leq M \leq \min\lbrace N(N-1)/2, 2000 \rbrace
  • 1 \leq u_i, v_i \leq N
  • 0 \leq K \leq N
  • 1 \leq p_1 \lt p_2 \lt \cdots \lt p_K \leq N
  • 0 \leq d_i \leq N
  • The given graph is simple and connected.
  • All values in the input are integers.

Input

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

N M
u_1 v_1
u_2 v_2
\vdots
u_M v_M
K
p_1 d_1
p_2 d_2
\vdots
p_K d_K

Output

If there is no way to paint each vertex black or white to satisfy the conditions, print No.
Otherwise, print Yes in the first line, and a string S representing a coloring of the vertices in the second line, as shown below.
Here, S is a string of length N such that, for each i = 1, 2, \ldots, N, the i-th character of S is 1 if vertex i is painted black and 0 if white.

Yes
S

If multiple solutions exist, you may print any of them.


Sample Input 1

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

Sample Output 1

Yes
10100

One way to satisfy the conditions is to paint vertices 1, 3 black and vertices 2, 4, 5 white.
Indeed, for each i = 1, 2, 3, 4, 5, let A_i denote the minimum distance between vertex i and a vertex painted black, and we have (A_1, A_2, A_3, A_4, A_5) = (0, 1, 0, 1, 2), where A_1 = 0, A_5 = 2.


Sample Input 2

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

Sample Output 2

No

There is no way to satisfy the conditions by painting each vertex black or white, so you should print No.


Sample Input 3

1 0
0

Sample Output 3

Yes
1
I - Black and White Rooks

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

配点 : 500

問題文

N 行、横 M 列のマス目に、黒い飛車の駒 B 個と白い飛車の駒 W 個を設置することを考えましょう。

以下の条件をすべて満たす設置の仕方を いい配置 と呼びます。

  • B+W 個の駒すべてが設置されている。
  • 1 つのマスに置かれている駒の数は高々 1 つである。
  • ある白い駒と黒い駒の組であって、互いが互いを攻撃しているようなものが存在しない。すなわち、ある白い駒と黒い駒の組であって、一方が 1 手の移動によってもう片方が置かれているマスに到達できるようなものが存在しない。

ここで、飛車の駒は、今いる位置から上、下、右、左のいずれかの方向に伸びる直線上にあり、かつ他の駒を飛び越えずに到達できるマスに 1 手で移動することができます。

いい配置としてあり得るものは何通りありますか?答えは非常に大きくなることがあるので、998244353 で割ったあまりを出力してください。

同じ色の駒同士は区別しないものとします。

制約

  • 1 \leq N,M \leq 50
  • 1 \leq B,W \leq 2500
  • B+W \leq N \times M
  • 入力はすべて整数

入力

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

N M B W

出力

答えを 998244353 で割ったあまりを出力せよ。


入力例 1

2 2 1 1

出力例 1

4

いい配置としてあり得るものは以下の 4 通りです。


入力例 2

1 2 1 1

出力例 2

0

いい配置としてあり得るものが存在しない場合もあります。


入力例 3

40 40 30 30

出力例 3

467620384

998244353 で割ったあまりを出力することに注意してください。

Score : 500 points

Problem Statement

Consider placing B black rooks and W white rooks on a grid with N horizontal rows and M vertical columns.

A placement of the rooks satisfying all of the following conditions is called a good placement.

  • All B+W rooks are placed on the grid.
  • At most one rook is placed in the same square.
  • There is no pair of white rook and black rook attacking each other. That is, there is no pair of white rook and black rook such that one of them can reach the square in which the other is placed in one move.

Here, in one move, a rook can reach any square that is on a horizontal or vertical line from its current position and is reachable without jumping over another rook.

How many good placements are there? Since this count can be enormous, print it modulo 998244353.

Rooks in the same color are not distinguished.

Constraints

  • 1 \leq N,M \leq 50
  • 1 \leq B,W \leq 2500
  • B+W \leq N \times M
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M B W

Output

Print the count modulo 998244353.


Sample Input 1

2 2 1 1

Sample Output 1

4

There are four good placements as follows.


Sample Input 2

1 2 1 1

Sample Output 2

0

There may be no good placement.


Sample Input 3

40 40 30 30

Sample Output 3

467620384

Be sure to print the count modulo 998244353.