#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
int n, a[200005], l[200005], r[200005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  a[0] = a[n + 1] = -1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    l[i] = i - 1;
    while ((a[i] | a[l[i]]) == a[i]) {
      l[i] = l[l[i]];
    }
  }
  for (int i = n; i >= 1; 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 = (1ll * n * (n + 1)) >> 1;
  for (int i = 1; i <= n; i++) {
    ans -= 1ll * (i - l[i]) * (r[i] - i);
  }
  cout << ans << endl;
  return 0;
}
