Dasha and Photos

题意翻译

给你一个 $n \times m$ 的方格,每个格子里有一个小写英文字母。 现在你有 $k$ 个 $n \times m$ 的方格,这些方格都是在给出方格的基础上将一个矩形区域的方格中的字母全部变成一种得到的。 定义两个方格的距离为所有格子中字母在字母表中位置的差的和。你要找到 $k$ 个方格中的一个方格,满足它到其他 $k-1$ 个矩阵的距离之和最小,并输出这个最小值。 ### 输入格式 第一行三个正整数 $n, m, k$。 以下 $n$ 行,每行 $m$ 个小写字母,表示原始方格。 以下 $k$ 行,每行 $4$ 个正整数 $a_i, b_i, c_i, d_i$ 和一个字符 $ch$,表示这个方格是将原始方格左上角为 $a_i$ 行 $b_i$ 列的格子、右下角为 $c_i$ 行 $d_i$ 列的格子中的字母全部替换成 $ch$ 得到的。 ### 输出格式 输出一行一个整数,表示最小的距离之和。

题目描述

Dasha decided to have a rest after solving the problem $ D $ and began to look photos from previous competitions. Let's call photos as the matrix with the size $ n×m $ , which consists of lowercase English letters. Some $ k $ photos especially interested her, because they can be received from photo-template by painting a rectangular area in a certain color. Let's call such photos special. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF761F/ff915ee1c7a85910e49e0252b0f437800b1b420a.png)More formally the $ i $ -th special photo is received from the photo-template by replacing all characters on some rectangle with upper left corner of the cell with coordinates $ (a_{i},b_{i}) $ and lower right corner in the cell with coordinates $ (c_{i},d_{i}) $ to the symbol $ e_{i} $ . Dasha asks you to find the special photo so that the total distance from it to all other special photos is minimum. And calculate this distance. Determine the distance between two photos as the sum of distances between all corresponding letters. The distance between two letters is the difference module of their positions in the alphabet. For example, the distance between letters 'h' and 'm' equals $ |8-13|=5 $ , because the letter 'h' is the 8-th in the alphabet, the letter 'm' is the 13-th.

输入输出格式

输入格式


The first line contains three integers $ n $ , $ m $ , $ k $ $ (1<=n,m<=10^{3},1<=k<=3·10^{5}) $ — the number of strings in the photo-template, the number of columns and the number of special photos which are interesting for Dasha. The next $ n $ lines contains the string with $ m $ length which consists of little Latin characters — the description of the photo-template. Each of the next $ k $ lines contains the description of the special photo in the following format, " $ a_{i} $ $ b_{i} $ $ c_{i} $ $ d_{i} $ $ e_{i} $ " $ (1<=a_{i}<=c_{i}<=n,1<=b_{i}<=d_{i}<=m) $ , where $ (a_{i},b_{i}) $ — is the coordinate of the upper left corner of the rectangle, $ (c_{i},d_{i}) $ — is the description of the lower right corner, and $ e_{i} $ — is the little Latin letter which replaces the photo-template in the described rectangle.

输出格式


In the only line print the minimum total distance from the found special photo to all other special photos.

输入输出样例

输入样例 #1

3 3 2
aaa
aaa
aaa
1 1 2 2 b
2 2 3 3 c

输出样例 #1

10

输入样例 #2

5 5 3
abcde
eabcd
deabc
cdeab
bcdea
1 1 3 4 f
1 2 3 3 e
1 3 3 4 i

输出样例 #2

59

说明

In the first example the photos are following: `<br></br>bba aaa<br></br>bba acc<br></br>aaa acc<br></br>`The distance between them is $ 10 $ .