Learning Dishes

hard
<a href="https://www.codechef.com/problems/UPDOTR">https://www.codechef.com/problems/UPDOTR</a>

Input Format

.

Output Format

.

Constraints

.

Notice

.

Example

Input
1
5
2 3 1 4 5
1 2 2 3
2
2 1
1 0
Output
2
1
Previous
Cats And Tree
Next
Longest Good Segment

Related Questions