#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
vector<long long> a(maxn, 0), b(maxn, 0);
const int LOG = 31;
long long dp1[LOG][maxn], dp2[LOG][maxn];
int nxt[maxn], pre[maxn];
int n;
const long long INF = 1e18;
void prec() {
  for (int i = 1; i <= n; ++i) nxt[i] = pre[i] = i;
  a[0] = a[n + 1] = INF;
  multiset<pair<long long, long long> > cur;
  for (int i = 0; i <= n + 1; ++i) {
    while (!cur.empty() && (*cur.begin()).first < a[i]) {
      nxt[(*cur.begin()).second] = i - 1;
      cur.erase(cur.find(*cur.begin()));
    }
    cur.insert({a[i], i});
  }
  cur.clear();
  for (int i = n + 1; i >= 0; --i) {
    while (!cur.empty() && (*cur.begin()).first <= a[i]) {
      pre[(*cur.begin()).second] = i + 1;
      cur.erase(cur.find(*cur.begin()));
    }
    cur.insert({a[i], i});
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    b[i - 1] = a[i];
    for (int j = 0; j < LOG; ++j) {
      dp1[j][i] = dp1[j][i - 1];
      if (a[i] & (1LL << j)) dp1[j][i] = i;
    }
  }
  for (int i = n; i > 0; --i) {
    for (int j = 0; j < LOG; ++j) {
      dp2[j][i] = dp2[j][i + 1];
      if (a[i] & (1LL << j)) dp2[j][i] = i;
    }
  }
  prec();
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    int bit = LOG;
    long long l = 0, r = 0;
    for (int j = LOG - 1; j >= 0; --j) {
      if (a[i] >= (1LL << j) && !(a[i] & (1LL << j))) {
        bit = j;
        if (dp1[j][i] != 0) {
          if (l == 0)
            l = dp1[j][i];
          else
            l = max(l, dp1[j][i]);
        }
        if (dp2[j][i] != 0) {
          if (r == 0)
            r = dp2[j][i];
          else
            r = min(r, dp2[j][i]);
        }
      }
    }
    assert((l == 0 || l < i) && (r == 0 || r > i));
    if (bit == LOG) continue;
    long long left = pre[i];
    long long right = nxt[i];
    if (l != 0 && left <= l)
      ans += (long long)(l - left + 1) * (long long)(right - i + 1);
    if (r != 0 && right >= r)
      ans += (long long)(right - r + 1) * (long long)(i - left + 1);
    if (l != 0 && left <= l && r != 0 && right >= r) {
      ans -= (long long)(l - left + 1) * (long long)(right - r + 1);
    }
  }
  cout << ans;
  return 0;
}
