#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5 + 7;
int a[N];
struct SegmentTree {
  vector<int> x, mx;
  int n;
  SegmentTree(int _n, int* arr) : n(_n) {
    x.resize(4 * n);
    mx.resize(4 * n);
    build(1, 0, n - 1, arr);
  }
  void build(int v, int l, int r, int* arr) {
    if (l == r) {
      x[v] = arr[l];
      mx[v] = l;
    } else {
      int mid = (l + r) >> 1;
      build(v + v, l, mid, arr);
      build(v + v + 1, mid + 1, r, arr);
      x[v] = x[v + v] | x[v + v + 1];
      mx[v] = arr[mx[v + v]] > arr[mx[v + v + 1]] ? mx[v + v] : mx[v + v + 1];
    }
  }
  pair<int, int> get(int v, int l, int r, int L, int R) {
    if (R < L) return {0, n};
    if (l == L && r == R)
      return {x[v], mx[v]};
    else {
      int mid = (l + r) >> 1;
      auto ql = get(v + v, l, mid, L, min(mid, R));
      auto qr = get(v + v + 1, mid + 1, r, max(mid + 1, L), R);
      return {ql.first | qr.first,
              a[qr.second] > a[ql.second] ? qr.second : ql.second};
    }
  }
  int get_or(int l, int r) { return get(1, 0, n - 1, l, r).first; }
  int get_mx(int l, int r) { return get(1, 0, n - 1, l, r).second; }
};
ll res;
void go(int l, int r, SegmentTree& tree) {
  if (r < l) return;
  int mx = tree.get_mx(l, r);
  int ql, qr;
  {
    ql = mx;
    int L = l, R = mx;
    while (L <= R) {
      int mid = (L + R) >> 1;
      if (tree.get_or(mid, mx) == a[mx]) {
        ql = mid;
        R = mid - 1;
      } else
        L = mid + 1;
    }
  }
  {
    int L = mx, R = r;
    qr = mx;
    while (L <= R) {
      int mid = (L + R) >> 1;
      if (tree.get_or(mx, mid) == a[mx]) {
        L = mid + 1;
        qr = mid;
      } else
        R = mid - 1;
    }
  }
  ll mns = (mx - ql + 1) * 1LL * (qr - mx + 1) - 1;
  res -= mns;
  go(l, mx - 1, tree);
  go(mx + 1, r, tree);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  a[n] = -1;
  SegmentTree tree(n, a);
  go(0, n - 1, tree);
  res += n * 1LL * (n - 1) / 2;
  printf("%lld\n", res);
  return 0;
}
