#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int st[MAXN][40], pos[40][MAXN], bit[40][MAXN], a[MAXN], tot[MAXN], lg[MAXN],
    bin[40];
int n;
long long ans;
void init() {
  bin[0] = 1;
  for (int i = 1; i <= 30; ++i) bin[i] = bin[i - 1] * 2;
  for (int i = 1; i <= n; ++i) {
    lg[i] = log(i) / log(2);
  }
}
void rmq() {
  for (int i = 1; i <= n; ++i) st[i][0] = i;
  for (int i = 1; i <= 30; ++i) {
    for (int j = 1; j + (1 << i) - 1 <= n; ++j) {
      if (a[st[j][i - 1]] > a[st[j + (1 << (i - 1))][i - 1]])
        st[j][i] = st[j][i - 1];
      else
        st[j][i] = st[j + (1 << (i - 1))][i - 1];
    }
  }
}
int getrmq(int l, int r) {
  int k = 0;
  while (l + (1 << k) - 1 <= r) ++k;
  --k;
  return a[st[l][k]] > a[st[r - (1 << k) + 1][k]] ? st[l][k]
                                                  : st[r - (1 << k) + 1][k];
}
void solve(int l, int r) {
  if (l > r) return;
  int mid = getrmq(l, r);
  int L = l - 1, R = r + 1;
  for (int i = 0; i <= 30; ++i) {
    if (!(a[mid] & (1 << i))) {
      if (pos[i][mid]) L = max(L, bit[i][pos[i][mid]]);
      if (pos[i][mid] < tot[i]) R = min(R, bit[i][pos[i][mid] + 1]);
    }
  }
  ans -= 1ll * (mid - L) * (R - mid);
  solve(l, mid - 1);
  solve(mid + 1, r);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  rmq();
  for (int i = 0; i <= 30; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (a[j] & (1 << i)) {
        bit[i][++tot[i]] = j;
      }
      pos[i][j] = tot[i];
    }
  }
  ans = 1ll * n * (n + 1) / 2;
  solve(1, n);
  printf("%lld\n", ans);
  return 0;
}
