Gamers
As you probably know, the streets and crossroads of Bucharest form a perfect grid. What you probably don't know, is that there is exactly one gaming club and exactly one gamer on each of these crossroads. Strangely enough, each gaming club offers exactly one game. Gamers are also a bit strange, but they generally live a simple life, determined by the following rules:
A gamer never plays in the club of his own crossroads. Never!!!
During a day each gamer has to play each of the games when this is not contradicting the Rule 1.
Gamers travel from one crossroads to another only by horizontals or verticals.
A gamer can not go directly from one club to another. It has to come back home and eat something first and has to finish the day in his own intersection.
A gamer has to live optimally, thus always picking the best possible strategy to implement the above rules, so that she has enough time for gaming.
Having in mind that all the gamers are the same, the Association of Computer Maniacs decided that the city should be optimized in order to minimize the total non-gaming effort. The non-gaming effort is the number of crossroads that a gamer walks trough the day. The total non-gaming effort is the sum of the non-gaming efforts for all gamers in the city. In order to perform the optimizations, ACM needs a program that calculates the total non-gaming effort for a given description of the city.
Input
Several city descriptions are given in the standard input. Each of them starts with a line of two integers R and C (1 ≤ R, C ≤ 1000), denoting the number of rows and the number of columns of the crossroads in the city. R lines of C characters follow, denoting the kind of game that is offered by the club of each of the crossroads. Each game is coded using a single digit ('0' to '9').
Output
For each of the city descriptions the program has to write on a separate line of the standard output a line containing one integer – the total non-gaming effort for the city.