A - 12435

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

配点 : 150

問題文

(1,2,3,4,5) を並び替えた整数列 A=(A_1,A_2,A_3,A_4,A_5) が与えられます。

A の隣り合う 2 つの項を入れ替える操作を ちょうど 1 行うことで A を昇順にすることができるか判定してください。

制約

  • A(1,2,3,4,5) を並び替えてできる長さ 5 の整数列

入力

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

A_1 A_2 A_3 A_4 A_5

出力

ちょうど 1 回の操作で A を昇順にすることができるならば Yes を、できないならば No を出力せよ。


入力例 1

1 2 4 3 5

出力例 1

Yes

A_3A_4 を入れ替えることで A=(1,2,3,4,5) となり、 A を昇順に並び替えることができます。したがって、 Yes を出力してください。


入力例 2

5 3 2 4 1

出力例 2

No

どのような操作をしても A を昇順に並び替えることはできません。


入力例 3

1 2 3 4 5

出力例 3

No

ちょうど 1 回操作をする必要があります。


入力例 4

2 1 3 4 5

出力例 4

Yes

Score : 150 points

Problem Statement

You are given an integer sequence A=(A_1,A_2,A_3,A_4,A_5) obtained by permuting (1,2,3,4,5).

Determine whether A can be sorted in ascending order by performing exactly one operation of swapping two adjacent elements in A.

Constraints

  • A is an integer sequence of length 5 obtained by permuting (1,2,3,4,5).

Input

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

A_1 A_2 A_3 A_4 A_5

Output

If A can be sorted in ascending order by exactly one operation, print Yes; otherwise, print No.


Sample Input 1

1 2 4 3 5

Sample Output 1

Yes

By swapping A_3 and A_4, A becomes (1,2,3,4,5), so it can be sorted in ascending order. Therefore, print Yes.


Sample Input 2

5 3 2 4 1

Sample Output 2

No

No matter what operation is performed, it is impossible to sort A in ascending order.


Sample Input 3

1 2 3 4 5

Sample Output 3

No

You must perform exactly one operation.


Sample Input 4

2 1 3 4 5

Sample Output 4

Yes
B - Leap Year

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

配点 : 100

問題文

1583 以上 2023 以下の整数 Y が与えられます。

西暦 Y 年の日数を求めてください。

なお、制約の範囲内では西暦 Y 年の日数は以下の通りです。

  • Y4 の倍数でない年は 365

  • Y4 の倍数で、かつ 100 の倍数でない年は 366

  • Y100 の倍数で、かつ 400 の倍数でない年は 365

  • Y400 の倍数である年は 366

制約

  • Y1583 以上 2023 以下の整数

入力

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

Y

出力

西暦 Y 年の日数を整数として出力せよ。


入力例 1

2023

出力例 1

365

20234 の倍数でないので 365 日です。


入力例 2

1992

出力例 2

366

19924 の倍数で、かつ 100 の倍数でないので 366 日です。


入力例 3

1800

出力例 3

365

1800100 の倍数で、かつ 400 の倍数でないので 365 日です。


入力例 4

1600

出力例 4

366

1600400 の倍数なので 366 日です。

Score : 100 points

Problem Statement

You are given an integer Y between 1583 and 2023.

Find the number of days in the year Y of the Gregorian calendar.

Within the given range, the year Y has the following number of days:

  • if Y is not a multiple of 4, then 365 days;

  • if Y is a multiple of 4 but not a multiple of 100, then 366 days;

  • if Y is a multiple of 100 but not a multiple of 400, then 365 days;

  • if Y is a multiple of 400, then 366 days.

Constraints

  • Y is an integer between 1583 and 2023, inclusive.

Input

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

Y

Output

Print the number of days in the year Y as an integer.


Sample Input 1

2023

Sample Output 1

365

2023 is not a multiple of 4, so it has 365 days.


Sample Input 2

1992

Sample Output 2

366

1992 is a multiple of 4 but not a multiple of 100, so it has 366 days.


Sample Input 3

1800

Sample Output 3

365

1800 is a multiple of 100 but not a multiple of 400, so it has 365 days.


Sample Input 4

1600

Sample Output 4

366

1600 is a multiple of 400, so it has 366 days.

C - Prefix?

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

配点 : 200

問題文

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

接頭辞とは 長さ 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 つです。

制約

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

入力

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

S
T

出力

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


入力例 1

atco
atcoder

出力例 1

Yes

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


入力例 2

code
atcoder

出力例 2

No

