#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N] = {-1}, ans[N], tree[N << 2], L[N], R[N], n;
int p[50], s[50];
void update(int l, int r, int x, int p) {
  if (l > x || r < x) return;
  if (l == r) {
    tree[p] = x;
  } else {
    int m = l + r >> 1;
    update(l, m, x, p << 1);
    update(m + 1, r, x, p << 1 | 1);
    tree[p] = (a[tree[p << 1]] >= a[tree[p << 1 | 1]] ? tree[p << 1]
                                                      : tree[p << 1 | 1]);
  }
}
int getMax(int l, int r, int L, int R, int p) {
  if (l > R || L > r) return 0;
  if (L <= l && R >= r) {
    return tree[p];
  }
  int m = l + r >> 1;
  int left = getMax(l, m, L, R, p << 1);
  int right = getMax(m + 1, r, L, R, p << 1 | 1);
  return a[left] >= a[right] ? left : right;
}
long long solve(int l, int r) {
  if (l > r) return 0;
  long long m = getMax(1, n, l, r, 1);
  long long left = max(L[m], l - 1);
  long long right = min(R[m], r + 1);
  return solve(l, m - 1) + solve(m + 1, r) + (left - l + 1) * (r - m + 1) +
         (r - right + 1) * (m - left);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    update(1, n, i, 1);
    for (int bit = 30; ~bit; --bit) {
      s[bit] = n + 1;
    }
    R[i] = n + 1;
  }
  for (int i = 1; i <= n; ++i) {
    for (int bit = 30; ~bit; --bit) {
      if (~a[i] >> bit & 1) {
        L[i] = max(L[i], p[bit]);
      } else {
        p[bit] = i;
      }
    }
  }
  for (int i = n; i >= 1; --i) {
    for (int bit = 30; ~bit; --bit) {
      if (~a[i] >> bit & 1) {
        R[i] = min(R[i], s[bit]);
      } else {
        s[bit] = i;
      }
    }
  }
  cout << solve(1, n) << '\n';
}
