#include #include #include using namespace std; typedef long long ll; int main(){ int n; cin >> n; vector v(n); for(int i = 0; i < n; i++) cin >> v[i]; ll ans = accumulate(v.begin(), v.end(), 0ll); vector d(100001); for(int i = 0; i < n; i++){ ll x = v[i]; for(ll i = 1; i*i <= x; i++){ if(x%i) continue; d[i] += x-x/i; if(i*i != x) d[x/i] += x-i; } } // ζŽƒγε‡Ίγ— int rank = 0; for(int i = 17; i >= 0; i--){ int j; for(j = rank; j < n; j++){ if((v[j]>>i)&1) break; } if(j == n) continue; swap(v[rank], v[j]); for(j = 0; j < n; j++){ if(j == rank) continue; if((v[j]>>i)&1) v[j] ^= v[rank]; } rank++; } ll sub = 0; for(int i = 1; i < 1<>j)&1) xo ^= v[j]; if(xo <= 100000) sub = max(sub, d[xo]); } cout << ans-sub << endl; return 0; }