#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int mlog = 32;
int vis[maxn];
int m;
int pref[mlog][maxn];
int seq[maxn];
int lef[maxn], rig[maxn];
int bs(int lo, int hi, bool flag2, int s) {
  int cl = lo;
  int ch = hi;
  int m, found = -1;
  while (lo <= hi) {
    m = (lo + hi) / 2;
    bool flag = false;
    for (int j = 0; j < mlog; j++) {
      if (s & (1 << j)) continue;
      int a;
      if (!flag2) {
        a = pref[j][m] - pref[j][cl - 1];
      } else
        a = pref[j][ch] - pref[j][m - 1];
      if (a) {
        flag = true;
        break;
      }
    }
    if (flag) {
      if (!flag2) {
        found = m;
        hi = m - 1;
      } else {
        found = m;
        lo = m + 1;
      }
    } else {
      if (!flag2) {
        lo = m + 1;
      } else {
        hi = m - 1;
      }
    }
  }
  if (!flag2) {
    if (found == -1)
      return ch;
    else
      return found - 1;
  } else {
    if (found == -1)
      return cl;
    else
      return found + 1;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> seq[i];
  }
  for (int j = 0; j < mlog; j++) {
    for (int i = 1; i <= n; i++) {
      pref[j][i] = pref[j][i - 1];
      if (seq[i] & (1 << j)) {
        pref[j][i]++;
      }
    }
  }
  lef[1] = 0;
  stack<pair<int, int> > s;
  s.push({seq[1], 1});
  for (int i = 2; i <= n; i++) {
    while ((!s.empty()) && s.top().first < seq[i]) {
      s.pop();
    }
    if (s.empty()) {
      lef[i] = 0;
    } else
      lef[i] = s.top().second;
    s.push({seq[i], i});
  }
  while (!s.empty()) s.pop();
  rig[n] = n + 1;
  s.push({seq[n], n});
  for (int i = n - 1; i > 0; i--) {
    while ((!s.empty()) && s.top().first <= seq[i]) {
      s.pop();
    }
    if (s.empty()) {
      rig[i] = n + 1;
    } else
      rig[i] = s.top().second;
    s.push({seq[i], i});
  }
  long long ans = 0;
  int l, r;
  for (int i = 1; i <= n; i++) {
    if (seq[i] == 0) continue;
    l = lef[i] + 1;
    r = rig[i] - 1;
    ans += 1ll * (r - i + 1) * (i - l + 1);
    r = bs(i + 1, r, false, seq[i]);
    l = bs(l, i - 1, true, seq[i]);
    ans -= 1ll * (r - i + 1) * (i - l + 1);
  }
  cout << ans << endl;
  return 0;
}
