#include <bits/stdc++.h>
using namespace std;
stack<pair<int, int> > s, EMPTY;
int n, a[200005], pre[200005], nxt[200005], l[200005], r[200005], f[35];
long long ans;
int main() {
  ios::sync_with_stdio(false);
  int i, j;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) {
    while (!s.empty() && s.top() < make_pair(a[i], i)) s.pop();
    if (s.empty())
      pre[i] = 1;
    else
      pre[i] = s.top().second + 1;
    s.push(make_pair(a[i], i));
  }
  s = EMPTY;
  for (i = n; i; i--) {
    while (!s.empty() && s.top() < make_pair(a[i], i)) s.pop();
    if (s.empty())
      nxt[i] = n;
    else
      nxt[i] = s.top().second - 1;
    s.push(make_pair(a[i], i));
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j <= 30; j++)
      if ((a[i] >> j) & 1)
        f[j] = i;
      else
        l[i] = max(l[i], f[j]);
  }
  for (j = 0; j <= 30; j++) f[j] = n + 1;
  for (i = 1; i <= n; i++) r[i] = n + 1;
  for (i = n; i; i--) {
    for (j = 0; j <= 30; j++)
      if ((a[i] >> j) & 1)
        f[j] = i;
      else
        r[i] = min(r[i], f[j]);
  }
  for (i = 1; i <= n; i++)
    ans += (long long)(i - pre[i] + 1) * max(0, nxt[i] - r[i] + 1) +
           (long long)(nxt[i] - i + 1) * max(0, l[i] - pre[i] + 1) -
           (long long)max(0, l[i] - pre[i] + 1) * max(0, nxt[i] - r[i] + 1);
  cout << ans;
  return 0;
}
