#include <bits/stdc++.h>
using namespace std;
inline void read(long long &x) {
  long long w = 1;
  char ch = 0;
  x = 0;
  while (ch ^ '-' && (ch < '0' || ch > '9')) ch = getchar();
  if (ch == '-') w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
  x = x * w;
}
long long f[(200005)][(18) + 1], g[(200005)][(18) + 1], pre[(200005)][40],
    nxt[(200005)][40], a[(200005)], n, ans;
inline long long rmq(long long l, long long r) {
  long long d = (double)log2(r - l + 1);
  return f[l][d] > f[r - (1 << d) + 1][d] ? g[l][d] : g[r - (1 << d) + 1][d];
}
inline void solve(long long l, long long r) {
  if (l > r) return;
  long long pos = rmq(l, r), now = a[pos];
  long long left = l - 1, right = r + 1;
  for (long long i = 0; i < 31; i++)
    if (!((1LL << i) & now)) {
      long long L = pre[pos][i], R = nxt[pos][i];
      if (L > pos || R < pos) continue;
      left = ((left) > (L) ? (left) : (L)),
      right = ((right) < (R) ? (right) : (R));
    }
  ans += (left - l + 1) * (r - pos + 1);
  ans += (r - right + 1) * (pos - l + 1);
  ans -= (left - l + 1) * (r - right + 1);
  solve(l, pos - 1), solve(pos + 1, r);
}
int main() {
  read(n);
  for (long long i = 1; i <= n; i++) read(a[i]), f[i][0] = a[i], g[i][0] = i;
  for (long long i = 1; i <= n + 1; i++)
    for (long long j = 0; j < 30; j++) nxt[i][j] = n + 1;
  for (long long i = 1; i <= n; i++)
    for (long long j = 0; j < 30; j++)
      if ((1LL << j) & a[i])
        pre[i][j] = i;
      else
        pre[i][j] = pre[i - 1][j];
  for (long long i = n; i >= 1; i--)
    for (long long j = 0; j < 30; j++)
      if ((1LL << j) & a[i])
        nxt[i][j] = i;
      else
        nxt[i][j] = nxt[i + 1][j];
  for (long long j = 1; j <= (18); j++)
    for (long long i = 1; i <= n; i++) {
      if (i + (1 << j) - 1 > n) continue;
      if (f[i][j - 1] > f[i + (1 << j - 1)][j - 1])
        f[i][j] = f[i][j - 1], g[i][j] = g[i][j - 1];
      else
        f[i][j] = f[i + (1 << j - 1)][j - 1],
        g[i][j] = g[i + (1 << j - 1)][j - 1];
    }
  solve(1, n);
  printf("%I64d", ans);
  return 0;
}
