CF761F Dasha and Photos
Description
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.
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 Format
The first line contains three integers $ n $ , $ m $ , $ k $ $ (1
Output Format
In the only line print the minimum total distance from the found special photo to all other special photos.
Explanation/Hint
In the first example the photos are following:
`
bba aaa
bba acc
aaa acc
`The distance between them is $ 10 $ .
bba aaa
bba acc
aaa acc
`The distance between them is $ 10 $ .