#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int mx[MAXN][22], sum[MAXN][22];
int n, a[MAXN];
void init() {
  for (int i = 1; i <= n; i++) {
    mx[i][0] = sum[i][0] = a[i];
  }
  for (int j = 1; (1 << j) <= n; j++) {
    for (int i = 1; i + (1 << j) - 1 <= n; i++) {
      mx[i][j] = max(mx[i][j - 1], mx[i + (1 << j - 1)][j - 1]);
      sum[i][j] = sum[i][j - 1] | sum[i + (1 << j - 1)][j - 1];
    }
  }
}
int RMQ1(int L, int R) {
  int k = 0;
  while ((1 << (k + 1)) <= R - L + 1) k++;
  return sum[L][k] | sum[R - (1 << k) + 1][k];
}
int RMQ2(int L, int R) {
  if (L > R) return -1;
  int k = 0;
  while ((1 << (k + 1)) <= R - L + 1) k++;
  return max(mx[L][k], mx[R - (1 << k) + 1][k]);
}
int find1(int l, int r, int i) {
  int ret = i;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (RMQ1(mid, i) == a[i]) {
      ret = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  return ret;
}
int find2(int l, int r, int i) {
  int ret = i;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (RMQ1(i, mid) == a[i]) {
      ret = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return ret;
}
int find3(int l, int r, int i) {
  int ret = i;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (RMQ2(mid, i - 1) < a[i]) {
      ret = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  return ret;
}
int find4(int l, int r, int i) {
  int ret = i;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (RMQ2(i + 1, mid) <= a[i]) {
      ret = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  init();
  int l1, r1, l2, r2;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    l1 = find1(1, i, i);
    r1 = find2(i, n, i);
    l2 = find3(1, i - 1, i);
    r2 = find4(i + 1, n, i);
    int cnt1 = max(0, (i - l2 + 1) - (i - l1 + 1));
    int cnt2 = max(0, (r2 - i + 1) - (r1 - i + 1));
    ans += (long long)cnt1 * (r2 - i + 1);
    ans += (long long)cnt2 * (i - l2 + 1);
    ans -= (long long)cnt1 * cnt2;
  }
  printf("%I64d\n", ans);
  return 0;
}
