#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200050;
int n, bit[MAXN], a[MAXN], f[MAXN][30], g[MAXN][30], L[MAXN], R[MAXN], tot;
void read() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    f[i][0] = g[i][0] = a[i];
  }
}
void init() {
  bit[1] = 0;
  for (int i = 2; i <= n; i++) {
    bit[i] = bit[i - 1];
    if (((1 << (bit[i] + 1))) <= i) bit[i]++;
  }
  for (int i = 1; i <= bit[n] + 1; i++)
    for (int j = 1; j <= n; j++) {
      if (j + (1 << i) - 1 > n) break;
      f[j][i] = f[j][i - 1] | f[j + (1 << (i - 1))][i - 1];
      g[j][i] = max(g[j][i - 1], g[j + (1 << (i - 1))][i - 1]);
    }
}
int R1(int l, int r) {
  int t = bit[r - l + 1];
  return f[l][t] | f[r - (1 << t) + 1][t];
}
int R2(int l, int r) {
  int t = bit[r - l + 1];
  return max(g[l][t], g[r - (1 << t) + 1][t]);
}
int main() {
  read();
  init();
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    tot = 0;
    int loc = i;
    while (loc <= n) {
      int tmp = R1(i, loc);
      int l = loc, r = n, pos = tmp;
      while (l <= r) {
        int mid = (l + r) >> 1;
        int tmp2 = R1(i, mid);
        if (tmp2 > tmp) {
          r = mid - 1;
        } else {
          l = mid + 1;
          pos = mid;
        }
      }
      tot++;
      L[tot] = loc;
      R[tot] = pos;
      loc = pos + 1;
    }
    for (int j = 1; j <= tot; j++) {
      int l = L[j], r = R[j], pos = 0;
      int OR = R1(i, l);
      while (l <= r) {
        int mid = (l + r) >> 1;
        int tmp = R2(i, mid);
        if (tmp < OR) {
          pos = mid;
          l = mid + 1;
        } else {
          r = mid - 1;
        }
      }
      if (pos == 0) continue;
      ans += pos - L[j] + 1;
    }
  }
  cout << ans;
  return 0;
}
