Partial Rectangles

Time limit2sMemory limit128 MB

Summary
Given an N x M grid doubled into a 2N x 2M grid, count how many times each letter appears summed over every possible subrectangle.
Level

Medium5 of 10

Topics
Combinatorics, Math, Matrix, Implementation
Solved
No attempts yet

Problem

Minsik has an N x M rectangular table filled with uppercase letters. He copies the table once horizontally and once vertically, making a larger 2N x 2M table made from four copies of the original. Then he considers every subrectangle of this larger table.

Consider the following 1 x 2 table.

OK

After copying it into a 2 x 2 arrangement of copies, the larger table is:

OKOK
OKOK

This table has 30 subrectangles. They are shown below, where . is used only as a separator.

OKOK .... OKOK OKO. .... OKO. .KOK .... .KOK OK.. .... OK.. .KO. .... .KO.
OKOK OKOK .... OKO. OKO. .... .KOK .KOK .... OK.. OK.. .... .KO. .KO. ....

..OK ..OK .... O... .... O... .K.. .... .K.. ..O. .... ..O. ...K .... ...K
..OK .... ..OK O... O... .... .K.. .K.. .... ..O. ..O. .... ...K ...K ....

Find, over all subrectangles of the larger table, how many times each uppercase letter appears in total. In the case above, K appears 40 times and O appears 40 times.

Input

The first line contains two integers N and M. The next N lines contain the rows of the table. Every character is an uppercase English letter.

Output

Print 26 lines. The first line is the total number of appearances of A, the second line is the total number of appearances of B, and so on through Z.

Constraints

  • 1 <= N, M <= 50

Examples3

  1. Example 1

    Input
    2 4
    GOOD
    LUCK
    
    Expected output
    0
    0
    320
    280
    0
    0
    280
    0
    0
    0
    280
    280
    0
    0
    640
    0
    0
    0
    0
    0
    320
    0
    0
    0
    0
    0
    
  2. Example 2

    Input
    1 2
    OK
    
    Expected output
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    40
    0
    0
    0
    40
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    
  3. Example 3

    Input
    4 5
    TANYA
    HAPPY
    BIRTH
    DAYYY
    
    Expected output
    5168
    1280
    0
    1120
    0
    0
    0
    2560
    1472
    0
    0
    0
    0
    1344
    0
    3008
    0
    1536
    0
    2592
    0
    0
    0
    0
    6320
    0