#include <bits/stdc++.h>
const int N = 200005;
using namespace std;
int n, a[N], L[N], R[N];
int sta[N], tp;
void getL() {
  a[0] = 1 << 30;
  sta[tp = 1] = 0;
  for (int i = 1; i <= n; ++i) {
    while (a[i] >= a[sta[tp]]) --tp;
    L[i] = sta[tp] + 1;
    sta[++tp] = i;
  }
}
void getR() {
  a[n + 1] = 1 << 30;
  sta[tp = 1] = n + 1;
  for (int i = n; i >= 1; --i) {
    while (a[i] > a[sta[tp]]) --tp;
    R[i] = sta[tp] - 1;
    sta[++tp] = i;
  }
}
vector<int> bit[35];
int findL(int x, int p) {
  int l, r, mid, ret = -1;
  l = 0;
  r = bit[x].size() - 1;
  while (l <= r) {
    mid = (l + r) / 2;
    if (bit[x][mid] > p)
      r = mid - 1;
    else {
      ret = mid;
      l = mid + 1;
    }
  }
  if (ret != -1) ret = bit[x][ret];
  return ret;
}
int findR(int x, int p) {
  int l, r, mid, ret = -1;
  l = 0;
  r = bit[x].size() - 1;
  while (l <= r) {
    mid = (l + r) / 2;
    if (bit[x][mid] < p)
      l = mid + 1;
    else {
      ret = mid;
      r = mid - 1;
    }
  }
  if (ret != -1)
    ret = bit[x][ret];
  else
    ret = n + 1;
  return ret;
}
int main() {
  int l, r;
  long long ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  getL();
  getR();
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j <= 30; ++j)
      if (a[i] & (1 << j)) bit[j].push_back(i);
  for (int i = 1; i <= n; ++i) {
    l = 0;
    r = n + 1;
    for (int j = 0; j <= 30; ++j)
      if (!(a[i] & (1 << j))) {
        l = max(l, findL(j, i - 1));
        r = min(r, findR(j, i + 1));
      }
    if (l >= L[i]) ans += 1ll * (l - L[i] + 1) * (R[i] - i + 1);
    if (r <= R[i]) ans += 1ll * (R[i] - r + 1) * (i - L[i] + 1);
    if (l >= L[i] && r <= R[i]) ans -= 1ll * (l - L[i] + 1) * (R[i] - r + 1);
  }
  printf("%I64d\n", ans);
  return 0;
}
