#include <bits/stdc++.h>
using namespace std;
const int N = 200003;
int n, a[N], S[N], s, l[35][N], r[35][N], l_[N], L[N], R[N];
long long ans, x, y;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i), L[i] = i, R[i] = n - i + 1;
  for (int i = 1; i <= n; i++)
    for (int k = 0; k <= 31; k++)
      l[k][i] = ((1 << k) & a[i]) ? 0 : l[k][i - 1] + 1;
  for (int i = n; i >= 1; i--)
    for (int k = 31; k >= 0; k--)
      r[k][i] = ((1 << k) & a[i]) ? 0 : r[k][i + 1] + 1;
  for (int i = 1; i <= n; i++)
    for (int k = 0; k <= 31; k++)
      if (!(a[i] & (1 << k))) L[i] = min(L[i], l[k][i]);
  for (int i = n; i >= 1; i--)
    for (int k = 31; k >= 0; k--)
      if (!(a[i] & (1 << k))) R[i] = min(R[i], r[k][i]);
  for (int i = 1; i <= n; i++) {
    while (s && a[S[s]] < a[i]) s--;
    l_[i] = S[s];
    S[++s] = i;
    s = i == n ? 0 : s;
  }
  for (int i = 1; i <= n; i++) {
    x = L[i], y = R[i];
    if (l_[i]) x = min(x, 1ll * i - 1ll * l_[i]);
    ans += x * y - 1;
  }
  printf("%I64d\n", 1ll * n * (n - 1) / 2 - ans);
  return 0;
}
