#include <bits/stdc++.h>
using namespace std;
const int maxn = (1e6) + 7;
const int inf = (1e9) + 7;
const long long LLinf = (1e18) + 7;
const long double eps = 1e-9;
const long long mod = 1e9 + 7;
const int maxlog = 31;
stack<pair<int, int> > stos;
int tab[maxn];
int lewo[maxn];
int prawo[maxn];
int le[maxn][maxlog];
int pr[maxn][maxlog];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i < n + 1; i++) {
    cin >> tab[i];
    while (((int)(stos).size()) && stos.top().first < tab[i]) stos.pop();
    if (((int)(stos).size())) lewo[i] = stos.top().second;
    stos.push({tab[i], i});
  }
  while (((int)(stos).size())) stos.pop();
  for (int i = n; i > 0; i--) {
    while (((int)(stos).size()) && stos.top().first <= tab[i]) stos.pop();
    if (((int)(stos).size()))
      prawo[i] = stos.top().second;
    else
      prawo[i] = n + 1;
    stos.push({tab[i], i});
  }
  for (int bit = 0; bit < maxlog; bit++) {
    int curr = 0;
    for (int i = 1; i < n + 1; i++) {
      if (tab[i] & (1 << bit)) curr = i;
      le[i][bit] = curr;
    }
    curr = n + 1;
    for (int i = n; i > 0; i--) {
      if (tab[i] & (1 << bit)) curr = i;
      pr[i][bit] = curr;
    }
  }
  long long res = 0LL;
  for (int i = 1; i < n + 1; i++) {
    int l = 0;
    int p = n + 1;
    for (int bit = 0; bit < maxlog; bit++) {
      if (tab[i] & (1 << bit)) continue;
      l = max(l, le[i][bit]);
      p = min(p, pr[i][bit]);
    }
    if (l - lewo[i] > 0) res += (l - lewo[i]) * (long long)(prawo[i] - i);
    if (prawo[i] - p > 0) res += (prawo[i] - p) * (long long)(i - lewo[i]);
    if (prawo[i] - p > 0 && l - lewo[i] > 0)
      res -= (prawo[i] - p) * (long long)(l - lewo[i]);
  }
  cout << res;
  return 0;
}
