#include <bits/stdc++.h>
long long mod = 1000000007;
using namespace std;
long long mxTb[200009][20], OR[200009][20];
long long logtb[200009], ar[200009];
const long long inf = 1ll << 58;
void pre() {
  memset(mxTb, -1, sizeof(mxTb));
  logtb[1] = 0;
  for (int i = 2; i < 200009; i++) logtb[i] = logtb[i - 1] + (!(i & i - 1));
  for (int i = 0; i < 200009; i++) OR[i][0] = mxTb[i][0] = ar[i];
  for (int j = 1; j < 20; j++) {
    for (int i = 0; i + (1 << j) - 1 < 200009; i++) {
      mxTb[i][j] = max(mxTb[i][j - 1], mxTb[i + (1 << (j - 1))][j - 1]);
      OR[i][j] = OR[i][j - 1] | OR[i + (1 << (j - 1))][j - 1];
    }
  }
}
pair<long long, long long> Q(int l, int r) {
  if (l > r) return {inf, inf};
  long long val1 = 0, val2 = 0;
  int lim = logtb[r - l + 1];
  val1 = max(mxTb[l][lim], mxTb[r - (1 << lim) + 1][lim]);
  val2 = OR[l][lim] | OR[r - (1 << lim) + 1][lim];
  return {val1, val2};
}
bool isSubset(long long sub, long long mask) {
  if ((mask & sub) == sub) return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> ar[i];
  pre();
  long long ans = n * (n + 1) / 2;
  for (int i = 0; i < n; i++) {
    long long li = i, ri = i;
    long long l = 0, r = i - 1;
    while (l <= r) {
      int mid = (l + r) >> 1;
      pair<long long, long long> val = Q(mid, i - 1);
      if (val.first < ar[i] && isSubset(val.second, ar[i]))
        r = --mid;
      else
        l = ++mid;
    }
    li = l;
    l = i + 1, r = n - 1;
    while (l <= r) {
      int mid = (l + r) >> 1;
      pair<long long, long long> val = Q(i + 1, mid);
      if (val.first <= ar[i] && isSubset(val.second, ar[i]))
        l = ++mid;
      else
        r = --mid;
    }
    ri = r;
    ans -= 1ll * (i - li + 1) * (ri - i + 1);
  }
  cout << ans << "\n";
  return 0;
}
