HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > C. T. 2011 > problem:


Colored hills

Volume problems

• Butterfly
• Word power
• Buying hay
• Best Grass
• Cow PinBall
• Cow Sorting
• Maximum Sum
• Making Change
• Colored hills
• Word Statistics
• Going to the Movies
• A to the power of B
• Connected components
• Binary transformations
• Fleas
• Babel tower
• Pizza delivery

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 1000/1000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.

Problem description

There are N colored hills. Some of them are connected with bridges. We want to paint bridges to the same color with the hills they connect. But it is not always possible (when connected hills have different colors). Calculate number of bridges that can not be painted.

Input

There is a single integer on the first line of input N (1 <= N <= 100), then N lines with N integers (0 - no brige, 1 - connected with bridge, adjacency matrix of graph). In the last line there are N integers from 1 to 3 - colors of hills.

Output

Write number of bridges that can not be painted.

Example

stdin stdout

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

Для отправки решений необходимо выполнить вход.

www.contester.ru