#P979D. Kuro and GCD and XOR and SUM
Kuro and GCD and XOR and SUM
No submission language available for this problem.
Description
Kuro is currently playing an educational game about numbers. The game focuses on the greatest common divisor (GCD), the XOR value, and the sum of two numbers. Kuro loves the game so much that he solves levels by levels day by day.
Sadly, he's going on a vacation for a day, and he isn't able to continue his solving streak on his own. As Katie is a reliable person, Kuro kindly asked her to come to his house on this day to play the game for him.
Initally, there is an empty array . The game consists of tasks of two types. The first type asks Katie to add a number to . The second type asks Katie to find a number existing in such that , , and is maximized, where denotes the bitwise XOR operation, denotes the greatest common divisor of integers and , and means is divisible by , or report -1 if no such numbers are found.
Since you are a programmer, Katie needs you to automatically and accurately perform the tasks in the game to satisfy her dear friend Kuro. Let's help her!
The first line contains one integer () — the number of tasks the game wants you to perform.
lines follow, each line begins with an integer — the type of the task:
- If , an integer follow () — you have to add to the array .
- If , three integers , , and follow () — you must find a number existing in the array such that , , and is maximized, where denotes the XOR operation, or report -1 if no such numbers are found.
It is guaranteed that the type of the first task is type , and there exists at least one task of type .
For each task of type , output on one line the desired number , or -1 if no such numbers are found.
Input
The first line contains one integer () — the number of tasks the game wants you to perform.
lines follow, each line begins with an integer — the type of the task:
- If , an integer follow () — you have to add to the array .
- If , three integers , , and follow () — you must find a number existing in the array such that , , and is maximized, where denotes the XOR operation, or report -1 if no such numbers are found.
It is guaranteed that the type of the first task is type , and there exists at least one task of type .
Output
For each task of type , output on one line the desired number , or -1 if no such numbers are found.
Samples
Note
In the first example, there are 5 tasks:
- The first task requires you to add into . is now .
- The second task requires you to add into . is now .
- The third task asks you a question with , and . Taking both and as satisfies and . Because , is the answer to this task.
- The fourth task asks you a question with , and . Only satisfies and , so is the answer to this task.
- The fifth task asks you a question with , and . There are no elements in that satisfy the conditions, so we report -1 as the answer to this task.