#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, vector< vector >& v, bool is_extended = false) { int rank = 0; for (int i = 0; i < MAX_ROW; i++) v[i].push_back(i); 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; swap(A[pivot], A[rank]); swap(ids[pivot], ids[rank]); for (int row = 0; row < A.H; ++row) { if (row != rank && A[row][col]) { A[row] ^= A[rank]; for (int x : v[ids[rank]]) v[ids[row]].push_back(x); } } ++rank; } return rank; } constexpr ll MAXV = 100000; ll cnt[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(MAX_ROW); iota(ids.begin(), ids.end(), 0); vector< vector > v(MAX_ROW); int rank = GaussJordan(A, ids, v); ll ans = sum; for (int i = 1; i <= maxa; i++) { vector hoge(MAX_ROW, false); for (int j = 0; j < MAX_ROW; j++) { hoge[j] = ((i & (1 << j)) > 0); } bool f = true; for (int jj = rank; jj < MAX_ROW; jj++) { int j = ids[jj]; int val = 0; for (int k : v[j]) { val ^= hoge[k]; } if (val) { f = false; break; } } if (!f) continue; ans = min(ans, sum - cnt[i] + cnt[i] / i); } cout << ans << "\n"; return 0; }