#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long read() {
  long long s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * f;
}
const long long maxn = 5e5 + 10;
long long a[maxn], st[maxn][20], st2[maxn][20], lg[maxn], ans;
void build() {
  for (long long j = 1; j <= lg[n]; ++j) {
    for (long long i = 1; i <= n; ++i) {
      st[i][j] = max(st[i][j - 1], st[min(i + (1 << (j - 1)), n)][j - 1]);
      st2[i][j] = st2[i][j - 1] | st2[min(i + (1 << (j - 1)), n)][j - 1];
    }
  }
}
long long query1(long long l, long long r) {
  long long len = lg[r - l + 1];
  return max(st[l][len], st[r - (1 << len) + 1][len]);
}
long long query2(long long l, long long r) {
  long long len = lg[r - l + 1];
  return st2[l][len] | st2[r - (1 << len) + 1][len];
}
long long solve(long long x) {
  long long l = 1, r = x - 1;
  long long ans1 = x, ans2 = x;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (query1(mid, x - 1) < a[x] && query2(mid, x) <= a[x]) {
      ans1 = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  l = x + 1, r = n;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (query1(x + 1, mid) <= a[x] && query2(x, mid) <= a[x]) {
      ans2 = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return (x - ans1 + 1) * (ans2 - x + 1);
}
signed main() {
  n = read();
  for (long long i = 1; i <= n; ++i) {
    a[i] = read();
    st[i][0] = st2[i][0] = a[i];
  }
  lg[0] = -1;
  long long anss = n * (n + 1) / 2;
  for (long long i = 1; i <= n; ++i) {
    lg[i] = lg[i >> 1] + 1;
  }
  build();
  for (long long i = 1; i <= n; ++i) {
    anss -= solve(i);
  }
  cout << anss;
}
