#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, y = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') y = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return y ? -x : x;
}
template <typename T>
inline T read() {
  T x = 0;
  int y = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') y = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return y ? -x : x;
}
int a[200005], f[200005][20], g[200005][20], lg[200005];
long long ans;
inline int Max(int x, int y) { return a[x] > a[y] ? x : y; }
void ST(int n) {
  for (register int i = 2; i <= n; ++i) lg[i] = lg[i >> 1] + 1;
  for (register int j = 1; j <= lg[n]; ++j)
    for (register int i = 1; i + (1 << j - 1) <= n; ++i)
      f[i][j] = f[i][j - 1] | f[i + (1 << j - 1)][j - 1],
      g[i][j] = Max(g[i][j - 1], g[i + (1 << j - 1)][j - 1]);
}
inline int query1(int l, int r) {
  int len = lg[r - l + 1];
  return f[l][len] | f[r - (1 << len) + 1][len];
}
inline int query2(int l, int r) {
  int len = lg[r - l + 1];
  return Max(g[l][len], g[r - (1 << len) + 1][len]);
}
void solve(int l, int r) {
  if (l >= r) {
    if (l == r) ++ans;
    return;
  }
  int pos = query2(l, r), L = l, R = pos, res, mid;
  while (L < R) {
    mid = L + R >> 1;
    if ((query1(mid, pos) | a[pos]) == a[pos])
      R = mid;
    else
      L = mid + 1;
  }
  res = pos - L + 1, L = pos, R = r;
  while (L < R) {
    mid = L + R + 1 >> 1;
    if ((query1(pos, mid) | a[pos]) == a[pos])
      L = mid;
    else
      R = mid - 1;
  }
  ans += 1ll * (L - pos + 1) * res;
  solve(l, pos - 1), solve(pos + 1, r);
}
signed main() {
  int n = read();
  for (register int i = 1; i <= n; ++i) a[i] = f[i][0] = read(), g[i][0] = i;
  ST(n), solve(1, n);
  printf("%I64d\n", (1ll * n * (n + 1) >> 1) - ans);
}
