A - Christmas Present

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 100

問題文

野球少年の高橋君は今年とても良い子にしていたので、サンタさんはバットかグローブのうち値段が高い方を高橋君にプレゼントすることにしました。

バットの値段が B 円、グローブの値段が G 円 (B\neq G) のとき、サンタさんが高橋君にプレゼントするのはどちらですか?

制約

  • B,G1 以上 1000 以下の相異なる整数

入力

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

B G

出力

サンタさんが高橋君にプレゼントするのがバットであるとき Bat を、グローブであるとき Glove を出力せよ。


入力例 1

300 100

出力例 1

Bat

バットの方がグローブより値段が高いので、サンタさんは高橋君にバットをプレゼントします。


入力例 2

334 343

出力例 2

Glove

グローブの方がバットより値段が高いので、サンタさんは高橋君にグローブをプレゼントします。

Score : 100 points

Problem Statement

Takahashi, a young baseball enthusiast, has been a very good boy this year, so Santa has decided to give him a bat or a glove, whichever is more expensive.

If a bat costs B yen and a glove costs G yen (B\neq G), which one will Santa give to Takahashi?

Constraints

  • B and G are different integers between 1 and 1000, inclusive.

Input

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

B G

Output

If Santa gives Takahashi a bat, print Bat; if Santa gives him a glove, print Glove.


Sample Input 1

300 100

Sample Output 1

Bat

The bat is more expensive than the glove, so Santa will give Takahashi the bat.


Sample Input 2

334 343

Sample Output 2

Glove

The glove is more expensive than the bat, so Santa will give Takahashi the glove.

B - Christmas Trees

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 250

問題文

東西に無限に伸びる道路があり、この道路上のある基準となる地点から東に x\mathrm{\,m} のところにある地点の座標x と定められています。 特に、基準となる地点から西に x\mathrm{\,m} のところにある地点の座標は -x です。

すぬけ君は今から、座標が A である地点を基点にして M\mathrm{\,m} おきにクリスマスツリーを立てます。 すなわち、座標がある整数 k を用いて A+kM と表されるような地点それぞれにクリスマスツリーを立てます。

高橋君と青木君はそれぞれ座標が L,R\ (L\leq R) である地点に立っています。 高橋君と青木君の間(高橋君と青木君が立っている地点を含む)に立てられるクリスマスツリーの本数を求めてください。

制約

  • -10^{18}\leq A \leq 10^{18}
  • 1\leq M \leq 10^9
  • -10^{18}\leq L\leq R \leq 10^{18}
  • 入力は全て整数

入力

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

A M L R

出力

高橋君と青木君の間(高橋君と青木君が立っている地点を含む)に立てられるクリスマスツリーの本数を出力せよ。


入力例 1

5 3 -1 6

出力例 1

3

すぬけ君は、座標が \dots,-4,-1,2,5,8,11,14\dots である地点にクリスマスツリーを立てます。 これらのうち高橋君と青木君の間にあるのは、座標が -1,2,5 である地点に立てられる 3 本です。


入力例 2

-2 2 1 1

出力例 2

0

高橋君と青木君が同じ地点に立っていることもあります。


入力例 3

-177018739841739480 2436426 -80154573737296504 585335723211047198

出力例 3

273142010859

Score : 250 points

Problem Statement

There is a road that stretches infinitely to the east and west, and the coordinate of a point located x meters to the east from a certain reference point on this road is defined as x. In particular, the coordinate of a point located x meters to the west from the reference point is -x.

Snuke will set up Christmas trees at points on the road at intervals of M meters, starting from a point with coordinate A. In other words, he will set up a Christmas tree at each point that can be expressed as A+kM using some integer k.

Takahashi and Aoki are standing at points with coordinates L and R (L\leq R), respectively. Find the number of Christmas trees that will be set up between Takahashi and Aoki (including the points where they are standing).

Constraints

  • -10^{18}\leq A \leq 10^{18}
  • 1\leq M \leq 10^9
  • -10^{18}\leq L\leq R \leq 10^{18}
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

A M L R

Output

Print the number of Christmas trees that will be set up between Takahashi and Aoki (including the points where they are standing).


Sample Input 1

5 3 -1 6

