#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int a[200005], lef[200005], rigt[200005], pos[32], n;
long long ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  ans = (long long)n * (n + 1) / 2;
  for (int i = 0; i < 30; i++) pos[i] = 0;
  for (int i = 1; i <= n; i++) {
    lef[i] = mp[a[i]];
    for (int j = 0; j < 30; j++)
      if ((a[i] & (1 << j)) == 0) lef[i] = max(lef[i], pos[j]);
    for (int j = 0; j < 30; j++)
      if ((a[i] & (1 << j)) > 0) pos[j] = i;
    mp[a[i]] = i;
  }
  for (int i = 0; i < 30; i++) pos[i] = n + 1;
  for (int i = n; i >= 1; i--) {
    rigt[i] = n + 1;
    for (int j = 0; j < 30; j++)
      if ((a[i] & (1 << j)) == 0) rigt[i] = min(rigt[i], pos[j]);
    for (int j = 0; j < 30; j++)
      if ((a[i] & (1 << j)) > 0) pos[j] = i;
  }
  for (int i = 1; i <= n; i++) ans -= (long long)(i - lef[i]) * (rigt[i] - i);
  printf("%I64d\n", ans);
  return 0;
}
