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
(ai,bi) and lower right corner in the cell with coordinates
(ci,di) to the symbol
ei.
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.