#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int n, a[N], L[N], R[N];
vector<int> st, bits[32];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < n; ++i) {
    while (!st.empty() && a[st.back()] <= a[i]) st.pop_back();
    if (st.empty())
      L[i] = -1;
    else
      L[i] = st.back();
    st.push_back(i);
  }
  st.clear();
  for (int i = n - 1; i >= 0; --i) {
    while (!st.empty() && a[st.back()] < a[i]) st.pop_back();
    if (st.empty())
      R[i] = n;
    else
      R[i] = st.back();
    st.push_back(i);
  }
  int mxB = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0, x = a[i]; x != 0; ++j, x >>= 1) {
      if ((x & 1) == 1) bits[j].push_back(i);
      mxB = max(mxB, j + 1);
    }
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    int l = 0, r = 0, x = a[i];
    for (int j = 0; j < mxB; ++j, x >>= 1)
      if ((x & 1) == 0) {
        size_t k =
            lower_bound(bits[j].begin(), bits[j].end(), i) - bits[j].begin();
        if (k != bits[j].size()) r = max(r, R[i] - bits[j][k]);
        if (k > 0) l = max(l, bits[j][k - 1] - L[i]);
      }
    res += l + 1LL * l * (R[i] - i - 1);
    res += r + 1LL * r * (i - L[i] - 1);
    res -= 1LL * l * r;
  }
  printf("%lld\n", res);
  return 0;
}
