#include #define show(x) cerr << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair; using vi = vector; template ostream& operator<<(ostream& os, const vector& v) { os << "sz:" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template ostream& operator<<(ostream& os, const pair& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = 1e9 + 7; template constexpr T INF = numeric_limits::max() / 100; ll rec(const vector& a, const vector>& digit, const ll x, const ll d, const ll l, const ll r) // suffix = x, bit = d, range = a[l]~a[r-1] { if (d < 0) { return 0; } if (l >= r - 1) { return 0; } const ll y = x + (1LL << d); // dth-bit of object = 1 const ll z = x; // dth-bit of object = 0 const ll yl = lower_bound(a.begin(), a.end(), y) - a.begin(); const ll yu = upper_bound(a.begin(), a.end(), y + (1LL << d) - 1) - a.begin(); const ll zl = lower_bound(a.begin(), a.end(), z) - a.begin(); const ll zu = upper_bound(a.begin(), a.end(), z + (1LL << d) - 1) - a.begin(); if (yu == yl) { return rec(a, digit, z, d - 1, zl, zu); } if (zu == zl) { return rec(a, digit, y, d - 1, yl, yu); } return (1LL << d) + min(rec(a, digit, y, d - 1, yl, yu), rec(a, digit, z, d - 1, zl, zu)); } int main() { ll N; cin >> N; vector a(N); ll max_digits = 0; for (ll i = 0; i < N; i++) { cin >> a[i]; max_digits = max(max_digits, (ll)log2(a[i] - 1) + 1); } max_digits++; sort(a.begin(), a.end()); vector> digit(N, vector(max_digits, false)); for (ll i = 0; i < N; i++) { ll num = a[i]; for (ll j = 0; j < max_digits; j++) { digit[i][j] = (bool)(num % 2); num /= 2; } } cout << rec(a, digit, 0, max_digits - 1, 0, N) << endl; return 0; }