#include using namespace std; using ll = long long; // http://drken1215.hatenablog.com/entry/2019/03/20/202800 const int MAX_ROW = 17; // to be set appropriately const int MAX_COL = 100000; // to be set appropriately struct BitMatrix { int H, W; bitset val[MAX_ROW]; BitMatrix(int m = 1, int n = 1) : H(m), W(n) {} inline bitset& operator [] (int i) {return val[i];} }; int GaussJordan(BitMatrix &A, vector& ids, bool is_extended = false) { int rank = 0; for (int col = 0; col < A.W; ++col) { if (is_extended && col == A.W - 1) break; int pivot = -1; for (int row = rank; row < A.H; ++row) { if (A[row][col]) { pivot = row; break; } } if (pivot == -1) continue; ids.push_back(col); swap(A[pivot], A[rank]); for (int row = 0; row < A.H; ++row) { if (row != rank && A[row][col]) A[row] ^= A[rank]; } ++rank; } return rank; } constexpr ll MAXV = 100000; ll cnt[3 * MAXV + 1]; bool ok[3 * MAXV + 1]; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector a(n); BitMatrix A(MAX_ROW, n); ll sum = 0; ll maxa = 0; for (int i = 0; i < n; i++) { cin >> a[i]; maxa = max(maxa, a[i]); cnt[a[i]] += a[i]; sum += a[i]; for (int j = 0; j < MAX_ROW; j++) { if (a[i] & (1 << j)) A[j].set(i); } } for (int i = 1; i <= maxa; i++) { for (int j = i; (j += i) <= maxa; ) { cnt[i] += cnt[j]; } } vector ids; int rank = GaussJordan(A, ids); assert(ids.size() == rank); for (int i = 1; i < (1 << rank); i++) { ll val = 0; for (int j = 0; j < rank; j++) { if (i & (1 << j)) val ^= a[j]; } ok[val] = true; } ll ans = sum; for (int i = 1; i <= maxa; i++) { if (!ok[i]) continue; ans = min(ans, sum - cnt[i] + cnt[i] / i); } cout << ans << "\n"; return 0; }