#include <bits/stdc++.h>
using namespace std;
long long n, a[300000], l[300000], r[300000];
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  a[0] = a[n + 1] = -1;
  for (long long i = 1; i <= n; i++) {
    l[i] = i - 1;
    while ((a[i] | a[l[i]]) == a[i]) l[i] = l[l[i]];
  }
  for (long long i = n; i > 0; i--) {
    r[i] = i + 1;
    while ((a[i] | a[r[i]]) == a[i] && a[r[i]] < a[i]) r[i] = r[r[i]];
  }
  long long ans = n * (n + 1) >> 1;
  for (long long i = 1; i <= n; i++) ans -= (i - l[i]) * (r[i] - i);
  cout << ans << endl;
  return 0;
}
