A - Probably English

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

英小文字からなる N 個の文字列 W_1,W_2,\dots,W_N が与えられます。
これらのうち一つ以上が and, not, that, the, you のいずれかと一致するなら Yes 、そうでないなら No と出力してください。

制約

  • N1 以上 100 以下の整数
  • 1 \le |W_i| \le 50 ( |W_i| は文字列 W_i の長さ )
  • W_i は英小文字からなる

入力

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

N
W_1 W_2 \dots W_N

出力

答えを出力せよ。


入力例 1

10
in that case you should print yes and not no

出力例 1

Yes

例えば W_4= you なので、 Yes と出力します。


入力例 2

10
in diesem fall sollten sie no und nicht yes ausgeben

出力例 2

No

文字列 W_i はいずれも、 and, not, that, the, you のいずれとも一致しません。

Score : 100 points

Problem Statement

You are given N strings W_1,W_2,\dots,W_N consisting of lowercase English letters.
If one or more of these strings equal and, not, that, the, or you, then print Yes; otherwise, print No.

Constraints

  • N is an integer between 1 and 100, inclusive.
  • 1 \le |W_i| \le 50 (|W_i| is the length of W_i.)
  • W_i consists of lowercase English letters.

Input

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

N
W_1 W_2 \dots W_N

Output

Print the answer.


Sample Input 1

10
in that case you should print yes and not no

Sample Output 1

Yes

We have, for instance, W_4= you, so you should print Yes.


Sample Input 2

10
in diesem fall sollten sie no und nicht yes ausgeben

Sample Output 2

No

None of the strings W_i equals any of and, not, that, the, and you.

B - Bombs

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

R 行横 C 列の盤面があります。上から i 行目、左から j 列目のマスを (i,j) と表します。

(i,j) の現在の状態が文字 B_{i,j} として与えられます。 . は空きマス、# は壁があるマスを表し、 1, 2,\dots, 9 はそれぞれ威力 1,2,\dots,9 の爆弾があるマスを表します。

次の瞬間に、全ての爆弾が同時に爆発します。 爆弾が爆発すると、爆弾があるマスからのマンハッタン距離がその爆弾の威力以下であるような全てのマス(その爆弾があるマス自体を含む)が空きマスに変わります。 ここで、(r_1,c_1) から (r_2,c_2) までのマンハッタン距離は |r_1-r_2|+|c_1-c_2| です。

爆発後の盤面を出力してください。

制約

  • 1\leq R,C \leq 20
  • R,C は整数
  • B_{i,j}., #, 1, 2,\dots, 9 のいずれかである

入力

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

R C
B_{1,1}B_{1,2}\dots B_{1,C}
\vdots
B_{R,1}B_{R,2}\dots B_{R,C}

出力

爆発後の盤面を R 行で出力せよ。盤面の表し方は入力と同じ形式を用いること (RC を出力する必要はない)。


入力例 1

4 4
.1.#
###.
.#2.
#.##

出力例 1

...#
#...
....
#...

爆弾の効果範囲を表す図

  • (1,2) にある爆弾の爆発によって、上図の青いマスと紫のマスが空きマスに変わります。
  • (3,3) にある爆弾の爆発によって、上図の赤いマスと紫のマスが空きマスに変わります。

この例のように、爆弾が効果を及ぼす範囲に被りがあることもあります。


入力例 2

2 5
..#.#
###.#

出力例 2

..#.#
###.#

爆弾が 1 つもないこともあります。


入力例 3

2 3
11#
###

出力例 3

...
..#

入力例 4

4 6
#.#3#.
###.#.
##.###
#1..#.

出力例 4

......
#.....
#....#
....#.

Score : 200 points

Problem Statement

We have a board with R rows running horizontally and C columns running vertically. Let (i,j) denote the square at the i-th row from the top and j-th column from the left.

You are given characters B_{i,j} representing the current states of (i,j). . represents an empty square; # represents a square with a wall; 1, 2,\dots, 9 represent a square with a bomb of power 1,2,\dots,9, respectively.

At the next moment, all bombs will explode simultaneously. When a bomb explodes, every square whose Manhattan distance from the square with the bomb is not greater than the power of the bomb will turn into an empty square. Here, the Manhattan distance from (r_1,c_1) to (r_2,c_2) is |r_1-r_2|+|c_1-c_2|.

