JDCC '16 Contest 1 P3 - Painting Cost

View as PDF

Submit solution


Points: 5
Time limit: 2.0s
Memory limit: 64M

Author:
Problem types

Melissa's family has just moved to a new house and she is excited to start painting her bedroom walls. After coming up with a great design, she realizes that she will need to ask her parents to fund the project. Wanting to seem independent, she would prefer to ask her parents for as little money as possible. Can you help her figure out how much money she will need to pay the painters?

Melissa's paint design is given as a grid of colours arranged in R rows and C columns. The painters will paint the wall in 2x2 blocks and will charge Melissa $1 for every unique colour in a 2x2 block.

Input

A test case begins with two integers R, C (1 \le R, C \le 100, R and C are even). The next R lines contain C characters, each representing a unique colour.

Output

Output one integer, the cost of the paint job.

Sample Input

2 2
RG
BR

Sample Output

3

Sample Input

4 4
WWRB
WWRR
WWRR
WBBB

Sample Output

7

Explanation of Sample Input/Output

In the second case, the painters will paint the wall in four blocks:

WW RB WW RR
WW RR WB BB

Making the total cost 1 + 2 + 2 + 2 = 7.


Comments

There are no comments at the moment.