#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 5;
int n, a[N];
static inline int lg(int x) { return 32 - __builtin_clz(x) - 1; }
struct Sparse {
  static const int mk = 19;
  int* tb[mk];
  int* orr[mk];
  Sparse(int* a, int n) {
    for (int i = 0; i < mk; i++) {
      tb[i] = new int[n + 5];
      orr[i] = new int[n + 5];
    }
    for (int i = 0; i < n; i++) {
      tb[0][i] = a[i];
      orr[0][i] = a[i];
    }
    for (int k = 1; k <= lg(n); k++) {
      for (int i = 0; i < n; i++) {
        int nx = i + (1 << (k - 1));
        if (nx < n) {
          tb[k][i] = max(tb[k - 1][i], tb[k - 1][nx]);
          orr[k][i] = orr[k - 1][i] | orr[k - 1][nx];
        } else {
          tb[k][i] = tb[k - 1][i];
          orr[k][i] = orr[k - 1][i];
        }
      }
    }
  }
  int getmax(int l, int r) {
    int g = lg(r - l + 1);
    return max(tb[g][l], tb[g][r - (1 << g) + 1]);
  }
  int getor(int l, int r) {
    int g = lg(r - l + 1);
    return orr[g][l] | orr[g][r - (1 << g) + 1];
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  Sparse st(a, n);
  int K = lg(n) + 2;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    int curOR = a[i];
    int curIdx = i;
    int prevIdx = i;
    int add = 0;
    while (true) {
      curIdx++;
      prevIdx = curIdx;
      curOR = st.getor(i, curIdx);
      int cor = curOR;
      if ((curOR | a[curIdx + 1]) == curOR) {
        for (int k = K; k >= 0; k--) {
          if (curIdx + (1 << k) >= n) continue;
          int ni = curIdx + (1 << k);
          if (st.getor(i, ni) == curOR) {
            cor |= st.orr[k][curIdx];
            curIdx = ni;
          }
        }
      }
      if (curIdx >= n) break;
      int r = prevIdx - 1;
      int cmax = st.getmax(i, curIdx);
      for (int k = K; k >= 0; k--) {
        if (r + (1 << k) > curIdx) continue;
        int ni = r + (1 << k);
        if (st.getmax(i, ni) < curOR) {
          cmax = max(cmax, st.tb[k][r]);
          r = ni;
        }
      }
      add += (r - prevIdx + 1);
    }
    ans += add;
  }
  cout << ans << '\n';
}
