#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, a[N], i, b[40], j, pre[N], nxt[N];
long long ans;
map<int, int> AK;
int main() {
  scanf("%d", &n);
  ans = (long long)n * (n + 1) >> 1;
  for (i = 1; i <= n; ++i) {
    scanf("%d", a + i);
    if (!AK.count(a[i])) AK[a[i]] = 0;
    for (j = 0, pre[i] = AK[a[i]]; j < 30; ++j)
      if (a[i] >> j & 1)
        b[j] = i;
      else
        pre[i] = max(b[j], pre[i]);
    AK[a[i]] = i;
  }
  for (i = 0; i < 30; ++i) b[i] = n + 1;
  for (i = n; i; --i)
    for (j = 0, nxt[i] = n + 1; j < 30; ++j)
      if (a[i] >> j & 1)
        b[j] = i;
      else
        nxt[i] = min(b[j], nxt[i]);
  for (i = 1; i <= n; ++i) ans -= 1ll * (i - pre[i]) * (nxt[i] - i);
  cout << ans << endl;
  return 0;
}
