#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int prv_bit[32];
int arr[MAXN];
vector<pair<int, int> > decrease;
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  int N;
  cin >> N;
  decrease.push_back({0x3fffffff, 0});
  long long ans = 0;
  for (int a = 1; a <= N; a++) {
    cin >> arr[a];
    for (int b = 0; b < 32; b++) {
      if (arr[a] & (1 << b)) {
        prv_bit[b] = a;
      }
    }
    vector<int> uniq;
    for (int a = 0; a < 32; a++) {
      uniq.push_back(prv_bit[a]);
    }
    uniq.push_back(a);
    sort(uniq.begin(), uniq.end());
    uniq.erase(unique(uniq.begin(), uniq.end()), uniq.end());
    reverse(uniq.begin(), uniq.end());
    long long added = 0;
    int orv = arr[a];
    for (int b = 1; b < (int)uniq.size(); b++) {
      if (orv > arr[a]) {
        int first_good = prev(lower_bound(decrease.begin(), decrease.end(),
                                          pair<int, int>(orv - 1, 9999999),
                                          greater<pair<int, int> >()))
                             ->second +
                         1;
        first_good = max(first_good, uniq[b] + 1);
        first_good = min(first_good, uniq[b - 1] + 1);
        added += uniq[b - 1] - first_good + 1;
      }
      orv |= arr[uniq[b]];
    }
    while (decrease.back().first < arr[a]) {
      decrease.pop_back();
    }
    decrease.push_back(pair<int, int>(arr[a], a));
    ans += added;
  }
  cout << ans;
}
