#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int l[MAXN];
int r[MAXN];
int v[MAXN];
stack<int> s, s1;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    l[i] = -1;
    r[i] = n;
  }
  for (int i = 0; i < n; i++) {
    if (s.size()) {
      while (s.size() && ((v[s.top()] | v[i]) == v[i])) {
        if (v[s.top()] == v[i]) break;
        s.pop();
      }
      if (s.size()) l[i] = s.top();
    }
    s.push(i);
  }
  long long ans = 1LL * n * (n + 1) / 2LL;
  for (int i = n - 1; i >= 0; i--) {
    if (s1.size()) {
      while (s1.size() && ((v[s1.top()] | v[i]) == v[i])) {
        s1.pop();
      }
      if (s1.size()) r[i] = s1.top();
    }
    s1.push(i);
    ans -= 1LL * (r[i] - i) * (i - l[i]);
  }
  cout << ans << '\n';
  return 0;
}
