#include <bits/stdc++.h>
using namespace std;
const int LG = 30;
const int maxn = int(2e5) + 100;
int n;
int a[maxn];
int q[maxn], L[maxn], R[maxn];
int Lone[maxn][LG + 10], Rone[maxn][LG + 10];
long long ans;
void read() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
}
void solve() {
  a[0] = int(1e9) + 100;
  q[1] = 0;
  int tail = 1;
  for (int i = 1; i <= n; ++i) {
    while (a[i] > a[q[tail]]) {
      R[q[tail]] = i;
      --tail;
    }
    L[i] = q[tail];
    q[++tail] = i;
  }
  while (tail) R[q[tail--]] = n + 1;
  for (int i = 0; i < LG; ++i) {
    Lone[0][i] = 0;
    Rone[n + 1][i] = n + 1;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j < LG; ++j)
      Lone[i][j] = (((a[i] >> j) & 1) ? i : Lone[i - 1][j]);
  for (int i = n; i > 0; --i)
    for (int j = 0; j < LG; ++j)
      Rone[i][j] = (((a[i] >> j) & 1) ? i : Rone[i + 1][j]);
  for (int i = 1; i <= n; ++i) {
    int Lmax = 0;
    int Rmin = n + 1;
    for (int j = 0; j < LG; ++j)
      if (!((a[i] >> j) & 1)) {
        Lmax = max(Lmax, Lone[i][j]);
        Rmin = min(Rmin, Rone[i][j]);
      }
    long long sL = 0, sR = 0;
    if (L[i] < Lmax) sL = Lmax - L[i];
    if (Rmin < R[i]) sR = R[i] - Rmin;
    ans += sL * (R[i] - i) + sR * (i - L[i]) - sL * sR;
  }
  printf("%I64d\n", ans);
}
int main() {
  read();
  solve();
  return 0;
}
