#include <bits/stdc++.h>
const double eps = (1e-9);
using namespace std;
int dcmp(long double a, long double b) {
  return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;
}
int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
long long setBit0(long long num, int idx) { return num & ~(1ll << idx); }
long long flipBit(int num, int idx) { return num ^ (1 << idx); }
void FS() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
const int N = 200009;
int n, arr[N], tree[4 * N], last[N], nxt[N];
vector<int> v1[N], pos[40];
void build(int s = 0, int e = n - 1, int p = 1) {
  if (s == e) {
    tree[p] = s;
    return;
  }
  int m = (s + e) / 2;
  build(s, m, p * 2);
  build(m + 1, e, p * 2 + 1);
  if (arr[tree[p * 2]] >= arr[tree[p * 2 + 1]])
    tree[p] = tree[p * 2];
  else
    tree[p] = tree[p * 2 + 1];
}
int query(int a, int b, int s = 0, int e = n - 1, int p = 1) {
  if (b < s || a > e) return -1;
  if (s >= a && e <= b) return tree[p];
  int m = (s + e) / 2;
  int p1 = query(a, b, s, m, p * 2);
  int p2 = query(a, b, m + 1, e, p * 2 + 1);
  if (p1 != -1 && p2 != -1) {
    if (arr[p1] >= arr[p2])
      return p1;
    else
      return p2;
  } else if (p1 != -1)
    return p1;
  else if (p2 != -1)
    return p2;
}
long long solve(long long l, long long r) {
  if (r <= l) {
    return 0;
  }
  long long po = query(l, r);
  long long nxt_po = nxt[po];
  long long last_po = last[po];
  if (nxt_po == -1 || nxt_po > r) nxt_po = r + 1;
  if (last_po == -1 || last_po < l) last_po = l - 1;
  long long n1 = (nxt_po - po);
  long long n2 = (po - last_po);
  long long ans = (r - po + 1) * (po - l + 1) - n1 * n2;
  return ans + solve(l, po - 1) + solve(po + 1, r);
}
vector<int> to_bin(int no) {
  vector<int> vv;
  while (no) {
    vv.push_back(no % 2);
    no /= 2;
  }
  while (((int)(vv).size()) < 30) vv.push_back(0);
  return vv;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; i++) {
    vector<int> vv;
    vv = to_bin(arr[i]);
    v1[i] = vv;
    for (int j = 0; j < ((int)(vv).size()); j++) {
      if (vv[j] == 1) pos[j].push_back(i);
    }
  }
  memset(nxt, -1, sizeof(nxt));
  memset(last, -1, sizeof(last));
  for (int i = 0; i < n; i++) {
    int id1 = N, id2 = -1;
    for (int j = 0; j < ((int)(v1[i]).size()); j++) {
      if (v1[i][j] == 0) {
        auto it1 = upper_bound(((pos[j]).begin()), ((pos[j]).end()), i);
        if (it1 != pos[j].end()) {
          id1 = min(id1, *it1);
          nxt[i] = id1;
        }
        auto it2 = upper_bound(((pos[j]).begin()), ((pos[j]).end()), i);
        if (it2 != pos[j].begin()) {
          it2--;
          id2 = max(id2, *it2);
          last[i] = id2;
        }
      }
    }
  }
  build();
  cout << solve(0, n - 1) << endl;
}
