#include <bits/stdc++.h>
using namespace std;
int a[200009], pre[200009][33], suf[200009][33], lft[200009], rgt[200009];
stack<int> s1;
int main() {
  int i, j, t1, t2, t3, t4, n, l, r;
  long long int ans, buf1;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j < 31; j++) {
      if ((1 << j) & a[i]) {
        pre[i][j] = i;
      } else {
        pre[i][j] = pre[i - 1][j];
      }
    }
  }
  for (j = 0; j < 31; j++) {
    suf[n + 1][j] = n + 1;
  }
  for (i = n; i >= 1; i--) {
    for (j = 0; j < 31; j++) {
      if ((1 << j) & a[i]) {
        suf[i][j] = i;
      } else {
        suf[i][j] = suf[i + 1][j];
      }
    }
  }
  a[0] = a[n + 1] = 2e9;
  s1.push(0);
  for (i = 1; i <= n; i++) {
    while (a[s1.top()] <= a[i]) {
      s1.pop();
    }
    lft[i] = s1.top() + 1;
    s1.push(i);
  }
  while (!s1.empty()) {
    s1.pop();
  }
  s1.push(n + 1);
  for (i = n; i >= 1; i--) {
    while (a[s1.top()] < a[i]) {
      s1.pop();
    }
    rgt[i] = s1.top() - 1;
    s1.push(i);
  }
  ans = 1ll * n * (n + 1);
  ans /= 2;
  for (i = 1; i <= n; i++) {
    l = 1;
    r = n;
    for (j = 0; j < 31; j++) {
      if (!((1 << j) & a[i])) {
        l = max(l, pre[i][j] + 1);
        r = min(r, suf[i][j] - 1);
      }
    }
    l = max(l, lft[i]);
    r = min(r, rgt[i]);
    buf1 = 1ll * (i - l + 1) * (r - i + 1);
    ans -= buf1;
  }
  printf("%lld\n", ans);
  return 0;
}
