#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using cd = complex<double>;
using ul = unsigned long;
void f_io() {
  ios_base ::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
const ll MAX = 2e5 + 10, MOD = 1e9 + 7, M = 3e6;
ll gc(ll a, ll b) {
  if (!a || !b) {
    return max(a, b);
  }
  ll r = a % b;
  while (r) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
ll mult(ll a, ll b) { return ((a % MOD) * 1LL * (b % MOD)) % MOD; }
ll add(ll a, ll b) {
  b = (b % MOD + MOD) % MOD;
  return (a + b) % MOD;
}
ll pw(ll a, ll b) {
  if (b < 0) {
    return 1;
  }
  ll r = 1;
  while (b) {
    if (b & 1) {
      r = mult(a, r);
    }
    b >>= 1;
    a = mult(a, a);
  }
  return r;
}
vector<int> ve[70];
int main() {
  int n;
  cin >> n;
  int ar[n];
  int gel[n], gr[n];
  vector<pair<int, int>> v;
  v.push_back(make_pair(MOD, -1));
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    for (int j = 0; j < 32; j++) {
      if ((ar[i] >> j) & 1) {
        ve[j].push_back(i);
      }
    }
    while (v.back().first < ar[i]) {
      v.pop_back();
    }
    gel[i] = v.back().second;
    v.push_back(make_pair(ar[i], i));
  }
  v.clear();
  v.push_back(make_pair(MOD, n));
  for (int i = n - 1; i >= 0; i--) {
    while (v.back().first <= ar[i]) {
      v.pop_back();
    }
    gr[i] = v.back().second;
    v.push_back(make_pair(ar[i], i));
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    int mi = gel[i], ma = gr[i];
    for (int j = 0; j < 32; j++) {
      if (((ar[i] >> j) & 1) == 0) {
        auto x = upper_bound(ve[j].begin(), ve[j].end(), i);
        if (x != ve[j].end()) {
          ma = min(ma, *x);
        }
        if (x != ve[j].begin()) {
          x--;
          mi = max(mi, *x);
        }
      }
    }
    ans += ((i - gel[i]) * 1LL * (gr[i] - i) - (i - mi) * 1LL * (ma - i));
  }
  cout << ans << "\n";
}
