#include <bits/stdc++.h>
using namespace std;
inline void gtmx(int &a, int b) {
  if (a < b) a = b;
}
inline void gtmn(int &a, int b) {
  if (a > b) a = b;
}
int a[200010];
int l[200010], r[200010];
int lst[33];
map<int, int> mp;
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  memset(lst, 255, sizeof(lst));
  long long res = 1ll * n * (n - 1);
  res >>= 1;
  for (int i = 1; i <= n; ++i) {
    int mx = -1;
    if (mp.find(a[i]) != mp.end()) {
      mx = mp[a[i]];
    }
    mp[a[i]] = i;
    for (int j = 30; ~j; --j) {
      if (a[i] & (1 << j)) {
        lst[j] = i;
      } else {
        gtmx(mx, lst[j]);
      }
    }
    l[i] = (~mx) ? i - mx : i;
  }
  memset(lst, 63, sizeof(lst));
  for (int i = n; i; --i) {
    int mn = n + 1;
    for (int j = 30; ~j; --j) {
      if (a[i] & (1 << j)) {
        lst[j] = i;
      } else {
        gtmn(mn, lst[j]);
      }
    }
    r[i] = (mn <= n) ? mn - i : n - i + 1;
  }
  for (int i = 1; i <= n; ++i) {
    res -= 1ll * l[i] * r[i] - 1;
  }
  printf("%I64d", res);
  return 0;
}
