#include <bits/stdc++.h>
using namespace std;
struct val {
  int mx, o;
  val operator+(const val& a) const { return {max(mx, a.mx), o | a.o}; }
};
class SegmentTree {
 private:
  vector<val> tree;
  int size;

 public:
  SegmentTree(vector<int>& arr) {
    size = 1;
    while (size < (int)arr.size()) size <<= 1;
    tree.resize(size << 1);
    for (int i = 0; i < arr.size(); i++) {
      tree[i + size] = {arr[i], arr[i]};
    }
    for (int i = size - 1; i > 0; i--) {
      tree[i] = tree[i << 1] + tree[i << 1 | 1];
    }
  }
  val value(int l, int r) {
    l += size, r += size;
    val v = {0, 0};
    while (l < r) {
      if (l & 1) v = tree[l] + v;
      if (!(r & 1)) v = v + tree[r];
      ++l, --r;
      l >>= 1, r >>= 1;
    }
    if (l == r) v = v + tree[l];
    return v;
  }
  int o(int l, int r) { return value(l, r).o; }
  int mx(int l, int r) { return value(l, r).mx; }
};
inline void input() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  input();
  int n;
  cin >> n;
  vector<int> arr(n);
  for (auto& i : arr) cin >> i;
  SegmentTree tree(arr);
  int lmax, rmax, lor, ror;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int l = i, r = n;
    while (l < r - 1) {
      int m = (l + r) >> 1;
      if (tree.mx(i + 1, m) >= arr[i])
        r = m;
      else
        l = m;
    }
    rmax = l;
    l = -1, r = i + 1;
    while (l < r - 1) {
      int m = (l + r) >> 1;
      if (tree.mx(m, i) > arr[i])
        l = m;
      else
        r = m;
    }
    lmax = r;
    l = i - 1, r = n;
    while (l < r - 1) {
      int m = (l + r) >> 1;
      if (tree.o(i, m) > arr[i])
        r = m;
      else
        l = m;
    }
    ror = r;
    l = -1, r = i + 1;
    while (l < r - 1) {
      int m = (l + r) >> 1;
      if (tree.o(m, i) > arr[i])
        l = m;
      else
        r = m;
    }
    lor = l;
    long long left = 0, right = 0;
    if (rmax >= ror) right = rmax - ror + 1;
    if (lor >= lmax) left = lor - lmax + 1;
    ans += left * (rmax - i + 1);
    ans += right * (i - lmax + 1);
    ans -= left * right;
  }
  cout << ans;
  return 0;
}
