#include <bits/stdc++.h>
using namespace std;
int zz[200005 * 32], zy[200005 * 32], c, a, b, er[35], top, n, op, aa[200005],
    sta[200005], tong[35], f[200005][35], g[200005][35], lin[200005];
long long zuo[200005], you[200005], ans, i, j;
bool nozuizuo[200005];
int main() {
  scanf("%d", &n);
  er[0] = 1;
  for (i = 1; i <= 30; i++) er[i] = er[i - 1] * 2;
  for (i = 1; i <= n; i++) {
    scanf("%d", &aa[i]);
  }
  top = 0;
  for (i = 1; i <= n; i++) {
    zuo[i] = 1;
    while (top && aa[sta[top]] < aa[i]) zuo[i] += zuo[sta[top]], top--;
    sta[++top] = i;
  }
  top = 0;
  for (i = n; i >= 1; i--) {
    you[i] = 1;
    while (top && aa[sta[top]] < aa[i]) you[i] += you[sta[top]], top--;
    if (aa[sta[top]] == aa[i]) nozuizuo[sta[a]] = 1;
    sta[++top] = i;
  }
  top = 0;
  for (i = n; i >= 1; i--) {
    lin[i] = 1;
    while (top && aa[sta[top]] <= aa[i]) lin[i] += you[sta[top]], top--;
    if (nozuizuo[i] != 1) you[i] = lin[i];
    sta[++top] = i;
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j <= 30; j++) {
      f[i][j] = tong[j];
    }
    for (j = 0; j <= 30; j++) {
      if (er[j] & aa[i]) tong[j] = i;
    }
  }
  for (i = 0; i <= 30; i++) tong[i] = 9999999;
  for (i = n; i >= 1; i--) {
    for (j = 0; j <= 30; j++) {
      g[i][j] = tong[j];
    }
    for (j = 0; j <= 30; j++) {
      if (er[j] & aa[i]) tong[j] = i;
    }
  }
  for (i = 1; i <= n; i++) {
    int lin = aa[i], o = 0, j = 0;
    long long l1 = 0, l2 = 9999999;
    while (lin) {
      if (!(lin & 1)) {
        if (f[i][j] >= i - zuo[i] + 1) l1 = max(f[i][j], int(l1));
        if (g[i][j] <= you[i] + i - 1) l2 = min(g[i][j], int(l2));
      }
      lin /= 2;
      ++j;
    }
    if (l1 != 0 && l2 != 9999999) {
      ans += (l1 - (i - zuo[i] + 1) + 1) * (you[i]);
      ans += (i - l1) * ((you[i] + i - 1) - l2 + 1);
    }
    if (l1 != 0 && l2 == 9999999) {
      ans += (l1 - (i - zuo[i] + 1) + 1) * (you[i]);
    }
    if (l1 == 0 && l2 != 9999999) {
      ans += zuo[i] * ((i + you[i] - 1) - l2 + 1);
    }
  }
  printf("%I64d", ans);
}
