#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; 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()); a.erase(unique(a.begin(), a.end()), a.end()); N = a.size(); vector> b(N); for (ll i = 0; i < N; i++) { b[i].first = a[i]; b[i].second = i; } 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; } } ll mini = INF; for (ll i = 0; i < N; i++) { ll suff = 0; ll maximum = 0; auto lower = b.begin(); auto upper = b.end(); for (ll d = max_digits - 1; d >= 0; d--) { const ll inf = suff; const ll sup = suff + (1LL << (d + 1)) - 1; upper = upper_bound(lower, upper, make_pair(sup, INF)); lower = lower_bound(lower, upper, make_pair(inf, 0)); if (upper - lower == 1) { break; } const bool first = digit[lower->second][d]; bool same = true; for (auto it = lower + 1; it != upper; it++) { if (first != digit[it->second][d]) { same = false; break; } } if (not same) { maximum += 1LL << d; } suff += (ll)(digit[i][d]) << d; } mini = min(mini, maximum); } cout << mini << endl; return 0; }