#include <bits/stdc++.h>
using namespace std;
const long long md = 1e9 + 7;
long long a[200005], n, l[200005], r[200005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long q, m, h, k, ans = 0, sum = 0, p, x, y;
  cin >> n;
  a[0] = a[n + 1] = -1;
  for (int i = 1; i <= n; cin >> a[i++])
    ;
  for (int i = 1; i <= n; ++i) {
    l[i] = i - 1;
    while ((a[l[i]] | a[i]) == a[i]) l[i] = l[l[i]];
  }
  for (int i = n; i > 0; --i) {
    r[i] = i + 1;
    while ((a[r[i]] | a[i]) == a[i] && a[r[i]] < a[i]) r[i] = r[r[i]];
  }
  for (int i = 1; i <= n; ++i) ans += (i - l[i]) * (r[i] - i);
  cout << n * (n + 1) / 2 - ans;
}
