You are given a length- sequence of nonnegative integers, a length- sequence , and a length- sequence . The indices of range from to , while the other sequences are indexed from to .
For a nonempty sequence , is the smallest nonnegative integer that does not occur in .
The score of an interval is defined as
You are given queries. For each query , find the maximum score among all intervals satisfying .
The input is given from Standard Input in the following format:
For each query, print the maximum score of a valid interval on its own line.
For the first query, interval has MEX and score .
| 3 | 59 | No additional constraints. |