#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
using namespace std;
const long long SIZE = 1e5 + 4, S2 = 1e6 * 2, MOD = 1e9 + 7,
                INF = 1e9 * 1e9 * 2 + 100, P = 28;
multiset<long long> s;
long long curN = 0;
struct tree {
  tree* one = 0;
  tree* zer = 0;
  long long cnt = 0, amL = 0, amR = 0;
};
tree* rt = new tree();
tree* v;
void ins(int x, int add, int k = 34) {
  tree* pr;
  if ((1ll << k) & x) {
    if (!v->one) v->one = new tree();
    pr = v;
    v = v->one;
    x ^= (1ll << k);
  } else {
    if (!v->zer) v->zer = new tree();
    pr = v;
    v = v->zer;
  }
  if (k == 0) {
    v->cnt += add;
    v = pr;
    if (v->zer) v->amL = v->zer->cnt + v->zer->amL + v->zer->amR;
    if (v->one) v->amR = v->one->cnt + v->one->amL + v->one->amR;
    return;
  }
  ins(x, add, k - 1);
  v = pr;
  if (v->zer) v->amL = v->zer->cnt + v->zer->amL + v->zer->amR;
  if (v->one) v->amR = v->one->cnt + v->one->amL + v->one->amR;
}
void find(tree* v, int x, int k = 34) {
  long long wn = 1;
  if (k == -1) return;
  if ((1ll << k) & x) {
    wn = 0;
  }
  if (wn == 0 && v->zer && v->amL >= 1) {
    find(v->zer, x, k - 1);
  } else {
    if ((1ll << k) & x) x ^= (1ll << k);
    curN ^= (1ll << k);
    if (v->one && v->amR >= 1) {
      find(v->one, x, k - 1);
    } else {
      curN ^= (1ll << k);
      find(v->zer, x, k - 1);
    }
  }
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  ;
  long long q;
  cin >> q;
  v = rt;
  ins(0, 1);
  while (q--) {
    char type;
    int x;
    cin >> type >> x;
    if (type == '+') {
      s.insert(x);
      ins(x, 1);
      rt = v;
    }
    if (type == '-') {
      s.erase(s.find(x));
      ins(x, -1);
      rt = v;
    }
    if (type == '?') {
      curN = 0;
      find(rt, x);
      cout << (curN ^ x) << "\n";
    }
  }
  return 0;
}

### Prompt

Your challenge is to write a cpp solution to the following problem:

Author has gone out of the stories about Vasiliy, so here is just a formal task description.

You are given q queries and a multiset A, initially containing only integer 0. There are three types of queries:

  1. "+ x" — add integer x to multiset A.
  2. "- x" — erase one occurrence of integer x from multiset A. It's guaranteed that at least one x is present in the multiset A before this query.
  3. "? x" — you are given integer x and need to compute the value <image>, i.e. the maximum value of bitwise exclusive OR (also know as XOR) of integer x and some integer y from the multiset A.



Multiset is a set, where equal elements are allowed.

Input

The first line of the input contains a single integer q (1 ≤ q ≤ 200 000) — the number of queries Vasiliy has to perform.

Each of the following q lines of the input contains one of three characters '+', '-' or '?' and an integer xi (1 ≤ xi ≤ 109). It's guaranteed that there is at least one query of the third type.

Note, that the integer 0 will always be present in the set A.

Output

For each query of the type '?' print one integer — the maximum value of bitwise exclusive OR (XOR) of integer xi and some integer from the multiset A.

Example

Input

10
+ 8
+ 9
+ 11
+ 6
+ 1
? 3
- 8
? 3
? 8
? 11


Output

11
10
14
13

Note

After first five operations multiset A contains integers 0, 8, 9, 11, 6 and 1.

The answer for the sixth query is integer <image> — maximum among integers <image>, <image>, <image>, <image> and <image>.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
using namespace std;
const long long SIZE = 1e5 + 4, S2 = 1e6 * 2, MOD = 1e9 + 7,
                INF = 1e9 * 1e9 * 2 + 100, P = 28;
multiset<long long> s;
long long curN = 0;
struct tree {
  tree* one = 0;
  tree* zer = 0;
  long long cnt = 0, amL = 0, amR = 0;
};
tree* rt = new tree();
tree* v;
void ins(int x, int add, int k = 34) {
  tree* pr;
  if ((1ll << k) & x) {
    if (!v->one) v->one = new tree();
    pr = v;
    v = v->one;
    x ^= (1ll << k);
  } else {
    if (!v->zer) v->zer = new tree();
    pr = v;
    v = v->zer;
  }
  if (k == 0) {
    v->cnt += add;
    v = pr;
    if (v->zer) v->amL = v->zer->cnt + v->zer->amL + v->zer->amR;
    if (v->one) v->amR = v->one->cnt + v->one->amL + v->one->amR;
    return;
  }
  ins(x, add, k - 1);
  v = pr;
  if (v->zer) v->amL = v->zer->cnt + v->zer->amL + v->zer->amR;
  if (v->one) v->amR = v->one->cnt + v->one->amL + v->one->amR;
}
void find(tree* v, int x, int k = 34) {
  long long wn = 1;
  if (k == -1) return;
  if ((1ll << k) & x) {
    wn = 0;
  }
  if (wn == 0 && v->zer && v->amL >= 1) {
    find(v->zer, x, k - 1);
  } else {
    if ((1ll << k) & x) x ^= (1ll << k);
    curN ^= (1ll << k);
    if (v->one && v->amR >= 1) {
      find(v->one, x, k - 1);
    } else {
      curN ^= (1ll << k);
      find(v->zer, x, k - 1);
    }
  }
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  ;
  long long q;
  cin >> q;
  v = rt;
  ins(0, 1);
  while (q--) {
    char type;
    int x;
    cin >> type >> x;
    if (type == '+') {
      s.insert(x);
      ins(x, 1);
      rt = v;
    }
    if (type == '-') {
      s.erase(s.find(x));
      ins(x, -1);
      rt = v;
    }
    if (type == '?') {
      curN = 0;
      find(rt, x);
      cout << (curN ^ x) << "\n";
    }
  }
  return 0;
}

```