Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 100 点
問題文
正整数 A,B が与えられます。
A^B+B^A の値を出力してください。
制約
- 2 \leq A \leq B \leq 9
- 入力される数値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
答えを整数として出力せよ。
入力例 1
2 8
出力例 1
320
A = 2, B = 8 のとき、A^B = 256, B^A = 64 なので A^B + B^A = 320 です。
入力例 2
9 9
出力例 2
774840978
入力例 3
5 6
出力例 3
23401
Score : 100 points
Problem Statement
You are given positive integers A and B.
Print the value A^B+B^A.
Constraints
- 2 \leq A \leq B \leq 9
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Print the answer as an integer.
Sample Input 1
2 8
Sample Output 1
320
For A = 2, B = 8, we have A^B = 256, B^A = 64, so A^B + B^A = 320.
Sample Input 2
9 9
Sample Output 2
774840978
Sample Input 3
5 6
Sample Output 3
23401
Time Limit: 2 sec / Memory Limit: 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
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
N 個の整数 A_1, A_2, \ldots, A_N が与えられます。 このうち最大でない整数の中で最大である整数を求めてください。
ただし、この問題の制約下で答えは必ず存在します。
制約
- 2 \leq N \leq 100
- 1 \leq A_i \leq 100
- A_1, A_2, \ldots, A_N がすべて等しいということはない
- 入力値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
5 2 1 3 3 2
出力例 1
2
2,1,3,3,2 の中で最大である整数は 3 です。
2,1,3,3,2 の中で 3 でない整数は 2,1,2 の 3 つであり、これらの中で最大である整数は 2 です。
入力例 2
4 4 3 2 1
出力例 2
3
入力例 3
8 22 22 18 16 22 18 18 22
出力例 3
18
Score : 200 points
Problem Statement
You are given N integers A_1, A_2, \ldots, A_N. Find the largest among those integers that are not the largest.
The constraints of this problem guarantee that the answer exists.
Constraints
- 2 \leq N \leq 100
- 1 \leq A_i \leq 100
- It is not the case that all A_1, A_2, \ldots, A_N are equal.
- 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
5 2 1 3 3 2
Sample Output 1
2
The largest integer among 2,1,3,3,2 is 3.
The integers that are not 3 among 2,1,3,3,2 are 2,1,2, among which the largest is 2.
Sample Input 2
4 4 3 2 1
Sample Output 2
3
Sample Input 3
8 22 22 18 16 22 18 18 22
Sample Output 3
18
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
xy 平面上に N 人の人 1,2,\dots,N がおり、人 i は座標 (X_i,Y_i) にいます。
このうち、 K 人の人 A_1,A_2,\dots,A_K に同じ強さの明かりを持たせます。
座標 (x,y) にいる人が強さ R の明かりを持っている時、その明かりによって中心 (x,y) 、半径 R の円の内部全体(境界を含む)が照らされます。
すべての人が少なくとも 1 つの明かりによって照らされるために必要な明かりの強さの最小値を求めてください。
制約
- 入力は全て整数
- 1 \le K < N \le 1000
- 1 \le A_1 < A_2 < \dots < A_K \le N
- |X_i|,|Y_i| \le 10^5
- i \neq j ならば (X_i,Y_i) \neq (X_j,Y_j)
入力
入力は以下の形式で標準入力から与えられる。
N K A_1 A_2 \dots A_K X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
出力
答えを実数として出力せよ。
出力された解と想定解との絶対誤差または相対誤差が 10^{-5} 以下であるならば、出力は正しいと見なされる。
入力例 1
4 2 2 3 0 0 0 1 1 2 2 0
出力例 1
2.23606797749978969
この入力では人が 4 人おり、そのうち人 2,3 が明かりを持ちます。
R \ge \sqrt{5} \approx 2.236068 である時、すべての人が少なくとも 1 つの明かりによって照らされます。
入力例 2
2 1 2 -100000 -100000 100000 100000
出力例 2
282842.712474619009
入力例 3
8 3 2 6 8 -17683 17993 93038 47074 58079 -57520 -41515 -89802 -72739 68805 24324 -73073 71049 72103 47863 19268
出力例 3
130379.280458974768
Score : 200 points
Problem Statement
There are N people numbered 1, 2, \dots, N in the xy-plane. Person i is at the coordinates (X_i, Y_i).
K of these people, Persons A_1, A_2, \dots, A_K, will receive lights of the same strength.
When a person at coordinates (x, y) has a light of strength R, it lights up the interior of a circle of radius R centered at (x, y) (including the boundary).
Find the minimum strength of the lights needed for every person to be lit by at least one light.  
Constraints
- All values in input are integers.
- 1 \le K < N \le 1000
- 1 \le A_1 < A_2 < \dots < A_K \le N
- |X_i|,|Y_i| \le 10^5
- (X_i,Y_i) \neq (X_j,Y_j), if i \neq j.
Input
Input is given from Standard Input in the following format:
N K A_1 A_2 \dots A_K X_1 Y_1 X_2 Y_2 \vdots X_N Y_N
Output
Print the answer as a real number.
Your output will be considered correct if its absolute or relative error from the judge's output is at most 10^{-5}.
Sample Input 1
4 2 2 3 0 0 0 1 1 2 2 0
Sample Output 1
2.23606797749978969
This input contains four people. Among them, Persons 2 and 3 will have lights.
Every person will be lit by at least one light if R \ge \sqrt{5} \approx 2.236068.
Sample Input 2
2 1 2 -100000 -100000 100000 100000
Sample Output 2
282842.712474619009
Sample Input 3
8 3 2 6 8 -17683 17993 93038 47074 58079 -57520 -41515 -89802 -72739 68805 24324 -73073 71049 72103 47863 19268
Sample Output 3
130379.280458974768
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
N 個の袋があります。
袋 i には L_i 個のボールが入っていて、袋 i の j(1\leq j\leq L_i) 番目のボールには正の整数 a_{i,j} が書かれています。  
それぞれの袋から 1 つずつボールを取り出します。
取り出したボールに書かれた数の総積が X になるような取り出し方は何通りありますか?  
ただし、書かれた数が同じであっても全てのボールは区別します。
制約
- N \geq 2
- L_i \geq 2
- 袋に入っているボールの個数の総積は 10^5 を超えない。すなわち、\displaystyle\prod_{i=1}^{N}L_i \leq 10^5
- 1 \leq a_{i,j} \leq 10^9
- 1 \leq X \leq 10^{18}
- 入力に含まれる値は全て整数である。
入力
入力は以下の形式で標準入力から与えられる。
N X
L_1 a_{1,1} a_{1,2} \ldots a_{1,L_1}
L_2 a_{2,1} a_{2,2} \ldots a_{2,L_2}
\vdots
L_N a_{N,1} a_{N,2} \ldots a_{N,L_N}
出力
答えを出力せよ。
入力例 1
2 40 3 1 8 4 2 10 5
出力例 1
2
袋 1 の 3 番目のボールと袋 2 の 1 番目のボールを選ぶと、a_{1,3} \times a_{2,1} = 4 \times 10 = 40 となります。
袋 1 の 2 番目のボールと袋 2 の 2 番目のボールを選ぶと、a_{1,2} \times a_{2,2} = 8 \times 5 = 40 となります。
これ以外に総積が 40 になる取り出し方は存在しないので、答えは 2 です。
入力例 2
3 200 3 10 10 10 3 10 10 10 5 2 2 2 2 2
出力例 2
45
書かれた数が同じであっても全てのボールは区別することに注意してください。
入力例 3
3 1000000000000000000 2 1000000000 1000000000 2 1000000000 1000000000 2 1000000000 1000000000
出力例 3
0
総積が X になる取り出し方が 1 つも存在しないこともあります。
Score : 300 points
Problem Statement
We have N bags.
Bag i contains L_i balls. The j-th ball (1\leq j\leq L_i) in Bag i has a positive integer a_{i,j} written on it.
We will pick out one ball from each bag.
How many ways are there to pick the balls so that the product of the numbers written on the picked balls is X?
Here, we distinguish all balls, even with the same numbers written on them.
Constraints
- N \geq 2
- L_i \geq 2
- The product of the numbers of balls in the bags is at most 10^5: \displaystyle\prod_{i=1}^{N}L_i \leq 10^5.
- 1 \leq a_{i,j} \leq 10^9
- 1 \leq X \leq 10^{18}
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N X
L_1 a_{1,1} a_{1,2} \ldots a_{1,L_1}
L_2 a_{2,1} a_{2,2} \ldots a_{2,L_2}
\vdots
L_N a_{N,1} a_{N,2} \ldots a_{N,L_N}
Output
Print the answer.
Sample Input 1
2 40 3 1 8 4 2 10 5
Sample Output 1
2
When choosing the 3-rd ball in Bag 1 and 1-st ball in Bag 2, we have a_{1,3} \times a_{2,1} = 4 \times 10 = 40.
When choosing the 2-nd ball in Bag 1 and 2-nd ball in Bag 2, we have a_{1,2} \times a_{2,2} = 8 \times 5 = 40.
There are no other ways to make the product 40, so the answer is 2.
Sample Input 2
3 200 3 10 10 10 3 10 10 10 5 2 2 2 2 2
Sample Output 2
45
Note that we distinguish all balls, even with the same numbers written on them.
Sample Input 3
3 1000000000000000000 2 1000000000 1000000000 2 1000000000 1000000000 2 1000000000 1000000000
Sample Output 3
0
There may be no way to make the product X.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 300 点
問題文
英小文字、,、" からなる長さ N の文字列 S が与えられます。S に含まれる " の個数は偶数であることが保証されています。
S に含まれる " の個数を 2K 個とすると、各 i=1,2,\ldots,K について 2i-1 番目の " から 2i 番目の " までの文字のことを 括られた文字 と呼びます。
あなたの仕事は、 S に含まれる , のうち、括られた文字 でないもの を . で置き換えて得られる文字列を答えることです。
制約
- N は 1 以上 2\times 10^5 以下の整数
- S は英小文字、,、"からなる長さ N の文字列
- S に含まれる "の個数は偶数
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
答えを出力せよ。
入力例 1
8 "a,b"c,d
出力例 1
"a,b"c.d
S のうち "a,b" が括られた文字であり、c,d は括られた文字ではありません。
S に含まれる , のうち、括られた文字でないのは S の左から 7 番目の文字なので、7 番目の文字を . で置き換えたものが答えとなります。
入力例 2
5 ,,,,,
出力例 2
.....
入力例 3
20 a,"t,"c,"o,"d,"e,"r,
出力例 3
a."t,"c."o,"d."e,"r.
Score : 300 points
Problem Statement
You are given a string S of length N consisting of lowercase English letters, ,, and ". It is guaranteed that S contains an even number of ".
Let 2K be the number of " in S. For each i=1,2,\ldots,K, the characters from the (2i-1)-th " through the (2i)-th " are said to be enclosed.
Your task is to replace each , in S that is not an enclosed character with . and print the resulting string.
Constraints
- N is an integer between 1 and 2\times 10^5, inclusive.
- S is a string of length N consisting of lowercase English letters, ,, and".
- S contains an even number of ".
Input
The input is given from Standard Input in the following format:
N S
Output
Print the answer.
Sample Input 1
8 "a,b"c,d
Sample Output 1
"a,b"c.d
In S, "a,b" are enclosed characters, and c,d are not.
The , in S that is not an enclosed character is the seventh character from the left in S, so replace that character with . to get the answer.
Sample Input 2
5 ,,,,,
Sample Output 2
.....
Sample Input 3
20 a,"t,"c,"o,"d,"e,"r,
Sample Output 3
a."t,"c."o,"d."e,"r.
Time Limit: 3 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
文字列 S があり、初め S= 1 です。
以下の形式のクエリが Q 個与えられるので順に処理してください。
- 1 x: S の末尾に数字 x を追加する
- 2: S の先頭の数字を削除する
- 3: S を十進数表記の数とみなした値を 998244353 で割った余りを出力する
制約
- 1 \leq Q \leq 6 \times 10^5
- 1 番目の形式のクエリについて、x \in \{1,2,3,4,5,6,7,8,9\}
- 2 番目の形式のクエリは S が 2 文字以上の時にのみ与えられる
- 3 番目の形式のクエリが 1 個以上存在する
入力
入力は以下の形式で標準入力から与えられる。
Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q
ただし \mathrm{query}_i は i 番目のクエリを表し、以下のいずれかの形式である。
1 x
2
3
出力
3 番目の形式のクエリの個数を q として、q 行出力せよ。i (1 \leq i \leq q) 行目には i 番目の 3 番目の形式のクエリに対する出力をせよ。
入力例 1
3 3 1 2 3
出力例 1
1 12
1 番目のクエリにおいて、S は 1 なので ( 1 を 998244353 で割った余りに等しい) 1 を出力します。
2 番目のクエリにおいて、S は 12 になります。
3 番目のクエリにおいて、S は 12 なので ( 12 を 998244353 で割った余りに等しい) 12 を出力します。  
入力例 2
3 1 5 2 3
出力例 2
5
入力例 3
11 1 9 1 9 1 8 1 2 1 4 1 4 1 3 1 5 1 3 2 3
出力例 3
0
出力されるべき値は 998244353 で割った余りであることに注意してください。
Score : 400 points
Problem Statement
We have a string S. Initially, S= 1.
Process Q queries in the following formats in order.
- 1 x: Append a digit x at the end of S.
- 2: Delete the digit at the beginning of S.
- 3: Print the number represented by S in decimal, modulo 998244353.
Constraints
- 1 \leq Q \leq 6 \times 10^5
- For each query in the first format, x \in \{1,2,3,4,5,6,7,8,9\}.
- A query in the second format is given only if S has a length of 2 or greater.
- There is at least one query in the third format.
Input
The input is given from Standard Input in the following format:
Q
\mathrm{query}_1
\vdots
\mathrm{query}_Q
Here, \mathrm{query}_i denotes the i-th query, which is in one of the following formats:
1 x
2
3
Output
Print q lines, where q is the number of queries in the third format. The i-th line (1 \leq i \leq q) should correspond to the i-th query in the third format.
Sample Input 1
3 3 1 2 3
Sample Output 1
1 12
In the first query, S is 1, so you should print 1 modulo 998244353, that is, 1.
In the second query, S becomes 12.
In the third query, S is 12, so you should print 12 modulo 998244353, that is, 12.  
Sample Input 2
3 1 5 2 3
Sample Output 2
5
Sample Input 3
11 1 9 1 9 1 8 1 2 1 4 1 4 1 3 1 5 1 3 2 3
Sample Output 3
0
Be sure to print numbers modulo 998244353.
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
N 頂点 M 辺の単純連結無向グラフが与えられます。
辺 i は頂点 A_i と頂点 B_i を結ぶ長さ C_i の辺です。
以下の条件を満たすようにいくつかの辺を削除します。削除する辺の数の最大値を求めてください。
- 辺を削除した後のグラフも連結である。
- 全ての頂点対 (s,t) について、頂点 s と頂点 t の間の距離が削除前と削除後で変化しない。
注釈
単純連結無向グラフとは、単純かつ連結で辺に向きの無いグラフのことをいいます。
グラフが単純であるとは、グラフが自己ループや多重辺を含まないことをいいます。
グラフが連結であるとは、グラフ上の任意の 2 頂点 s, t について s から t へ辺をたどって行けることをいいます。
頂点 s と頂点 t の間の距離とは、頂点 s と頂点 t の間の最短路の長さのことをいいます。
制約
- 2 \leq N \leq 300
- N-1 \leq M \leq \frac{N(N-1)}{2}
- 1 \leq A_i \lt B_i \leq N
- 1 \leq C_i \leq 10^9
- i \neq j ならば (A_i, B_i) \neq (A_j, B_j) である。
- 与えられるグラフは連結である。
- 入力はすべて整数である。
入力
入力は以下の形式で標準入力から与えられる。
N M A_1 B_1 C_1 A_2 B_2 C_2 \vdots A_M B_M C_M
出力
答えを出力せよ。
入力例 1
3 3 1 2 2 2 3 3 1 3 6
出力例 1
1
辺を削除する前の全ての頂点対の距離は次の通りです。
- 頂点 1 と頂点 2 の距離は 2
- 頂点 1 と頂点 3 の距離は 5
- 頂点 2 と頂点 3 の距離は 3
辺 3 を削除しても全ての頂点間の距離は変化しません。また、問題文の条件を満たすように 2 本以上の辺を削除することはできないので、答えは 1 本になります。
入力例 2
5 4 1 3 3 2 3 9 3 5 3 4 5 3
出力例 2
0
どの辺も削除することができません。
入力例 3
5 10 1 2 71 1 3 9 1 4 82 1 5 64 2 3 22 2 4 99 2 5 1 3 4 24 3 5 18 4 5 10
出力例 3
5
Score : 500 points
Problem Statement
You are given a simple connected undirected graph with N vertices and M edges.
Edge i connects Vertex A_i and Vertex B_i, and has a length of C_i.
Let us delete some number of edges while satisfying the conditions below. Find the maximum number of edges that can be deleted.
- The graph is still connected after the deletion.
- For every pair of vertices (s, t), the distance between s and t remains the same before and after the deletion.
Notes
A simple connected undirected graph is a graph that is simple and connected and has undirected edges.
A graph is simple when it has no self-loops and no multi-edges.
A graph is connected when, for every pair of two vertices s and t, t is reachable from s by traversing edges.
The distance between Vertex s and Vertex t is the length of a shortest path between s and t.
Constraints
- 2 \leq N \leq 300
- N-1 \leq M \leq \frac{N(N-1)}{2}
- 1 \leq A_i \lt B_i \leq N
- 1 \leq C_i \leq 10^9
- (A_i, B_i) \neq (A_j, B_j) if i \neq j.
- The given graph is connected.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M A_1 B_1 C_1 A_2 B_2 C_2 \vdots A_M B_M C_M
Output
Print the answer.
Sample Input 1
3 3 1 2 2 2 3 3 1 3 6
Sample Output 1
1
The distance between each pair of vertices before the deletion is as follows.
- The distance between Vertex 1 and Vertex 2 is 2.
- The distance between Vertex 1 and Vertex 3 is 5.
- The distance between Vertex 2 and Vertex 3 is 3.
Deleting Edge 3 does not affect the distance between any pair of vertices. It is impossible to delete two or more edges while satisfying the condition, so the answer is 1.
Sample Input 2
5 4 1 3 3 2 3 9 3 5 3 4 5 3
Sample Output 2
0
No edge can be deleted.
Sample Input 3
5 10 1 2 71 1 3 9 1 4 82 1 5 64 2 3 22 2 4 99 2 5 1 3 4 24 3 5 18 4 5 10
Sample Output 3
5
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 525 点
問題文
N \times M のグリッドがあります。
このグリッドの上から i 行目、左から j 列目のマスを (i,j) と書きます。
このグリッドの各マスは 白 か 黒 であり、その情報は N 個の長さ M の文字列 S_1,S_2,\dots,S_N として与えられます。
- もし S_i の j 文字目が .なら、マス (i,j) は 白 である。
- もし S_i の j 文字目が #なら、マス (i,j) は 黒 である。
以下の条件を満たすグリッドを 美しい グリッドと呼びます。
- 全ての 1 \le i \le N, 1 \le j \le M を満たす整数組 (i,j) について、マス (i,j) が 黒 であれば、その下と右下のマスも (存在すれば) 黒 である。
- 厳密には、以下の条件を全て満たす。- マス (i,j) が 黒 でありマス (i+1,j) が存在するなら、マス (i+1,j) も 黒 である。
- マス (i,j) が 黒 でありマス (i+1,j+1) が存在するなら、マス (i+1,j+1) も 黒 である。
 
