#include <bits/stdc++.h>   using namespace std;   int n, nxt[200010], a[200010], sz[200010][31];   long long ans = 0;   map<int, int> mp;   inline char gc() {     static char *S, *T, buf[1 << 16];     if (T == S) {       T = (S = buf) + fread(buf, 1, 1 << 16, stdin);       if (T == S) return EOF;     }     return *S++;   }   inline int read() {     int x = 0, f = 1;     char ch = gc();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = gc();     }     while ( 0  <= ch && ch <=  9 ) x = x * 10 + ch -  0 , ch = gc();     return x * f;   }   inline int check(int l, int r) {     int res = 0;     for (int i = 0; i <= 30; ++i) res |= ((sz[r][i] - sz[l - 1][i]) > 0) << i;     return res;   }   int main() {     n = read();     for (int i = 1; i <= n; ++i) {       a[i] = read(), nxt[i] = mp[a[i]], mp[a[i]] = i;       for (int j = 0; j <= 30; ++j) {         sz[i][j] = sz[i - 1][j];         if (a[i] & (1 << j)) sz[i][j]++;       }     }     for (int i = 1; i <= n; ++i) {       int l = max(nxt[i] + 1, 1), r = i, nowl = i;       while (l <= r) {         int mid = l + r >> 1;         if (check(mid, i) == a[i])           nowl = mid, r = mid - 1;         else           l = mid + 1;       }       l = i, r = n;       int nowr = i;       while (l <= r) {         int mid = l + r >> 1;         if (check(i, mid) == a[i])           nowr = mid, l = mid + 1;         else           r = mid - 1;       }       ans += 1ll * (i - nowl + 1) * (nowr - i + 1);     }     printf( %I64d n , 1ll * n * (n + 1) / 2 - ans);     return 0;   }   