#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, a[N], lm[N], rm[N], q[N];
vector<int> tree[35];
long long ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    for (int j = 0; (1 << j) <= a[i]; j++)
      if (a[i] & (1 << j)) tree[j].push_back(i);
  }
  int tail = 0;
  for (int i = 1; i <= n; i++) {
    while (tail && a[q[tail - 1]] < a[i]) tail--;
    lm[i] = tail ? q[tail - 1] + 1 : 1;
    q[tail++] = i;
  }
  tail = 0;
  for (int i = n; i; i--) {
    while (tail && a[q[tail - 1]] <= a[i]) tail--;
    rm[i] = tail ? q[tail - 1] - 1 : n;
    q[tail++] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (lm[i] == rm[i]) continue;
    int tl = lm[i] - 1, tr = rm[i] + 1;
    for (int j = 0; (1 << j) <= a[i]; j++)
      if (!((1 << j) & a[i])) {
        if (tree[j].size() == 0) continue;
        auto it = lower_bound(tree[j].begin(), tree[j].end(), i);
        if (it != tree[j].begin()) {
          it--;
          tl = max(tl, *it);
        }
        it = upper_bound(tree[j].begin(), tree[j].end(), i);
        if (it != tree[j].end()) tr = min(tr, *it);
      }
    ans +=
        1ll * (i - lm[i] + 1) * (rm[i] - i + 1ll) - 1ll * (i - tl) * (tr - i);
  }
  cout << ans << endl;
}
