Under construction

Still being built. Things may change

Class

Interview

Time limit1sMemory limit1024 MB

Summary
Given a grid of digits, sum each cell's average absolute difference from its up to four orthogonal neighbors, and print the total with four decimals.
Level

Easy3 of 10

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

Problem

A classroom is full of students seated in rows and columns. Each student is interested to some degree in computers and in sports. A student interested only in sports is labeled 00. A student interested only in computers is labeled 99. Every other student is labeled with a digit from 11 to 88 according to their level of interest.

Students with similar interests chat with one another and ignore the teacher. The smaller the difference between two neighboring students' interests, the more they chat. For example, a student with interest 77 surrounded by other students who also have interest 77 pays no attention to the teacher at all.

Each student's attention is defined as the average of the absolute differences between their own interest and the interests of their neighbors. Neighbors are the students seated directly in front of, behind, to the left of, or to the right of a given student.

The total attention of the class equals the sum of the individual students' attention values. Write a program that computes it.

Input

The first line contains two integers MM and NN (1≤M≤2001 \le M \le 200, 1≤N≤2001 \le N \le 200), the number of rows and columns in the classroom. The classroom has at least two students. Each of the next MM lines contains exactly NN characters, each a digit from 00 to 99.

Output

Print a single number: the total attention of the class, with exactly four digits after the decimal point.

Examples1

  1. Example 1

    Input
    3 4
    6021
    1937
    3138
    
    Expected output
    46.5000