#include <bits/stdc++.h>
using namespace std;
const int N = 200008;
int n, a[N], b[N], c[N];
int main(void) {
  int i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", a + i);
  a[0] = a[n + 1] = ~0;
  for (i = 1; i <= n; i++) {
    b[i] = i - 1;
    while ((a[i] | a[b[i]]) == a[i]) b[i] = b[b[i]];
  }
  for (i = n; i >= 1; i--) {
    c[i] = i + 1;
    while ((a[i] | a[c[i]]) == a[i] && a[c[i]] < a[i]) c[i] = c[c[i]];
  }
  long long s = (n - 1ll) * n / 2 + n;
  for (i = 1; i <= n; i++) s -= (i - b[i] + 0ll) * (c[i] - i);
  cout << s;
  return 0;
}