codeatcoder の接頭辞ではありません。よって、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
D - Count Distinct Integers

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

配点 : 200

問題文

長さ N の正整数列 a = (a_1, a_2, \dots, a_N) には何種類の整数が現れますか?

制約

  • 1 \leq N \leq 1000
  • 1 \leq a_i \leq 10^9 \, (1 \leq i \leq N)
  • 入力は全て整数

入力

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

N
a_1 \ldots a_N

出力

答えを出力せよ。


入力例 1

6
1 4 1 2 2 1

出力例 1

3

1, 2, 43 種類の整数が現れます。


入力例 2

1
1

出力例 2

1

入力例 3

11
3 1 4 1 5 9 2 6 5 3 5

出力例 3

7

Score : 200 points

Problem Statement

In a sequence of N positive integers a = (a_1, a_2, \dots, a_N), how many different integers are there?

Constraints

  • 1 \leq N \leq 1000
  • 1 \leq a_i \leq 10^9 \, (1 \leq i \leq N)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
a_1 \ldots a_N

Output

Print the answer.


Sample Input 1

6
1 4 1 2 2 1

Sample Output 1

3

There are three different integers: 1, 2, 4.


Sample Input 2

1
1

Sample Output 2

1

Sample Input 3

11
3 1 4 1 5 9 2 6 5 3 5

Sample Output 3

7
E - Black Intervals

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

配点 : 350

問題文

左右一列に N 個のマスが並んでいます。 最初、すべてのマスは白く塗られています。

Q 個のクエリを順に処理してください。i 個目のクエリでは 1 以上 N 以下の整数 A_i が与えられ、次の操作を行います。

左から A_i 番目のマスの色を反転させる。 具体的には、左から A_i 番目のマスが、白く塗られていたならば黒く塗り、黒く塗られていたならば白く塗る。
その後、黒く塗られたマスが連続している区間の個数を求める。

ここで、黒く塗られたマスが連続している区間とは次をすべてみたす整数の組 (l,r) (1\leq l\leq r\leq N) を指す。

  • 左から l, l+1, \ldots, r 番目のマスはすべて黒く塗られている。
  • l=1 であるか、または左から (l-1) 番目のマスは白く塗られている。
  • r=N であるか、または左から (r+1) 番目のマスは白く塗られている。

制約

  • 1\leq N,Q\leq 5\times 10^5
  • 1\leq A_i\leq N
  • 入力はすべて整数

入力

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

N Q
A_1 A_2 \ldots A_Q

出力

Q 行出力せよ。i 行目 (1\leq i\leq Q) には i 個目のクエリの答えを出力せよ。


入力例 1

5 7
2 3 3 5 1 5 2

出力例 1

1
1
1
2
2
1
1

以下では、左から i 番目のマスを マス i と表します。
各クエリの後は次のような状態になっています。

  • 1 個目のクエリの後、マス 2 のみが黒く塗られています。黒く塗られたマスが連続している区間は (l,r)=(2,2)1 つです。
  • 2 個目のクエリの後、マス 2,3 が黒く塗られています。黒く塗られたマスが連続している区間は (l,r)=(2,3)1 つです。
  • 3 個目のクエリの後、マス 2 のみが黒く塗られています。黒く塗られたマスが連続している区間は (l,r)=(2,2)1 つです。
  • 4 個目のクエリの後、マス 2,5 が黒く塗られています。黒く塗られたマスが連続している区間は (l,r)=(2,2), (5,5)2 つです。
  • 5 個目のクエリの後、マス 1,2,5 が黒く塗られています。黒く塗られたマスが連続している区間は (l,r)=(1,2), (5,5)2 つです。
  • 6 個目のクエリの後、マス 1,2 のみが黒く塗られています。黒く塗られたマスが連続している区間は (l,r)=(1,2)1 つです。
  • 7 個目のクエリの後、マス 1 のみが黒く塗られています。黒く塗られたマスが連続している区間は (l,r)=(1,1)1 つです。

よって、1,1,1,2,2,1,1 を改行区切りで出力します。


入力例 2

1 2
1 1

出力例 2

1
0

2 個目のクエリの後、すべてのマスは白く塗られているため、2 行目には 0 を出力します。


入力例 3

3 3
1 3 2

出力例 3

1
2
1

Score : 350 points

Problem Statement

There are N squares arranged in a row from left to right. Initially, all squares are painted white.

Process Q queries in order. The i-th query gives an integer A_i between 1 and N, inclusive, and performs the following operation:

