#include <bits/stdc++.h>
const double Pi = acos(-1.0);
using namespace std;
const int maxN = 200005;
long long n;
int a[maxN];
long long l[maxN], r[maxN];
int main(int argc, char** argv) {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    r[i] = n + 1;
  }
  vector<int> pre;
  for (int i = 1; i <= n; i++) {
    while (pre.size() && a[pre.back()] < a[i]) pre.pop_back();
    if (pre.size()) l[i] = pre.back();
    pre.push_back(i);
  }
  long long last;
  for (int i = 0; i <= 30; i++) {
    last = 0;
    for (int j = 1; j <= n; j++) {
      if ((a[j] >> i) & 1)
        last = j;
      else
        l[j] = max(l[j], last);
    }
    last = n + 1;
    for (int j = n; j; j--) {
      if ((a[j] >> i) & 1)
        last = j;
      else
        r[j] = min(r[j], last);
    }
  }
  long long ans = n * (n + 1) / 2;
  for (int i = 1; i <= n; i++) ans -= (i - l[i]) * (r[i] - i);
  printf("%lld", ans);
  return 0;
}
