#include <bits/stdc++.h>
using namespace std;
int n, a[((long long)201 * 1000)], pre[((long long)201 * 1000)],
    nex[((long long)201 * 1000)];
vector<int> v[((long long)30)];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    for (int j = 0; j < ((long long)30); j++)
      if ((a[i] & (1 << j))) v[j].push_back(i);
  }
  stack<long long> s;
  s.push(1);
  for (int i = 2; i <= n; i++) {
    while (s.size() && a[s.top()] < a[i]) s.pop();
    if (s.size()) pre[i] = s.top();
    s.push(i);
  }
  while (s.size()) s.pop();
  s.push(n);
  nex[n] = n + 1;
  for (int i = n - 1; i >= 1; i--) {
    while (s.size() && a[s.top()] <= a[i]) s.pop();
    if (s.size())
      nex[i] = s.top();
    else
      nex[i] = n + 1;
    s.push(i);
  }
  long long ans = 1LL * n * (n + 1) / 2;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < ((long long)30); j++)
      if (!(a[i] & (1 << j)) && v[j].size()) {
        int ex = lower_bound(v[j].begin(), v[j].end(), i) - v[j].begin();
        if (ex != v[j].size()) nex[i] = min(nex[i], v[j][ex]);
        if (ex != 0) pre[i] = max(pre[i], v[j][ex - 1]);
      }
    ans -= 1LL * (nex[i] - i) * (i - pre[i]);
  }
  cout << ans << "\n";
  return 0;
}