高橋くんは、 白 のマスを 0 個以上何個でも 黒 に塗ることができ、この操作によってグリッドを美しくしようとしています。
高橋くんが作ることのできる美しいグリッドの種類数を 998244353 で割った余りを求めてください。
但し、ある 2 つのグリッドが異なるとは、両者で色が異なるマスが存在することを指します。
制約
- 1 \le N,M \le 2000
- S_i は .と#からなる長さ M の文字列
入力
入力は以下の形式で標準入力から与えられる。
N M S_1 S_2 \vdots S_N
出力
答えを整数として出力せよ。
入力例 1
2 2 .# ..
出力例 1
3
作ることのできる美しいグリッドは以下の 3 種類です。
.# .# ## .# ## ##
入力例 2
5 5 ....# ...#. ..#.. .#.#. #...#
出力例 2
92
入力例 3
25 25 ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... .........................
出力例 3
604936632
998244353 で割った余りを求めてください。
Score : 525 points
Problem Statement
There is an N \times M grid and a player standing on it.
Let (i,j) denote the square at the i-th row from the top and j-th column from the left of this grid.
Each square of this grid is black or white, which is represented by N strings S_1,S_2,\dots,S_N of length M as follows:
- if the j-th character of S_i is ., square (i,j) is white;
- if the j-th character of S_i is #, square (i,j) is black.
The grid is said to be beautiful when the following condition is satisfied.
- For every pair of integers (i,j) such that 1 \le i \le N, 1 \le j \le M, if square (i,j) is black, the square under (i,j) and the square to the immediate lower right of (i,j) are also black (if they exist).
- Formally, all of the following are satisfied.- If square (i,j) is black and square (i+1,j) exists, square (i+1,j) is also black.
- If square (i,j) is black and square (i+1,j+1) exists, square (i+1,j+1) is also black.
 
Takahashi can paint zero or more white squares black, and he will do so to make the grid beautiful.
Find the number of different beautiful grids he can make, modulo 998244353.
Two grids are considered different when there is a square that has different colors in those two grids.
Constraints
- 1 \le N,M \le 2000
- S_i is a string of length M consisting of  .and#.
Input
The input is given from Standard Input in the following format:
N M S_1 S_2 \vdots S_N
Output
Print the answer as an integer.
Sample Input 1
2 2 .# ..
Sample Output 1
3
He can make the following three different beautiful grids:
.# .# ## .# ## ##
Sample Input 2
5 5 ....# ...#. ..#.. .#.#. #...#
Sample Output 2
92
Sample Input 3
25 25 ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... ......................... .........................
Sample Output 3
604936632
Find the count modulo 998244353.