I. IT Nightmare
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output
Examples
Input
5
0 0 0 0 0
1 2
1 3
2 4
2 5
5
1 5 4
2 3
1 4 3
2 2
1 3 4
Output
0
1
1
4
4
1 1 0 1 1 
Input
3
0 0 0
1 2
1 3
4
2 2
1 1 2
1 2 3
2 1
Output
1
1
1
2
1 1 0 
Input
7
1 1 1 0 0 0 0
4 7
6 3
1 7
7 6
2 7
5 3
3
1 1 2
2 6
1 5 4
Output
3
4
4
0 1 0 1 0 1 1