#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
inline int ri() {
  int x = 0;
  bool f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = 0;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
  return f ? x : -x;
}
long long ans = 0;
int n;
int a[N];
int b[40], id[40];
int find(int l, int r, int mx, int val, int lim) {
  if ((val | b[r]) <= mx) return lim;
  int mid;
  while (l < r) {
    mid = (l + r) >> 1;
    if ((val | b[mid]) <= mx)
      l = mid + 1;
    else
      r = mid;
  }
  return id[l];
}
void cdq(int l, int r) {
  if (l == r) return;
  int mid = (l + r) >> 1, mx, val, j, tt;
  cdq(l, mid);
  cdq(mid + 1, r);
  mx = 0, val = 0, j = mid + 1, tt = 0;
  for (int i = (mid); i >= (l); --i) {
    mx = max(mx, a[i]);
    val |= a[i];
    for (; j <= r && a[j] <= mx; ++j) {
      if (tt > 0 && (b[tt] | a[j]) == b[tt]) continue;
      b[tt + 1] = b[tt] | a[j];
      id[++tt] = j;
    }
    if (tt > 0) ans += j - find(1, tt, mx, val, j);
  }
  mx = 0, val = 0, j = mid, tt = 0;
  for (int i = (mid + 1); i <= (r); ++i) {
    mx = max(mx, a[i]);
    val |= a[i];
    for (; j >= l && a[j] < mx; --j) {
      if (tt > 0 && (b[tt] | a[j]) == b[tt]) continue;
      b[tt + 1] = b[tt] | a[j];
      id[++tt] = j;
    }
    if (tt > 0) ans += find(1, tt, mx, val, j) - j;
  }
}
int main() {
  n = ri();
  for (int i = (1); i <= (n); ++i) a[i] = ri();
  cdq(1, n);
  printf("%I64d\n", ans);
  return 0;
}
