#include <bits/stdc++.h>
using namespace std;
stack<pair<long long, long long> > s;
long long l[200111], d[200111], arr[200111];
long long bit[55];
int main() {
  long long n;
  scanf("%lld", &n);
  for (long long i = 0; i < n; i++) scanf("%lld", arr + i);
  s.push(make_pair(1e9 + 11111, -1));
  for (long long i = 0; i <= 31; i++) bit[i] = -1;
  for (long long i = 0; i < n; i++) {
    while (arr[i] >= s.top().first) s.pop();
    l[i] = s.top().second + 1;
    s.push(make_pair(arr[i], i));
    for (long long j = 0; j <= 31; j++) {
      if (arr[i] & (1 << j))
        bit[j] = i;
      else
        l[i] = max(l[i], bit[j] + 1);
    }
  }
  while (!s.empty()) s.pop();
  s.push(make_pair(1e9 + 11111, n));
  for (long long i = 0; i <= 31; i++) bit[i] = n;
  for (long long i = n - 1; i >= 0; i--) {
    while (arr[i] > s.top().first) s.pop();
    d[i] = s.top().second - 1;
    s.push(make_pair(arr[i], i));
    for (long long j = 0; j <= 31; j++) {
      if (arr[i] & (1 << j))
        bit[j] = i;
      else
        d[i] = min(d[i], bit[j] - 1);
    }
  }
  long long all = n * (n + 1) / 2LL;
  long long minus = 0;
  for (long long i = 0; i < n; i++)
    minus += 1LL * (i - l[i] + 1) * (d[i] - i + 1);
  printf("%lld\n", all - minus);
  return 0;
}
