#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  x = 0;
  T f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do x = x * 10 + ch - '0', ch = getchar();
  while (ch <= '9' && ch >= '0');
  x *= f;
}
template <typename A, typename B>
inline void read(A &x, B &y) {
  read(x);
  read(y);
}
template <typename A, typename B, typename C>
inline void read(A &x, B &y, C &z) {
  read(x);
  read(y);
  read(z);
}
template <typename A, typename B, typename C, typename D>
inline void read(A &x, B &y, C &z, D &w) {
  read(x);
  read(y);
  read(z);
  read(w);
}
map<int, int> pre;
const int maxn = 200005;
int Log[maxn];
int st[maxn][20];
int a[maxn], n;
void initst() {
  Log[0] = -1;
  for (int i = 1; i <= n; i++) {
    Log[i] = ((i & (i - 1)) == 0) ? Log[i - 1] + 1 : Log[i - 1];
    st[i][0] = a[i];
  }
  for (int j = 1; j <= Log[n]; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      st[i][j] = st[i][j - 1] | st[i + (1 << (j - 1))][j - 1];
}
inline int query(int x, int y) {
  int k = Log[y - x + 1];
  return st[x][k] | st[y - (1 << k) + 1][k];
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) read(a[i]);
  initst();
  long long res = (long long)n * (n + 1) / 2;
  for (int i = 1; i <= n; i++) {
    int l, r, mid, ff, rr;
    l = 1;
    r = i;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (query(mid, i) == a[i])
        r = mid - 1;
      else
        l = mid + 1;
    }
    ff = l;
    l = i, r = n;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (query(i, mid) == a[i])
        l = mid + 1;
      else
        r = mid - 1;
    }
    rr = r;
    int t = pre[a[i]];
    pre[a[i]] = i;
    if (ff <= t) ff = t + 1;
    res -= (long long)(rr - i + 1ll) * (i - ff + 1);
  }
  cout << res << endl;
  return 0;
}
