#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n;
const int N = 2e5 + 7;
int a[N], q[N], L[N], R[N];
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  int top = 0;
  for (int i = 1; i <= n; i++) {
    while (top && ((a[q[top]] | a[i]) == a[i]) && a[q[top]] != a[i]) top--;
    if (top)
      L[i] = q[top] + 1;
    else
      L[i] = 1;
    q[++top] = i;
  }
  top = 0;
  for (int i = n; i >= 1; i--) {
    while (top && ((a[q[top]] | a[i]) == a[i])) top--;
    if (top)
      R[i] = q[top] - 1;
    else
      R[i] = n;
    q[++top] = i;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    ans += 1ll * (i - L[i]) * (1ll * (R[i] - i)) + R[i] - L[i];
  printf("%I64d\n", 1ll * (1ll * n * (n - 1)) / 2 - ans);
  return 0;
}
