#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
const int maxn = 200010;
int n, A[maxn];
int pre[31][maxn], nxt[31][maxn], mx[20][maxn], Log[maxn];
void init() {
  for (int j = 0; j <= 30; j++) {
    int p = 0;
    for (int i = 1; i <= n; i++) {
      pre[j][i] = p;
      if (A[i] >> j & 1) p = i;
    }
    p = n + 1;
    for (int i = n; i >= 1; i--) {
      nxt[j][i] = p;
      if (A[i] >> j & 1) p = i;
    }
  }
  Log[0] = -1;
  for (int i = 1; i <= n; i++) Log[i] = Log[i >> 1] + 1;
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      mx[j][i] = max(mx[j - 1][i], mx[j - 1][i + (1 << j - 1)]);
}
int query(int l, int r) {
  int k = Log[r - l + 1];
  return max(mx[k][l], mx[k][r - (1 << k) + 1]);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) A[i] = mx[0][i] = read();
  init();
  long long ans = 0;
  for (int x = 1; x <= n; x++) {
    ans += x;
    int l = 1, r = x, ql, qr;
    while (l < r) {
      int mid = l + r >> 1;
      if (query(mid, x - 1) < A[x])
        r = mid;
      else
        l = mid + 1;
    }
    ql = l;
    l = x;
    r = n + 1;
    while (l + 1 < r) {
      int mid = l + r >> 1;
      if (query(x, mid) == A[x])
        l = mid;
      else
        r = mid;
    }
    qr = l;
    int l2 = 0, r2 = n + 1;
    for (int j = 0; j <= 30; j++)
      if (!(A[x] >> j & 1)) {
        l2 = max(l2, pre[j][x] + 1);
        r2 = min(r2, nxt[j][x] - 1);
      }
    ql = max(ql, l2);
    qr = min(qr, r2);
    ans -= (long long)(x - ql + 1) * (qr - x + 1);
  }
  printf("%I64d\n", ans);
  return 0;
}
