#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 9;
long long l[maxn], r[maxn];
int n;
int arr[maxn];
int main() {
  scanf("%d", &n);
  long long ans = n;
  ans *= (ans + 1);
  ans /= 2ll;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
  }
  stack<int> sta;
  sta.push(1);
  for (int i = 2; i <= n; i++) {
    while (sta.size()) {
      int e = sta.top();
      if ((arr[e] | arr[i]) != arr[e]) {
        r[e] = i - 1;
        sta.pop();
        continue;
      }
      break;
    }
    sta.push(i);
  }
  while (!sta.empty()) {
    int e = sta.top();
    r[e] = n;
    sta.pop();
  }
  sta.push(n);
  for (int i = n - 1; i > 0; i--) {
    while (sta.size()) {
      int e = sta.top();
      if ((arr[e] | arr[i]) != arr[e]) {
        l[e] = i + 1;
        sta.pop();
        continue;
      }
      break;
    }
    while (sta.size() && arr[sta.top()] == arr[i]) {
      l[sta.top()] = i + 1;
      sta.pop();
    }
    sta.push(i);
  }
  while (!sta.empty()) {
    int e = sta.top();
    sta.pop();
    l[e] = 1;
  }
  long long tol = 0;
  for (int i = 1; i <= n; i++) {
    l[i] = i - l[i] + 1;
    r[i] = r[i] - i + 1;
    ans -= (l[i]) * (r[i]);
  }
  tol /= 2;
  ans -= tol;
  cout << ans << endl;
}
