#include <bits/stdc++.h>
using namespace std;
using INT = long long;
using pii = pair<int, int>;
int a[200100];
int cnt[200100][30], nxt[200100];
map<int, int> pos;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    for (int j = 0; j < 30; j++) {
      cnt[i][j] = cnt[i - 1][j];
      if ((a[i] & (1 << j))) {
        cnt[i][j]++;
      }
    }
  }
  for (int i = n; i >= 1; i--) {
    if (pos.count(a[i])) nxt[i] = pos[a[i]];
    pos[a[i]] = i;
  }
  INT ans = 0;
  for (int i = 1; i <= n; i++) {
    int st = 0, ed = i, l, r;
    while (st + 1 < ed) {
      int md = (st + ed) >> 1, flag = 0;
      for (int j = 0; j < 30; j++) {
        if (cnt[i][j] == cnt[md - 1][j]) continue;
        if ((a[i] & (1 << j)) == 0) {
          flag = 1;
          break;
        }
      }
      if (flag)
        st = md;
      else
        ed = md;
    }
    l = ed;
    st = i, ed = n + 1;
    if (nxt[i] != 0) ed = nxt[i];
    while (st + 1 < ed) {
      int md = (st + ed) >> 1, flag = 0;
      for (int j = 0; j < 30; j++) {
        if (cnt[md][j] == cnt[i - 1][j]) continue;
        if ((a[i] & (1 << j)) == 0) {
          flag = 1;
          break;
        }
      }
      if (flag)
        ed = md;
      else
        st = md;
    }
    r = st;
    ans += 1LL * (i - l) * (r - i);
    ans += (i - l);
    ans += (r - i);
  }
  ans = 1LL * n * (n - 1) / 2 - ans;
  cout << ans << endl;
  return 0;
}