Sample Output 1

3

Snuke will set up Christmas trees at points with coordinates \dots,-4,-1,2,5,8,11,14\dots. Three of them at coordinates -1, 2, and 5 are between Takahashi and Aoki.


Sample Input 2

-2 2 1 1

Sample Output 2

0

Sometimes, Takahashi and Aoki are standing at the same point.


Sample Input 3

-177018739841739480 2436426 -80154573737296504 585335723211047198

Sample Output 3

273142010859
C - Socks 2

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 350

問題文

高橋君は N 組の靴下を持っており、i 番目の組は色 i の靴下 2 枚からなります。 ある日タンスの中を整理した高橋君は、色 A_1,A_2,\dots,A_K の靴下を 1 枚ずつなくしてしまったことに気づいたので、残っている 2N-K 枚の靴下を使って、靴下 2 枚ずつからなる \lfloor\frac{2N-K}{2}\rfloor 個の組を新たに作り直すことにしました。 色 i の靴下と色 j の靴下からなる組の奇妙さ|i-j| として定義され、高橋君は奇妙さの総和をできるだけ小さくしたいです。

残っている靴下をうまく組み合わせて \lfloor\frac{2N-K}{2}\rfloor 個の組を作ったとき、奇妙さの総和が最小でいくつになるか求めてください。 なお、2N-K が奇数のとき、どの組にも含まれない靴下が 1 枚存在することに注意してください。

制約

  • 1\leq K\leq N \leq 2\times 10^5
  • 1\leq A_1 < A_2 < \dots < A_K \leq N
  • 入力は全て整数

入力

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

N K
A_1 A_2 \dots A_K

出力

奇妙さの総和の最小値を整数として出力せよ。


入力例 1

4 2
1 3

出力例 1

2

以下、色 i の靴下と色 j の靴下からなる組を (i,j) と表記します。

1,2,3,4 の靴下がそれぞれ 1,2,1,2 枚ずつあります。 (1,2),(2,3),(4,4)3 組を作ると、奇妙さの総和は |1-2|+|2-3|+|4-4|=2 となり、これが最小です。


入力例 2

5 1
2

出力例 2

0

(1,1),(3,3),(4,4),(5,5)4 組を作り、色 2 の靴下を 1 枚余らせる(どの組にも入れない)のが最適です。


入力例 3

8 5
1 2 4 7 8

出力例 3

2

Score : 350 points

Problem Statement

Takahashi has N pairs of socks, and the i-th pair consists of two socks of color i. One day, after organizing his chest of drawers, Takahashi realized that he had lost one sock each of colors A_1, A_2, \dots, A_K, so he decided to use the remaining 2N-K socks to make \lfloor\frac{2N-K}{2}\rfloor new pairs of socks, each pair consisting of two socks. The weirdness of a pair of a sock of color i and a sock of color j is defined as |i-j|, and Takahashi wants to minimize the total weirdness.

Find the minimum possible total weirdness when making \lfloor\frac{2N-K}{2}\rfloor pairs from the remaining socks. Note that if 2N-K is odd, there will be one sock that is not included in any pair.

Constraints

  • 1\leq K\leq N \leq 2\times 10^5
  • 1\leq A_1 < A_2 < \dots < A_K \leq N
  • All input values are integers.

Input

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

N K
A_1 A_2 \dots A_K

Output

Print the minimum total weirdness as an integer.


Sample Input 1

4 2
1 3

Sample Output 1

2

Below, let (i,j) denote a pair of a sock of color i and a sock of color j.

There are 1, 2, 1, 2 socks of colors 1, 2, 3, 4, respectively. Creating the pairs (1,2),(2,3),(4,4) results in a total weirdness of |1-2|+|2-3|+|4-4|=2, which is the minimum.


Sample Input 2

5 1
2

Sample Output 2

0

The optimal solution is to make the pairs (1,1),(3,3),(4,4),(5,5) and leave one sock of color 2 as a surplus (not included in any pair).


Sample Input 3

8 5
1 2 4 7 8

Sample Output 3

2
D - Reindeer and Sleigh

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 400

問題文

N 台のソリがあり、各ソリには 1,2,\ldots, N の番号がつけられています。

