#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[210000];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = n * (n + 1) / 2;
  long long lidx[n];
  long long ridx[n];
  for (int i = 0; i < n; i++) {
    lidx[i] = 0;
    ridx[i] = n - 1;
  }
  map<long long, long long> nextval;
  for (int i = 0; i < n; i++) {
    if (nextval.find(a[i]) != nextval.end())
      lidx[i] = max(lidx[i], nextval[a[i]] + 1);
    nextval[a[i]] = i;
  }
  for (long long c = 0; c < 33; c++) {
    long long d = (1LL << c);
    long long last1 = -1;
    for (int i = 0; i < n; i++) {
      if (a[i] & d) {
        last1 = i;
        continue;
      }
      lidx[i] = max(lidx[i], last1 + 1);
    }
  }
  for (long long c = 0; c < 33; c++) {
    long long d = (1LL << c);
    long long last1 = n;
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] & d) {
        last1 = i;
        continue;
      }
      ridx[i] = min(ridx[i], last1 - 1);
    }
  }
  for (long long i = 0; i < n; i++) {
    ans -= (i - lidx[i] + 1) * (ridx[i] - i + 1);
  }
  cout << ans << endl;
}
