#include #include using namespace std; using i32 = int; using i64 = long long; using i128 = __int128_t; using f64 = double; using p2 = pair; using p3 = tuple; using mint = atcoder::modint998244353; constexpr i64 inf = 1e18; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(18); _main(); } void _main() { i64 n; cin >> n; vector a(n); for (i64 i = 0; i < n; i++) { cin >> a[i]; } vector cnt(30, 0); vector ok(n, true); vector> g(n); i64 ans = 0; for (i64 k = cnt.size() - 1; k >= 0; k--) { if (k % 2 == 1) { for (i64 i = 0; i < n; i++) { if (!ok[i]) continue; if (a[i] >> k & 1) { cnt[k]++; g[i].push_back(k); } } if (cnt[k] > 0) ans |= 1 << k; } else { vector ncnt = cnt; bool f = false; for (i64 i = 0; i < n; i++) { if (!ok[i]) continue; if (a[i] >> k & 1) { f = true; continue; } for (i64 x : g[i]) ncnt[x]--; } for (i64 i = 0; i < cnt.size(); i++) if (cnt[i] > 0 && ncnt[i] == 0) f = false; if (!f) continue; for (i64 i = 0; i < n; i++) { if (!ok[i]) continue; if (a[i] >> k & 1) continue; ok[i] = false; for (i64 x : g[i]) cnt[x]--; } ans |= 1 << k; } } cout << ans << "\n"; }