#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
long long ans;
int n, a[MAXN], l[MAXN], r[MAXN];
int main() {
  scanf("%d", &n);
  ans = (1ll * n * (n + 1)) / (1ll * 2);
  a[0] = a[n + 1] = -1;
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= n; ++i) {
    l[i] = i - 1;
    while ((a[i] | a[l[i]]) == a[i]) l[i] = l[l[i]];
  }
  for (int i = n; i >= 1; --i) {
    r[i] = i + 1;
    while ((a[i] | a[r[i]]) == a[i] && a[i] > a[r[i]]) r[i] = r[r[i]];
  }
  for (int i = 1; i <= n; ++i) ans -= 1ll * (i - l[i]) * (r[i] - i);
  printf("%I64d\n", ans);
  return 0;
}
