#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  vector<long long> lt(n);
  vector<long long> rt(n);
  stack<long long> st;
  for (long long i = 0; i < n; i++) {
    lt[i] = i;
    while (!st.empty() && v[st.top()] < v[i]) st.pop();
    if (!st.empty())
      lt[i] = st.top() + 1;
    else
      lt[i] = 0;
    st.push(i);
  }
  while (!st.empty()) st.pop();
  for (long long i = n - 1; i >= 0; i--) {
    rt[i] = i;
    while (!st.empty() && v[st.top()] <= v[i]) st.pop();
    if (!st.empty())
      rt[i] = st.top() - 1;
    else
      rt[i] = n - 1;
    st.push(i);
  }
  vector<vector<long long> > cnt(32);
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < 32; j++) {
      if (v[i] & (1 << j)) cnt[j].push_back(i);
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    long long l = -1;
    long long r = n;
    for (long long j = 0; j < 32; j++) {
      if ((v[i] & (1 << j)) == 0) {
        vector<long long>::iterator it =
            lower_bound(cnt[j].begin(), cnt[j].end(), i);
        if (it != cnt[j].end()) r = min(r, *it - 1);
        if (it != cnt[j].begin()) {
          it--;
          l = max(l, *it + 1);
        }
      }
    }
    if (l < lt[i]) l = lt[i];
    if (r > rt[i]) r = rt[i];
    if (l == -1) l = i;
    if (r == n) r = i;
    ans += (i - lt[i] + 1) * (rt[i] - i + 1) - (i - l + 1) * (r - i + 1);
  }
  cout << ans;
  return 0;
}
