# 50164. Dice

## I'm a slow walker, but I never walk backwards.

We have a two dimensional array filled with numbers from one to six. Write a program to find out the number of ways to select six neighboring array elements to form a dice. A dice is a cube that has numbers from 1 to 6 on its six surfaces, and the sums of all three pairs of numbers on the opposite faces are all 7. To simplify this task, we only consider dices that have four numbers on the same row, as in the following figures.

## Input Format

The first line has the number of rows $R$ and columns $C$ of the two dimensional array. Each of the following $R$ lines has $C$ numbers from 1 to 6, indicating the numbers of the array.

• $5 \leq R,C \leq 1000$

## Output Format

The output has only one integer - the numbers of dices that can be formed according to the rules described earlier.

## Sample Input 1

5 51 1 1 1 11 1 4 4 31 2 1 5 61 4 3 3 21 1 1 1 1


## Sample Output 1

5


1
2
3
5
4
6

(3D Interactive cube by Jordan Leigh, https://codepen.io/jordizle/pen/haIdo/)