#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * 1e5 + 10;
int a[maxn], l[maxn], r[maxn], pos[40];
map<int, int> M;
int main() {
  long long ans, n;
  scanf("%I64d", &n);
  ans = n * (n + 1) / 2;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  memset(pos, 0, sizeof(pos));
  for (int i = 1; i <= n; i++) {
    l[i] = M[a[i]];
    for (int j = 0; j < 32; j++) {
      if (!(a[i] & (1 << j))) l[i] = max(l[i], pos[j]);
    }
    for (int j = 0; j < 32; j++) {
      if (a[i] & (1 << j)) pos[j] = i;
    }
    M[a[i]] = i;
  }
  for (int j = 0; j < 32; j++) pos[j] = n + 1;
  for (int i = n; i > 0; i--) {
    r[i] = n + 1;
    for (int j = 0; j < 32; j++) {
      if (!(a[i] & (1 << j))) r[i] = min(r[i], pos[j]);
    }
    for (int j = 0; j < 32; j++) {
      if (a[i] & (1 << j)) pos[j] = i;
    }
    ans -= (long long)(i - l[i]) * (r[i] - i);
  }
  printf("%I64d", ans);
  return 0;
}
