#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int N; vector idx[28]; void solve() { cin >> N; for(int i = 0;i < 28;i++) idx[i].push_back(-1); for(int i = 0;i < N;i++) { int A; cin >> A; for(int j = 0;j < 28;j++) if(A >> j & 1) idx[j].push_back(i); } for(int i = 0;i < 28;i++) idx[i].push_back(N); long long ans = 0,t = 1; for(int i = 0;i < 28;i++) { long long cur = (long long)N*(N+1)/2; for(int j = 0;j+1 < (int)idx[i].size();j++) { int len = idx[i][j+1]-idx[i][j]-1; cur -= (long long)len*(len+1)/2; } ans += t*cur; t <<= 1; } cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); //tanosimu int tt = 1; //cin >> tt; while(tt--) solve(); }