#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
int dp[maxn][20];
int a[maxn];
vector<int> bi[35];
void rmq_max_init(int n) {
  memset(dp, 0x00, sizeof(dp));
  for (int i = 1; i <= n; i++) dp[i][0] = i;
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      if (a[dp[i][j - 1]] < a[dp[i + (1 << (j - 1))][j - 1]])
        dp[i][j] = dp[i + (1 << (j - 1))][j - 1];
      else
        dp[i][j] = dp[i][j - 1];
}
int rmq_max(int l, int r) {
  int k = 0;
  while ((1 << (k + 1)) <= r - l + 1) k++;
  if (a[dp[l][k]] < a[dp[r - (1 << k) + 1][k]]) return dp[r - (1 << k) + 1][k];
  return dp[l][k];
}
void init(int x, int id) {
  for (int i = 0; (1 << i) <= x; i++) {
    if (x & (1 << i)) bi[i].push_back(id);
  }
}
long long sum;
void dfs(int l, int r, int n) {
  if (l >= r) return;
  int mid = rmq_max(l, r);
  int left = 0, right = n + 1;
  for (int i = 0; (1 << i) <= 1e9; i++) {
    if (!(a[mid] & (1 << i))) {
      int k = lower_bound(bi[i].begin(), bi[i].end(), mid) - bi[i].begin();
      if (k < bi[i].size()) right = min(right, bi[i][k]);
      k--;
      if (k >= 0) left = max(left, bi[i][k]);
    }
  }
  if (left != 0 && left >= l) {
    sum += (long long)(left - l + 1) * (long long)(r - mid + 1);
  }
  if (right != n + 1 && right <= r) {
    sum += (long long)(mid - l + 1) * (long long)(r - right + 1);
  }
  if (left != 0 && left >= l && right != n + 1 && right <= r) {
    sum -= (long long)(left - l + 1) * (long long)(r - right + 1);
  }
  dfs(l, mid - 1, n);
  dfs(mid + 1, r, n);
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    init(a[i], i);
  }
  rmq_max_init(n);
  sum = 0;
  dfs(1, n, n);
  cout << sum;
}
