#include <bits/stdc++.h>
using namespace std;
long long n, t1, t2, t3, t4, ans, l, r, md, a[200005], b[530000], k1[200005],
    k2[200005];
map<long long, long long> v;
stack<long long> e;
long long f(long long p, long long q) {
  long long w = 0;
  while (p < q) {
    if ((p & 1) == 1) w = max(w, b[p++]);
    if ((q & 1) == 0) w = max(w, b[q--]);
    p >>= 1;
    q >>= 1;
  }
  if (p == q) w = max(w, b[p]);
  return w;
}
int main() {
  long long i, k, t;
  cin >> n;
  for (k = 1; k < n; k *= 2)
    ;
  for (i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    b[k + i - 1] = a[i];
  }
  for (i = k - 1; i >= 1; i--) {
    b[i] = max(b[i * 2], b[i * 2 + 1]);
  }
  for (i = 1; i <= n; i++) {
    while (!e.empty()) {
      t = e.top();
      if ((a[t] | a[i]) == a[t]) break;
      e.pop();
      k1[t] = i;
    }
    e.push(i);
  }
  while (!e.empty()) {
    t = e.top();
    e.pop();
    k1[t] = n + 1;
  }
  for (i = n; i >= 1; i--) {
    while (!e.empty()) {
      t = e.top();
      if ((a[t] | a[i]) == a[t]) break;
      e.pop();
      k2[t] = i;
    }
    e.push(i);
  }
  while (!e.empty()) {
    t = e.top();
    e.pop();
    k2[t] = -1;
  }
  for (i = 1; i <= n; i++) {
    t1 = k2[i];
    t2 = i + 1;
    l = v[a[i]] + 1;
    r = i;
    while (l < r) {
      md = (l + r) / 2;
      if (f(k + md - 1, k + i - 2) > a[i]) {
        l = md + 1;
      } else {
        r = md;
        t2 = min(t2, md);
      }
    }
    t3 = k1[i];
    t4 = i - 1;
    l = i + 1;
    r = n + 1;
    while (l < r) {
      md = (l + r) / 2;
      if (f(k + i, k + md - 1) > a[i]) {
        r = md;
      } else {
        l = md + 1;
        t4 = max(t4, md);
      }
    }
    ans += max((t1 - t2 + 1), 0ll) * max((t4 - i), 0ll);
    ans += max((t4 - t3 + 1), 0ll) * max((i - t2), 0ll);
    ans -= max((t1 - t2 + 1), 0ll) * max((t4 - t3 + 1), 0ll);
    ans += max((t1 - t2 + 1), 0ll);
    ans += max((t4 - t3 + 1), 0ll);
    v[a[i]] = i;
  }
  cout << ans;
  return 0;
}
