#include <bits/stdc++.h>
using namespace std;
const int N = 200002;
int tree[4 * N];
int n;
int nxt[N][32], arr[N];
int ST[N][20];
int logs[N];
unordered_map<int, vector<int> > mapp;
int buildTree(int pos, int l, int r) {
  if (l == r) return tree[pos] = l;
  int mid = (l + r) / 2;
  int a = buildTree(pos * 2, l, mid), b = buildTree(pos * 2 + 1, mid + 1, r);
  if (arr[a] < arr[b]) return tree[pos] = b;
  return tree[pos] = a;
}
int get(int pos, int l, int r, int qLow, int qHigh) {
  if (l > qHigh || r < qLow || l > r) return n;
  if (l >= qLow && r <= qHigh) return tree[pos];
  int mid = (l + r) / 2;
  int a = get(pos * 2, l, mid, qLow, qHigh),
      b = get(pos * 2 + 1, mid + 1, r, qLow, qHigh);
  if (arr[a] < arr[b]) return b;
  return a;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    mapp[arr[i]].push_back(i);
  }
  for (int i = 0; i <= n; i++) logs[i] = log2(i);
  for (int i = 0; i < n; i++) ST[i][0] = i;
  for (int j = 1; (1 << j) <= n; j++) {
    for (int i = 0; i + (1 << j) - 1 < n; i++) {
      if (arr[ST[i][j - 1]] > arr[ST[i + (1 << (j - 1))][j - 1]])
        ST[i][j] = ST[i][j - 1];
      else
        ST[i][j] = ST[i + (1 << (j - 1))][j - 1];
    }
  }
  for (int i = 0; i < 31; i++) nxt[n][i] = n;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < 31; j++) {
      nxt[i][j] = nxt[i + 1][j];
      if (arr[i + 1] & (1 << j)) nxt[i][j] = i + 1;
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int curr = arr[i], lst = i;
    bool eq = true;
    set<int> st;
    for (int j = 0; j < 31; j++) {
      if (curr & (1 << j)) continue;
      st.insert(nxt[lst][j]);
    }
    while (lst < n) {
      if (!eq && mapp.count(curr)) {
        vector<int>::iterator it =
            lower_bound(mapp[curr].begin(), mapp[curr].end(), lst + 1);
        if (it != mapp[curr].end()) st.insert(*it);
      }
      int nx = *st.begin();
      st.erase(st.begin());
      int k = logs[nx - i + 1];
      int currMax = arr[ST[i][k]] >= arr[ST[nx - (1 << k) + 1][k]]
                        ? ST[i][k]
                        : ST[nx - (1 << k) + 1][k];
      curr |= arr[nx];
      if (!eq) ans += (nx - lst);
      lst = nx;
      if (curr == arr[currMax])
        eq = true;
      else
        eq = false;
    }
  }
  printf("%I64d", ans);
  return 0;
}
