#include <bits/stdc++.h>
using namespace std;
namespace READ {
inline int nxt() {
  int n;
  scanf("%d", &n);
  return n;
}
inline long long lnxt() {
  long long n;
  scanf("%I64d", &n);
  return n;
}
const int inf = 1000 * 1000 * 1000;
const long long linf = (long long)inf * (long long)inf;
const long long mod = 1000 * 1000 * 1000 + 7;
const int num = 1000 * 1000 + 7;
const int N = 256;
const long double PI = acos((long double)-1.0);
}  // namespace READ
using namespace READ;
int a[num];
int pre[num], suf[num], b[num], d[num], near_le[num], near_ra[num];
void solve() {
  int n = nxt();
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1; i <= n; ++i) {
    for (int ast = 0; ast <= 30; ++ast) {
      if (a[i] & (1 << ast))
        b[ast] = i;
      else
        pre[i] = max(pre[i], b[ast]);
    }
  }
  for (int i = n; i >= 1; i--) {
    suf[i] = n + 1;
    near_ra[n + 1] = n + 1;
    for (int ast = 0; ast <= 30; ++ast) {
      if (a[i] & (1 << ast)) {
        d[ast] = i;
      } else if (d[ast])
        suf[i] = min(suf[i], d[ast]);
    }
  }
  long long ans = ((long long)n) * ((long long)n + 1ll) / 2ll;
  for (int i = n; i >= 1; i--) {
    int pos = i + 1;
    while (pos <= n && a[pos] <= a[i]) pos = near_ra[pos];
    near_ra[i] = pos;
  }
  for (int i = 1; i <= n; ++i) {
    int pos = i - 1;
    while (pos > 0 && a[pos] < a[i]) pos = near_le[pos];
    near_le[i] = pos;
    int le = max(near_le[i], pre[i]) + 1;
    int ra = min(near_ra[i], suf[i]) - 1;
    ans -= (long long)(ra - i + 1) * (long long)(i - le + 1);
  }
  cout << ans << endl;
}
int main() {
  for (int i = 0; i < 1; ++i) {
    solve();
  }
  return 0;
}
