F. What a Colorful Wall
time limit per test
3.0 с
memory limit per test
1024 megabytes
input
standard input
output
standard output
Examples
Input
3
1 6 3 3 1
3 4 6 1 2
2 5 5 2 1
Output
2
Input
3
2 3 3 2 3
1 4 4 1 1
5 4 6 3 2
Output
2
Input
3
0 1 2 0 1
0 1 1 0 2
2 1 3 0 2
Output
2