Mirko is a huge fan of chess and programming, but typical chess soon became boring for him, so he started having fun with rook pieces.
He found a chessboard with
Mirko's game is made of the following rules:
- Each rook's power is determined by an integer.
- A rook sees all the fields that are in his row or column except its own field.
- We say that a field is attacked if the binary
of all the powers of the rooks that see the field is greater than 0.
Notice that the field a rook is at can be attacked or not.
Initially, Mirko placed the rooks in a certain layout on the board and will make
After each move, determine how many fields are attacked.
Every rook can be moved to any free field on the whole board (not only across column and row).
Input Specification
The first line of input contains integers
Each of the following
Each of the following
It is guaranteed that there will not be two rooks on one field at any point.
In test cases worth 25% of total points,
Output Specification
The output must consist of
Sample Input 1
2 2 2
1 1 1
2 2 1
2 2 2 1
1 1 1 2
Sample Output 1
4
0
Explanation for Sample Output 1
After the first move, every field on the board is attacked. For example, field
Sample Input 2
2 2 2
1 1 1
2 2 2
2 2 2 1
1 1 1 2
Sample Output 2
4
2
Sample Input 3
3 3 4
1 1 1
2 2 2
2 3 3
2 3 3 3
3 3 3 1
1 1 1 2
3 1 3 2
Sample Output 3
6
7
7
9
Comments