#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
int n, a[N], l[N], r[N], lor[N], ror[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  stack<int> st;
  st.push(0);
  a[0] = 2e9;
  for (int i = 1; i <= n; ++i) {
    while (a[i] >= a[st.top()]) st.pop();
    l[i] = st.top();
    st.push(i);
  }
  while (!st.empty()) st.pop();
  st.push(0);
  for (int i = 1; i <= n; ++i) {
    while (a[i] >= (a[i] | a[st.top()])) st.pop();
    lor[i] = st.top();
    st.push(i);
  }
  while (!st.empty()) st.pop();
  a[n + 1] = 2e9;
  st.push(n + 1);
  for (int i = n; i >= 1; --i) {
    while (a[st.top()] < a[i]) st.pop();
    r[i] = st.top();
    st.push(i);
  }
  while (!st.empty()) st.pop();
  st.push(n + 1);
  for (int i = n; i >= 1; --i) {
    while ((a[st.top()] | a[i]) <= a[i]) st.pop();
    ror[i] = st.top();
    st.push(i);
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    lor[i] = max(lor[i], l[i]);
    ror[i] = min(ror[i], r[i]);
    ans += (i - l[i]) * 1ll * (r[i] - i);
    ans -= (i - lor[i]) * 1ll * (ror[i] - i);
  }
  printf("%lld\n", ans);
}
