#include <bits/stdc++.h>
using namespace std;
long long n, t[200010];
pair<int, int> f1[20][200010], f2[20][200010];
long long ans;
int main() {
  long long i, j, k, len;
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) scanf("%lld", &t[i]);
  t[0] = (1 << 30) - 1;
  t[n + 1] = (1 << 30) - 1;
  for (i = 0; i <= n + 1; i++) {
    f1[0][i] = make_pair(t[i], t[i]);
    f2[0][i] = make_pair(t[i], t[i]);
  }
  for (k = 1; k < 20; k++)
    for (i = 0; i <= n; i++) {
      j = min(n, i + (1 << (k - 1)));
      f2[k][i] = make_pair(f2[k - 1][i].first | f2[k - 1][j].first,
                           max(f2[k - 1][i].second, f2[k - 1][j].second));
      j = max(0LL, i - (1 << (k - 1)));
      f1[k][i] = make_pair(f1[k - 1][i].first | f1[k - 1][j].first,
                           max(f1[k - 1][i].second, f1[k - 1][j].second));
    }
  long long l1, l2, r1, r2, x;
  for (i = 1; i <= n; i++) {
    l1 = i;
    l2 = i - 1;
    x = 0;
    for (k = 20 - 1; k >= 0; k--) {
      if (f1[k][l2].second < t[i]) l2 = max(l2 - (1 << k), 0LL);
      if ((x | f1[k][l1].first) <= t[i]) {
        x |= f1[k][l1].first;
        l1 = max(l1 - (1 << k), 0LL);
      }
    }
    l1 = max(l2, l1);
    r1 = i;
    r2 = i;
    x = 0;
    for (k = 20 - 1; k >= 0; k--) {
      if (f2[k][r2].second <= t[i]) r2 = min(r2 + (1 << k), n + 1);
      if ((x | f2[k][r1].first) <= t[i]) {
        x |= f2[k][r1].first;
        r1 = min(r1 + (1 << k), n + 1);
      }
    }
    ans += (r2 - i) * (i - l2) - (r1 - i) * (i - l1);
  }
  printf("%lld", ans);
}
