#include <bits/stdc++.h>
using namespace std;
vector<int> temp[30];
map<int, int> m;
void solve() {
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) cin >> x[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 30; j++) {
      if (x[i] & (1 << j)) temp[j].push_back(i);
    }
  }
  long long ans = (1LL * n * (n - 1)) / 2;
  for (int i = 0; i < n; i++) {
    int curmax = n;
    int curmin;
    if (m.count(x[i]))
      curmin = m[x[i]];
    else
      curmin = -1;
    m[x[i]] = i;
    for (int j = 0; j < 30; j++) {
      if ((x[i] & (1 << j)) == 0) {
        auto it = upper_bound((temp[j]).begin(), (temp[j]).end(), i);
        if (it != temp[j].end()) curmax = min(curmax, *it);
        if (it != temp[j].begin()) {
          it--;
          curmin = max(curmin, *it);
        }
      }
    }
    ans -= (1LL * (curmax - i) * (i - curmin) - 1);
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
