Олимпиадный тренинг

Задача 22019. colored rain


There are a lot of hills connected by bridges in the Banana Republic. There was an accident at a chemical plant, as a result of which the experimental fertilizer "zovan" evaporated. The next day, colored rain fell, and it only passed over the hills, in some places red drops fell, in some - blue, and in the rest - green, as a result of which the hills became the corresponding color. The President of the Banana Republic liked this, but he wanted to paint the bridges between the hilltops so that the bridges were painted in the color of the hills they connect. Unfortunately, if the hills are of different colors, then it will not be possible to paint the bridge in this way.
Count the number of such "bad" bridges.
 
Input: 
- the first line contains N (\(0<N<=100\)) - the number of hills; 
- then comes the adjacency matrix, which describes the presence of bridges between hills (1-bridge exists, 0-no);
- the last line contains N numbers indicating the color of the hills: 1 - red; 2 - blue; 3 - green.
 
Output: output the number of "bad" bridges. 
 
 

Examples

# Input Output
1
7
0 1 0 0 0 1 1 
1 0 1 0 0 0 0
0 1 0 0 1 1 0 
0 0 0 0 0 0 0
0 0 1 0 0 1 0 
1 0 1 0 1 0 0 
1 0 0 0 0 0 0 
1 1 1 1 1 3 3
4