#include <bits/stdc++.h>   const long long MAX_N = 2e5 + 100;   const long long MOD = 1e9 + 7;   using namespace std;   long long rm[MAX_N][20];   long long a[MAX_N];   map<int, int> last;   long long ans;   const long long c = (1ll << 50) - 1;   long long ask(long long l, long long r) {     long long len = r - l + 1;     int lg = (int)log2(len);     long long s = r - (1 << lg) + 1;     return (rm[l][lg] | rm[s][lg]);   }   bool check(long long i, long long j) {     j ^= c;     if (j & i) return true;     return false;   }   int main() {     long long n;     cin >> n;     ans = n * (n + 1) / 2;     for (int i = 1; i <= n; ++i) cin >> a[i], last[a[i]] = 0;     for (int i = 1; i <= n; ++i) rm[i][0] = a[i];     for (int i = 1; i < 20; ++i) {       for (int j = 1; j <= n - (1 << i) + 1; ++j) {         rm[j][i] = rm[j][i - 1] | rm[j + (1 << (i - 1))][i - 1];       }     }     for (int i = 1; i <= n; ++i) {       long long l1 = i;       long long r1 = last[a[i]] + 1;       long long l2 = i;       long long r2 = n;       if (!check(ask(r1, i), a[i]))         l1 = r1;       else {         while (l1 - r1 > 1) {           long long mid = (l1 + r1) / 2;           if (!check(ask(mid, i), a[i]))             l1 = mid;           else             r1 = mid;         }       }       if (!check(ask(i, n), a[i]))         l2 = n;       else {         while (r2 - l2 > 1) {           long long mid = (l2 + r2) / 2;           if (!check(ask(i, mid), a[i]))             l2 = mid;           else             r2 = mid;         }       }       ans -= (i - l1 + 1) * (l2 - i + 1);       last[a[i]] = i;     }     cout << ans;     return 0;   }   