#include <bits/stdc++.h>
using namespace std;
long long int l[200005], r[200005], a[200005], n, ans = 0, bor[25][200005];
stack<long long int> s;
long long int get(int l, int r) {
  int kk = log2l(r - l + 1);
  return (bor[kk][l] | bor[kk][r - (1 << kk) + 1]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i <= n - 1; i++) cin >> a[i], l[i] = 0, r[i] = n - 1;
  for (int i = 0; i <= n - 1; i++) {
    while (1) {
      if (s.empty()) break;
      int id = s.top();
      if (a[id] <= a[i])
        s.pop();
      else {
        l[i] = id + 1;
        break;
      }
    }
    s.push(i);
  }
  while (!s.empty()) s.pop();
  for (int i = n - 1; i >= 0; i--) {
    while (1) {
      if (s.empty()) break;
      int id = s.top();
      if (a[id] < a[i])
        s.pop();
      else {
        r[i] = id - 1;
        break;
      }
    }
    s.push(i);
  }
  for (int i = 0; i <= n - 1; i++) {
    bor[0][i] = a[i];
  }
  for (int j = 1; (1 << j) <= n; j++) {
    for (int i = 0; i + (1 << j) - 1 < n; i++) {
      bor[j][i] = (bor[j - 1][i] | bor[j - 1][i + (1 << (j - 1))]);
    }
  }
  for (int i = 0; i <= n - 1; i++) {
    long long int cntl = 0, cntr = 0;
    long long int lo = l[i], hi = i, mid;
    while (lo <= hi) {
      mid = (lo + hi) / 2;
      if (get(mid, i) > a[i]) {
        cntl = mid - l[i] + 1;
        lo = mid + 1;
      } else {
        hi = mid - 1;
      }
    }
    lo = i, hi = r[i];
    while (lo <= hi) {
      mid = (lo + hi) / 2;
      if (get(i, mid) > a[i]) {
        int kk = log2l(mid - i + 1);
        cntr = r[i] - mid + 1;
        hi = mid - 1;
      } else {
        lo = mid + 1;
      }
    }
    long long int l1 = i - l[i] + 1, r1 = r[i] - i + 1;
    ans += cntl * r1 + cntr * l1 - cntl * cntr;
  }
  cout << ans;
  return 0;
}
