Codeforces Round 394 (Div. 2)
F
Dasha and Photos
Codeforces
2600
原题
← E→
翻译中…

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.

翻译中…

image

翻译中…

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.

翻译中…

Input

翻译中…

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.

翻译中…

Output

翻译中…

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

翻译中…

Note

翻译中…

In the first example the photos are following:

翻译中…

bba    aaa
bba    acc
aaa    acc

翻译中…

The distance between them is $10$.

翻译中…

样例

Input #1
3 3 2
aaa
aaa
aaa
1 1 2 2 b
2 2 3 3 c
Output #1
10
InputCopy OutputCopy
Input #2
5 5 3
abcde
eabcd
deabc
cdeab
bcdea
1 1 3 4 f
1 2 3 3 e
1 3 3 4 i
Output #2
59
InputCopy OutputCopy
题目信息
题号
761F
时间限制
4 s
内存限制
512 MB
标签
暴力
数据结构
动态规划
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。