#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b, long long c) {
  return max((a), max((b), (c)));
}
long long read() {
  long long x = 0, p = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') p = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ '0');
    c = getchar();
  }
  return x * p;
}
const long long N = 501000;
struct Tree {
  long long l, r, val, Max;
} tr[N << 2];
long long n, a[N], f[N][21];
void build(long long k, long long s, long long t) {
  tr[k].l = s;
  tr[k].r = t;
  if (s == t) {
    tr[k].val = tr[k].Max = a[s];
    return;
  }
  long long mid = s + t >> 1;
  build(k << 1, s, mid);
  build(k << 1 | 1, mid + 1, t);
  tr[k].val = tr[k << 1].val | tr[k << 1 | 1].val;
  tr[k].Max = max(tr[k << 1].Max, tr[k << 1 | 1].Max);
}
long long query_or(long long k, long long l, long long r) {
  long long L = floor(log2(r - l + 1));
  return f[l][L] | f[r - (1 << L) + 1][L];
}
long long get_l(long long x, long long st, long long ed) {
  long long l = st, r = ed, mid, ans = x;
  while (l <= r) {
    mid = l + r >> 1;
    if ((query_or(1, mid, ed) | a[x]) == a[x])
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  return ans;
}
long long get_r(long long x, long long st, long long ed) {
  long long l = st, r = ed, mid, ans = x;
  while (l <= r) {
    mid = l + r >> 1;
    if ((query_or(1, st, mid) | a[x]) == a[x])
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  return ans;
}
map<long long, long long> pos;
int main() {
  n = read();
  for (long long i = 1; i <= n; i++) f[i][0] = a[i] = read();
  for (int j = 1; j < 19; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      f[i][j] = f[i][j - 1] | f[i + (1 << (j - 1))][j - 1];
  long long ans = n * (n + 1) / 2;
  for (long long i = 1; i <= n; i++) {
    long long L = get_l(i, 1, i - 1), R = get_r(i, i + 1, n);
    L = max(L, pos[a[i]] + 1);
    pos[a[i]] = i;
    ans -= 1ll * (i - L + 1) * (R - i + 1);
  }
  cout << ans;
  return 0;
}