Print the board after the explosions.

Constraints

  • 1\leq R,C \leq 20
  • R and C are integers.
  • Each B_{i,j} is one of ., #, 1, 2, \dots, 9.

Input

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

R C
B_{1,1}B_{1,2}\dots B_{1,C}
\vdots
B_{R,1}B_{R,2}\dots B_{R,C}

Output

Print R lines representing the board after the explosions. Use the format used in the input (do not print R or C).


Sample Input 1

4 4
.1.#
###.
.#2.
#.##

Sample Output 1

...#
#...
....
#...

Figure representing the explosion ranges of bombs

  • The explosion of the bomb at (1,2) will turn the blue squares and purple squares in the above figure into empty squares.
  • The explosion of the bomb at (3,3) will turn the red squares and purple squares in the above figure into empty squares.

As seen in this sample, the explosion ranges of bombs may overlap.


Sample Input 2

2 5
..#.#
###.#

Sample Output 2

..#.#
###.#

There may be no bombs.


Sample Input 3

2 3
11#
###

Sample Output 3

...
..#

Sample Input 4

4 6
#.#3#.
###.#.
##.###
#1..#.

Sample Output 4

......
#.....
#....#
....#.
C - Socks

Time Limit: 4 sec / Memory Limit: 1024 MB

配点 : 300

問題文

N 枚の靴下があります。i 枚目の靴下の色は A_i です。

あなたは以下の操作をできるだけ多い回数行いたいです。最大で何回行うことができますか?

  • まだペアになっていない靴下の中から同じ色の靴下を 2 枚選んでペアにする。

制約

  • 1\leq N \leq 5\times 10^5
  • 1\leq A_i \leq 10^9
  • 入力は全て整数

入力

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

N
A_1 A_2 \dots A_N

出力

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


入力例 1

6
4 1 7 4 1 4

出力例 1

2

以下のようにして、2 回の操作を行うことができます。

  • 色が 1 である靴下を 2 枚選んでペアにする。
  • 色が 4 である靴下を 2 枚選んでペアにする。

このとき、色が 4 である靴下と 7 である靴下が 1 枚ずつ残るため、これ以上操作はできません。 また、どのように操作をしても 3 回以上操作を行うことはできないため、2 を出力します。


入力例 2

1
158260522

出力例 2

0

入力例 3

10
295 2 29 295 29 2 29 295 2 29

出力例 3

4

Score : 300 points

Problem Statement

You have N socks. The color of the i-th sock is A_i.

You want to perform the following operation as many times as possible. How many times can it be performed at most?

  • Choose two same-colored socks that are not paired yet, and pair them.

Constraints

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

Input

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

N
A_1 A_2 \dots A_N

Output

Print an integer representing the answer.


Sample Input 1

6
4 1 7 4 1 4

Sample Output 1

2

You can do the operation twice as follows.

  • Choose two socks with the color 1 and pair them.
  • Choose two socks with the color 4 and pair them.

Then, you will be left with one sock with the color 4 and another with the color 7, so you can no longer do the operation. There is no way to do the operation three or more times, so you should print 2.


Sample Input 2

1
158260522

Sample Output 2

0

Sample Input 3

10
295 2 29 295 29 2 29 295 2 29

Sample Output 3

4
D - Three Days Ago

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

20230322 は並べ替えると 02320232 となり、これは 02322 度繰り返しています。
このように、数字のみからなる文字列であって、適切に文字を並び替える (そのままでもよい) ことによって同じ列を 2 度繰り返すようにできるものを 嬉しい列 と呼びます。
数字のみからなる文字列 S が与えられるので、以下の条件を全て満たす整数の組 (l,r) はいくつあるか求めてください。

  • 1 \le l \le r \le |S| ( |S|S の長さ)
  • Sl 文字目から r 文字目までの (連続する) 部分文字列は嬉しい列である。

制約

  • S は数字のみからなる長さ 1 以上 5 \times 10^5 以下の文字列

入力

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

S

出力

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


入力例 1

20230322

出力例 1

4