Flip the color of the A_i-th square from the left. Specifically, if the A_i-th square from the left is painted white, paint it black; if it is painted black, paint it white.
Then, find the number of intervals of consecutively painted black squares.

Here, an interval of consecutively painted black squares is a pair of integers (l,r) (1\leq l\leq r\leq N) that satisfy all of the following:

  • The l-th, (l+1)-th, \ldots, r-th squares from the left are all painted black.
  • Either l=1, or the (l-1)-th square from the left is painted white.
  • Either r=N, or the (r+1)-th square from the left is painted white.

Constraints

  • 1\leq N,Q\leq 5\times 10^5
  • 1\leq A_i\leq N
  • All input values are integers.

Input

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

N Q
A_1 A_2 \ldots A_Q

Output

Output Q lines. On the i-th line (1\leq i\leq Q), output the answer to the i-th query.


Sample Input 1

5 7
2 3 3 5 1 5 2

Sample Output 1

1
1
1
2
2
1
1

Below, the i-th square from the left is referred to as square i.
After each query, the state is as follows:

  • After the 1st query, only square 2 is painted black. There is 1 interval of consecutively painted black squares: (l,r)=(2,2).
  • After the 2nd query, squares 2,3 are painted black. There is 1 interval of consecutively painted black squares: (l,r)=(2,3).
  • After the 3rd query, only square 2 is painted black. There is 1 interval of consecutively painted black squares: (l,r)=(2,2).
  • After the 4th query, squares 2,5 are painted black. There are 2 intervals of consecutively painted black squares: (l,r)=(2,2), (5,5).
  • After the 5th query, squares 1,2,5 are painted black. There are 2 intervals of consecutively painted black squares: (l,r)=(1,2), (5,5).
  • After the 6th query, only squares 1,2 are painted black. There is 1 interval of consecutively painted black squares: (l,r)=(1,2).
  • After the 7th query, only square 1 is painted black. There is 1 interval of consecutively painted black squares: (l,r)=(1,1).

Thus, output 1,1,1,2,2,1,1 separated by newlines.


Sample Input 2

1 2
1 1

Sample Output 2

1
0

After the 2nd query, all squares are painted white, so output 0 on the 2nd line.


Sample Input 3

3 3
1 3 2

Sample Output 3

1
2
1
F - K Swap

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

配点 : 300

問題文

長さ N の数列 A=(a_1,\ldots,a_N) があります。また、整数 K が与えられます。

あなたは次の操作を 0 回以上何度でも行えます。

  • 1 \leq i \leq N-K を満たす整数 i を選び、a_ia_{i+K} の値を入れ替える。

A を昇順に並べ替えることが出来るかどうかを判定してください。

制約

  • 2 \leq N \leq 2 \times 10^5
  • 1 \leq K \leq N-1
  • 1 \leq a_i \leq 10^9
  • 入力はすべて整数

入力

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

N K
a_1 \ldots a_N

出力

A を昇順に並び替えることが出来るならば Yes と、出来ないならば No と出力せよ。


入力例 1

5 2
3 4 1 3 4

出力例 1

Yes

次のように操作をすることで A を昇順に並び替えることが出来ます。

  • i=1 とし、a_1a_3 の値を入れ替える。数列は (1,4,3,3,4) となる。
  • i=2 とし、a_2a_4 の値を入れ替える。数列は (1,3,3,4,4) となる。

入力例 2

5 3
3 4 1 3 4

出力例 2

No

入力例 3

7 5
1 2 3 4 5 5 10

出力例 3

Yes

操作を行う必要が無い場合もあります。

Score : 300 points

Problem Statement

We have a sequence of length N: A=(a_1,\ldots,a_N). Additionally, you are given an integer K.

You can perform the following operation zero or more times.

  • Choose an integer i such that 1 \leq i \leq N-K, then swap the values of a_i and a_{i+K}.

Determine whether it is possible to sort A in ascending order.

Constraints

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

Input

Input is given from Standard Input in the following format:

N K
a_1 \ldots a_N

Output

If it is possible to sort A in ascending order, print Yes; otherwise, print No.


Sample Input 1

5 2
3 4 1 3 4

Sample Output 1

Yes

The following sequence of operations sorts A in ascending order.

  • Choose i=1 to swap the values of a_1 and a_3. A is now (1,4,3,3,4).
  • Choose i=2 to swap the values of a_2 and a_4. A is now (1,3,3,4,4).

Sample Input 2

5 3
3 4 1 3 4

Sample Output 2

No

Sample Input 3

7 5
1 2 3 4 5 5 10

