#P1322. Happy Patting

Happy Patting

Happy Patting

题目描述

The "Happy Patting" game is to arrange the children into nn rows, with mm people in each row. When the game starts, each child will receive a digital command on his/her mobile phone simultaneously: 11 for forward, 22 for backward, 33 for left, and 44 for right. The children must follow the command to pat the children in the specified direction. How many children are patted by more than one friend? Note: In the plane diagram, the top of a grid is "front" and the bottom is "back". Children in the corners may pat the air, which is also allowed.

输入格式

Each input file contains one test case. The first line gives 22 positive integers nn and mm (2n2≤n,m100m≤100), which are the number of rows and the number of people in each row, respectively. Then nn lines follow, each contains mm numbers, which represent the digital commands received by the children at the corresponding position. All the numbers in a line are separated by a space.

输出格式

For each test case, print in a line the number of children who are patted by more than one friend.

样例 #1

样例输入 #1

3 5
1 2 3 4 1
4 1 4 3 3
3 2 1 1 3

样例输出 #1

4