#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n;
long long A[N];
long long L[32][N], R[32][N], last[32], mxL[N], mxR[N];
int main() {
  cin >> n;
  for (int x = 0, qwerty = n; x < qwerty; x++) cin >> A[x];
  for (int i = 0, qwerty = 32; i < qwerty; i++) last[i] = -1;
  for (int x = 0, qwerty = n; x < qwerty; x++) {
    for (int i = 0, qwerty = 32; i < qwerty; i++)
      if ((1LL << i) & A[x]) last[i] = x;
    for (int i = 0, qwerty = 32; i < qwerty; i++) L[i][x] = last[i];
  }
  for (int i = 0, qwerty = 32; i < qwerty; i++) last[i] = n;
  for (int x = n - 1; x >= 0; x--) {
    for (int i = 0, qwerty = 32; i < qwerty; i++)
      if ((1LL << i) & A[x]) last[i] = x;
    for (int i = 0, qwerty = 32; i < qwerty; i++) R[i][x] = last[i];
  }
  stack<pair<long long, long long> > st;
  st.push({2e9, -1});
  for (int x = 0, qwerty = n; x < qwerty; x++) {
    while (st.top().first < A[x]) st.pop();
    mxL[x] = st.top().second;
    st.push({A[x], x});
  }
  while (!st.empty()) st.pop();
  st.push({2e9, n});
  for (int x = n - 1; x >= 0; x--) {
    while (st.top().first <= A[x]) st.pop();
    mxR[x] = st.top().second;
    st.push({A[x], x});
  }
  long long ans = 0;
  for (int x = 0, qwerty = n; x < qwerty; x++) {
    long long l = mxL[x], r = mxR[x];
    for (int i = 0, qwerty = 32; i < qwerty; i++)
      if (!((1LL << i) & A[x])) {
        l = max(l, 1LL * L[i][x]);
        r = min(r, 1LL * R[i][x]);
      }
    long long tmp1 = max(0LL, 1LL * l - mxL[x]);
    long long tmp2 = max(0LL, mxR[x] - 1LL * r);
    ans += tmp1 * (mxR[x] - x * 1LL);
    ans += tmp2 * (x * 1LL - l);
  }
  cout << ans << "\n";
}
