#include <bits/stdc++.h>
using namespace std;
long long n, a[200010];
long long sta[200010], rs[200010], ls[200010];
long long l[35][200010], r[35][200010];
int main() {
  scanf("%I64d", &n);
  for (long long i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  long long top = 0;
  for (long long i = 1; i <= n; i++) {
    while (top && a[sta[top]] < a[i]) rs[sta[top--]] = i - 1;
    ls[i] = sta[top] + 1;
    sta[++top] = i;
  }
  while (top) rs[sta[top--]] = n;
  for (long long k = 0; k <= 32; k++) {
    long long top = 0, last = 0;
    for (long long i = 1; i <= n; i++) {
      while (top && (a[i] & (1LL << k))) r[k][sta[top--]] = i;
      l[k][i] = last;
      sta[++top] = i;
      if (a[i] & (1LL << k)) last = i;
    }
    while (top) r[k][sta[top--]] = n + 1;
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    long long L = ls[i] - 1, R = rs[i] + 1;
    for (long long k = 0; k <= 32; k++)
      if ((a[i] & (1LL << k)) == 0) L = max(L, l[k][i]), R = min(R, r[k][i]);
    ans = ans + (long long)(rs[i] - R + 1) * (long long)(i - ls[i] + 1) +
          (long long)(L - ls[i] + 1) * (long long)(rs[i] - i + 1) -
          (long long)(L - ls[i] + 1) * (long long)(rs[i] - R + 1);
  }
  printf("%I64d", ans);
}
