#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000001;
const long long INF = 2e18;
const long long MOD = 1000000007;
const double pi = 3.14159265358979323846;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
  }
  vector<vector<int> > sum(n + 1, vector<int>(20));
  for (int i = 0; i < (int)(n); i++) {
    int mask = 1;
    for (int j = 0; j < (int)(20); j++) {
      if ((a[i] & mask)) {
        sum[i + 1][j] = sum[i][j] + 1;
      } else {
        sum[i + 1][j] = sum[i][j];
      }
      mask <<= 1;
    }
  }
  long long ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    int ok = i, ng = n + 1;
    while (ok + 1 < ng) {
      int mid = (ng + ok) / 2;
      bool flag = true;
      for (int j = 0; j < (int)(20); j++) {
        if (sum[mid][j] - sum[i][j] >= 2) {
          flag = false;
          break;
        }
      }
      if (flag) {
        ok = mid;
      } else {
        ng = mid;
      }
    }
    ans += (long long)(ok - i);
  }
  cout << ans << endl;
}