ソリ i を引くために必要なトナカイは R_i 匹です。

また、各トナカイが引けるソリは高々 1 台です。より厳密には、m 台のソリ i_1, i_2, \ldots, i_m を引くために必要なトナカイは \sum_{k=1}^{m} R_{i_k} 匹です。

以下の形式のクエリが Q 個与えられるので、答えを求めてください。

  • 整数 X が与えられる。トナカイが X 匹いるときに最大で何台のソリを引けるか求めよ。

制約

  • 1 \leq N, Q \leq 2 \times 10^5
  • 1 \leq R_i \leq 10^9
  • 1 \leq X \leq 2 \times 10^{14}
  • 入力される数値はすべて整数

入力

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

N Q
R_1 R_2 \ldots R_N
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q

各クエリは次の形式で与えられる。

X

出力

Q 行出力せよ。

i 行目には i 個目のクエリに対する答えを出力せよ。


入力例 1

4 3
5 3 11 8
16
7
1000

出力例 1

3
1
4

トナカイが 16 匹いるとき、ソリ 1,2,4 を引くことができます。

16 匹のトナカイで 4 台のソリを引くことはできないので、クエリ 1 の答えは 3 となります。


入力例 2

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

出力例 2

1
1
2
2
2
3

入力例 3

2 2
1000000000 1000000000
200000000000000
1

出力例 3

2
0

Score : 400 points

Problem Statement

There are N sleighs numbered 1,2,\ldots, N.

R_i reindeer are required to pull sleigh i.

Additionally, each reindeer can pull at most one sleigh. More precisely, \sum_{k=1}^{m} R_{i_k} reindeer are required to pull m sleighs i_1, i_2, \ldots, i_m.

Find the answer to Q queries of the following form:

  • You are given an integer X. Determine the maximum number of sleighs that can be pulled when there are X reindeer.

Constraints

  • 1 \leq N, Q \leq 2 \times 10^5
  • 1 \leq R_i \leq 10^9
  • 1 \leq X \leq 2 \times 10^{14}
  • All input values are integers.

Input

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

N Q
R_1 R_2 \ldots R_N
\text{query}_1
\text{query}_2
\vdots
\text{query}_Q

Each query is given in the following format:

X

Output

Print Q lines.

The i-th line should contain the answer to the i-th query.


Sample Input 1

4 3
5 3 11 8
16
7
1000

Sample Output 1

3
1
4

When there are 16 reindeer, sleighs 1,2,4 can be pulled.

It is impossible to pull four sleighs with 16 reindeer, so the answer to query 1 is 3.


Sample Input 2

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

Sample Output 2

1
1
2
2
2
3

Sample Input 3

2 2
1000000000 1000000000
200000000000000
1

Sample Output 3

2
0
E - Christmas Color Grid 1

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 450

問題文

この問題は問題 G と似た設定です。問題文の相違点を赤字で示します。

HW 列のグリッドがあり、グリッドの各マスは赤色あるいは緑色に塗られています。

グリッドの上から i 行目、左から j 列目のマスをマス (i,j) と表記します。

マス (i,j) の色は文字 S_{i,j} で表され、S_{i,j} = . のときマス (i,j) は赤色、S_{i,j} = # のときマス (i,j) は緑色に塗られています。

グリッドにおいて、緑色に塗られたマスを頂点集合、隣り合った 2 つの緑色のマスを結ぶ辺全体を辺集合としたグラフにおける連結成分の個数を 緑の連結成分数 と呼びます。ただし、2 つのマス (x,y)(x',y') が隣り合っているとは、|x-x'| + |y-y'| = 1 であることを指します。

赤色に塗られたマスを一様ランダムに 1 つ選び、緑色に塗り替えたとき、塗り替え後のグリッドの緑の連結成分数の期待値を \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 H,W \leq 1000
  • S_{i,j} = . または S_{i,j} = #
  • S_{i,j} = . なる (i,j) が存在する。

入力

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

H W
S_{1,1}S_{1,2}\ldotsS_{1,W}
S_{2,1}S_{2,2}\ldotsS_{2,W}
\vdots
S_{H,1}S_{H,2}\ldotsS_{H,W}

出力

答えを出力せよ。


入力例 1

