#include <bits/stdc++.h>
using namespace std;
const double g = 10.0, eps = 1e-7;
const int N = 500000 + 10, maxn = 10000 + 10, inf = 0x3f3f3f;
int a[N], l[N], r[N], pos[32];
map<int, int> last;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    l[i] = last[a[i]];
    for (int j = 0; j < 32; j++)
      if ((a[i] & (1 << j)) == 0) l[i] = max(l[i], pos[j]);
    for (int j = 0; j < 32; j++)
      if ((a[i] & (1 << j)) > 0) pos[j] = i;
    last[a[i]] = i;
  }
  for (int i = 0; i < 32; i++) pos[i] = n + 1;
  for (int i = n; i >= 1; i--) {
    r[i] = n + 1;
    for (int j = 0; j < 32; j++)
      if ((a[i] & (1 << j)) == 0) r[i] = min(r[i], pos[j]);
    for (int j = 0; j < 32; j++)
      if ((a[i] & (1 << j)) > 0) pos[j] = i;
  }
  long long ans = (long long)n * (n + 1) / 2;
  for (int i = 1; i <= n; i++) {
    long long t1 = i - l[i], t2 = r[i] - i;
    ans -= t1 * t2;
  }
  printf("%lld\n", ans);
  return 0;
}
