Under construction

Still being built. Things may change

Digit-only subrectangles

Time limit3sMemory limit1024 MB

Summary
Given a grid of digits and asterisks, sum the squared digit totals of all rectangles that contain only digits, modulo 998244353.
Level

Medium6 of 10

Topics
Prefix sum, Math, Implementation
Solved
No attempts yet

Statement

The grid has HH rows and WW columns of square cells. Each cell holds either a digit or an asterisk (‘*’). Let (i,j)(i,j) denote the cell in row ii from the top and column jj from the left.

A subrectangle is a set of cells that forms a rectangle. Precisely, a set SS is a subrectangle if there are integers tt, bb, ll, rr with 1≤t≤b≤H1 \le t \le b \le H, 1≤l≤r≤W1 \le l \le r \le W, and S={(i,j)∣t≤i≤b∧l≤j≤r}S = \{(i,j) \mid t \le i \le b \wedge l \le j \le r \}. A subrectangle is digit-only if every cell in it holds a digit. The score of a digit-only subrectangle is the square of the sum of its digits.

Compute the sum of scores of all digit-only subrectangles, modulo 998244353998244353.

Input

The input is given in the following format.

HH WW A1,1A1,2⋯A1,WA_{1,1}A_{1,2}\cdots A_{1,W} A2,1A2,2⋯A2,WA_{2,1}A_{2,2}\cdots A_{2,W} ⋮\vdots AH,1AH,2⋯AH,WA_{H,1}A_{H,2}\cdots A_{H,W}

The first line contains HH and WW (1≤H≤20001 \le H \le 2000, 1≤W≤20001 \le W \le 2000). Each of the next HH lines contains WW characters, where Ai,jA_{i,j} is the character in cell (i,j)(i,j): a digit from 0 to 9 or an asterisk (‘*’). It is guaranteed that at least one digit-only subrectangle exists.

Output

Print the sum of scores of all digit-only subrectangles modulo 998244353998244353 on one line.

Hint

The first test case has five digit-only subrectangles, shown in the figure below. Their scores sum to 42+42+92+(4+4)2+(4+9)2=3464^2 + 4^2 + 9^2 + (4 + 4)^2 + (4 + 9)^2 = 346.

Figure F.1. Digit-only subrectangles in the first test case

Examples4

  1. Example 1

    Input
    2 2
    44
    9*
    
    Expected output
    346
    
  2. Example 2

    Input
    2 3
    314
    28*
    
    Expected output
    601
    
  3. Example 3

    Input
    4 6
    314159
    2*6535
    *89793
    238*4*
    
    Expected output
    37655
    
  4. Example 4

    Input
    18 20
    65929431919981098712
    34182289733359024486
    *5999742744659484782
    03563591172305229098
    55764088882794210744
    65542986390400199274
    24954674699538357427
    65448003011829165060
    0570520*394989799204
    21113635765787241691
    24382969673042349665
    04571518994293776944
    42950768895299998684
    02191975238817773041
    08629513210946362875
    91583470151322043009
    00337992511803056114
    59396973995193492513
    
    Expected output
    78257625