#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, a[N], bit[35], l[N], r[N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  map<int, int> pre;
  for (int i = 1; i <= n; ++i) {
    l[i] = pre[a[i]];
    for (int j = 0; j < 31; ++j)
      if (((a[i] >> j) & 1) == 0) l[i] = max(l[i], bit[j]);
    for (int j = 0; j < 31; ++j)
      if ((a[i] >> j) & 1) bit[j] = i;
    pre[a[i]] = i;
  }
  for (int i = 0; i < 35; ++i) bit[i] = n + 1;
  for (int i = n; i >= 1; --i) {
    r[i] = n + 1;
    for (int j = 0; j < 31; ++j)
      if (((a[i] >> j) & 1) == 0) r[i] = min(r[i], bit[j]);
    for (int j = 0; j < 31; ++j)
      if ((a[i] >> j) & 1) bit[j] = i;
  }
  long long ans = 1ll * n * (n + 1) / 2;
  for (int i = 1; i <= n; ++i) ans -= 1ll * (i - l[i]) * (r[i] - i);
  printf("%lld\n", ans);
  return 0;
}
