#include <bits/stdc++.h>
using namespace std;
const int lim = 31;
long long ans;
map<int, int> s;
int i, j, k, n, m, pre[310001], a[310001], b[310001][31], c[310001][31], t1, t2;
int main() {
  scanf("%d", &n);
  ans = ((long long)n * (long long)(n + 1)) / 2LL;
  for (i = 0; i < lim; i++) b[0][i] = 0, c[n + 1][i] = n + 1;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (!s.count(a[i]))
      pre[i] = 0;
    else
      pre[i] = s[a[i]];
    s[a[i]] = i;
    for (j = 0; j < lim; j++)
      if ((a[i] >> j) & 1)
        b[i][j] = i;
      else
        b[i][j] = b[i - 1][j];
  }
  for (i = n; i; i--)
    for (j = 0; j < lim; j++)
      if ((a[i] >> j) & 1)
        c[i][j] = i;
      else
        c[i][j] = c[i + 1][j];
  for (i = 1; i <= n; i++) {
    for (j = 0, t1 = pre[i], t2 = n + 1; j < lim; j++)
      if (!((a[i] >> j) & 1))
        t1 = max(t1, b[i - 1][j]), t2 = min(t2, c[i + 1][j]);
    ans -= (long long)(i - t1) * (long long)(t2 - i);
  }
  cout << ans << endl;
  return 0;
}