3 3
##.
#.#
#..

出力例 1

499122178

マス (1,3) を緑色に塗り替えたとき、緑の連結成分数は 1 となります。

マス (2,2) を緑色に塗り替えたとき、緑の連結成分数は 1 となります。

マス (3,2) を緑色に塗り替えたとき、緑の連結成分数は 2 となります。

マス (3,3) を緑色に塗り替えたとき、緑の連結成分数は 2 となります。

よって、赤色に塗られたマスを一様ランダムに 1 つ選び、緑色に塗り替えた後の緑の連結成分数の期待値は (1+1+2+2)/4 = 3/2 となります。


入力例 2

4 5
..#..
.###.
#####
..#..

出力例 2

598946613

入力例 3

3 4
#...
.#.#
..##

出力例 3

285212675

Score : 450 points

Problem Statement

This problem has a similar setting to Problem G. Differences in the problem statement are indicated in red.

There is a grid with H rows and W columns, where each cell is painted red or green.

Let (i,j) denote the cell in the i-th row from the top and the j-th column from the left.

The color of cell (i,j) is represented by the character S_{i,j}, where S_{i,j} = . means cell (i,j) is red, and S_{i,j} = # means cell (i,j) is green.

The number of green connected components in the grid is the number of connected components in the graph with the vertex set being the green cells and the edge set being the edges connecting two adjacent green cells. Here, two cells (x,y) and (x',y') are considered adjacent when |x-x'| + |y-y'| = 1.

Consider choosing one red cell uniformly at random and repainting it green. Print the expected value of the number of green connected components in the grid after repainting, modulo 998244353.

What does "print the expected value modulo 998244353" mean? It can be proved that the sought expected value is always rational. Furthermore, the constraints of this problem guarantee that if that value is expressed as \frac{P}{Q} using two coprime integers P and Q, there is exactly one integer R such that R \times Q \equiv P \pmod{998244353} and 0 \leq R < 998244353. Print this R.

Constraints

  • 1 \leq H,W \leq 1000
  • S_{i,j} = . or S_{i,j} = #.
  • There is at least one (i,j) such that S_{i,j} = ..

Input

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

H W
S_{1,1}S_{1,2}\ldotsS_{1,W}
S_{2,1}S_{2,2}\ldotsS_{2,W}
\vdots
S_{H,1}S_{H,2}\ldotsS_{H,W}

Output

Print the answer.


Sample Input 1

3 3
##.
#.#
#..

Sample Output 1

499122178

If cell (1,3) is repainted green, the number of green connected components becomes 1.

If cell (2,2) is repainted green, the number of green connected components becomes 1.

If cell (3,2) is repainted green, the number of green connected components becomes 2.

If cell (3,3) is repainted green, the number of green connected components becomes 2.

Therefore, the expected value of the number of green connected components after choosing one red cell uniformly at random and repainting it green is (1+1+2+2)/4 = 3/2.


Sample Input 2

4 5
..#..
.###.
#####
..#..

Sample Output 2

598946613

Sample Input 3

3 4
#...
.#.#
..##

Sample Output 3

285212675
F - Christmas Present 2

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 550

問題文

xy 平面として表される町があり、サンタさんと、1 から N までの番号が付けられた N 人の子供が住んでいます。 サンタさんの家の座標は (S_X,S_Y) であり、子供 i\ (1\leq i\leq N) の家の座標は (X_i,Y_i) です。

サンタさんは、N 人の子供たちに番号順にプレゼントを 1 個ずつ配りたいです。 子供 i にプレゼントを配るためには、プレゼントを 1 個以上持った状態で子供 i の家に行く必要があります。 しかし、サンタさんは同時に K 個までしかプレゼントを持つことができず、プレゼントを補充するためには一旦自分の家に戻る必要があります(サンタさんの家には十分な数のプレゼントがあります)。

サンタさんが自分の家を出発し、N 人の子供たち全員にプレゼントを配って、自分の家まで戻ってくるために移動する距離の最小値を求めてください。

制約

  • 1\leq K\leq N \leq 2\times 10^5
  • -10^9\leq S_X,S_Y,X_i,Y_i \leq 10^9
  • (S_X,S_Y)\neq (X_i,Y_i)
  • (X_i,Y_i)\neq (X_j,Y_j)\ (i\neq j)
  • 入力は全て整数

