#include <bits/stdc++.h>
using namespace std;
map<long long, long long> m1;
const long long MAXN = 3e5 + 5;
long long arr[MAXN];
long long l[MAXN];
long long r[MAXN];
long long arr2[MAXN];
int main() {
  long long n;
  cin >> n;
  long long ans = n * (n + 1) / 2;
  for (long long i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (long long i = 1; i <= n; i++) {
    l[i] = m1[arr[i]] + 1;
    m1[arr[i]] = i;
    for (long long j = 0; j <= 30; j++) {
      if (!(arr[i] & (1 << j))) {
        l[i] = max(l[i], arr2[j] + 1);
      } else {
        arr2[j] = i;
      }
    }
  }
  for (long long i = 0; i <= 30; i++) {
    arr2[i] = n + 1;
  }
  for (long long i = n; i >= 1; i--) {
    r[i] = n + 1;
    for (long long j = 0; j <= 30; j++) {
      if (!(arr[i] & (1 << j))) {
        r[i] = min(r[i], arr2[j] - 1);
      } else {
        arr2[j] = i;
      }
    }
    ans -= (i - l[i] + 1) * (r[i] - i + 1);
  }
  cout << ans << endl;
}
