#include // created [2019/11/29] 22:16:35 #pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-conversion" using i32 = int32_t; using i64 = int64_t; using u32 = uint32_t; using u64 = uint64_t; using uint = unsigned int; using usize = std::size_t; using ll = long long; using ull = unsigned long long; using ld = long double; template constexpr T popcount(const T u) { return u ? static_cast(__builtin_popcountll(static_cast(u))) : static_cast(0); } template constexpr T log2p1(const T u) { return u ? static_cast(64 - __builtin_clzll(static_cast(u))) : static_cast(0); } template constexpr T msbp1(const T u) { return log2p1(u); } template constexpr T lsbp1(const T u) { return __builtin_ffsll(u); } template constexpr T clog(const T u) { return u ? log2p1(u - 1) : static_cast(u); } template constexpr bool ispow2(const T u) { return u and (static_cast(u) & static_cast(u - 1)) == 0; } template constexpr T ceil2(const T u) { return static_cast(1) << clog(u); } template constexpr T floor2(const T u) { return u == 0 ? static_cast(0) : static_cast(1) << (log2p1(u) - 1); } template constexpr bool btest(const T mask, const usize ind) { return static_cast((static_cast(mask) >> ind) & static_cast(1)); } template void bset(T& mask, const usize ind) { mask |= (static_cast(1) << ind); } template void breset(T& mask, const usize ind) { mask &= ~(static_cast(1) << ind); } template void bflip(T& mask, const usize ind) { mask ^= (static_cast(1) << ind); } template void bset(T& mask, const usize ind, const bool b) { (b ? bset(mask, ind) : breset(mask, ind)); } template constexpr T bcut(const T mask, const usize ind) { return ind == 0 ? static_cast(0) : static_cast((static_cast(mask) << (64 - ind)) >> (64 - ind)); } template bool chmin(T& a, const T& b) { return (a > b ? a = b, true : false); } template bool chmax(T& a, const T& b) { return (a < b ? a = b, true : false); } constexpr unsigned int mod = 1000000007; template constexpr T inf_v = std::numeric_limits::max() / 4; template constexpr Real pi_v = Real{3.141592653589793238462643383279502884}; template T read() { T v; return std::cin >> v, v; } template auto read(const usize size, Args... args) { std::vector(args...))> ans(size); for (usize i = 0; i < size; i++) { ans[i] = read(args...); } return ans; } template auto reads() { return std::tuple...>{read()...}; } # define SHOW(...) static_cast(0) template std::vector make_v(const usize size, const T v) { return std::vector(size, v); } template auto make_v(const usize size, Args... args) { return std::vector(size, make_v(args...)); } template std::vector divisors(const T n) { std::vector head, tail; for (T i = 1; i * i <= n; i++) { if (n % i == 0) { head.push_back(i); if (i * i != n) { tail.push_back(n / i); } } } for (auto it = tail.rbegin(); it != tail.rend(); it++) { head.push_back(*it); } return head; } template class bit_matrix { public: bit_matrix(const usize row) : row{row}, table(row) {} bit_matrix(const bit_matrix& m) : row{m.row}, table{m.table} {} bit_matrix& operator=(const bit_matrix& m) { assert(row == m.row), assert(column == m.column); for (usize i = 0; i < row; i++) { table[i] = m[i]; } return *this; } const std::bitset& operator[](const usize r) const { return assert(r < row), table[r]; } std::bitset& operator[](const usize r) { return assert(r < row), table[r]; } friend bit_matrix operator+(const bit_matrix& m) { return m; } friend bit_matrix operator^(const bit_matrix& m1, const bit_matrix& m2) { assert(m1.row == m2.row); bit_matrix ans(m1.row); for (usize i = 0; i < m1.row; i++) { ans[i] = m1.table[i] ^ m2.table[i]; } return ans; } template friend bit_matrix operator*(const bit_matrix& m1, const bit_matrix& m2) { assert(column == m2.row); bit_matrix ans(m1.row); for (usize i = 0; i < m1.row; i++) { for (usize j = 0; j < column; j++) { if (not m1.table[i][j]) { continue; } ans[i] ^= m2.table[j]; } } return ans; } friend bit_matrix operator^(const bit_matrix& m, const unsigned long long n) { return assert(m.row == m.column), n == 0 ? bit_matrix::id(m.row) : n % 2 == 1 ? m*(m ^ (n - 1)) : ((m * m) ^ (n / 2)); } friend bit_matrix& operator^=(bit_matrix& m1, const bit_matrix& m2) { assert(m1.row == m2.row), assert(m1.column == m2.column); for (usize i = 0; i < m1.row; i++) { m1.table[i] ^= m2.table[i]; } return m1; } friend bit_matrix& operator*=(bit_matrix& m1, const bit_matrix& m2) { return m1 = m1 * m2; } friend bit_matrix& operator^=(bit_matrix& m, const unsigned long long n) { return m = m ^ n; } friend std::ostream& operator<<(std::ostream& os, const bit_matrix& m) { os << "[\n"; for (usize i = 0; i < m.row; i++) { os << "[" << m[i] << "]\n"; } return (os << "]\n"); } static bit_matrix id(const usize n) { bit_matrix ans(n); for (usize i = 0; i < n; i++) { ans[i].set(i); } return ans; } usize row; private: std::vector> table; }; template bit_matrix gauss_jordan(bit_matrix mat) { for (usize r = 0, ci = 0; ci < column; ci++) { const usize c = column - ci - 1; if (r == mat.row) { break; } usize piv = r; for (; piv < mat.row and not mat[piv][c]; piv++) {} if (piv == mat.row) { continue; } std::swap(mat[piv], mat[r]); for (usize j = 0; j < mat.row; j++) { if (j == r) { continue; } if (mat[j][c]) { mat[j] ^= mat[r]; } } r++; } return mat; } int main() { const int N = read(); const auto A = read(N); constexpr uint lg = 17; std::vector as; for (uint i = 0; i < N; i++) { for (uint a = A[i]; a <= 100000; a *= 2) { as.push_back(a); } } bit_matrix m(as.size()); for (int r = 0; r < as.size(); r++) { m[r] = as[r]; } const auto base = gauss_jordan(m); std::vector bs; for (int i = 0; i < as.size(); i++) { if (base[i].to_ullong() == 0) { break; } bs.push_back(base[i].to_ulong()); } // SHOW(bs); const int bn = bs.size(); std::set ok; const int mask = 1 << bn; for (int m = 0; m < mask; m++) { uint a = 0; for (int i = 0; i < bn; i++) { if (not btest(m, i)) { continue; } a ^= bs[i]; } if (a <= 100000) { ok.insert(a); } } // SHOW(ok); std::vector S(100001, 0); for (int i = 0; i < N; i++) { S[A[i]] += A[i]; } std::vector minus(100001, 0); for (const int i : ok) { if (i == 0) { continue; } for (int j = i; j < 100000; j += i) { minus[i] += S[j] - S[j] / i; } } const ll sum = std::accumulate(A.begin(), A.end(), 0LL); std::cout << sum - *std::max_element(minus.begin(), minus.end()) << std::endl; return 0; }