C. Maximum Query
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

In this problem, your task is to maintain a multiset $$$T$$$ whose elements are pairs $$$(v_i,w_i)$$$. Initially, $$$T$$$ is empty. You are required to perform $$$n$$$ operations, each of which is one of the following three types:

  • "+ v w" ($$$1\leq v\leq 500\,000$$$, $$$1\leq w\leq n$$$): Insert a pair $$$(v,w)$$$ into the multiset $$$T$$$.
  • "- v w" ($$$1\leq v\leq 500\,000$$$, $$$1\leq w\leq n$$$): Remove a pair $$$(v,w)$$$ from $$$T$$$. It is guaranteed that such a pair always exists. Note that $$$T$$$ is a multiset, when multiple pairs match $$$(v,w)$$$, just remove one pair.
  • "? k" ($$$1\leq k\leq 500\,000$$$): It is a query. You are required to find a pair $$$(v,w)$$$ from $$$T$$$ such that $$$\gcd(v,k)=1$$$ and $$$w$$$ is maximized. You need to report the value of $$$w$$$. When there is no finding, please report "-1" instead.
Input

There is only one test case in each test.

The test case starts with a line containing a single integer $$$n$$$ ($$$1 \leq n \leq 200\,000$$$), denoting the number of operations.

Each of the next $$$n$$$ lines describes an operation in the formats described in the statement above.

Output

For each query, print a single line containing a single integer, denoting the value of $$$w$$$ that you find, or "-1" if there is no finding.

Example
Input
6
+ 4 5
+ 3 4
? 2
? 3
- 3 4
? 4
Output
4
5
-1