#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int N, a[MAXN], lef[MAXN], rig[MAXN], lfor[MAXN], rgor[MAXN];
int dig[35];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < (int)(N); ++i) scanf("%d", &a[i]);
  int stk[MAXN], kt = 0;
  lef[0] = -1, stk[kt++] = 0;
  for (int i = 1; i <= (int)(N - 1); ++i) {
    while (kt && a[stk[kt - 1]] < a[i]) kt--;
    lef[i] = kt == 0 ? -1 : stk[kt - 1];
    stk[kt++] = i;
  }
  rig[N - 1] = N;
  kt = 0;
  stk[kt++] = N - 1;
  for (int i = N - 2; i >= 0; --i) {
    while (kt && a[stk[kt - 1]] <= a[i]) kt--;
    rig[i] = kt == 0 ? N : stk[kt - 1];
    stk[kt++] = i;
  }
  for (int i = 0; i < (int)(30); ++i) dig[i] = -1;
  for (int i = 0; i < (int)(N); ++i) {
    lfor[i] = lef[i];
    for (int j = 0; j < (int)(30); ++j) {
      if (a[i] >> j & 1)
        dig[j] = i;
      else
        lfor[i] = max(lfor[i], dig[j]);
    }
  }
  for (int i = 0; i < (int)(30); ++i) dig[i] = N;
  for (int i = N - 1; i >= 0; --i) {
    rgor[i] = rig[i];
    for (int j = 0; j < (int)(30); ++j) {
      if (a[i] >> j & 1)
        dig[j] = i;
      else
        rgor[i] = min(rgor[i], dig[j]);
    }
  }
  long long ret = 0;
  for (int i = 0; i < (int)(N); ++i) {
    ret +=
        1ll * (i - lef[i]) * (rig[i] - i) - 1ll * (i - lfor[i]) * (rgor[i] - i);
  }
  printf("%lld\n", ret);
  return 0;
}
