#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10, logv = 35;
inline long long rd() {
  long long x = 0;
  char c = getchar();
  int neg = 1;
  while (c < '0' || c > '9') {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * neg;
}
int L[maxn], R[maxn], a[maxn], N;
int stk[maxn], sh;
int pre[logv][maxn], nxt[logv][maxn];
int main() {
  int i, j, k;
  N = rd();
  for (i = 1; i <= N; i++) a[i] = rd();
  for (i = 1; i <= N; i++) {
    for (j = 1, k = a[i]; j <= 30; j++, k >>= 1) {
      if (k & 1)
        pre[j][i] = i;
      else
        pre[j][i] = pre[j][i - 1];
    }
  }
  memset(nxt, 127, sizeof(nxt));
  for (i = N; i; i--) {
    for (j = 1, k = a[i]; j <= 30; j++, k >>= 1) {
      if (k & 1)
        nxt[j][i] = i;
      else
        nxt[j][i] = nxt[j][i + 1];
    }
  }
  for (i = 1; i <= N; i++) {
    while (sh && a[stk[sh]] <= a[i]) R[stk[sh--]] = i - 1;
    stk[++sh] = i;
  }
  while (sh) R[stk[sh--]] = N;
  for (i = N; i; i--) {
    while (sh && a[stk[sh]] < a[i]) L[stk[sh--]] = i + 1;
    stk[++sh] = i;
  }
  while (sh) L[stk[sh--]] = 1;
  long long ans = 1ll * N * (N + 1) / 2;
  for (i = 1; i <= N; i++) {
    int mi = N + 1, ma = 0;
    for (j = 1, k = a[i]; j <= 30; j++, k >>= 1) {
      if (!(k & 1)) mi = min(mi, nxt[j][i]), ma = max(ma, pre[j][i]);
    }
    ans -= 1ll * min(i - L[i] + 1, i - ma) * min(R[i] - i + 1, mi - i);
  }
  printf("%I64d\n", ans);
  return 0;
}
