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