Strange sum
문제
Egor has table of size , where all lines are numbered from to and all columns are numbered from to . Each cell is painted in some color that can be presented as integer from to .
Let us call the cell that lies in -th row and -th column as . We define the manhattan distance between two cells and as the length of shortest path between them where each consecutive cells have common side. The path can go through cells of any color. For example, the manhattan distance between and is 3, one of the shortest paths is the following: .
Egor decided to calculate the sum of manhattan distances between each pair of cells of same color. Help him to calculate this sum.
입력
The first line contains two integers and (, ) --- number of rows and columns in the table.
Each of next lines describes the rows of the table. -th line contains integers () --- colors of cells in -th row.
출력
Print one integer --- the the sum of manhattan distances between each pair of cells of same color.
힌트
In the first sample there are three pairs of cells of same color: in coordinates and , in coordinates and , in coordinates and . The manhattan distances between them are , and , the sum is .
예제
예제 1
2 3 1 2 3 3 2 1
7
예제 2
3 4 1 1 2 2 2 1 1 2 2 2 1 1
76
예제 3
4 4 1 1 2 3 2 1 1 2 3 1 2 1 1 1 2 1
129