#include <bits/stdc++.h>
using namespace std;
int n, m, mid, mac[200005], ys1[200005];
int x[200005], vnt[200005], tot;
long long full[35], mi[36], q;
struct sd {
  int a, b;
  bool operator<(sd const &e) const { return a < e.a; };
} does[200005];
char h;
inline void add(int r, int pos) {
  if (pos <= 0) return;
  for (int i = pos; i <= tot; i += (-i) & i) vnt[i] += r;
}
int query(int pos) {
  int h = 0;
  for (int i = pos; i > 0; i -= i & (-i)) h += vnt[i];
  return h + 1;
}
int find(long long k) {
  int l = 0, r = tot, mid;
  if (ys1[tot] < k) return tot;
  while (l < r) {
    mid = l + r >> 1;
    if (ys1[mid] == k) return mid;
    if (ys1[mid] < k)
      l = mid + 1;
    else
      r = mid;
  }
  return l;
}
int main() {
  mi[0] = 1;
  mi[1] = 2;
  for (int i = 2; i <= 34; i++) mi[i] = mi[i - 1] * 2;
  for (int i = 1; i <= 34; i++) {
    full[i] = mi[i] - 1;
  }
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    getchar();
    h = getchar();
    switch (h) {
      case '+':
        mac[i] = 1;
        break;
      case '-':
        mac[i] = 2;
        break;
      case '?':
        mac[i] = 3;
    }
    scanf("%d", &does[i].a);
    does[i].b = i;
  }
  sort(does + 1, does + n + 1);
  int pre = 0, po1, po2;
  for (int i = 1; i <= n; i++) {
    if (does[i].a != pre) tot++;
    ys1[tot] = does[i].a;
    pre = does[i].a;
    x[does[i].b] = tot;
  }
  vnt[0] = 1;
  for (int i = 1; i <= n; i++) {
    if (mac[i] == 1) add(1, x[i]);
    if (mac[i] == 2) add(-1, x[i]);
    if (mac[i] == 3) {
      long long k = 0, num;
      for (int j = 32; j >= 0; j--) {
        q = k | mi[j];
        q--;
        q |= mi[j];
        if (query(find(q)) == 1) break;
        int s = ys1[x[i]] & mi[j];
        if (s > 0) {
          q = k | mi[j];
          q--;
        } else {
          k |= mi[j];
          q = k - 1;
          q |= mi[j];
        }
        po1 = find(q);
        if (ys1[po1] > q) po1--;
        po2 = find(k - 1);
        if (ys1[po2] > k - 1) po2--;
        num = query(po1) - query(po2);
        if (num <= 0) {
          if (s) {
            if (k == 0) break;
            k = q + 1;
          } else
            k = k & (full[34] ^ full[j + 1]);
        }
      }
      printf("%I64d\n", k ^ ys1[x[i]]);
    }
  }
  return 0;
}

### Prompt

Please formulate 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>
using namespace std;
int n, m, mid, mac[200005], ys1[200005];
int x[200005], vnt[200005], tot;
long long full[35], mi[36], q;
struct sd {
  int a, b;
  bool operator<(sd const &e) const { return a < e.a; };
} does[200005];
char h;
inline void add(int r, int pos) {
  if (pos <= 0) return;
  for (int i = pos; i <= tot; i += (-i) & i) vnt[i] += r;
}
int query(int pos) {
  int h = 0;
  for (int i = pos; i > 0; i -= i & (-i)) h += vnt[i];
  return h + 1;
}
int find(long long k) {
  int l = 0, r = tot, mid;
  if (ys1[tot] < k) return tot;
  while (l < r) {
    mid = l + r >> 1;
    if (ys1[mid] == k) return mid;
    if (ys1[mid] < k)
      l = mid + 1;
    else
      r = mid;
  }
  return l;
}
int main() {
  mi[0] = 1;
  mi[1] = 2;
  for (int i = 2; i <= 34; i++) mi[i] = mi[i - 1] * 2;
  for (int i = 1; i <= 34; i++) {
    full[i] = mi[i] - 1;
  }
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    getchar();
    h = getchar();
    switch (h) {
      case '+':
        mac[i] = 1;
        break;
      case '-':
        mac[i] = 2;
        break;
      case '?':
        mac[i] = 3;
    }
    scanf("%d", &does[i].a);
    does[i].b = i;
  }
  sort(does + 1, does + n + 1);
  int pre = 0, po1, po2;
  for (int i = 1; i <= n; i++) {
    if (does[i].a != pre) tot++;
    ys1[tot] = does[i].a;
    pre = does[i].a;
    x[does[i].b] = tot;
  }
  vnt[0] = 1;
  for (int i = 1; i <= n; i++) {
    if (mac[i] == 1) add(1, x[i]);
    if (mac[i] == 2) add(-1, x[i]);
    if (mac[i] == 3) {
      long long k = 0, num;
      for (int j = 32; j >= 0; j--) {
        q = k | mi[j];
        q--;
        q |= mi[j];
        if (query(find(q)) == 1) break;
        int s = ys1[x[i]] & mi[j];
        if (s > 0) {
          q = k | mi[j];
          q--;
        } else {
          k |= mi[j];
          q = k - 1;
          q |= mi[j];
        }
        po1 = find(q);
        if (ys1[po1] > q) po1--;
        po2 = find(k - 1);
        if (ys1[po2] > k - 1) po2--;
        num = query(po1) - query(po2);
        if (num <= 0) {
          if (s) {
            if (k == 0) break;
            k = q + 1;
          } else
            k = k & (full[34] ^ full[j + 1]);
        }
      }
      printf("%I64d\n", k ^ ys1[x[i]]);
    }
  }
  return 0;
}

```