#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 213;
int l[N], r[N], a[N];
pair<int, int> b[N];
bool diff(int a, int b) {
  for (int i = 1; i < 1e9; i *= 2)
    if ((b & i) != 0 && (a & i) == 0) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  set<int> s;
  cin >> n;
  s.insert(0);
  s.insert(n + 1);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = make_pair(a[i], i);
  }
  sort(b + 1, b + n + 1, greater<pair<int, int> >());
  for (int i = 2; i <= n; i++) {
    l[i] = i - 1;
    while (l[i] != 0 && !diff(a[i], a[l[i]])) l[i] = l[l[i]];
  }
  r[n] = n + 1;
  for (int i = n - 1; i >= 1; i--) {
    r[i] = i + 1;
    while (r[i] != n + 1 && !diff(a[i], a[r[i]])) r[i] = r[r[i]];
  }
  for (int i = 1; i <= n; i++) {
    int now = b[i].second;
    auto it = s.lower_bound(now);
    int rr = *it;
    it--;
    int ll2 = *it;
    s.insert(now);
    if (ll2 + 2 == rr) continue;
    r[now] = min(r[now], rr);
    l[now] = max(ll2, l[now]);
    long long len = (r[now] - now) * (long long)(now - l[now]);
    ans += (rr - now) * (long long)(now - ll2) - len;
  }
  cout << ans << endl;
  return 0;
}
