#include <bits/stdc++.h>
using namespace std;
int n, a[200010];
stack<int> s;
int l[200010], r[200010];
long long ans;
int tr[525000];
inline void build_tree(int p, int l, int r) {
  if (l == r) {
    tr[p] = l;
    return;
  }
  int mid = (l + r) >> 1;
  build_tree(p << 1, l, mid);
  build_tree(p << 1 | 1, mid + 1, r);
  if (a[tr[p << 1]] > a[tr[p << 1 | 1]])
    tr[p] = tr[p << 1];
  else
    tr[p] = tr[p << 1 | 1];
}
inline int query(int p, int l, int r, int ll, int rr) {
  if (l >= ll && r <= rr) return tr[p];
  int mid = (l + r) >> 1;
  if (rr <= mid) return query(p << 1, l, mid, ll, rr);
  if (ll > mid) return query(p << 1 | 1, mid + 1, r, ll, rr);
  int lll = query(p << 1, l, mid, ll, rr);
  int rrr = query(p << 1 | 1, mid + 1, r, ll, rr);
  if (a[lll] > a[rrr]) return lll;
  return rrr;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  build_tree(1, 1, n);
  for (int i = 1; i <= n; i++) {
    while (!s.empty() && (a[s.top()] | a[i]) != a[s.top()]) {
      r[s.top()] = i - 1;
      s.pop();
    }
    s.push(i);
  }
  while (!s.empty()) r[s.top()] = n, s.pop();
  for (int i = n; i >= 1; i--) {
    while (!s.empty() && (a[s.top()] | a[i]) != a[s.top()]) {
      l[s.top()] = i + 1;
      s.pop();
    }
    s.push(i);
  }
  while (!s.empty()) l[s.top()] = 1, s.pop();
  ans = 1ll * n * (n + 1) / 2;
  for (int i = 1; i <= n; i++) {
    if (l[i] < i) {
      int x = query(1, 1, n, l[i], i - 1);
      if (a[x] == a[i]) l[i] = x + 1;
    }
    ans -= 1ll * (i - l[i] + 1) * (r[i] - i + 1);
  }
  cout << ans;
  return 0;
}
