#include <bits/stdc++.h>
using namespace std;
int n, a[1000005], Lmax[1000005], Rmax[1000005], Left[1000005][33],
    Right[1000005][33], Stack[1000005];
long long ans;
int read() {
  char c = getchar();
  int ans = 0;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9')
    ans = (ans << 1) + (ans << 3) + (c ^ 48), c = getchar();
  return ans;
}
void Write(long long x) {
  if (x < 10)
    putchar(x ^ 48);
  else
    Write(x / 10), putchar((x % 10) ^ 48);
  return;
}
int main() {
  n = read();
  ans = n * (n + 1ll) / 2;
  for (register int i = 1; i <= n; i++) a[i] = read();
  a[0] = 2000000000, a[n + 1] = 2000000000;
  Stack[Stack[0] = 1] = 0;
  for (register int i = 1; i <= n; i++) {
    while (a[Stack[Stack[0]]] <= a[i]) --Stack[0];
    Lmax[i] = Stack[Stack[0]] + 1;
    Stack[++Stack[0]] = i;
  }
  Stack[Stack[0] = 1] = n + 1;
  for (register int i = n; i >= 1; i--) {
    while (a[Stack[Stack[0]]] < a[i]) --Stack[0];
    Rmax[i] = Stack[Stack[0]] - 1;
    Stack[++Stack[0]] = i;
  }
  for (register int j = 0; j <= 30; j++) Right[n + 1][j] = n + 1;
  for (register int i = 1; i <= n; i++)
    for (register int j = 0; j <= 30; j++)
      Left[i][j] = (a[i] & (1 << j)) ? i : Left[i - 1][j];
  for (register int i = n; i >= 1; i--)
    for (register int j = 0; j <= 30; j++)
      Right[i][j] = (a[i] & (1 << j)) ? i : Right[i + 1][j];
  for (register int i = 1; i <= n; i++) {
    int LL = Lmax[i], RR = Rmax[i];
    for (register int j = 0; j <= 30; j++)
      if (!(a[i] & (1 << j)))
        LL = max(LL, Left[i][j] + 1), RR = min(RR, Right[i][j] - 1);
    ans -= (RR - i + 1) * (i - LL + 1ll);
  }
  Write(ans);
  return 0;
}
