#include <bits/stdc++.h>
using namespace std;
vector<long> v[33];
long n, a[200005], r[200005], l[200005];
long getbit(long x, long i) { return (x >> i) & 1; }
void nhap() {
  for (long i = 0; i <= 30; ++i) v[i].push_back(0);
  cin >> n;
  for (long i = 1; i <= n; ++i) {
    cin >> a[i];
    for (long j = 0; j <= 30; ++j) {
      if (getbit(a[i], j) == 1) v[j].push_back(i);
    }
  }
  for (long i = 0; i <= 30; ++i) v[i].push_back(n + 1);
}
void lam() {
  stack<long> st;
  st.push(0);
  a[0] = (1 << 30);
  for (long i = 1; i <= n; ++i) {
    while (st.size() && a[st.top()] <= a[i]) st.pop();
    l[i] = st.top();
    st.push(i);
  }
  while (st.size()) st.pop();
  st.push(n + 1);
  a[n + 1] = (1 << 30);
  for (long i = n; i >= 1; --i) {
    while (st.size() && a[st.top()] < a[i]) st.pop();
    r[i] = st.top();
    st.push(i);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  nhap();
  lam();
  long long res = 0;
  for (long i = 1; i <= n; ++i) {
    long l1 = 0, l2 = n + 1;
    if (a[i] == 0) continue;
    for (long j = 0; j <= 30; ++j) {
      if (getbit(a[i], j) == 0) {
        long r1 = upper_bound(v[j].begin(), v[j].end(), i) - v[j].begin() - 1;
        long r2 = upper_bound(v[j].begin(), v[j].end(), i) - v[j].begin();
        r1 = v[j][r1];
        r2 = v[j][r2];
        l1 = max(l1, r1);
        l2 = min(l2, r2);
      }
    }
    l1 = max(l1, l[i]);
    l2 = min(l2, r[i]);
    res += 1ll * (r[i] - l2) * (i - l[i]) + 1ll * (l1 - l[i]) * (r[i] - i) -
           1ll * (l1 - l[i]) * (r[i] - l2);
  }
  cout << res;
  return 0;
}
