#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn], L[maxn], R[maxn];
int nxt[maxn][31], pre[maxn][31];
int n;
int main() {
  iostream::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  stack<int> st;
  st.push(0);
  a[0] = 1e9 + 5;
  for (int i = 1; i <= n; ++i) {
    while (a[st.top()] <= a[i]) st.pop();
    L[i] = st.top() + 1;
    st.push(i);
  }
  while (st.size()) st.pop();
  st.push(n + 1);
  a[n + 1] = 1e9 + 5;
  for (int i = n; i > 0; --i) {
    while (a[st.top()] < a[i]) st.pop();
    R[i] = st.top() - 1;
    st.push(i);
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= 30; ++j)
      if (a[i] >> j & 1)
        pre[i][j] = i;
      else
        pre[i][j] = pre[i - 1][j];
  }
  memset(nxt[n + 1], 127, sizeof(nxt[n + 1]));
  for (int i = n; i > 0; --i) {
    for (int j = 0; j <= 30; ++j)
      if (a[i] >> j & 1)
        nxt[i][j] = i;
      else
        nxt[i][j] = nxt[i + 1][j];
  }
  int64_t res = 0;
  for (int i = 1; i <= n; ++i) {
    int l = L[i] - 1, r = R[i] + 1;
    for (int j = 0; j <= 30; ++j)
      if (!(a[i] >> j & 1)) {
        l = max(l, pre[i - 1][j]);
        r = min(r, nxt[i + 1][j]);
      }
    res += 1ll * (R[i] - i + 1) * (i - L[i] + 1) - 1ll * (r - i) * (i - l);
  }
  cout << res;
  return 0;
}