S= 20230322 です。
条件を満たす整数組 (l,r)(1,6),(1,8),(2,7),(7,8)4 つです。


入力例 2

0112223333444445555556666666777777778888888889999999999

出力例 2

185

S の先頭が 0 である場合もあります。


入力例 3

3141592653589793238462643383279502884197169399375105820974944

出力例 3

9

Score : 400 points

Problem Statement

The string 20230322 can be rearranged into 02320232, which is a repetition of 0232 twice.
Similarly, a string consisting of digits is said to be happy when it can be rearranged into (or already is) a repetition of some string twice.
You are given a string S consisting of digits. Find the number of pairs of integers (l,r) satisfying all of the following conditions.

  • 1 \le l \le r \le |S|. (|S| is the length of S.)
  • The (contiguous) substring formed of the l-th through r-th characters of S is happy.

Constraints

  • S is a string consisting of digits whose length is between 1 and 5 \times 10^5, inclusive.

Input

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

S

Output

Print an integer representing the answer.


Sample Input 1

20230322

Sample Output 1

4

We have S= 20230322.

Here are the four pairs of integers (l,r) that satisfy the condition: (1,6), (1,8), (2,7), and (7,8).


Sample Input 2

0112223333444445555556666666777777778888888889999999999

Sample Output 2

185

S may begin with 0.


Sample Input 3

3141592653589793238462643383279502884197169399375105820974944

Sample Output 3

9
E - Kth Number

Time Limit: 4 sec / Memory Limit: 1024 MB

配点 : 500

問題文

0 以上 M 以下の整数からなる長さ N の数列 A=(A_1,A_2,\dots,A_N) があります。

今からすぬけくんが以下の操作 1, 2 を順に行います。

  1. A_i=0 を満たすそれぞれの i について、1 以上 M 以下の整数を独立かつ一様ランダムに選び、A_i をその整数で置き換える。
  2. A を昇順に並び替える。

すぬけくんが操作 1, 2 を行ったあとの A_K の期待値を \text{mod } 998244353 で出力してください。

「期待値を \text{mod } 998244353 で出力」とは 求める期待値は必ず有理数となることが証明できます。 またこの問題の制約下では、その値を互いに素な 2 つの整数 P, Q を用いて \frac{P}{Q} と表したとき、 R \times Q \equiv P\pmod{998244353} かつ 0 \leq R \lt 998244353 を満たす整数 R がただ 1 つ存在することが証明できます。この R を出力してください。

制約

  • 1\leq K \leq N \leq 2000
  • 1\leq M \leq 2000
  • 0\leq A_i \leq M
  • 入力は全て整数

入力

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

N M K
A_1 A_2 \dots A_N

出力

すぬけくんが操作 1, 2 を行ったあとの A_K の期待値を \text{mod } 998244353 で出力せよ。


入力例 1

3 5 2
2 0 4

出力例 1

3

すぬけくんは操作 1 において A_21 以上 5 以下の整数で置き換えます。この整数を x とすると、

  • x=1,2 のとき、すぬけくんが操作 1, 2 を行ったあと A_2=2 です。
  • x=3 のとき、すぬけくんが操作 1, 2 を行ったあと A_2=3 です。
  • x=4,5 のとき、すぬけくんが操作 1, 2 を行ったあと A_2=4 です。

よって、A_2 の期待値は \frac{2+2+3+4+4}{5}=3 です。


入力例 2

2 3 1
0 0

出力例 2

221832080

期待値は \frac{14}{9} です。


入力例 3

10 20 7
6 5 0 2 0 0 0 15 0 0

出力例 3

617586310

Score : 500 points

Problem Statement

We have a sequence of length N consisting of integers between 0 and M, inclusive: A=(A_1,A_2,\dots,A_N).

Snuke will perform the following operations 1 and 2 in order.

  1. For each i such that A_i=0, independently choose a uniform random integer between 1 and M, inclusive, and replace A_i with that integer.
  2. Sort A in ascending order.

Print the expected value of A_K after the two operations, modulo 998244353.

How to print a number modulo 998244353? It can be proved that the sought expected value is always rational. Additionally, under the Constraints of this problem, when that value is represented as \frac{P}{Q} using two coprime integers P and Q, it can be proved that there is a unique integer R such that R \times Q \equiv P\pmod{998244353} and 0 \leq R \lt 998244353. Print this R.

