#include <bits/stdc++.h>
using namespace std;
long long n, h[200005], l[200005], r[200005], ans;
stack<int> st;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  ans = (n * (n + 1)) / 2;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    while (!st.empty() && (h[st.top()] | h[i]) == h[i]) {
      if (h[st.top()] == h[i]) break;
      st.pop();
    }
    if (st.empty())
      l[i] = 0;
    else
      l[i] = st.top();
    st.push(i);
  }
  while (!st.empty()) st.pop();
  for (int i = n; i >= 1; i--) {
    while (!st.empty() && (h[st.top()] | h[i]) == h[i]) {
      st.pop();
    }
    if (st.empty())
      r[i] = n + 1;
    else
      r[i] = st.top();
    st.push(i);
    ans -= ((r[i] - i) * (i - l[i]));
  }
  cout << ans;
  return 0;
}
