#include <bits/stdc++.h>
using namespace std;
int n;
int a[200011], lmax[200011], rmax[200011], lch[200011], rch[200011],
    sta[200011], top;
int hus[33][200011], hut[33];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  top = 0;
  for (int i = 1; i <= n; i++) {
    while (top && a[sta[top]] <= a[i]) top--;
    if (!top)
      lmax[i] = 1;
    else
      lmax[i] = sta[top] + 1;
    sta[++top] = i;
  }
  top = 0;
  for (int i = n; i >= 1; i--) {
    while (top && a[sta[top]] < a[i]) top--;
    if (!top)
      rmax[i] = n;
    else
      rmax[i] = sta[top] - 1;
    sta[++top] = i;
  }
  memset(hut, 0, sizeof(hut));
  for (int i = 1; i <= n; i++) {
    lch[i] = 0;
    for (int j = 0; j <= 30; j++) {
      if (a[i] & (1 << j))
        hus[j][++hut[j]] = i;
      else if (hut[j])
        lch[i] = max(lch[i], hus[j][hut[j]]);
    }
    if (lch[i] < lmax[i]) lch[i] = lmax[i] - 1;
  }
  memset(hut, 0, sizeof(hut));
  for (int i = n; i >= 1; i--) {
    rch[i] = n + 1;
    for (int j = 0; j <= 30; j++) {
      if (a[i] & (1 << j))
        hus[j][++hut[j]] = i;
      else if (hut[j])
        rch[i] = min(rch[i], hus[j][hut[j]]);
    }
    if (rch[i] > rmax[i]) rch[i] = rmax[i] + 1;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    ans += 1ll * (rmax[i] - rch[i] + 1) * (i - lmax[i] + 1) +
           1ll * (rmax[i] - i + 1) * (lch[i] - lmax[i] + 1) -
           1ll * (rmax[i] - rch[i] + 1) * (lch[i] - lmax[i] + 1);
  printf("%I64d\n", ans);
  return 0;
}
