Despite everything going on in the world, you must still attend online school. Alas, you find yourself in a Zoom call about PHE. Due to the obvious, you become bored and start to think about the upcoming classes in the day. Your next class is coding. Your teacher, Dr. Bruce, has an interesting way to keep students focused. He will generate values using his method way to determine which kids to call on.
Your class contains , people. He chooses a value by creating two arrays and of length . Then, he fills the arrays with his favourite positive integers in the range . From there, he generates an by grid such that .
After, he will determine who to call on using one of the following queries:
1 w
: Find the maximum element of column .
2 w
: Find the minimum element of column .
3 w
: Find the maximum element of row .
4 w
: Find the minimum element of row .
You will be given all these values and queries in the form above.
Input Specification
The first line of input will contain positive integer .
The second line of input will contain array of length with each element separated by a space.
The third line of input will contain array of length with each element separated by a space.
The fourth line of input will contain positive integer .
The next lines will contain a query in one of the four forms listed above.
Output Specification
On the line, output the answer to the query.
Constraints
Note that you will NOT be required to pass all the samples to receive points.
Subtask 1 [20%]
Subtask 2 [80%]
No additional constraints.
Sample Input
5
1 4 5 10 2
2 3 6 7 8
3
1 2
2 2
3 5
Sample Output
8
4
10
Explanation for Sample
The grid looks like this:
2 4 5 10 2
3 4 5 10 3
6 6 6 10 6
7 7 7 10 7
8 8 8 10 8
For the first query, the maximum element in column is . For the second query, the minimum element in column is . For the third and final query, the maximum element of row is .
Comments