#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 10, lg = 30;
long long a[maxn];
struct sparse {
  long long arr[lg][maxn];
  void init(long long n) {
    for (long long i = 0; i < n; ++i) arr[0][i] = a[i];
    for (long long i = 1; (1 << i) <= n; ++i) {
      for (long long j = 0; j + (1 << i) <= n; ++j)
        arr[i][j] = (arr[i - 1][j] | arr[i - 1][j + (1 << (i - 1))]);
    }
  }
  long long query(long long l, long long r) {
    long long p = 31 - __builtin_clz(r - l + 1);
    return arr[p][l] | arr[p][r - (1 << p) + 1];
  }
} sp;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; ++i) cin >> a[i];
  sp.init(n);
  map<long long, long long> pos;
  long long ans = n * 1ll * (n - 1) / 2;
  for (long long i = 0; i < n; ++i) {
    long long d = 1;
    while (d <= n) d <<= 1;
    long long l = i, r = i;
    while (d >>= 1) {
      if (l - d >= 0)
        if (sp.query(l - d, i) == a[i]) l -= d;
      if (r + d < n)
        if (sp.query(i, r + d) == a[i]) r += d;
    }
    if (pos.find(a[i]) != pos.end()) l = max(l, pos[a[i]] + 1);
    ans -= (r - i + 1) * (i - l + 1) - 1;
    pos[a[i]] = i;
  }
  cout << ans << endl;
  return 0;
}
