Gamers#1398

Gamers

4 seconds
64 megabytes
Medium

The streets and crossroads of Bucharest form a perfect grid. At each crossroads, there is exactly one gaming club and one gamer. Each gaming club offers exactly one game. Gamers live according to the following rules:

  1. A gamer never plays in the club at their own crossroads. Never!!!

  2. During the day, each gamer must play each of the games, provided this does not contradict Rule 1.

  3. Gamers move between crossroads only horizontally or vertically.

  4. A gamer cannot go directly from one club to another. They must return home first before moving to another club, and must finish the day at their own intersection.

  5. A gamer must live optimally, always choosing the best possible strategy to follow the above rules so that there is enough time for gaming.

Since all gamers are the same, the Association of Computer Maniacs decided to optimize the city to minimize the total non-gaming effort. The non-gaming effort is the number of crossroads a gamer traverses in a day. The total non-gaming effort is the sum of the non-gaming effort for all gamers in the city. To perform these optimizations, ACM needs a program that calculates the total non-gaming effort for a given city description.

Input

Several city descriptions are given in the standard input. Each description begins with a line of two integers and (1 \leq R, C \leq 1000), denoting the number of rows and columns of crossroads in the city. lines follow, each containing characters, describing the game offered at each club at each crossroads. Each game is represented by a single digit ( to ).

Output

For each city description, output the total non-gaming effort for the city on a separate line.

Examples

Example 1

Loading
Loading