#include <bits/stdc++.h>
using namespace std;
const int N = 200020;
const int LN = 20;
int v[N], n;
int table[N][LN][2];
int _LOG[N];
inline int mymax(int x, int y) { return v[x] > v[y] ? x : y; }
void build() {
  for (int i = 0; i < n; i++) {
    table[i][0][0] = i;
    table[i][0][1] = v[i];
  }
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 0; i + (1 << j) - 1 < n; i++) {
      table[i][j][0] =
          mymax(table[i][j - 1][0], table[i + (1 << (j - 1))][j - 1][0]);
      table[i][j][1] = table[i][j - 1][1] | table[i + (1 << (j - 1))][j - 1][1];
    }
}
int queryMax(int l, int r) {
  int tam = r - l + 1;
  int lg = _LOG[tam];
  return mymax(table[l][lg][0], table[r - (1 << lg) + 1][lg][0]);
}
int queryOR(int l, int r) {
  int tam = r - l + 1;
  int lg = _LOG[tam];
  return table[l][lg][1] | table[r - (1 << lg) + 1][lg][1];
}
inline int getORRight(int l, int r, int k) {
  int lo = l, hi = r, ans = -1;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    int q = queryOR(mid, r);
    if ((q | k) > k) {
      ans = mid;
      lo = mid + 1;
    } else
      hi = mid - 1;
  }
  return ans;
}
inline int getORLeft(int l, int r, int k) {
  int lo = l, hi = r, ans = n;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    int q = queryOR(l, mid);
    if ((q | k) > k) {
      ans = mid;
      hi = mid - 1;
    } else
      lo = mid + 1;
  }
  return ans;
}
long long ans = 0;
void solve(int l, int r) {
  if (l >= r) return;
  int pos = queryMax(l, r);
  long long left = getORRight(l, pos - 1, v[pos]);
  if (left != -1) {
    ans += (left - l + 1) * (r - pos + 1);
  }
  long long right = getORLeft(pos + 1, r, v[pos]);
  if (right != n) {
    if (left != -1)
      ans += (pos - (left + 1) + 1) * (r - right + 1);
    else
      ans += (pos - l + 1) * (r - right + 1);
  }
  solve(l, pos - 1);
  solve(pos + 1, r);
}
int main(void) {
  _LOG[1] = 0;
  for (int i = 2; i < N; i++) {
    _LOG[i] = _LOG[i - 1];
    if ((1 << (_LOG[i] + 1)) == i) _LOG[i]++;
  }
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", v + i);
  build();
  solve(0, n - 1);
  cout << ans << endl;
  return 0;
}