入力

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

N K
S_X S_Y
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

出力

サンタさんが移動する距離の最小値を出力せよ。 出力は、真の値との絶対誤差または相対誤差が 10^{−6} 以下のとき正解と判定される。


入力例 1

3 2
1 1
3 1
1 2
3 2

出力例 1

9.236067977499790

上図において、赤い丸はサンタさんの家、中に数字が書かれた丸はその番号の子供の家を表しています。

サンタさんが以下のように行動することを考えます。

  1. プレゼントを 2 個持ってサンタさんの家を出る。
  2. 子供 1 の家に行ってプレゼントを 1 個配る。
  3. サンタさんの家に戻ってプレゼントを 1 個補充する。
  4. 子供 2 の家に行ってプレゼントを 1 個配る。
  5. 子供 3 の家に行ってプレゼントを 1 個配る。
  6. サンタさんの家に戻る。

このとき、サンタさんが移動する距離は 2+2+1+2+\sqrt{5}=7+\sqrt{5}=9.236\dots となり、これが最小です。


入力例 2

2 1
0 1
-1 1
1 1

出力例 2

4.000000000000000

入力例 3

8 3
735867677 193944314
586260100 -192321079
95834122 802780784
418379342 -790013317
-445130206 189801569
-354684803 -49687658
-204491568 -840249197
853829789 470958158
-751917965 762048217

出力例 3

11347715738.116592407226562

Score : 550 points

Problem Statement

There is a town represented as an xy-plane, where Santa lives, along with N children numbered 1 to N. Santa's house is at coordinates (S_X,S_Y), and the house of child i\ (1\leq i\leq N) is at (X_i,Y_i).

