#include <bits/stdc++.h>
using namespace std;
const int N = 200000;
int n;
int a[N + 5];
int cache[N + 5];
long long ans;
int main() {
  scanf("%d", &n);
  ans = (long long)n * (n - 1) / 2;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = n - 1; i >= 0; i--) {
    long long l = i - 1, r = i + 1;
    for (; r < n; r++) {
      if ((a[i] | a[r]) != a[i]) break;
      if (a[i] == a[r]) r = cache[r];
    }
    r--;
    for (; l >= 0; l--)
      if ((a[i] | a[l]) != a[i] || a[i] == a[l]) break;
    l++;
    ans -= (r - i + 1) * (i - l + 1) - 1;
    cache[i] = r;
  }
  printf("%lld", ans);
  return 0;
}
