You are given an array of elements. Each element belongs to its own group initially.
You need to process the following two types of queries:
- The array elements which are at positions and in the array merge their group.
- Print the maximum absolute difference of the array values that belong to the group of element of the array.
Note: It is possible that the elements and in the query of type already be in the same group. You need to simply ignore that query.
Input
The first line contains an integer as input that denotes the total number of elements of the array. The next line contains space separated integers that denote the elements of that array.
The next line of input contains an integer that denotes the total number of queries.
The next lines contain description of each query.
The description of each query begins with an integer which is 1 for 1st type of queries and 2 for second type of queries.
Output
For each query of type , print the answer in a new line.
Constraints:
Subtask 1: 50 Points
Subtask 2: 50 Points
Query 1: 4th element is alone in group, So maximum absolute difference will be 0. ([5], [3], [2], [9]).
Query 2: 1st and 4th element will join to form a group. ([5, 9], [3], [2], [5, 9]).
Query 3: 4th element had formed a group with 1st element [5,9]. So maximum absolute difference will be 4 (as 9-5=4). ([5, 9], [3], [2], [5, 9])
Query 4: 3rd element is alone in group. So maximum absolute difference will be 0. ([5, 9], [3], [2], [5, 9]).