#include <bits/stdc++.h>
using namespace std;
void addwedge(vector<pair<long long int, long long int>> adj[], long long int u,
              long long int v, long long int wt) {
  adj[u].push_back(make_pair(v, wt));
  adj[v].push_back(make_pair(u, wt));
}
void addedge(vector<long long int> adj[], long long int u, long long int v) {
  adj[u].push_back(v);
  adj[v].push_back(u);
}
vector<long long int> shortestpath(
    vector<pair<long long int, long long int>> adj[], long long int V,
    long long int src) {
  priority_queue<pair<long long int, long long int>,
                 vector<pair<long long int, long long int>>,
                 greater<pair<long long int, long long int>>>
      pq;
  vector<long long int> dist(V, 9e+18);
  pq.push(make_pair(0, src));
  dist[src] = 0;
  while (!pq.empty()) {
    long long int u = pq.top().second;
    pq.pop();
    for (auto x : adj[u]) {
      long long int v = x.first;
      long long int weight = x.second;
      if (dist[v] > dist[u] + weight) {
        dist[v] = dist[u] + weight;
        pq.push(make_pair(dist[v], v));
      }
    }
  }
  return dist;
}
void buildsegment(long long int arr[], long long int tree[], long long int n) {
  for (long long int i = 0; i < n; i++) tree[n + i] = arr[i];
  for (long long int i = n - 1; i > 0; --i)
    tree[i] = tree[i << 1] + tree[i << 1 | 1];
}
void updatesegment(long long int p, long long int value, long long int tree[],
                   long long int n) {
  tree[p + n] = value;
  p = p + n;
  for (long long int i = p; i > 1; i >>= 1)
    tree[i >> 1] = tree[i] + tree[i ^ 1];
}
long long int querysegment(long long int l, long long int r,
                           long long int tree[], long long int n) {
  long long int res = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) res += tree[l++];
    if (r & 1) res += tree[--r];
  }
  return res;
}
long long int findpar(long long int numb, long long int par[]) {
  if (par[numb] == numb)
    return numb;
  else
    return par[numb] = findpar(par[numb], par);
}
void setpar(long long int u1, long long int v1, long long int par[]) {
  long long int s1 = findpar(v1, par);
  long long int s2 = findpar(u1, par);
  if (s1 < s2) {
    par[s2] = s1;
  } else {
    par[s1] = s2;
  }
}
long long int extended_GCD(long long int a, long long int b, long long int &x,
                           long long int &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long int x1, y1;
  long long int gcd = extended_GCD(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return gcd;
}
long long int modinv(long long int a, long long int mod = 1000000007) {
  long long int x, y;
  extended_GCD(a, mod, x, y);
  if (x < 0) x += mod;
  return x;
}
long long int power(long long int a, long long int b,
                    long long int m = 1000000007) {
  a %= m;
  long long int ans = 1;
  while (b > 0) {
    if (b & 1) ans = ans * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return ans;
}
vector<long long int> nge(long long int arr[], long long int n) {
  stack<long long int> s;
  vector<long long int> ans(n, -1);
  s.push(0);
  for (long long int i = 1; i < n; i++) {
    if (s.empty()) {
      s.push(i);
      continue;
    }
    while (s.empty() == false && arr[s.top()] < arr[i]) {
      ans[s.top()] = i;
      s.pop();
    }
    s.push(arr[i]);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t, n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int f[32] = {0};
  for (long long int i = 0; i < n; i++) {
    long long int dum = a[i];
    long long int ind = 0;
    while (dum > 0) {
      long long int rem = dum % 2;
      dum /= 2;
      if (rem == 1) f[ind]++;
      ind++;
    }
  }
  long long int ansi = -1;
  for (long long int i = 31; i >= 0; i--) {
    if (f[i] == 1) {
      ansi = i;
      break;
    }
  }
  if (ansi != -1) {
    long long int ovb = 0;
    for (long long int i = 0; i < n; i++) {
      long long int dum = a[i];
      long long int ind = 0;
      while (dum > 0) {
        long long int rem = dum % 2;
        dum /= 2;
        if (rem == 1 && ansi == ind) {
          ansi = i;
          ovb = 1;
          break;
        }
        ind++;
      }
      if (ovb == 1) break;
    }
    cout << a[ansi] << " ";
    for (long long int i = 0; i < n; i++) {
      if (i != ansi) cout << a[i] << " ";
    }
    cout << endl;
  } else {
    for (long long int i = 0; i < n; i++) {
      cout << a[i] << " ";
    }
    cout << endl;
  }
  return 0;
}

### Prompt

Please formulate a Cpp solution to the following problem:

Anu has created her own function f: f(x, y) = (x | y) - y where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR). For example, f(11, 6) = (11|6) - 6 = 15 - 6 = 9. It can be proved that for any nonnegative numbers x and y value of f(x, y) is also nonnegative. 

She would like to research more about this function and has created multiple problems for herself. But she isn't able to solve all of them and needs your help. Here is one of these problems.

A value of an array [a_1, a_2, ..., a_n] is defined as f(f(... f(f(a_1, a_2), a_3), ... a_{n-1}), a_n) (see notes). You are given an array with not necessarily distinct elements. How should you reorder its elements so that the value of the array is maximal possible?

Input

The first line contains a single integer n (1 ≤ n ≤ 10^5).

The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 10^9). Elements of the array are not guaranteed to be different.

Output

Output n integers, the reordering of the array with maximum value. If there are multiple answers, print any.

Examples

Input


4
4 0 11 6


Output


11 6 4 0

Input


1
13


Output


13 

Note

In the first testcase, value of the array [11, 6, 4, 0] is f(f(f(11, 6), 4), 0) = f(f(9, 4), 0) = f(9, 0) = 9.

[11, 4, 0, 6] is also a valid answer.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
void addwedge(vector<pair<long long int, long long int>> adj[], long long int u,
              long long int v, long long int wt) {
  adj[u].push_back(make_pair(v, wt));
  adj[v].push_back(make_pair(u, wt));
}
void addedge(vector<long long int> adj[], long long int u, long long int v) {
  adj[u].push_back(v);
  adj[v].push_back(u);
}
vector<long long int> shortestpath(
    vector<pair<long long int, long long int>> adj[], long long int V,
    long long int src) {
  priority_queue<pair<long long int, long long int>,
                 vector<pair<long long int, long long int>>,
                 greater<pair<long long int, long long int>>>
      pq;
  vector<long long int> dist(V, 9e+18);
  pq.push(make_pair(0, src));
  dist[src] = 0;
  while (!pq.empty()) {
    long long int u = pq.top().second;
    pq.pop();
    for (auto x : adj[u]) {
      long long int v = x.first;
      long long int weight = x.second;
      if (dist[v] > dist[u] + weight) {
        dist[v] = dist[u] + weight;
        pq.push(make_pair(dist[v], v));
      }
    }
  }
  return dist;
}
void buildsegment(long long int arr[], long long int tree[], long long int n) {
  for (long long int i = 0; i < n; i++) tree[n + i] = arr[i];
  for (long long int i = n - 1; i > 0; --i)
    tree[i] = tree[i << 1] + tree[i << 1 | 1];
}
void updatesegment(long long int p, long long int value, long long int tree[],
                   long long int n) {
  tree[p + n] = value;
  p = p + n;
  for (long long int i = p; i > 1; i >>= 1)
    tree[i >> 1] = tree[i] + tree[i ^ 1];
}
long long int querysegment(long long int l, long long int r,
                           long long int tree[], long long int n) {
  long long int res = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1) res += tree[l++];
    if (r & 1) res += tree[--r];
  }
  return res;
}
long long int findpar(long long int numb, long long int par[]) {
  if (par[numb] == numb)
    return numb;
  else
    return par[numb] = findpar(par[numb], par);
}
void setpar(long long int u1, long long int v1, long long int par[]) {
  long long int s1 = findpar(v1, par);
  long long int s2 = findpar(u1, par);
  if (s1 < s2) {
    par[s2] = s1;
  } else {
    par[s1] = s2;
  }
}
long long int extended_GCD(long long int a, long long int b, long long int &x,
                           long long int &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long int x1, y1;
  long long int gcd = extended_GCD(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return gcd;
}
long long int modinv(long long int a, long long int mod = 1000000007) {
  long long int x, y;
  extended_GCD(a, mod, x, y);
  if (x < 0) x += mod;
  return x;
}
long long int power(long long int a, long long int b,
                    long long int m = 1000000007) {
  a %= m;
  long long int ans = 1;
  while (b > 0) {
    if (b & 1) ans = ans * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return ans;
}
vector<long long int> nge(long long int arr[], long long int n) {
  stack<long long int> s;
  vector<long long int> ans(n, -1);
  s.push(0);
  for (long long int i = 1; i < n; i++) {
    if (s.empty()) {
      s.push(i);
      continue;
    }
    while (s.empty() == false && arr[s.top()] < arr[i]) {
      ans[s.top()] = i;
      s.pop();
    }
    s.push(arr[i]);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t, n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int f[32] = {0};
  for (long long int i = 0; i < n; i++) {
    long long int dum = a[i];
    long long int ind = 0;
    while (dum > 0) {
      long long int rem = dum % 2;
      dum /= 2;
      if (rem == 1) f[ind]++;
      ind++;
    }
  }
  long long int ansi = -1;
  for (long long int i = 31; i >= 0; i--) {
    if (f[i] == 1) {
      ansi = i;
      break;
    }
  }
  if (ansi != -1) {
    long long int ovb = 0;
    for (long long int i = 0; i < n; i++) {
      long long int dum = a[i];
      long long int ind = 0;
      while (dum > 0) {
        long long int rem = dum % 2;
        dum /= 2;
        if (rem == 1 && ansi == ind) {
          ansi = i;
          ovb = 1;
          break;
        }
        ind++;
      }
      if (ovb == 1) break;
    }
    cout << a[ansi] << " ";
    for (long long int i = 0; i < n; i++) {
      if (i != ansi) cout << a[i] << " ";
    }
    cout << endl;
  } else {
    for (long long int i = 0; i < n; i++) {
      cout << a[i] << " ";
    }
    cout << endl;
  }
  return 0;
}

```