Constraints

  • 1\leq K \leq N \leq 2000
  • 1\leq M \leq 2000
  • 0\leq A_i \leq M
  • All values in the input are integers.

Input

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

N M K
A_1 A_2 \dots A_N

Output

Print the expected value of A_K after the two operations, modulo 998244353.


Sample Input 1

3 5 2
2 0 4

Sample Output 1

3

In the operation 1, Snuke will replace A_2 with an integer between 1 and 5. Let x be this integer.

  • If x=1 or 2, we will have A_2=2 after the two operations.
  • If x=3, we will have A_2=3 after the two operations.
  • If x=4 or 5, we will have A_2=4 after the two operations.

Thus, the expected value of A_2 is \frac{2+2+3+4+4}{5}=3.


Sample Input 2

2 3 1
0 0

Sample Output 2

221832080

The expected value is \frac{14}{9}.


Sample Input 3

10 20 7
6 5 0 2 0 0 0 15 0 0

Sample Output 3

617586310
F - substr = S

Time Limit: 4 sec / Memory Limit: 1024 MB

配点 : 500

問題文

T 個のテストケースについて、数字のみからなる文字列 S と正整数 L,R が与えられるので、以下の問題を解いてください。

正整数 x に対して f(x)= ( x を ( 先頭に 0 を含まないように ) 書き下した文字列の連続部分列のうち S と合致するものの個数 ) と定義します。

例えば S= 22 であるとき、f(122) = 1, f(123) = 0, f(226) = 1, f(222) = 2 となります。

このとき、 \displaystyle \sum_{k=L}^{R} f(k) を求めてください。

制約

  • 1 \le T \le 1000
  • S は数字のみからなる長さ 1 以上 16 以下の文字列
  • L,R1 \le L \le R < 10^{16} を満たす整数

入力

入力は以下の形式で標準入力から与えられる。\rm{case}_ii 個目のテストケースを表す。

T
\rm{case}_{1}
\rm{case}_{2}
\vdots
\rm{case}_{\it{T}}

各テストケースは以下の形式である。

S L R

出力

全体で T 行出力せよ。
そのうち i 行目には i 番目のテストケースに対する答えを整数として出力せよ。


入力例 1

6
22 23 234
0295 295 295
0 1 9999999999999999
2718 998244353 9982443530000000
869120 1234567890123456 2345678901234567
2023032520230325 1 9999999999999999

出力例 1

12
0
14888888888888889
12982260572545
10987664021
1

この入力には 6 個のテストケースが含まれます。

  • 1 つ目のケースは S= 22 ,L=23,R=234 です。
    • f(122)=f(220)=f(221)=f(223)=f(224)=\dots=f(229)=1
    • f(222)=2
    • 以上より、このケースに対する答えは 12 です。
  • 2 つ目のケースは S= 0295 ,L=295,R=295 です。
    • f(295)=0 となることに注意してください。

Score : 500 points

Problem Statement

You are given a string S consisting of digits and positive integers L and R for each of T test cases. Solve the following problem.

For a positive integer x, let us define f(x) as the number of contiguous substrings of the decimal representation of x (without leading zeros) that equal S.

For instance, if S= 22, we have f(122) = 1, f(123) = 0, f(226) = 1, and f(222) = 2.

Find \displaystyle \sum_{k=L}^{R} f(k).

Constraints

  • 1 \le T \le 1000
  • S is a string consisting of digits whose length is between 1 and 16, inclusive.
  • L and R are integers satisfying 1 \le L \le R < 10^{16}.

Input

The input is given from Standard Input in the following format, where \rm{case}_i denotes the i-th test case:

T
\rm{case}_{1}
\rm{case}_{2}
\vdots
\rm{case}_{\it{T}}

Each test case is in the following format:

S L R

Output

Print T lines in total.
The i-th line should contain an integer representing the answer to the i-th test case.


Sample Input 1

6
22 23 234
0295 295 295
0 1 9999999999999999
2718 998244353 9982443530000000
869120 1234567890123456 2345678901234567
2023032520230325 1 9999999999999999

Sample Output 1

