#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50, LOGN = 21;
map<int, int> pos;
int n, a[N], o[N][LOGN], lg[N];
long long ans;
int que(int a, int b) {
  int j = lg[b - a + 1];
  return o[a][j] | o[b - (1 << j) + 1][j];
}
int main(int argc, char *argv[]) {
  int i, j, l, r, vl, vr, mid;
  scanf("%d", &n);
  ans = 1ll * n * (n - 1) / 2;
  for (i = 1; i <= n; ++i) scanf("%d", a + i);
  for (lg[0] = -1, i = 1; i <= n; ++i) lg[i] = lg[i >> 1] + 1;
  for (int i = 0; i <= n; ++i)
    ;
  for (j = 0; (1 << j) <= n; ++j) {
    for (i = 1; i + (1 << j) - 1 <= n; ++i) {
      if (j)
        o[i][j] = o[i][j - 1] | o[i + (1 << (j - 1))][j - 1];
      else
        o[i][j] = a[i];
    }
  }
  for (i = 1; i <= n; ++i) {
    l = 0, r = i;
    while (r - l > 1) {
      mid = (l + r) >> 1;
      if (que(mid, i) == a[i])
        r = mid;
      else
        l = mid;
    }
    vl = r;
    l = i, r = n + 1;
    while (r - l > 1) {
      mid = (l + r) >> 1;
      if (que(i, mid) == a[i])
        l = mid;
      else
        r = mid;
    }
    vr = l;
    vl = max(vl, pos[a[i]] + 1);
    ;
    ans -= 1ll * (vr - i) * (i - vl) + i - vl + vr - i;
    ;
    pos[a[i]] = i;
  }
  printf("%lld\n", ans);
  return 0;
}
