#include <bits/stdc++.h>
using namespace std;
const long long N = 400010;
inline long long read() {
  long long s = 0, w = 1;
  register char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
  return s * w;
}
long long n, a[N], L[N], R[N], F[N], Ans;
map<long long, long long> Q;
signed main() {
  n = read();
  for (register long long i = 1; i <= n; i++) a[i] = read();
  for (register long long i = 1; i <= n; i++) {
    L[i] = Q[a[i]] + 1, Q[a[i]] = i;
    for (register long long j = 0; j <= 30; j++) {
      if ((a[i] >> j) & 1)
        F[j] = i;
      else
        L[i] = max(L[i], F[j] + 1);
    }
  }
  for (register long long i = 0; i <= 30; i++) F[i] = R[i] = n + 1;
  for (register long long i = n; i; i--) {
    R[i] = n + 1;
    for (register long long j = 0; j <= 30; j++) {
      if ((a[i] >> j) & 1)
        F[j] = i;
      else
        R[i] = min(R[i], F[j] - 1);
    }
  }
  for (register long long i = 1; i <= n; i++)
    Ans += (R[i] - i + 1) * (i - L[i] + 1);
  printf("%lld\n", max(n * (n + 1) / 2 - Ans, 0ll));
  return 0;
}
