#include <bits/stdc++.h>
using namespace std;
const int MX = 400500;
int u_mask = (1 << 30) + ((1 << 30) - 1);
int a[MX];
int n;
namespace tree {
const int delta = 1 << 18;
int val[2 * delta];
int rev[2 * delta];
void init() {
  val[delta] = rev[delta] = u_mask;
  for (int i = 1; i <= n; i++) {
    val[delta + i] = a[i];
    rev[delta + i] = a[n + 1 - i];
  }
  for (int i = delta - 1; i > 0; i--) {
    val[i] = val[2 * i] | val[2 * i + 1];
    rev[i] = rev[2 * i] | rev[2 * i + 1];
  }
}
int get_pos_before(int *val, int pos, int mask) {
  mask ^= u_mask;
  pos += delta;
  while ((val[pos] & mask) == 0) {
    if (pos & 1)
      pos >>= 1;
    else
      pos--;
  }
  while (pos < delta) {
    if (val[2 * pos + 1] & mask) {
      pos = 2 * pos + 1;
    } else
      pos *= 2;
  }
  return pos - delta;
}
int get_pos_before(int pos) { return get_pos_before(val, pos, a[pos]); }
int get_pos_after(int pos) {
  return n + 1 - get_pos_before(rev, n + 1 - pos, a[pos]);
}
}  // namespace tree
int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  tree::init();
  long long ans = n;
  ans *= n - 1;
  ans /= 2;
  map<int, int> min_pos;
  for (int i = 1; i <= n; i++) {
    long long l = tree::get_pos_before(i);
    long long r = tree::get_pos_after(i);
    auto &l2 = min_pos[a[i]];
    if (l < l2) {
      l = l2;
    }
    l2 = i;
    ans -= (i - l) * (r - i);
  }
  cout << ans + n << endl;
  return 0;
}
