#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int maxn = 3e5 + 10;
int n, N;
int a[maxn], b1[maxn], b2[maxn];
int seg[maxn << 2];
void update(int i, int v, int l = 0, int r = N, int id = 0) {
  if (r - l == 1) {
    seg[id] = v;
    return;
  }
  int mid = (l + r) >> 1;
  if (i < mid)
    update(i, v, l, mid, ((id << 1) + 1));
  else
    update(i, v, mid, r, ((id << 1) + 2));
  seg[id] = seg[((id << 1) + 1)] | seg[((id << 1) + 2)];
}
int solve(int l1, int r1, int l = 0, int r = N, int id = 0) {
  if (l >= r1 || r <= l1) return 0;
  if (l >= l1 && r <= r1) return seg[id];
  int mid = (l + r) >> 1;
  return solve(l1, r1, l, mid, ((id << 1) + 1)) |
         solve(l1, r1, mid, r, ((id << 1) + 2));
}
int32_t main() {
  scanf("%d", &n);
  int x = 1;
  while (x <= n) x <<= 1;
  N = x;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]), update(i, a[i]);
  vector<int> s;
  s.push_back(-1);
  for (int i = 0; i < n; i++) {
    if (s.back() == -1) {
      b1[i] = 0, s.push_back(i);
      continue;
    }
    while (s.back() != -1 && a[i] > a[s.back()]) s.pop_back();
    b1[i] = s.back() + 1;
    s.push_back(i);
  }
  s.clear();
  s.push_back(n);
  for (int i = n - 1; i >= 0; i--) {
    if (s.back() == n) {
      b2[i] = n - 1, s.push_back(i);
      continue;
    }
    while (s.back() != n && a[i] >= a[s.back()]) s.pop_back();
    b2[i] = s.back() - 1;
    s.push_back(i);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int l = b1[i] - 1, r = i;
    while (r - l > 1) {
      int mid = (l + r) >> 1;
      int x = solve(mid, i + 1);
      if ((x & a[i]) == x)
        r = mid;
      else
        l = mid;
    }
    int pt1 = r;
    l = i, r = b2[i] + 1;
    while (r - l > 1) {
      int mid = (l + r) >> 1;
      int x = solve(i, mid + 1);
      if ((x & a[i]) == x)
        l = mid;
      else
        r = mid;
    }
    int pt2 = l;
    long long L = i - pt1 + 1;
    long long R = pt2 - i + 1;
    long long res = L * R * 1LL;
    L = i - b1[i] + 1;
    R = b2[i] - i + 1;
    res = ((L * R) - res) * 1LL;
    ans += res;
  }
  printf("%lld\n", ans);
}