12
0
14888888888888889
12982260572545
10987664021
1

This input contains six test cases.

  • In the first test case, S= 22, L=23, R=234.
    • f(122)=f(220)=f(221)=f(223)=f(224)=\dots=f(229)=1.
    • f(222)=2.
    • Thus, the answer is 12.
  • In the second test case, S= 0295, L=295, R=295.
    • Note that f(295)=0.
G - Minimum Reachable City

Time Limit: 3 sec / Memory Limit: 1024 MB

配点 : 600

問題文

N 頂点の有向グラフ G_S があり、頂点には 1 から N までの番号が付けられています。 G_S には N-1 本の辺があり、i 本目 (1\leq i \leq N-1) の辺は頂点 p_i\ (1\leq p_i \leq i) から頂点 i+1 に伸びています。

N 頂点の有向グラフ G があり、頂点には 1 から N までの番号が付けられています。 最初、GG_S と一致しています。 G に関するクエリが Q 個与えられるので、与えられた順番に処理してください。クエリは次の 2 種類のいずれかです。

  • 1 u v : G に頂点 u から頂点 v に伸びる辺を追加する。 このとき、以下の条件が満たされることが保証される。
    • u \neq v
    • G_S 上で頂点 v からいくつかの辺を辿ることで頂点 u に到達可能である
  • 2 x : G 上で頂点 x からいくつかの辺を辿ることで到達可能な頂点 (頂点 x を含む) のうち、最も番号が小さい頂点の番号を出力する。

制約

  • 2\leq N \leq 2\times 10^5
  • 1\leq Q \leq 2\times 10^5
  • 1\leq p_i\leq i
  • 1 番目の形式のクエリについて、
    • 1\leq u,v \leq N
    • u \neq v
    • G_S 上で頂点 v からいくつかの辺を辿ることで頂点 u に到達可能である
  • 2 番目の形式のクエリについて、1\leq x \leq N
  • 入力は全て整数

入力

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

N
p_1 p_2 \dots p_{N-1}
Q
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q

ただし、\mathrm{query}_ii 個目のクエリを表しており、次のいずれかの形式で与えられる。

1 u v
2 x

出力

2 番目の形式のクエリの回数を q 回として、q 行出力せよ。 j\ (1\leq j \leq q) 行目には、2 番目の形式のクエリのうち j 個目のものに対する答えを出力せよ。


入力例 1

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

出力例 1

4
2
1
  • 1 個目のクエリの時点で、G 上で頂点 4 からいくつかの辺を辿ることで到達可能な頂点は 4 のみです。
  • 3 個目のクエリの時点で、G 上で頂点 4 からいくつかの辺を辿ることで到達可能な頂点は 2,3,4, 5 です。
  • 5 個目のクエリの時点で、G 上で頂点 4 からいくつかの辺を辿ることで到達可能な頂点は 1,2,3,4,5 です。

入力例 2

7
1 1 2 2 3 3
10
2 5
1 5 2
2 5
1 2 1
1 7 1
1 6 3
2 5
2 6
2 1
1 7 1

出力例 2

5
2
1
1
1

Score : 600 points

Problem Statement

We have a directed graph G_S with N vertices numbered 1 to N. It has N-1 edges. The i-th edge (1\leq i \leq N-1) goes from vertex p_i\ (1\leq p_i \leq i) to vertex i+1.

We have another directed graph G with N vertices numbered 1 to N. Initially, G equals G_S. Process Q queries on G in the order they are given. There are two kinds of queries as follows.

  • 1 u v : Add an edge to G that goes from vertex u to vertex v. It is guaranteed that the following conditions are satisfied.
    • u \neq v.
    • On G_S, vertex u is reachable from vertex v via some edges.
  • 2 x : Print the smallest vertex number of a vertex reachable from vertex x via some edges on G (including vertex x).

Constraints

  • 2\leq N \leq 2\times 10^5
  • 1\leq Q \leq 2\times 10^5
  • 1\leq p_i\leq i
  • For each query in the first format:
    • 1\leq u,v \leq N.
    • u \neq v.
    • On G_S, vertex u is reachable from vertex v via some edges.
  • For each query in the second format, 1\leq x \leq N.
  • All values in the input are integers.

