#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
const int LOG = 17;
int n, in[MAXN];
int take[MAXN];
int or_val[LOG + 1][MAXN];
int Or(int l, int r) {
  int gap = r - l + 1;
  return (or_val[take[gap]][l] | or_val[take[gap]][r - (1 << take[gap]) + 1]);
}
int main() {
  take[1] = 0;
  for (int i = 2; i < MAXN; ++i)
    if ((1 << (take[i - 1] + 1)) <= i)
      take[i] = take[i - 1] + 1;
    else
      take[i] = take[i - 1];
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &in[i]);
  for (int i = 0; i < n; ++i) or_val[0][i] = in[i];
  for (int l = 0; l < LOG; ++l)
    for (int i = 0; i < n; ++i) {
      or_val[l + 1][i] = or_val[l][i];
      if (i + (1 << l) < n) or_val[l + 1][i] |= or_val[l][i + (1 << l)];
    }
  vector<int> idx;
  for (int i = 0; i < n; ++i) idx.push_back(i);
  sort(idx.begin(), idx.end(), [](int f, int s) { return in[f] > in[s]; });
  long long bad_ivals = 0;
  set<pair<int, int> > ival;
  ival.insert(make_pair(0, n - 1));
  for (int e : idx) {
    auto it = ival.lower_bound(make_pair(e + 1, -1));
    --it;
    int lb = it->first, rb = it->second;
    ival.erase(*it);
    if (lb < e) ival.insert(make_pair(lb, e - 1));
    if (e < rb) ival.insert(make_pair(e + 1, rb));
    int il = e, ir = e;
    for (int gap = 1 << LOG; gap > 0;) {
      if (il - gap < lb || Or(il - gap, e) != in[e]) {
        gap >>= 1;
        continue;
      }
      il -= gap;
    }
    for (int gap = 1 << LOG; gap > 0;) {
      if (ir + gap > rb || Or(e, ir + gap) != in[e]) {
        gap >>= 1;
        continue;
      }
      ir += gap;
    }
    bad_ivals += (e - il + 1) * 1LL * (ir - e + 1);
  }
  cout << (n * (n - 1LL)) / 2 + n - bad_ivals << '\n';
  return 0;
}
