Coloured rain#994

Coloured rain

1 second
128 megabytes
Easy

In the Banana Republic there are many hills connected by bridges. An accident occurred at a chemical plant, as a result of which the experimental fertilizer "zovan" evaporated. The next day, a colored rain fell, but only over the hills. In some places red drops fell, in others — blue ones, and on the remaining hills — green ones, so the hills were colored accordingly.

The President of the Banana Republic liked this picture, and he decided to paint the bridges between the hills so that each bridge is colored in the color of the hills it connects. However, if the endpoints of a bridge are colored in different colors, it is impossible to paint it in such a way. Count the number of such "bad" bridges.

Input

The first line contains the number of hills n~(0 < n \le 100). The following lines contain an adjacency matrix describing the presence of bridges between the hills ( — a bridge exists, — no bridge). The last line contains integers denoting the colors of the hills: — red; — blue; — green.

Output

Print the number of "bad" bridges.

Examples

Example 1

Loading
Loading