#include <bits/stdc++.h>
using namespace std;
int a[200010];
long long l[200010], r[200010], lb[200010], rb[200010];
bool chk(int a, int b) {
  int z = (a | b);
  if (z != b) return false;
  return true;
}
int main() {
  int i, j, n, x;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    l[i] = lb[i] = 0;
    r[i] = rb[i] = n + 1;
  }
  stack<int> st;
  long long ans = 0;
  for (i = 1; i <= n; ++i) {
    while (!st.empty() and a[st.top()] < a[i]) st.pop();
    if (!st.empty()) l[i] = st.top();
    st.push(i);
  }
  while (!st.empty()) st.pop();
  for (i = n; i >= 1; --i) {
    while (!st.empty() and a[st.top()] <= a[i]) st.pop();
    if (!st.empty()) r[i] = st.top();
    st.push(i);
  }
  while (!st.empty()) st.pop();
  for (i = 1; i <= n; ++i) {
    while (!st.empty() and chk(a[st.top()], a[i])) st.pop();
    if (!st.empty()) lb[i] = st.top();
    st.push(i);
  }
  while (!st.empty()) st.pop();
  for (i = n; i >= 1; --i) {
    while (!st.empty() and chk(a[st.top()], a[i])) st.pop();
    if (!st.empty()) rb[i] = st.top();
    st.push(i);
  }
  while (!st.empty()) st.pop();
  for (i = 1; i <= n; ++i) {
    l[i]++;
    r[i]--;
    if (l[i] > lb[i] and r[i] < rb[i]) continue;
    if (l[i] <= lb[i] and r[i] >= rb[i]) {
      ans += (lb[i] - l[i] + 1) * 1LL * (r[i] - rb[i] + 1) +
             (i - lb[i]) * 1LL * (r[i] - rb[i] + 1) +
             (lb[i] - l[i] + 1) * 1LL * (rb[i] - i);
      continue;
    }
    if (l[i] <= lb[i]) {
      ans += (lb[i] - l[i] + 1) * 1LL * (r[i] - i + 1);
      continue;
    }
    if (r[i] >= rb[i]) {
      ans += (i - l[i] + 1) * 1LL * (r[i] - rb[i] + 1);
      continue;
    }
  }
  cout << ans << endl;
  return 0;
}
