#include <bits/stdc++.h>
using namespace std;
constexpr static int MAXN = 2e5 + 10;
int a[MAXN];
map<pair<int, int>, vector<int>> ranges;
vector<pair<int, int>> maxl, maxr;
vector<int> bitl[30], bitr[30];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = n - 1; i >= 0; i--) {
    while (maxr.size() > 0 && maxr.back().first <= a[i]) maxr.pop_back();
    maxr.push_back({a[i], i});
    for (int j = 0; j < 30; j++)
      if (a[i] & (1 << j)) bitr[j].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    while (maxl.size() > 0 && maxl.back().first <= a[i]) maxl.pop_back();
    int vl = maxl.size() == 0 ? 0 : (maxl.back().second + 1);
    maxl.push_back({a[i], i});
    while (maxr.size() > 0 && maxr.back().first <= a[i]) maxr.pop_back();
    int vr = maxr.size() == 0 ? (n - 1) : (maxr.back().second - 1);
    int bl = 0;
    int br = n - 1;
    for (int j = 0; j < 30; j++) {
      if ((a[i] & (1 << j)) == 0) {
        if (bitl[j].size() > 0) bl = max(bl, bitl[j].back() + 1);
        if (bitr[j].size() > 0) br = min(br, bitr[j].back() - 1);
      }
    }
    for (int j = 0; j < 30; j++) {
      if (bitr[j].size() > 0 && bitr[j].back() == i) bitr[j].pop_back();
      if (a[i] & (1 << j)) bitl[j].push_back(i);
    }
    int l = max(vl, bl);
    int r = min(vr, br);
    ranges[make_pair(l, r)].push_back(i);
  }
  int64_t total = 1LL * n * (n - 1) / 2;
  for (auto v : ranges) {
    auto range = v.first;
    auto idx = v.second;
    if (idx.size() == 1) {
      int i = idx.front();
      int64_t cnt = 1LL * (range.second - i + 1) * (i - range.first + 1);
      total -= cnt - 1;
    } else {
      int64_t dist = range.second - range.first + 1;
      int64_t cnt = dist * (dist + 1) / 2;
      for (int j = 0; j + 1 < idx.size(); j++) {
        int64_t m = idx[j + 1] - idx[j] - 1;
        cnt -= m * (m + 1) / 2;
      }
      int64_t m0 = idx.front() - range.first;
      cnt -= m0 * (m0 + 1) / 2;
      int64_t m1 = range.second - idx.back();
      cnt -= m1 * (m1 + 1) / 2;
      total -= cnt - idx.size();
    }
  }
  printf("%lld\n", total);
}
