#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
clock_t START;
inline long double TIME() {
  return (long double)(clock() - START) / CLOCKS_PER_SEC;
}
long double TL = 2.0;
long long calls = 0;
inline bool IS() {
  if (++calls == 1000) {
    calls = 0;
    if (TL - TIME() < 0.1) return true;
  }
  return false;
}
template <typename T1, typename T2>
inline void amin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void amax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p) {
  os << p.first << ' ' << p.second << endl;
  return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &u : v) is >> u;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto &u : v) os << u << ' ';
  os << endl;
  return os;
}
long long hash_mod[4] = {1000000007, 998244353, 1000000009, 999999937},
          mod = hash_mod[rnd() % 4];
long long hash_pows[4] = {179, 239, 1007, 2003}, P = hash_pows[rnd() % 4];
long long binpow(long long first, long long p) {
  long long res = 1;
  while (p) {
    if (p % 2) res = (res * first) % mod;
    first = (first * first) % mod;
    p /= 2;
  }
  return res;
}
const long long N = 1e6 + 7, NS = 2e3 + 7, lg = 30, sq = 550, inf = 2e9 + 7,
                SM = 1e2 + 7;
const long double eps = 1e-9;
long long L[N], R[N], a[N];
void solve() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  stack<long long> st;
  st.push(-1);
  for (long long i = 0; i < n; i++) {
    while (st.top() != -1 && a[st.top()] < a[i]) {
      R[st.top()] = i;
      st.pop();
    }
    st.push(i);
  }
  while (st.top() != -1) {
    R[st.top()] = n;
    st.pop();
  }
  for (long long i = n - 1; i >= 0; i--) {
    while (st.top() != -1 && a[st.top()] <= a[i]) {
      L[st.top()] = i;
      st.pop();
    }
    st.push(i);
  }
  while (st.top() != -1) {
    L[st.top()] = -1;
    st.pop();
  }
  vector<long long> last(lg, -1);
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < lg; j++) {
      if (a[i] & (1 << j))
        last[j] = i;
      else
        amax(L[i], last[j]);
    }
  }
  last = vector<long long>(lg, n);
  for (long long i = n - 1; i >= 0; i--) {
    for (long long j = 0; j < lg; j++) {
      if (a[i] & (1 << j))
        last[j] = i;
      else
        amin(R[i], last[j]);
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    ans += (R[i] - i) * (i - L[i]);
  }
  cout << (n * (n + 1)) / 2 - ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
