logo AlgoBeat OnlineJudge
登录 注册

#215779. [JAG 2023 Summer Camp #3] Digit-only subrectangles

内存限制:1024 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

There are rows and columns of square cells. Each cell has either a digit or an asterisk ('*'). The cell at the -th row from the top and the -th column from the left is denoted by .

In this problem we consider subrectangles, each of which is the set of cells which forms a rectangle. More precisely, a set of cells is a subrectangle if there are four integers , , and such that , and . A subrectangle is digit-only if every cell in the subrectangle has a digit. The score of a digit-only subrectangle is defined as the square of the sum of digits in cells in the subrectangle.

Your task is to calculate the sum of scores of all digit-only subrectangles. Since the answer may be large, output it modulo .

输入格式

The input consists of a single test case of the following format.

The first line consists of two integers and , which satisfy and . Each of the following lines consists of characters. Here, is the character in the cell , and it is either a digit between and , inclusive, or an asterisk ('*'). It is guaranteed that there is at least one digit-only subrectangle.

输出格式

Output in a line the sum of scores of all digit-only subrectangles modulo .

样例

样例输入 1

2 2
44
9*

样例输出 1

346

样例输入 2

2 3
314
28*

样例输出 2

601

样例输入 3

4 6
314159
2*6535
*89793
238*4*

样例输出 3

37655

样例输入 4

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

样例输出 4

78257625

数据范围与提示

In Sample Input 1, there are five digit-only subrectangles as illustrated below. The sum of their scores is .

:::align{center}

Figure F.1. Digit-only subrectangles in Sample Input 1 :::