#include <bits/stdc++.h>
using namespace std;
int64_t n, h[200005], L[200005], R[200005];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int64_t i = 1; i <= n; i++) cin >> h[i];
  for (int64_t i = 1; i <= n; i++) {
    L[i] = i;
    int64_t tmp = i - 1;
    while (tmp > 0 && (h[i] | h[tmp]) == h[i] && h[i] >= h[tmp]) {
      L[i] = L[tmp];
      tmp = L[tmp] - 1;
    }
  }
  for (int64_t i = n; i >= 1; i--) {
    R[i] = i;
    int64_t tmp = i + 1;
    while (tmp <= n && (h[i] | h[tmp]) == h[i] && h[i] > h[tmp]) {
      R[i] = R[tmp];
      tmp = R[tmp] + 1;
    }
  }
  int64_t res = n * (n - 1) / 2;
  for (int64_t i = 1; i <= n; i++) res -= (i - L[i] + 1) * (R[i] - i + 1) - 1;
  cout << res;
}
