#include <bits/stdc++.h>
using namespace std;
const long double pi = acosl(-1);
const int maxn = 200100;
const long long mod = 1e6 + 3;
const int inf = 1e9;
int n;
int a[maxn];
int b[40];
int le[maxn], ri[maxn], lb[maxn], rb[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n + 1; i++) scanf("%d", &a[i]);
  for (int i = 2; i < n + 1; i++) {
    int x = i - 1;
    while (x && a[x] < a[i]) x = le[x];
    le[i] = x;
  }
  for (int i = n + 1 - 1; i >= 1; i--) {
    int x = i + 1;
    while (x <= n && a[x] <= a[i]) x = ri[x];
    ri[i] = x;
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 0; j < 32; j++)
      if ((a[i] >> j) & 1)
        b[j] = i;
      else
        lb[i] = max(lb[i], b[j]);
  }
  for (int i = 1; i < n + 1; i++) rb[i] = n + 1;
  for (int i = 0; i < 32; i++) b[i] = n + 1;
  for (int i = n + 1 - 1; i >= 1; i--) {
    for (int j = 0; j < 32; j++)
      if ((a[i] >> j) & 1)
        b[j] = i;
      else
        rb[i] = min(rb[i], b[j]);
  }
  long long ans = (long long)n * (n + 1) / 2;
  for (int i = 1; i < n + 1; i++) {
    int L = max(le[i], lb[i]) + 1;
    int R = min(ri[i], rb[i]) - 1;
    ans -= (long long)(R - i + 1) * (i - L + 1);
  }
  cout << ans << endl;
  return 0;
}