Santa wants to deliver one present to each of the N children in numerical order. To deliver a present to child i, Santa must visit the house of child i with at least one present in hand. However, Santa can only carry up to K presents at a time, and he must return to his own house to replenish presents (there are enough presents at Santa's house).

Find the minimum distance Santa must travel to leave his house, deliver presents to all N children, and return to his house.

Constraints

  • 1\leq K\leq N \leq 2\times 10^5
  • -10^9\leq S_X,S_Y,X_i,Y_i \leq 10^9
  • (S_X,S_Y)\neq (X_i,Y_i)
  • (X_i,Y_i)\neq (X_j,Y_j)\ (i\neq j)
  • All input values are integers.

Input

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

N K
S_X S_Y
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N

Output

Print the minimum distance Santa must travel. The output will be considered correct if the absolute or relative error from the true value is at most 10^{−6}.


Sample Input 1

3 2
1 1
3 1
1 2
3 2

Sample Output 1

9.236067977499790

In the figure above, the red circle represents Santa's house, and the circles with numbers represent the houses of the children with those numbers.

Consider Santa acting as follows:

  1. Leave his house with two presents.
  2. Go to child 1's house and deliver a present.
  3. Return to his house and replenish one present.
  4. Go to child 2's house and deliver a present.
  5. Go to child 3's house and deliver a present.
  6. Return to his house.

In this case, Santa travels the distance of 2+2+1+2+\sqrt{5}=7+\sqrt{5}=9.236\dots, which is the minimum.


Sample Input 2

2 1
0 1
-1 1
1 1

Sample Output 2

4.000000000000000

Sample Input 3

8 3
735867677 193944314
586260100 -192321079
95834122 802780784
418379342 -790013317
-445130206 189801569
-354684803 -49687658
-204491568 -840249197
853829789 470958158
-751917965 762048217

Sample Output 3

11347715738.116592407226562
G - Christmas Color Grid 2

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 650

問題文

この問題は問題 E と似た設定です。問題文の相違点を赤字で示します。

HW 列のグリッドがあり、グリッドの各マスは赤色あるいは緑色に塗られています。

グリッドの上から i 行目、左から j 列目のマスをマス (i,j) と表記します。

マス (i,j) の色は文字 S_{i,j} で表され、S_{i,j} = . のときマス (i,j) は赤色、S_{i,j} = # のときマス (i,j) は緑色に塗られています。

グリッドにおいて、緑色に塗られたマスを頂点集合、隣り合った 2 つの緑色のマスを結ぶ辺全体を辺集合としたグラフにおける連結成分の個数を 緑の連結成分数 と呼びます。ただし、2 つのマス (x,y)(x',y') が隣り合っているとは、|x-x'| + |y-y'| = 1 であることを指します。

緑色に塗られたマスを一様ランダムに 1 つ選び、赤色に塗り替えたとき、塗り替え後のグリッドの緑の連結成分数の期待値を \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 H,W \leq 1000
  • S_{i,j} = . または S_{i,j} = #
  • S_{i,j} = # なる (i,j) が存在する。

入力

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

H W
S_{1,1}S_{1,2}\ldotsS_{1,W}
S_{2,1}S_{2,2}\ldotsS_{2,W}
\vdots
S_{H,1}S_{H,2}\ldotsS_{H,W}

出力

答えを出力せよ。


入力例 1

3 3
##.
#.#
#..

出力例 1

598946614

マス (1,1) を赤色に塗り替えたとき、緑の連結成分数は 3 となります。

マス (1,2) を赤色に塗り替えたとき、緑の連結成分数は 2 となります。

マス (2,1) を赤色に塗り替えたとき、緑の連結成分数は 3 となります。

マス (2,3) を赤色に塗り替えたとき、緑の連結成分数は 1 となります。

マス (3,1) を赤色に塗り替えたとき、緑の連結成分数は 2 となります。

よって、緑色に塗られたマスを一様ランダムに 1 つ選び、赤色に塗り替えた後の緑の連結成分数の期待値は (3+2+3+1+2)/5 =11/5 となります。


入力例 2

4 5
..#..
.###.
#####
..#..

出力例 2

199648872

入力例 3

3 4
#...
.#.#
..##

出力例 3

399297744

Score : 650 points

Problem Statement

This problem has a similar setting to Problem E. Differences in the problem statement are indicated in red.

There is a grid with H rows and W columns, where each cell is painted red or green.

Let (i,j) denote the cell in the i-th row from the top and the j-th column from the left.

The color of cell (i,j) is represented by the character S_{i,j}, where S_{i,j} = . means cell (i,j) is red, and S_{i,j} = # means cell (i,j) is green.

The number of green connected components in the grid is the number of connected components in the graph with the vertex set being the green cells and the edge set being the edges connecting two adjacent green cells. Here, two cells (x,y) and (x',y') are considered adjacent when |x-x'| + |y-y'| = 1.

Consider choosing one green cell uniformly at random and repainting it red. Print the expected value of the number of green connected components in the grid after repainting, modulo 998244353.

What does "print the expected value modulo 998244353" mean? It can be proved that the sought expected value is always rational. Furthermore, the constraints of this problem guarantee that if that value is expressed as \frac{P}{Q} using two coprime integers P and Q, there is exactly one integer R such that R \times Q \equiv P \pmod{998244353} and 0 \leq R < 998244353. Print this R.

Constraints

  • 1 \leq H,W \leq 1000
  • S_{i,j} = . or S_{i,j} = #.
  • There is at least one (i,j) such that S_{i,j} = #.

Input

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

H W
S_{1,1}S_{1,2}\ldotsS_{1,W}
S_{2,1}S_{2,2}\ldotsS_{2,W}
\vdots
S_{H,1}S_{H,2}\ldotsS_{H,W}

Output

Print the answer.


Sample Input 1

3 3
##.
#.#
#..

Sample Output 1

598946614

If cell (1,1) is repainted red, the number of green connected components becomes 3.

If cell (1,2) is repainted red, the number of green connected components becomes 2.

If cell (2,1) is repainted red, the number of green connected components becomes 3.

If cell (2,3) is repainted red, the number of green connected components becomes 1.

If cell (3,1) is repainted red, the number of green connected components becomes 2.

Therefore, the expected value of the number of green connected components after choosing one green cell uniformly at random and repainting it red is (3+2+3+1+2)/5 =11/5.


Sample Input 2

4 5
..#..
.###.
#####
..#..

Sample Output 2

199648872

Sample Input 3

3 4
#...
.#.#
..##

Sample Output 3

399297744