#include <bits/stdc++.h>
using namespace std;
const int HashMod = 1125022017;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int oo = 2e9;
const int nmax = 2e5 + 9;
stack<int> s;
int a[nmax];
int L[nmax];
int R[nmax];
int IT[nmax * 4];
int n;
long long ANS = 0;
void Build(int id, int l, int r) {
  if (l > r) return;
  if (l == r) {
    IT[id] = a[l];
    return;
  }
  int mid = (l + r) / 2;
  Build(id * 2, l, mid);
  Build(id * 2 + 1, mid + 1, r);
  IT[id] = IT[id * 2] | IT[id * 2 + 1];
  return;
}
int Query(int id, int l, int r, int u, int v) {
  if (l > v || r < u) return 0;
  if (l >= u && r <= v) return IT[id];
  int mid = (l + r) / 2;
  return Query(id * 2, l, mid, u, v) | Query(id * 2 + 1, mid + 1, r, u, v);
}
int FindL(int x, int L, int R) {
  int l = L;
  int r = R;
  int ans = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (Query(1, 1, n, mid, R) > x) {
      ans = max(ans, mid);
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return ans;
}
int FindR(int x, int L, int R) {
  int l = L;
  int r = R;
  int ans = oo;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (Query(1, 1, n, L, mid) > x) {
      ans = min(ans, mid);
      r = mid - 1;
    } else
      l = mid + 1;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    while (!s.empty() && a[i] >= a[s.top()]) {
      R[s.top()] = i - 1;
      s.pop();
    }
    if (s.empty())
      L[i] = 1;
    else
      L[i] = s.top() + 1;
    s.push(i);
  }
  while (!s.empty()) {
    R[s.top()] = n;
    s.pop();
  }
  Build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    long long L1 = FindL(a[i], L[i], i);
    long long R1 = FindR(a[i], i, R[i]);
    if (L1 != 0) L1 = L1 - L[i] + 1;
    if (R1 != oo)
      R1 = R[i] - R1 + 1;
    else
      R1 = 0;
    ANS += R1 * (i - L[i] + 1) + L1 * (R[i] - i + 1) - L1 * R1;
  }
  printf("%I64d", ANS);
  return 0;
}
