#include <bits/stdc++.h>
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int max(int x, int y) { return x > y ? x : y; }
int min(int x, int y) { return x < y ? x : y; }
int rmq[200005][20];
int lg[200005], bin[40];
int n;
int num[200005];
void getRmq() {
  for (int i = 1; i <= n; i++) rmq[i][0] = i;
  for (int j = 1; j <= lg[n]; j++)
    for (int i = 1; i + bin[j] - 1 <= n; i++) {
      rmq[i][j] = num[rmq[i][j - 1]] > num[rmq[i + bin[j - 1]][j - 1]]
                      ? rmq[i][j - 1]
                      : rmq[i + bin[j - 1]][j - 1];
    }
}
int getMax(int l, int r) {
  int w = lg[r - l + 1];
  return num[rmq[l][w]] > num[rmq[r - bin[w] + 1][w]] ? rmq[l][w]
                                                      : rmq[r - bin[w] + 1][w];
}
void init() {
  bin[0] = 1;
  for (int i = 1; i <= 30; i++) bin[i] = bin[i - 1] * 2;
  n = read();
  for (int i = 1; i <= n; i++) {
    num[i] = read();
    lg[i] = log(i) / log(2);
  }
}
long long ans;
int tot[40];
int pos[40][200005], bit[40][200005];
void slove(int l, int r) {
  if (l > r) return;
  int mid = getMax(l, r);
  int L = l - 1, R = r + 1;
  for (int i = 0; i <= 30; i++)
    if (!(num[mid] & bin[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 -= (long long)(mid - L) * (R - mid);
  slove(l, mid - 1);
  slove(mid + 1, r);
}
int main() {
  init();
  getRmq();
  for (int i = 0; i <= 30; i++)
    for (int j = 1; j <= n; j++) {
      if (num[j] & bin[i]) bit[i][++tot[i]] = j;
      pos[i][j] = tot[i];
    }
  ans = (long long)n * (n + 1) / 2;
  slove(1, n);
  printf("%I64d\n", ans);
}
