Problem A
Cinema Seating
The United Cinema Crowd Association of Stockholm plans to
have a showing of Old computer scientists and their
pieings at the local KTH Royal Institute of Technology
cinema. They have received bookings from
Not until far too late did the auditor of the association point out to the board that computer scientists are stereotypically introverted. They might even go so far as to leave the showing if they have too many people sitting nearby!
For a given person, the number of adjacent seats to them are
the 8 seats which are located at most a single row or column
away from the person. Your task is to compute how many people
have
Input
The first line of the input contains the integers
The next line contains the integer
No two bookings will be for the same seat.
Output
Output
Explanation of the sample
In the first example, the cinema is a fully occupied
In the second example, the situation is similar, except there is nobody in the middle. Thus, the people in the corners only have two adjacent occupied seats now, and the people on the sides have four adjacent occupied seats.
Sample Input 1 | Sample Output 1 |
---|---|
3 3 9 1 1 1 2 1 3 2 1 2 2 2 3 3 1 3 2 3 3 |
0 0 0 4 0 4 0 0 1 |
Sample Input 2 | Sample Output 2 |
---|---|
3 3 8 1 1 1 2 1 3 2 1 2 3 3 1 3 2 3 3 |
0 0 4 0 4 0 0 0 0 |