//#define _GLIBCXX_DEBUG #include "bits/stdc++.h" using namespace std; //------------------------------- Type Names -------------------------------// using i64 = int_fast64_t; using seika = string; //{akari : 1D, yukari : 2D, maki : 3D} vector template using akari = vector; template using yukari = akari>; template using maki = akari>; //{akane : ascending order, aoi : decending order} priority queue template using akane = priority_queue, greater>; template using aoi = priority_queue; //------------------------------- Libraries --------------------------------// //------------------------------- Dubug Functions ---------------------------// inline void print() { cout << endl; } template void print(const First &first, const Rest &... rest) { cout << first << ' '; print(rest...); } //------------------------------- Solver ------------------------------------// void solve() { int n; cin >> n; akari as(n), bs; for (int i = 0; i < n; i++) { cin >> as[i]; } bs = as; for (int d = 0; d < 20; d++) { int p = -1; for (int i = 0; i < n; i++) { if (as[i] >> d & 1) { p = i; break; } } if (p == -1) { continue; } if (p) { swap(as[p], as[0]); } for (int i = 0; i < n; i++) { if (i == p || !(as[i] >> d & 1)) { continue; } as[i] ^= as[p]; } } int lsb = -1; for (int d = 0; d < 20; d++) for (int i = 0; i < n; i++) { //cout << bitset<20>(as[i]) << endl; if (as[i] >> d & 1) { lsb = d; i = n; d = 20; } } //print(lsb); int mask = (1 << lsb) - 1; set fs; for (int i = 0; i < n; i++) { for (int f = 1; f * f <= bs[i]; f++) { if (bs[i] % f == 0) { fs.insert(f); if (f * f != bs[i]) { fs.insert(bs[i] / f); } } } } i64 ans = 1e15; for (int f : fs) { if (mask & f) { continue; } i64 res = 0; for (int i = 0; i < n; i++) { if (bs[i] % f == 0) { res += bs[i] / f; } else { res += bs[i]; } } ans = min(ans, res); } cout << ans << endl; } int main() { solve(); return 0; }