#include <bits/stdc++.h>
const int N = 200010;
using namespace std;
vector<int> vect;
int ORTable[N][19], MAXTable[N][19];
void prefill(int n) {
  for (int i = 0; i < n; i++) {
    ORTable[i][0] = vect[i];
    MAXTable[i][0] = i;
  }
  for (int j = 1; (1 << j) <= n; j++) {
    for (int i = 0; i + (1 << j) - 1 < n; i++) {
      ORTable[i][j] = ORTable[i][j - 1] | ORTable[i + (1 << (j - 1))][j - 1];
      if (vect[MAXTable[i][j - 1]] >
          vect[MAXTable[i + (1 << (j - 1))][j - 1]]) {
        MAXTable[i][j] = MAXTable[i][j - 1];
      } else {
        MAXTable[i][j] = MAXTable[i + (1 << (j - 1))][j - 1];
      }
    }
  }
}
int OR(int l, int r) {
  int k = log2(r - l + 1);
  return ORTable[l][k] | ORTable[r - (1 << k) + 1][k];
}
int MAX(int l, int r) {
  int k = log2(r - l + 1);
  if (vect[MAXTable[l][k]] > vect[MAXTable[r - (1 << k) + 1][k]]) {
    return MAXTable[l][k];
  } else {
    return MAXTable[r - (1 << k) + 1][k];
  }
}
int bin_search(int l, int r, bool b) {
  int start = vect[b ? l : r];
  int res = 0;
  for (int i = log2(r - l); i >= 0; i--) {
    if (res + (1 << i) > r - l) continue;
    if (b && OR(l, l + (1 << i) + res) <= start) {
      res += (1 << i);
    } else if (!b && OR(r - (1 << i) - res, r) <= start) {
      res += (1 << i);
    }
  }
  if (b) {
    return l + res;
  }
  return r - res;
}
long long solve(int l, int r) {
  if (l >= r) return 0;
  long long res = solve(l, MAX(l, r) - 1) + solve(MAX(l, r) + 1, r);
  int middle = MAX(l, r);
  long long t = bin_search(middle, r, true);
  long long u = bin_search(l, middle, false);
  if (t == r && u == l) {
    return res;
  }
  if (t == r) {
    return res + (u - l) * (r - middle + 1);
  }
  if (u == l) {
    return res + (r - t) * (middle - u + 1);
  }
  return res + (middle - l + 1) * (r - (long long)middle + 1) -
         (t - middle + 1) * (middle - u + 1);
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int in;
    cin >> in;
    vect.push_back(in);
  }
  prefill(n);
  cout << solve(0, n - 1);
  return 0;
}