Sample Output 3

Yes

No operations may be needed.

G - At Most 3 (Contestant ver.)

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

配点 : 400

問題文

整数 W が与えられます。
あなたは以下の条件をすべて満たすようにいくつかのおもりを用意することにしました。

  • おもりの個数は 1 個以上 300 個以下である。
  • おもりの重さは 10^6 以下の正整数である。
  • 1 以上 W 以下のすべての正整数は 良い整数 である。ここで、以下の条件を満たす正整数 n を良い整数と呼ぶ。
    • 用意したおもりのうち \bf{3} 個以下 の異なるおもりを自由に選んで、選んだおもりの重さの和を n にすることができる。  

条件を満たすようなおもりの組を 1 つ出力してください。

制約

  • 1 \leq W \leq 10^6
  • W は整数

入力

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

W

出力

N をおもりの個数、A_ii 番目のおもりの重さとして、以下の形式で出力せよ。答えが複数存在する場合、どれを出力しても正解とみなされる。

N
A_1 A_2 \dots A_N

ただし、N および A_1,A_2,\dots,A_N は以下の条件を満たす必要がある。

  • 1 \leq N \leq 300
  • 1 \leq A_i \leq 10^6

入力例 1

6

出力例 1

3
1 2 3

上の出力は重さ 1 のおもり、重さ 2 のおもり、重さ 3 のおもりの 3 個のおもりを用意しています。
この出力は条件を満たしています。特に 3 番目の条件について、以下のようにおもりを選ぶことで 1 以上 W 以下の整数すべてが良い整数であることが確認できます。

  • 1 番目のおもりのみを選ぶと、重さの和は 1 になる。
  • 2 番目のおもりのみを選ぶと、重さの和は 2 になる。
  • 3 番目のおもりのみを選ぶと、重さの和は 3 になる。
  • 1 番目と 3 番目のおもりを選ぶと、重さの和は 4 になる。
  • 2 番目と 3 番目のおもりを選ぶと、重さの和は 5 になる。
  • 1 番目、2 番目と 3 番目のおもりを選ぶと、重さの和は 6 になる。

入力例 2

12

出力例 2

6
2 5 1 2 5 1

同じ重さのおもりを 2 個以上用意しても良いです。

Score : 400 points

Problem Statement

You are given an integer W.
You are going to prepare some weights so that all of the conditions below are satisfied.

  • The number of weights is between 1 and 300, inclusive.
  • Each weight has a mass of positive integer not exceeding 10^6.
  • Every integer between 1 and W, inclusive, is a good integer. Here, a positive integer n is said to be a good integer if the following condition is satisfied:
    • We can choose at most 3 different weights from the prepared weights with a total mass of n.

Print a combination of weights that satisfies the conditions.

Constraints

  • 1 \leq W \leq 10^6
  • W is an integer.

Input

Input is given from Standard Input in the following format:

W

Output

Print in the following format, where N is the number of weights and A_i is the mass of the i-th weight. If multiple solutions exist, printing any of them is accepted.

N
A_1 A_2 \dots A_N

Here, N and A_1,A_2,\dots,A_N should satisfy the following conditions:

  • 1 \leq N \leq 300
  • 1 \leq A_i \leq 10^6

Sample Input 1

6

Sample Output 1

3
1 2 3

In the output above, 3 weights with masses 1, 2, and 3 are prepared.
This output satisfies the conditions. Especially, regarding the 3-rd condition, we can confirm that every integer between 1 and W, inclusive, is a good integer.

  • If we choose only the 1-st weight, it has a total mass of 1.
  • If we choose only the 2-nd weight, it has a total mass of 2.
  • If we choose only the 3-rd weight, it has a total mass of 3.
  • If we choose the 1-st and the 3-rd weights, they have a total mass of 4.
  • If we choose the 2-nd and the 3-rd weights, they have a total mass of 5.
  • If we choose the 1-st, the 2-nd, and the 3-rd weights, they have a total mass of 6.

Sample Input 2

12

Sample Output 2

6
2 5 1 2 5 1

You may prepare multiple weights with the same mass.

H - How to Win the Election

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

配点 : 500

問題文

1,2,\ldots,N の番号のついた N 人の候補者で選挙が行われています。K 票の投票があり、現在一部の開票作業が行なわれました。

これまでの開票作業では、i 番目の候補者に A_i 票が入りました。

全ての票が開票された後、i 番目 (1 \leq i \leq N) の候補者はその候補者より多く票を獲得した候補者が M 人未満であるとき、かつその時に限り当選します。複数の候補者が当選することもあります。

