#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long n;
int arr[201010];
int seg[401001];
int query(int l, int r) {
  int res = 0;
  l--;
  for (l += n + 1, r += n + 1; l < r; l >>= 1, r >>= 1) {
    if (l & 1) res |= seg[l++];
    if (r & 1) res |= seg[--r];
  }
  return res;
}
int last[201000], nxt[201010];
unordered_map<int, int> occur;
int main() {
  cin >> n;
  long long ans = (n * n + n) / 2;
  int mxm = 0;
  for (int i = 1; i < 1 + n; i++) {
    scanf("%d", &arr[i]);
    mxm = max(mxm, arr[i]);
    last[i] = occur[arr[i]];
    occur[arr[i]] = i;
  }
  for (int i = 1; i < n + 1; i++) {
    nxt[last[i]] = i;
  }
  arr[n + 1] = 1e9 + 5;
  for (int i = 0; i < n + 1; i++) {
    seg[i + n + 1] = arr[i + 1];
  }
  for (int i = n; i > 0; --i) seg[i] = seg[i << 1] | seg[i << 1 | 1];
  for (int i = 1; i < n + 1; i++) {
    long long int l = i, r = n + 1, L, R;
    while (l + 1 < r) {
      int m = l + r;
      m >>= 1;
      int q = query(i, m);
      if (q & (~arr[i])) {
        r = m;
      } else
        l = m;
    }
    if ((query(i, r) & (~arr[i])) == 0)
      R = r;
    else
      R = l;
    l = last[i] + 1;
    r = i;
    while (l + 1 < r) {
      int m = l + r;
      m >>= 1;
      int q = query(m, i);
      if (q & (~arr[i])) {
        l = m;
      } else
        r = m;
    }
    if ((query(l, i) & (~arr[i])) == 0)
      L = l;
    else
      L = r;
    ans -= ((i - L + 1) * (R - i + 1));
  }
  printf("%lld\n", ans);
}