Input

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

N
p_1 p_2 \dots p_{N-1}
Q
\mathrm{query}_1
\mathrm{query}_2
\vdots
\mathrm{query}_Q

Here, \mathrm{query}_i denotes the i-th query and is in one of the following formats:

1 u v
2 x

Output

Print q lines, where q is the number of queries in the second format. The i-th line (1\leq j \leq q) should contain the answer to the j-th query in the second format.


Sample Input 1

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

Sample Output 1

4
2
1
  • At the time of the first query, only vertex 4 is reachable from vertex 4 via some edges on G.
  • At the time of the third query, vertices 2, 3, 4, and 5 are reachable from vertex 4 via some edges on G.
  • At the time of the fifth query, vertices 1, 2, 3, 4, and 5 are reachable from vertex 4 via some edges on G.

Sample Input 2

7
1 1 2 2 3 3
10
2 5
1 5 2
2 5
1 2 1
1 7 1
1 6 3
2 5
2 6
2 1
1 7 1

Sample Output 2

5
2
1
1
1
Ex - E or m

Time Limit: 4 sec / Memory Limit: 1024 MB

配点 : 600

問題文

NM 列のグリッド A があり、はじめ全てのマスに 0 が書き込まれています。
ここに以下の操作を行います。

  • 1 \le i \le N を満たす各整数 i に対して、 Ai 行目の左から 0 個以上のマスの数字を 1 にする。
  • 1 \le j \le M を満たす各整数 j に対して、 Aj 列目の上から 0 個以上のマスの数字を 1 にする。

この手続きによって作ることのできる A の集合を S とします。

0, 1, ? からなる NM 列のグリッド X が与えられます。
?01 に置き換えて得られるグリッドは X に含まれる ? の総数を q とすると 2^q 個ありますが、このうち S の要素であるものはいくつありますか?
答えは非常に大きくなる場合があるので、 998244353 で割った余りを求めてください。

制約

  • N,M は整数
  • 1 \le N,M \le 18
  • X0, 1, ? からなる NM 列のグリッド

入力

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

N M
X_{1,1} X_{1,2} \dots X_{1,M}
X_{2,1} X_{2,2} \dots X_{2,M}
\vdots
X_{N,1} X_{N,2} \dots X_{N,M}

出力

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


入力例 1

2 3
0?1
?1?

出力例 1

6

条件を満たすグリッドは以下の 6 つです。

011  011  001
010  011  110

001  011  011
111  110  111

入力例 2

5 3
101
010
101
010
101

出力例 2

0

X? が存在しない場合も、答えが 0 である場合もあります。


入力例 3

18 18
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????

出力例 3

462237431

答えを 998244353 で割った余りを求めることに注意してください。

Score : 600 points

Problem Statement

We have a grid A with N rows and M columns. Initially, 0 is written on every square.
Let us perform the following operation.

  • For each integer i such that 1 \le i \le N, in the i-th row, turn the digits in zero or more leftmost squares into 1.
  • For each integer j such that 1 \le j \le M, in the j-th column, turn the digits in zero or more topmost squares into 1.

Let S be the set of grids that can be obtained in this way.

You are given a grid X with N rows and M columns consisting of 0, 1, and ?.
There are 2^q grids that can be obtained by replacing each ? with 0 or 1, where q is the number of ? in X. How many of them are in S?
This count can be enormous, so find it modulo 998244353.

Constraints

  • N and M are integers.
  • 1 \le N,M \le 18
  • X is a grid with N rows and M columns consisting of 0, 1, and ?.

Input

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

N M
X_{1,1} X_{1,2} \dots X_{1,M}
X_{2,1} X_{2,2} \dots X_{2,M}
\vdots
X_{N,1} X_{N,2} \dots X_{N,M}

Output

Print an integer representing the answer.


Sample Input 1

2 3
0?1
?1?

Sample Output 1

6

The following six grids are in S.

011  011  001
010  011  110

001  011  011
111  110  111

Sample Input 2

5 3
101
010
101
010
101

Sample Output 2

0

X may have no ?, and the answer may be 0.


Sample Input 3

18 18
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????
??????????????????

Sample Output 3

462237431

Be sure to find the count modulo 998244353.