各候補者が当選を確定させるためには残りの票のうち最小で何票追加で票が必要か求めてください。

より厳密には、i = 1,2,\ldots,N に対して次の問題を解いてください。

次の条件を満たす K - \displaystyle{\sum_{i=1}^{N}} A_i 以下の非負整数 X が存在するか判定し、存在するならその最小値を求めてください。

  • これ以降の開票作業で i 番目の候補者へ X 票入るなら、i 番目の候補者は必ず当選する。

制約

  • 1 \leq M \leq N \leq 2 \times 10^5
  • 1 \leq K \leq 10^{12}
  • 0 \leq A_i \leq 10^{12}
  • \displaystyle{\sum_{i=1}^{N} A_i} \leq K
  • 入力はすべて整数

入力

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

N M K
A_1 A_2 \ldots A_N

出力

候補者 i が当選を確定させるために必要な票数を C_i としたとき、C_1,C_2,\ldots,C_N を空白区切りで出力せよ。

ただし、候補者 i がすでに当選を確定させている場合は C_i=0、候補者 i が当選を確定させることができない場合は C_i=-1 とします。


入力例 1

5 2 16
3 1 4 1 5

出力例 1

2 -1 1 -1 0

すでに 14 票の開票が終了しており、残りの票数は 2 票です。
答えるべき C(2, -1, 1, -1, 0) です。たとえば:

  • 候補者 1 は追加で 2 票得ることで当選を確定することができます。追加で 1 票獲得することでは当選を確定することができないので、C_1 = 2 です。
  • 候補者 2 はどのようにしても(例えば、残り 2 票をすべて獲得しても)当選することが不可能なので、 C_2 = -1 です。

入力例 2

12 1 570
81 62 17 5 5 86 15 7 79 26 6 28

出力例 2

79 89 111 117 117 74 112 116 80 107 117 106

Score : 500 points

Problem Statement

An election is being held with N candidates numbered 1, 2, \ldots, N. There are K votes, some of which have been counted so far.

Up until now, candidate i has received A_i votes.

After all ballots are counted, candidate i (1 \leq i \leq N) will be elected if and only if the number of candidates who have received more votes than them is less than M. There may be multiple candidates elected.

For each candidate, find the minimum number of additional votes they need from the remaining ballots to guarantee their victory regardless of how the other candidates receive votes.

Formally, solve the following problem for each i = 1,2,\ldots,N.

Determine if there is a non-negative integer X not exceeding K - \displaystyle{\sum_{i=1}^{N}} A_i satisfying the following condition. If it exists, find the minimum possible such integer.

  • If candidate i receives X additional votes, then candidate i will always be elected.

Constraints

  • 1 \leq M \leq N \leq 2 \times 10^5
  • 1 \leq K \leq 10^{12}
  • 0 \leq A_i \leq 10^{12}
  • \displaystyle{\sum_{i=1}^{N} A_i} \leq K
  • All input values are integers.

Input

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

N M K
A_1 A_2 \ldots A_N

Output

Let C_i be the minimum number of additional votes candidate i needs from the remaining ballots to guarantee their victory regardless of how other candidates receive votes. Print C_1, C_2, \ldots, C_N separated by spaces.

If candidate i has already secured their victory, then let C_i = 0. If candidate i cannot secure their victory under any circumstances, then let C_i = -1.


Sample Input 1

5 2 16
3 1 4 1 5

Sample Output 1

2 -1 1 -1 0

14 votes have been counted so far, and 2 votes are left.
The C to output is (2, -1, 1, -1, 0). For example:

  • Candidate 1 can secure their victory by obtaining 2 more votes, while not by obtaining 1 more vote. Thus, C_1 = 2.
  • Candidate 2 can never (even if they obtain 2 more votes) secure their victory, so C_2 = -1.

Sample Input 2

12 1 570
81 62 17 5 5 86 15 7 79 26 6 28

Sample Output 2

79 89 111 117 117 74 112 116 80 107 117 106
I - Yet Another Grid Task

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

配点 : 525

問題文

N \times M のグリッドがあります。
このグリッドの上から i 行目、左から j 列目のマスを (i,j) と書きます。
このグリッドの各マスは 白 か 黒 であり、その情報は N 個の長さ M の文字列 S_1,S_2,\dots,S_N として与えられます。

  • もし S_ij 文字目が . なら、マス (i,j) は 白 である。
  • もし S_ij 文字目が # なら、マス (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.