#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int l[maxn], r[maxn], a[maxn], pos[40];
map<int, int> m;
int main() {
  int n;
  scanf("%d", &n);
  long long ans = (long long)n * (n + 1) / 2;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  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 i = 0; i <= 32; i++) pos[i] = n + 1;
  for (int i = 1; i <= n; i++) r[i] = n + 1;
  for (int i = n; i > 0; i--) {
    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;
      }
    }
    long long t = 1LL * (i - l[i]) * (r[i] - i);
    ans -= t;
  }
  printf("%I64d\n", ans);
  return 0;
}
