#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long power(long long a, long long n) {
  a %= 1000000007;
  if (n == 1) return a;
  if (n == 0) return 1;
  if (n % 2)
    return (a * (power((a * a) % 1000000007, n / 2) % 1000000007)) % 1000000007;
  return power((a * a) % 1000000007, n / 2) % 1000000007;
}
const long long inf = (long long)1e18;
long long inverse(long long x) { return power(x, 1000000007 - 2) % 1000000007; }
long long n;
vector<long long> v(1000005);
vector<pair<long long, long long> > u(1000005);
const long long N = 1e6 + 1;
const long long K = 21;
long long table[N + 5][K + 5];
long long numlog[N + 5];
void build() {
  numlog[1] = 0;
  for (long long i = 2; i < N; i++) numlog[i] = numlog[i / 2] + 1;
  for (long long i = 1; i <= n; i++) table[i][0] = v[i];
  for (long long j = 1; j < K; j++)
    for (long long i = 1; i + (1 << j) - 1 <= n; i++)
      table[i][j] = (table[i][j - 1] | table[i + (1 << (j - 1))][j - 1]);
}
long long query(long long l, long long r) {
  long long curlog = numlog[r - l + 1];
  return (table[l][curlog] | table[r - (1 << curlog) + 1][curlog]);
}
void solve() {
  cin >> n;
  for (long long i = 1; i < n + 1; ++i) cin >> v[i], u[i] = {v[i], i};
  build();
  sort(u.begin() + 1, u.begin() + n + 1,
       greater<pair<long long, long long> >());
  long long ans = (n * (n + 1)) / 2;
  set<long long> done;
  for (long long i = 1; i < n + 1; ++i) {
    long long pos = u[i].second, st, la;
    auto it = done.lower_bound(pos);
    if (it == done.end())
      la = n;
    else
      la = (*it) - 1;
    if (it == done.begin())
      st = 1;
    else
      --it, st = (*it) + 1;
    long long lo = pos, hi = la, l, r;
    while (lo < hi) {
      long long mid = (lo + hi + 1) / 2, val = query(pos, mid);
      if ((val & v[pos]) == val)
        lo = mid;
      else
        hi = mid - 1;
    }
    r = lo;
    lo = st, hi = pos;
    while (lo < hi) {
      long long mid = (lo + hi) / 2, val = query(mid, pos);
      if ((val & v[pos]) == val)
        hi = mid;
      else
        lo = mid + 1;
    }
    l = lo;
    ans -= (r - pos + 1) * (pos - l + 1);
    done.insert(pos);
  }
  cout << ans << "\n";
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long T = 1;
  for (long long t = 1; t < T + 1; ++t) {
    solve();
    cout << "\n";
  }
  return 0;
}
