#include <bits/stdc++.h>
#pragma diag_suppress 177
using namespace std;
const int MM = 220000;
int m, n, k, p1, p2, p3, f, a[MM], pr[MM], af[MM], tree[4 * MM];
string s, s1, s2;
int MINN = 0;
int func(int aa, int bb) { return (aa | bb); }
void build(int node, int start, int end) {
  if (start == end)
    tree[node] = a[start];
  else {
    int mid = (start + end) / 2;
    build(2 * node, start, mid);
    build(2 * node + 1, mid + 1, end);
    tree[node] = func(tree[2 * node], tree[2 * node + 1]);
  }
}
int query(int node, int start, int end, int l, int r) {
  if (r < start or end < l) return MINN;
  if (l <= start and end <= r) return tree[node];
  int mid = (start + end) / 2;
  int px1 = query(2 * node, start, mid, l, r);
  int px2 = query(2 * node + 1, mid + 1, end, l, r);
  return func(px1, px2);
}
bool chk(int hi, int mid, int val) {
  return (query(1, 0, n - 1, mid, hi) > val);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  int cur;
  priority_queue<pair<int, int> > pq;
  vector<int> ind;
  for (int i = 0; i < n; i++) {
    cur = i;
    while (!ind.empty() && a[ind.back()] <= a[i]) {
      cur = pr[ind.back()];
      ind.pop_back();
    }
    pr[i] = cur;
    ind.push_back(i);
  }
  ind.clear();
  for (int i = n - 1; i >= 0; i--) {
    cur = i;
    while (!ind.empty() && a[ind.back()] < a[i]) {
      cur = af[ind.back()];
      ind.pop_back();
    }
    af[i] = cur;
    ind.push_back(i);
  }
  long long ans = 0;
  build(1, 0, n - 1);
  int ls, rs, hi, lo, mid, xx, yy;
  for (int i = 0; i < n; i++) {
    ls = i - pr[i] + 1;
    rs = af[i] - i + 1;
    hi = i;
    lo = pr[i];
    while (hi > lo) {
      mid = (hi + lo) / 2;
      if (chk(i, mid, a[i]))
        lo = mid + 1;
      else
        hi = mid;
    }
    xx = i - lo + 1;
    ans += (long long)ls * (long long)rs;
    hi = af[i];
    lo = i;
    while (hi > lo) {
      mid = (hi + lo) / 2;
      if (chk(mid, i, a[i]))
        hi = mid;
      else
        lo = mid + 1;
    }
    if (chk(lo, i, a[i])) lo--;
    yy = lo - i + 1;
    ans -= (long long)xx * (long long)yy;
  }
  printf("%lld", ans);
  return 0;
}
