#include <bits/stdc++.h>
using namespace std;
const int inf = ~0u >> 1, MOD = 1e9 + 7;
char *TT, *mo, but[(1 << 15) + 2];
inline int rd() {
  int first, c, f = 1;
  while (!isdigit(
      c = ((TT == mo &&
            (mo = ((TT = but) + fread(but, 1, 1 << 15, stdin)), TT == mo))
               ? -1
               : *TT++)))
    f = c != '-';
  first = c - '0';
  while (isdigit(
      c = ((TT == mo &&
            (mo = ((TT = but) + fread(but, 1, 1 << 15, stdin)), TT == mo))
               ? -1
               : *TT++)))
    first = first * 10 + c - '0';
  return f ? first : -first;
}
const int N = 200010;
int n, c[N];
int Le[N], Ri[N], stk[N], _top;
long long ans, tot;
bool ck(int first) { return (_top && (c[stk[_top]] | c[first]) == c[first]); }
int main() {
  n = rd();
  for (int i = 1; i <= n; i++) c[i] = rd();
  for (int i = 1; i <= n; i++) {
    while (ck(i) && (c[stk[_top]] ^ c[i])) _top--;
    Le[i] = stk[_top] + 1, stk[++_top] = i;
  }
  _top = 0;
  for (int i = n; i; i--) {
    while (ck(i)) _top--;
    Ri[i] = (!_top) ? n : stk[_top] - 1, stk[++_top] = i;
  }
  ans = 1LL * n * (n - 1) / 2;
  for (int i = 1; i <= n; i++) {
    tot += (Ri[i] - Le[i]);
    tot += 1LL * (i - Le[i]) * (Ri[i] - i);
  }
  cout << ans - tot << endl;
}
