Problem Z: 小恐龙从0开始的自闭ACM之旅

Problem Z: 小恐龙从0开始的自闭ACM之旅

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1  Solved: 1
[Submit] [Status] [Web Board] [Creator:]

Description

Input

Output

Sample Input Copy

8
1 4 2 3 0 1 0 7
5
2 4 8
2 6 8
1 1 0
2 1 5
2 1 8

Sample Output Copy

2
-1
4
2

HINT