#include <bits/stdc++.h>
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> arr(n + 2);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
  }
  vector<long long> left(n + 2), right(n + 2);
  for (int i = 1; i <= n; i++) {
    left[i] = i;
    while (left[i] > 1 && (arr[left[i] - 1] | arr[i]) == arr[i] &&
           arr[i] > arr[left[i] - 1])
      left[i] = left[left[i] - 1];
  }
  for (int i = n; i >= 1; i--) {
    right[i] = i;
    while (right[i] < n && (arr[right[i] + 1] | arr[i]) == arr[i])
      right[i] = right[right[i] + 1];
  }
  long long ans = n;
  ans = ans * (n + 1) / 2;
  for (int i = 1; i <= n; i++) ans -= (i - left[i] + 1) * (right[i] - i + 1);
  printf("%lld", ans);
  return 0;
}
