# include <bits/stdc++.h>

# define y1 aasjdladljskdj

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef unsigned long long ull;

const int N = int(3e5) + 5;
const int inf = (int)1e9 + 7;

int n, a[N];
vector < int > all[80];
int p[N], l[N];
int odd[N], eve[N];
ll ans;

void solve(int pos, int r, int k){
  int e = l[pos];
  int sum = p[r] - p[pos - 1] - k;
  if(sum % 2){
    ans += odd[pos - 1] - odd[e];
  } else{
    ans += eve[pos - 1] - eve[e];
  }
}

int main(){
  scanf("%d", &n);
  for(int i = 1; i <= n; ++i){
    ll x;
    scanf("%lld", &x);
    a[i] = __builtin_popcountll(x);
    p[i] = p[i - 1] + a[i];
    odd[i] = odd[i - 1] + (p[i] % 2 == 1);
    eve[i] = eve[i - 1] + (p[i] % 2 == 0);
  }
  stack < int > s;
  for(int i = n; i >= 1; --i){
    if(!s.empty() && a[s.top()] < a[i]){
      l[s.top()] = i;
      s.pop();
    }
  }
  while(!s.empty()){
    l[s.top()] = 0;
    s.pop();
  }
  /// (sum - max * 2) % 2 = 0
  /// sum >= max * 2
  for(int r = 1; r <= n; ++r){
    int sum = 0;
    int mx = r;
    int L = 0;
    for(int l = r; l >= 1; --l){
      if(a[l] > a[mx]){
        mx = l;
      }
      sum += a[l];
      if(sum >= 130){
        L = l;
        break;
      }
      if(l != r && sum - a[mx] >= a[mx] && (sum - a[mx] * 2) % 2 == 0){
        ans++;
      }
    }
    if(L){
      if(a[L] != a[mx]){
        solve(L, r, a[mx] * 2);
        L = l[mx];
      }
      while(L){
        solve(L, r, a[L] * 2);
        L = l[L];
      }
    }
  }
  printf("%lld", ans);
  return 0;
}


# include <bits/stdc++.h>

# define y1 aasjdladljskdj

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef unsigned long long ull;

const int N = int(3e5) + 5;
const int inf = (int)1e9 + 7;

int n;
int a[N], odd, eve = 1;

int main(){
  scanf("%d", &n);
  for(int i = 1; i <= n; ++i){
    ll x;
    scanf("%lld", &x);
    a[i] = __builtin_popcountll(x);
  }
  ll ans = 0;
  int sum = 0;
  for(int i = 1; i <= n; ++i){
    sum += a[i];
    if(sum % 2){
      ans += odd;
      ++odd;
    } else{
      ans += eve;
      ++eve;
    }
  }
  for(int i = 1; i <= n; ++i){
    sum = 0;
    int mx = 0;
    for(int j = i; j <= n; ++j){
      sum += a[j];
      mx = max(mx, a[j]);
      if(sum < mx * 2 && sum % 2 == 0){
        --ans;
      }
      if(sum > 130){
        break;
      }
    }
  }
  printf("%lld", ans);

  return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")

#include<bits/stdc++.h>

#define mst(a, b) memset(a, b, sizeof(a))
#define clr(a) mst(a, 0)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define lowbit(x) (x&(-x))
#define fi first
#define se second
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define lt u << 1
#define rt u << 1 | 1

#define pr(x) cout << #x << " = " << x << " ";
#define prl(x) cout << #x << " = " << x << endl;

using namespace std;

template<typename T>
ostream& operator << (ostream & os, const vector<T>& v) {
		 for(int i = 0; i < v.size(); i++) os << v[i] << " ";
}

template<typename T>
ostream& operator << (ostream & os, const set<T>& v) {
		 for(typename set<T>::iterator it = v.begin(); it != v.end(); it++) os << *it << " ";
}

const double eps = 1e-9;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> V;
typedef pair<int, int> P;
typedef long double LDB;
typedef double DB;

int sgn(double a){return a < -eps ? -1 : a < eps ? 0 : 1;}

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int sum[N];
int s[N], a[N], L[N], R[N];
int main() {
	//freopen("a.in", "r", stdin);
	int n = gi();
	rep(i, 1, n) {
		ll x;
		scanf("%I64d", &x);
		int tot = 0;
		while(x) {
			if(x & 1) {
				tot++;
			}
			x >>= 1;
		}
		a[i] = tot;
		sum[i] = sum[i - 1] + a[i];
	}

	int top = 0;
	s[0] = 0;
	rep(i, 1, n) {
		while(top && a[s[top - 1]] <= a[i]) {
			top--;
		}
		if(top) L[i] = s[top - 1] + 1;
		else L[i] = 1;
		s[top++] = i;
	}
	top = 0;
	per(i, n, 1) {
		while(top && a[s[top - 1]] < a[i]) {
			top--;
		}
		if(top) R[i] = s[top - 1] - 1;
		else R[i] = n;
		s[top++] = i;
	}
	int odd = 0, even = 1;
	ll ans = (ll)n * (n - 1) / 2 + n;
	rep(i, 1, n) {
		if(sum[i] & 1) {
			ans -= even;
		} else {
			ans -= odd;
		}
		if(sum[i] & 1) {
			odd++;
		} else even++;
	}
	/*rep(i, 1, n) {
		int mx = a[i];
		rep(j, i, min(i + 100, n)) {
			mx = max(mx, a[j]);
			if(sum[j] - sum[i - 1] < 2 * mx && (sum[j] - sum[i - 1]) % 2 == 0) {
				ans--;
			}
		}
	}*/
	rep(i, 1, n) {
		L[i] = max(L[i], i - 64);
		R[i] = min(R[i], i + 64);
		rep(l, L[i], i) {
			rep(r, i, R[i]) {
				if(sum[r] - sum[l - 1] < 2 * a[i] && (sum[r] - sum[l - 1]) % 2 == 0) {
					ans--;
				}
				if(sum[r] - sum[l - 1] >= 2 * a[i]) break;
			}
		}
	}
	cout << ans;
	return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")

#include<bits/stdc++.h>

#define mst(a, b) memset(a, b, sizeof(a))
#define clr(a) mst(a, 0)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define lowbit(x) (x&(-x))
#define fi first
#define se second
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define lt u << 1
#define rt u << 1 | 1

#define pr(x) cout << #x << " = " << x << " ";
#define prl(x) cout << #x << " = " << x << endl;

using namespace std;

template<typename T>
ostream& operator << (ostream & os, const vector<T>& v) {
		 for(int i = 0; i < v.size(); i++) os << v[i] << " ";
}

template<typename T>
ostream& operator << (ostream & os, const set<T>& v) {
		 for(typename set<T>::iterator it = v.begin(); it != v.end(); it++) os << *it << " ";
}

const double eps = 1e-9;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> V;
typedef pair<int, int> P;
typedef long double LDB;
typedef double DB;

int sgn(double a){return a < -eps ? -1 : a < eps ? 0 : 1;}

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int sum[N];
int s[N], a[N], L[N], R[N];
int main() {
	//freopen("a.in", "r", stdin);
	int n = gi();
	rep(i, 1, n) {
		ll x;
		scanf("%I64d", &x);
		int tot = 0;
		while(x) {
			if(x & 1) {
				tot++;
			}
			x >>= 1;
		}
		a[i] = tot;
		sum[i] = sum[i - 1] + a[i];
	}

	int top = 0;
	s[0] = 0;
	rep(i, 1, n) {
		while(top && a[s[top - 1]] <= a[i]) {
			top--;
		}
		if(top) L[i] = s[top - 1] + 1;
		else L[i] = 1;
		s[top++] = i;
	}
	top = 0;
	per(i, n, 1) {
		while(top && a[s[top - 1]] < a[i]) {
			top--;
		}
		if(top) R[i] = s[top - 1] - 1;
		else R[i] = n;
		s[top++] = i;
	}
	ll ans = (ll)n * (n - 1) / 2 + n;
	rep(i, 1, n) {
		L[i] = max(L[i], i - 20);
		R[i] = min(R[i], i + 20);
		rep(l, L[i], i) {
			rep(r, i, R[i]) {
				if(sum[r] - sum[l - 1] < 2 * a[i] || (sum[r] - sum[l - 1]) & 1) {
					ans--;
				}
			}
		}
	}
	cout << ans;
	return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")

#include<bits/stdc++.h>

#define mst(a, b) memset(a, b, sizeof(a))
#define clr(a) mst(a, 0)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define lowbit(x) (x&(-x))
#define fi first
#define se second
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define lt u << 1
#define rt u << 1 | 1

#define pr(x) cout << #x << " = " << x << " ";
#define prl(x) cout << #x << " = " << x << endl;

using namespace std;

template<typename T>
ostream& operator << (ostream & os, const vector<T>& v) {
		 for(int i = 0; i < v.size(); i++) os << v[i] << " ";
}

template<typename T>
ostream& operator << (ostream & os, const set<T>& v) {
		 for(typename set<T>::iterator it = v.begin(); it != v.end(); it++) os << *it << " ";
}

const double eps = 1e-9;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> V;
typedef pair<int, int> P;
typedef long double LDB;
typedef double DB;

int sgn(double a){return a < -eps ? -1 : a < eps ? 0 : 1;}

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int sum[N];
int s[N], a[N], L[N], R[N];
int main() {
	//freopen("a.in", "r", stdin);
	int n = gi();
	rep(i, 1, n) {
		ll x;
		scanf("%I64d", &x);
		int tot = 0;
		while(x) {
			if(x & 1) {
				tot++;
			}
			x >>= 1;
		}
		a[i] = tot;
		sum[i] = sum[i - 1] + a[i];
	}

	int top = 0;
	s[0] = 0;
	rep(i, 1, n) {
		while(top && a[s[top - 1]] <= a[i]) {
			top--;
		}
		if(top) L[i] = s[top - 1] + 1;
		else L[i] = 1;
		s[top++] = i;
	}
	top = 0;
	per(i, n, 1) {
		while(top && a[s[top - 1]] < a[i]) {
			top--;
		}
		if(top) R[i] = s[top - 1] - 1;
		else R[i] = n;
		s[top++] = i;
	}
	ll ans = (ll)n * (n - 1) / 2;
	rep(i, 1, n) {
		L[i] = max(L[i], i - 50);
		R[i] = min(R[i], i + 50);
		rep(l, L[i], i) {
			rep(r, i, R[i]) {
				if(l == r) continue;
				if(sum[r] - sum[l - 1] < 2 * a[i] || (sum[r] - sum[l - 1]) & 1) {
					ans--;
				}
			}
		}
	}
	cout << ans;
	return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")

#include<bits/stdc++.h>

#define mst(a, b) memset(a, b, sizeof(a))
#define clr(a) mst(a, 0)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define lowbit(x) (x&(-x))
#define fi first
#define se second
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define lt u << 1
#define rt u << 1 | 1

#define pr(x) cout << #x << " = " << x << " ";
#define prl(x) cout << #x << " = " << x << endl;

using namespace std;

template<typename T>
ostream& operator << (ostream & os, const vector<T>& v) {
		 for(int i = 0; i < v.size(); i++) os << v[i] << " ";
}

template<typename T>
ostream& operator << (ostream & os, const set<T>& v) {
		 for(typename set<T>::iterator it = v.begin(); it != v.end(); it++) os << *it << " ";
}

const double eps = 1e-9;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> V;
typedef pair<int, int> P;
typedef long double LDB;
typedef double DB;

int sgn(double a){return a < -eps ? -1 : a < eps ? 0 : 1;}

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int sum[N];
int s[N], a[N], L[N], R[N];
int main() {
	//freopen("a.in", "r", stdin);
	int n = gi();
	rep(i, 1, n) {
		ll x;
		scanf("%I64d", &x);
		int tot = 0;
		while(x) {
			if(x & 1) {
				tot++;
			}
			x >>= 1;
		}
		a[i] = tot;
		sum[i] = sum[i - 1] + a[i];
	}

	int top = 0;
	s[0] = 0;
	rep(i, 1, n) {
		while(top && a[s[top - 1]] <= a[i]) {
			top--;
		}
		if(top) L[i] = s[top - 1] + 1;
		else L[i] = 1;
		s[top++] = i;
	}
	top = 0;
	per(i, n, 1) {
		while(top && a[s[top - 1]] < a[i]) {
			top--;
		}
		if(top) R[i] = s[top - 1] - 1;
		else R[i] = n;
		s[top++] = i;
	}
	ll ans = (ll)n * (n - 1) / 2;
	rep(i, 1, n) {
		L[i] = max(L[i], i - 20);
		R[i] = min(R[i], i + 20);
		rep(l, L[i], i) {
			rep(r, i, R[i]) {
				if(l == r) continue;
				if(sum[r] - sum[l - 1] < 2 * a[i] || (sum[r] - sum[l - 1]) & 1) {
					ans--;
				}
			}
		}
	}
	cout << ans;
	return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")

#include<bits/stdc++.h>

#define mst(a, b) memset(a, b, sizeof(a))
#define clr(a) mst(a, 0)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define lowbit(x) (x&(-x))
#define fi first
#define se second
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define lt u << 1
#define rt u << 1 | 1

#define pr(x) cout << #x << " = " << x << " ";
#define prl(x) cout << #x << " = " << x << endl;

using namespace std;

template<typename T>
ostream& operator << (ostream & os, const vector<T>& v) {
		 for(int i = 0; i < v.size(); i++) os << v[i] << " ";
}

template<typename T>
ostream& operator << (ostream & os, const set<T>& v) {
		 for(typename set<T>::iterator it = v.begin(); it != v.end(); it++) os << *it << " ";
}

const double eps = 1e-9;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> V;
typedef pair<int, int> P;
typedef long double LDB;
typedef double DB;

int sgn(double a){return a < -eps ? -1 : a < eps ? 0 : 1;}

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int sum[N];
int s[N], a[N], L[N], R[N];
int main() {
	//freopen("a.in", "r", stdin);
	int n = gi();
	rep(i, 1, n) {
		ll x;
		scanf("%I64d", &x);
		int tot = 0;
		while(x) {
			if(x & 1) {
				tot++;
			}
			x >>= 1;
		}
		a[i] = tot;
		sum[i] = sum[i - 1] + a[i];
	}

	int top = 0;
	s[0] = 0;
	rep(i, 1, n) {
		while(top && a[s[top - 1]] <= a[i]) {
			top--;
		}
		if(top) L[i] = s[top - 1] + 1;
		else L[i] = 1;
		s[top++] = i;
	}
	top = 0;
	per(i, n, 1) {
		while(top && a[s[top - 1]] < a[i]) {
			top--;
		}
		if(top) R[i] = s[top - 1] - 1;
		else R[i] = n;
		s[top++] = i;
	}
	ll ans = (ll)n * (n - 1) / 2;
	rep(i, 1, n) {
		L[i] = max(L[i], i - 100);
		R[i] = min(R[i], i + 100);
		rep(l, L[i], i) {
			rep(r, i, R[i]) {
				if(l == r) continue;
				if(sum[r] - sum[l - 1] < 2 * a[i] || (sum[r] - sum[l - 1]) & 1) {
					ans--;
				}
			}
		}
	}
	cout << ans;
	return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")

#include<bits/stdc++.h>

#define mst(a, b) memset(a, b, sizeof(a))
#define clr(a) mst(a, 0)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define lowbit(x) (x&(-x))
#define fi first
#define se second
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define lt u << 1
#define rt u << 1 | 1

#define pr(x) cout << #x << " = " << x << " ";
#define prl(x) cout << #x << " = " << x << endl;

using namespace std;

template<typename T>
ostream& operator << (ostream & os, const vector<T>& v) {
		 for(int i = 0; i < v.size(); i++) os << v[i] << " ";
}

template<typename T>
ostream& operator << (ostream & os, const set<T>& v) {
		 for(typename set<T>::iterator it = v.begin(); it != v.end(); it++) os << *it << " ";
}

const double eps = 1e-9;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> V;
typedef pair<int, int> P;
typedef long double LDB;
typedef double DB;

int sgn(double a){return a < -eps ? -1 : a < eps ? 0 : 1;}

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int sum[N];
int s[N], a[N], L[N], R[N];
int main() {
	//freopen("a.in", "r", stdin);
	int n = gi();
	rep(i, 1, n) {
		ll x;
		scanf("%I64d", &x);
		int tot = 0;
		while(x) {
			if(x & 1) {
				tot++;
			}
			x >>= 1;
		}
		a[i] = tot;
		sum[i] = sum[i - 1] + a[i];
	}

	/*int top = 0;
	s[0] = 0;
	rep(i, 1, n) {
		while(top && a[s[top - 1]] <= a[i]) {
			top--;
		}
		if(top) L[i] = s[top - 1] + 1;
		else L[i] = 1;
		s[top++] = i;
	}
	top = 0;
	per(i, n, 1) {
		while(top && a[s[top - 1]] < a[i]) {
			top--;
		}
		if(top) R[i] = s[top - 1] - 1;
		else R[i] = n;
		s[top++] = i;
	}*/
	int odd = 0, even = 1;
	ll ans = (ll)n * (n - 1) / 2 + n;
	rep(i, 1, n) {
		if(sum[i] & 1) {
			ans -= even;
		} else {
			ans -= odd;
		}
		if(sum[i] & 1) {
			odd++;
		} else even++;
	}
	rep(i, 1, n) {
		int mx = a[i];
		rep(j, i, min(i + 70, n)) {
			mx = max(mx, a[j]);
			if(sum[j] - sum[i - 1] < 2 * mx && (sum[j] - sum[i - 1]) % 2 == 0) {
				ans--;
			}
			if(sum[j] - sum[i - 1] >= 2 * mx) break;
		}
	}
	/*rep(i, 1, n) {
		L[i] = max(L[i], i - 64);
		R[i] = min(R[i], i + 64);
		rep(l, L[i], i) {
			rep(r, i, R[i]) {
				if(sum[r] - sum[l - 1] < 2 * a[i] && (sum[r] - sum[l - 1]) % 2 == 0) {
					ans--;
				}
				if(sum[r] - sum[l - 1] >= 2 * a[i]) break;
			}
		}
	}*/
	cout << ans;
	return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")

#include<bits/stdc++.h>

#define mst(a, b) memset(a, b, sizeof(a))
#define clr(a) mst(a, 0)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define lowbit(x) (x&(-x))
#define fi first
#define se second
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define lt u << 1
#define rt u << 1 | 1

#define pr(x) cout << #x << " = " << x << " ";
#define prl(x) cout << #x << " = " << x << endl;

using namespace std;

template<typename T>
ostream& operator << (ostream & os, const vector<T>& v) {
		 for(int i = 0; i < v.size(); i++) os << v[i] << " ";
}

template<typename T>
ostream& operator << (ostream & os, const set<T>& v) {
		 for(typename set<T>::iterator it = v.begin(); it != v.end(); it++) os << *it << " ";
}

const double eps = 1e-9;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> V;
typedef pair<int, int> P;
typedef long double LDB;
typedef double DB;

int sgn(double a){return a < -eps ? -1 : a < eps ? 0 : 1;}

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int sum[N];
int s[N], a[N], L[N], R[N];
int main() {
	//freopen("a.in", "r", stdin);
	int n = gi();
	rep(i, 1, n) {
		ll x;
		scanf("%I64d", &x);
		int tot = 0;
		while(x) {
			if(x & 1) {
				tot++;
			}
			x >>= 1;
		}
		a[i] = tot;
		sum[i] = sum[i - 1] + a[i];
	}

	int top = 0;
	s[0] = 0;
	rep(i, 1, n) {
		while(top && a[s[top - 1]] <= a[i]) {
			top--;
		}
		if(top) L[i] = s[top - 1] + 1;
		else L[i] = 1;
		s[top++] = i;
	}
	top = 0;
	per(i, n, 1) {
		while(top && a[s[top - 1]] < a[i]) {
			top--;
		}
		if(top) R[i] = s[top - 1] - 1;
		else R[i] = n;
		s[top++] = i;
	}
	ll ans = (ll)n * (n - 1) / 2 + n;
	rep(i, 1, n) {
		L[i] = max(L[i], i - 30);
		R[i] = min(R[i], i + 30);
		rep(l, L[i], i) {
			rep(r, i, R[i]) {
				if(sum[r] - sum[l - 1] < 2 * a[i] || (sum[r] - sum[l - 1]) & 1) {
					ans--;
				}
			}
		}
	}
	cout << ans;
	return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")

#include<bits/stdc++.h>

#define mst(a, b) memset(a, b, sizeof(a))
#define clr(a) mst(a, 0)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define lowbit(x) (x&(-x))
#define fi first
#define se second
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define lt u << 1
#define rt u << 1 | 1

#define pr(x) cout << #x << " = " << x << " ";
#define prl(x) cout << #x << " = " << x << endl;

using namespace std;

template<typename T>
ostream& operator << (ostream & os, const vector<T>& v) {
		 for(int i = 0; i < v.size(); i++) os << v[i] << " ";
}

template<typename T>
ostream& operator << (ostream & os, const set<T>& v) {
		 for(typename set<T>::iterator it = v.begin(); it != v.end(); it++) os << *it << " ";
}

const double eps = 1e-9;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> V;
typedef pair<int, int> P;
typedef long double LDB;
typedef double DB;

int sgn(double a){return a < -eps ? -1 : a < eps ? 0 : 1;}

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int sum[N];
int s[N], a[N], L[N], R[N];
int main() {
	//freopen("a.in", "r", stdin);
	int n = gi();
	rep(i, 1, n) {
		ll x;
		scanf("%I64d", &x);
		int tot = 0;
		while(x) {
			if(x & 1) {
				tot++;
			}
			x >>= 1;
		}
		a[i] = tot;
		sum[i] = sum[i - 1] + a[i];
	}

	int top = 0;
	s[0] = 0;
	rep(i, 1, n) {
		while(top && a[s[top - 1]] <= a[i]) {
			top--;
		}
		if(top) L[i] = s[top - 1] + 1;
		else L[i] = 1;
		s[top++] = i;
	}
	top = 0;
	per(i, n, 1) {
		while(top && a[s[top - 1]] < a[i]) {
			top--;
		}
		if(top) R[i] = s[top - 1] - 1;
		else R[i] = n;
		s[top++] = i;
	}
	ll ans = (ll)n * (n - 1) / 2;
	rep(i, 1, n) {
		L[i] = max(L[i], L[i]);
		R[i] = min(R[i], R[i]);
		rep(l, L[i], i) {
			rep(r, i, R[i]) {
				if(l == r) continue;
				if(sum[r] - sum[l - 1] < 2 * a[i] || (sum[r] - sum[l - 1]) & 1) {
					ans--;
				}
			}
		}
	}
	cout << ans;
	return 0;
}


#pragma comment(linker, "/STACK:102400000,102400000")

#include<bits/stdc++.h>

#define mst(a, b) memset(a, b, sizeof(a))
#define clr(a) mst(a, 0)
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define lowbit(x) (x&(-x))
#define fi first
#define se second
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define lt u << 1
#define rt u << 1 | 1

#define pr(x) cout << #x << " = " << x << " ";
#define prl(x) cout << #x << " = " << x << endl;

using namespace std;

template<typename T>
ostream& operator << (ostream & os, const vector<T>& v) {
		 for(int i = 0; i < v.size(); i++) os << v[i] << " ";
}

template<typename T>
ostream& operator << (ostream & os, const set<T>& v) {
		 for(typename set<T>::iterator it = v.begin(); it != v.end(); it++) os << *it << " ";
}

const double eps = 1e-9;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> V;
typedef pair<int, int> P;
typedef long double LDB;
typedef double DB;

int sgn(double a){return a < -eps ? -1 : a < eps ? 0 : 1;}

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int sum[N];
int s[N], a[N], L[N], R[N];
int main() {
	//freopen("a.in", "r", stdin);
	int n = gi();
	rep(i, 1, n) {
		ll x;
		scanf("%I64d", &x);
		int tot = 0;
		while(x) {
			if(x & 1) {
				tot++;
			}
			x >>= 1;
		}
		a[i] = tot;
		sum[i] = sum[i - 1] + a[i];
	}

	/*int top = 0;
	s[0] = 0;
	rep(i, 1, n) {
		while(top && a[s[top - 1]] <= a[i]) {
			top--;
		}
		if(top) L[i] = s[top - 1] + 1;
		else L[i] = 1;
		s[top++] = i;
	}
	top = 0;
	per(i, n, 1) {
		while(top && a[s[top - 1]] < a[i]) {
			top--;
		}
		if(top) R[i] = s[top - 1] - 1;
		else R[i] = n;
		s[top++] = i;
	}*/
	int odd = 0, even = 1;
	ll ans = (ll)n * (n - 1) / 2 + n;
	rep(i, 1, n) {
		if(sum[i] & 1) {
			ans -= even;
		} else {
			ans -= odd;
		}
		if(sum[i] & 1) {
			odd++;
		} else even++;
	}
	rep(i, 1, n) {
		int mx = a[i];
		rep(j, i, i + 130) {
			mx = max(mx, a[j]);
			if(sum[j] - sum[i - 1] < 2 * mx && (sum[j] - sum[i - 1]) % 2 == 0) {
				ans--;
			}
			if(sum[j] - sum[i - 1] >= 2 * mx) break;
		}
	}
	/*rep(i, 1, n) {
		L[i] = max(L[i], i - 64);
		R[i] = min(R[i], i + 64);
		rep(l, L[i], i) {
			rep(r, i, R[i]) {
				if(sum[r] - sum[l - 1] < 2 * a[i] && (sum[r] - sum[l - 1]) % 2 == 0) {
					ans--;
				}
				if(sum[r] - sum[l - 1] >= 2 * a[i]) break;
			}
		}
	}*/
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int const N = 3e5 + 5;
int n, sum[N], cnt[N], maxs[N], dp[N][2];
int que[N];

int main()
{
    ios_base::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    cin >> n;
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        long long u;
        cin >> u;
        while (u) {
            cnt[i]++;
            u -= u & (-u);
        }

        sum[i] = sum[i-1] + cnt[i];
        dp[i][0] = dp[i-1][0] + (sum[i] % 2 == 0);
        dp[i][1] = dp[i-1][1] + (sum[i] % 2 == 1);
    }

    int top = 0;
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        while (top && cnt[que[top]] <= cnt[i]) {
            top--;
        }

        que[++top] = i;
        for (int j = top; j >= 1; j--) {
            int pos = upper_bound(sum, sum + n + 1, sum[i] - 2 * cnt[que[j]]) - sum - 1;
            if (pos < que[j-1]) {
                continue;
            }

            ans += dp[pos][sum[i] % 2];
            if (que[j-1] != 0) {
                ans -= dp[que[j-1]][sum[i] % 2];
            }
        }
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

int const N = 3e5 + 5;
int n, sum[N], cnt[N], maxs[N], dp[N][2];
int que[N];

int main()
{
    ios_base::sync_with_stdio(0);
   // freopen("inp.txt", "r", stdin);
    cin >> n;
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        long long u;
        cin >> u;
        while (u) {
            cnt[i]++;
            u -= u & (-u);
        }

        sum[i] = sum[i-1] + cnt[i];
        dp[i][0] = dp[i-1][0] + (sum[i] % 2 == 0);
        dp[i][1] = dp[i-1][1] + (sum[i] % 2 == 1);
    }

    int top = 0;
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        while (top && cnt[que[top]] <= cnt[i]) {
            top--;
        }

        que[++top] = i;
        for (int j = top; j >= 1; j--) {
            int pos = upper_bound(sum, sum + n + 1, sum[i] - 2 * cnt[que[j]]) - sum - 1;
            if (pos < que[j-1]) {
                continue;
            }
            pos = min(pos, que[j] - 1);

            ans += dp[pos][sum[i] % 2];
            if (que[j-1] != 0) {
                ans -= dp[que[j-1] - 1][sum[i] % 2];
            }
        }
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

int const N = 3e5 + 5;
int n, sum[N], cnt[N], maxs[N], dp[N][2];
int que[N];

int main()
{
    ios_base::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    cin >> n;
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        long long u;
        cin >> u;
        while (u) {
            cnt[i]++;
            u -= u & (-u);
        }

        sum[i] = sum[i-1] + cnt[i];
        dp[i][0] = dp[i-1][0] + (sum[i] % 2 == 0);
        dp[i][1] = dp[i-1][1] + (sum[i] % 2 == 1);
    }

    int top = 0;
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        while (top && cnt[que[top]] <= cnt[i]) {
            top--;
        }

        que[++top] = i;
        for (int j = top; j >= 1; j--) {
            int pos = upper_bound(sum, sum + n + 1, sum[i] - 2 * cnt[que[j]]) - sum - 1;
            if (pos < que[j-1]) {
                continue;
            }

            ans += dp[pos][sum[i] % 2];
            if (que[j-1] != 0) {
                ans -= dp[que[j-1] - 1][sum[i] % 2];
            }
        }
    }
    cout << ans << endl;
}


//  Copyright © 2018 Diego Garcia Rodriguez del Campo. All rights reserved.

#include<bits/stdc++.h>
#define MAX 300005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
using namespace std;
typedef long long i64;

i64 N, ans;
i64 a[MAX];
i64 sum[MAX];
i64 par[MAX];
i64 impar[MAX];

i64 bits( i64 x )
{
    i64 tmp = 0;
    while( x )
    {
        if( x & 1 ) tmp++;
        x /= 2;
    }
    return tmp;
}

int main()
{
    optimiza_io
    cin >> N;
    for( i64 i = 1; i <= N; i ++ )
    {
        cin >> a[i];
        a[i] = bits( a[i] );
        sum[i] = ( a[i] + sum[i - 1] ) % 2;
        par[i] = par[i - 1];
        impar[i] = impar[i - 1];
        if( ! ( sum[i] & 1 ) )
            par[i]++;
        else
            impar[i]++;
    }
    for( i64 i = 2; i <= N; i ++ )
    {
        i64 cnt = a[i];
        i64 may = a[i];
        i64 j = i - 1;
        while( j >= 1 )
        {
            may = max( may , a[j] );
            cnt += a[j];
            if( ! ( cnt & 1 ) && cnt >= 2*may )
                ans++;
            if( j < 1 or cnt > 126 )
                break;
            j--;
        }
        if( j < 1 )
            continue;
        if( sum[i] )
            ans += par[j];
        else
            ans += impar[j];
    }
    cout << ans;
    return 0;
}


//  Copyright © 2018 Diego Garcia Rodriguez del Campo. All rights reserved.

#include<bits/stdc++.h>
#define MAX 300005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
using namespace std;
typedef long long i64;

i64 N, ans;
i64 a[MAX];
i64 sum[MAX];
i64 par[MAX];
i64 impar[MAX];

i64 bits( i64 x )
{
    i64 tmp = 0;
    while( x )
    {
        if( x & 1 ) tmp++;
        x /= 2;
    }
    return tmp;
}

int main()
{
    optimiza_io
    cin >> N;
    for( i64 i = 1; i <= N; i ++ )
    {
        cin >> a[i];
        a[i] = bits( a[i] );
        sum[i] = ( a[i] + sum[i - 1] ) % 2;
        par[i] = par[i - 1];
        impar[i] = impar[i - 1];
        if( ! ( sum[i] & 1 ) )
            par[i]++;
        else
            impar[i]++;
    }
    for( i64 i = 2; i <= N; i ++ )
    {
        i64 cnt = a[i];
        i64 may = a[i];
        i64 j = i - 1;
        while( j >= 1 )
        {
            may = max( may , a[j] );
            cnt += a[j];
            if( ! ( cnt & 1 ) && cnt >= 2*may )
                ans++;
            j--;
            if( j < 1 or cnt > 126 )
                break;
        }
        if( j < 1 )
            continue;
        if( sum[i] & 1 )
            ans += impar[j];
        else
            ans += par[j];
    }
    cout << ans;
    return 0;
}


//  Copyright © 2018 Diego Garcia Rodriguez del Campo. All rights reserved.

#include<bits/stdc++.h>
#define MAX 300005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
using namespace std;
typedef long long i64;

i64 N, ans;
i64 a[MAX];
i64 sum[MAX];
i64 par[MAX];
i64 impar[MAX];

i64 bits( i64 x )
{
    i64 tmp = 0;
    while( x )
    {
        if( x & 1 ) tmp++;
        x /= 2;
    }
    return tmp;
}

int main()
{
    optimiza_io
    cin >> N;
    par[0]++;
    for( i64 i = 1; i <= N; i ++ )
    {
        cin >> a[i];
        a[i] = bits( a[i] );
        sum[i] = ( a[i] + sum[i - 1] ) % 2;
        par[i] = par[i - 1];
        impar[i] = impar[i - 1];
        if( ! ( sum[i] & 1 ) )
            par[i]++;
        else
            impar[i]++;
    }
    for( i64 i = 2; i <= N; i ++ )
    {
        i64 cnt = a[i];
        i64 may = a[i];
        i64 j = i - 1;
        while( j >= 1 )
        {
            may = max( may , a[j] );
            cnt += a[j];
            if( ! ( cnt & 1 ) && cnt >= 2*may )
                ans++;
            j--;
            if( j < 1 or cnt > 126 )
                break;
        }
        j--;
        if( sum[i] & 1 )
            ans += impar[j];
        else
            ans += par[j];
    }
    cout << ans;
    return 0;
}


//  Copyright © 2018 Diego Garcia Rodriguez del Campo. All rights reserved.

#include<bits/stdc++.h>
#define MAX 300005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
using namespace std;
typedef long long i64;

i64 ans;
int N, may;
int a[MAX];
int sum[MAX];
int tree[4*MAX];
int tam[4*MAX];
int tpar[8*MAX];
bool lazy[8*MAX];

void updLazy( int x , int t )
{
    if( ! lazy[x] )
        return;
    lazy[2*x+1] ^= 1;
    lazy[2*x+2] ^= 1;
    lazy[x] ^= 1;
    tpar[x] = t - tpar[x];
}

int qryPar( int x , int l , int r , int lq , int rq )
{
    updLazy( x , r - l + 1 );
    if( l > rq or r < lq )
        return 0;
    if( l >= lq && r <= rq )
        return tpar[x];
    int mid = ( l + r ) / 2;
    return qryPar( 2*x+1 , l , mid , lq , rq ) + qryPar( 2*x+2 , mid+1 , r , lq , rq );
}

void updPar( int x , int l , int r , int lq , int rq )
{
    updLazy( x , r - l + 1 );
    if( l > rq or r < lq )
        return;
    if( l >= lq && r <= rq )
    {
        lazy[x] ^= 1;
        updLazy( x , r - l + 1 );
        return;
    }
    int mid = ( l + r ) / 2;
    updPar( 2*x+1 , l , mid , lq , rq );
    updPar( 2*x+2 , mid+1 , r , lq , rq );
    tpar[x] = tpar[2*x+1] + tpar[2*x+2];
}

void initTree( int x , int l , int r )
{
    if( l == r )
    {
        tree[x] = a[l];
        tam[x] = a[l];
        if( ! ( a[l] & 1 ) )
            tpar[x] = 1;
        return;
    }
    int mid = ( l + r ) / 2;
    initTree( 2*x+1 , l , mid );
    initTree( 2*x+2 , mid+1 , r );
    tree[x] = max( tree[2*x+1] , tree[2*x+2] );
    tam[x] = tam[2*x+1] + tam[2*x+2];
    tpar[x] = tpar[2*x+1] + tpar[2*x+2];
}

int qrySum( int x , int l , int r , int lq , int rq )
{
    if( l > rq or r < lq )
        return 0;
    if( l >= lq && r <= rq )
        return tam[x];
    int mid = ( l + r ) / 2;
    return qrySum( 2*x+1 , l , mid , lq , rq ) + qrySum( 2*x+2 , mid+1 , r , lq ,rq );
}

int bin( int x , int r )
{
    int ini = 1;
    int fin = r;
    while( ini < fin )
    {
        int mid = ( ini + fin ) / 2;
        if( qrySum( 0 , 1 , N , mid , r ) >= x )
            fin = mid;
        else
            ini = mid + 1;
    }
    if( qrySum( 0 , 1 , N , ini , r ) < x )
        return 2*N;
    return ini;
}

int qry( int x , int l , int r , int lq , int rq )
{
    if( l > rq or r < lq )
        return 0;
    if( l >= lq && r <= rq )
        return tree[x];
    int mid = ( l + r ) / 2;
    return max( qry( 2*x+1 , l , mid , lq , rq ) , qry( 2*x+2 , mid+1 , r , lq ,rq ) );
}

int bits( int x )
{
    int tmp = 0;
    while( x )
    {
        if( x & 1 ) tmp++;
        x /= 2;
    }
    return tmp;
}

int main()
{
    optimiza_io
    cin >> N;
    for( int i = 1; i <= N; i ++ )
    {
        cin >> a[i];
        a[i] = bits( a[i] );
        sum[i] = a[i] + sum[i - 1];
    }
    initTree( 0 , 1 , N );
    for( int i = 2; i <= N; i ++ )
    {
        if( a[i] & 1 )
            updPar( 0 , 1 , N , 1 , i - 1 );
        int r = i - 1;
        int l = i - 1;
        int mact = a[i];
        while( 1 )
        {
            int ini = 1;
            int fin = r;
            while( ini < fin )
            {
                int mid = ( ini + fin ) / 2;
                if( qry( 0 , 1 , N , mid , r ) == mact )
                    fin = mid;
                else
                    ini = mid + 1;
            }
            l = ini;

            int pos = bin( 2*mact , i );
            int lt = max( l , pos );
            if( lt <= r )
                ans += qryPar( 0 , 1 , N , lt , r );
            r = l - 1;
            l = r;
            if( l <= 1 )
                break;

        }
    }
    cout << ans;
    return 0;
}


//  Copyright © 2018 Diego Garcia Rodriguez del Campo. All rights reserved.

#include<bits/stdc++.h>
#define MAX 300005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
using namespace std;
typedef long long i64;

i64 ans;
i64 N, may;
i64 a[MAX];
i64 sum[MAX];
i64 tree[4*MAX];
i64 tam[4*MAX];
i64 tpar[8*MAX];
bool lazy[8*MAX];

void updLazy( i64 x , i64 t )
{
    if( ! lazy[x] )
        return;
    lazy[2*x+1] ^= 1;
    lazy[2*x+2] ^= 1;
    lazy[x] ^= 1;
    tpar[x] = t - tpar[x];
}

i64 qryPar( i64 x , i64 l , i64 r , i64 lq , i64 rq )
{
    updLazy( x , r - l + 1 );
    if( l > rq or r < lq )
        return 0;
    if( l >= lq && r <= rq )
        return tpar[x];
    i64 mid = ( l + r ) / 2;
    return qryPar( 2*x+1 , l , mid , lq , rq ) + qryPar( 2*x+2 , mid+1 , r , lq , rq );
}

void updPar( i64 x , i64 l , i64 r , i64 lq , i64 rq )
{
    updLazy( x , r - l + 1 );
    if( l > rq or r < lq )
        return;
    if( l >= lq && r <= rq )
    {
        lazy[x] ^= 1;
        updLazy( x , r - l + 1 );
        return;
    }
    i64 mid = ( l + r ) / 2;
    updPar( 2*x+1 , l , mid , lq , rq );
    updPar( 2*x+2 , mid+1 , r , lq , rq );
    tpar[x] = tpar[2*x+1] + tpar[2*x+2];
}

void initTree( i64 x , i64 l , i64 r )
{
    if( l == r )
    {
        tree[x] = a[l];
        tam[x] = a[l];
        if( ! ( a[l] & 1 ) )
            tpar[x] = 1;
        return;
    }
    i64 mid = ( l + r ) / 2;
    initTree( 2*x+1 , l , mid );
    initTree( 2*x+2 , mid+1 , r );
    tree[x] = max( tree[2*x+1] , tree[2*x+2] );
    tam[x] = tam[2*x+1] + tam[2*x+2];
    tpar[x] = tpar[2*x+1] + tpar[2*x+2];
}

i64 qrySum( i64 x , i64 l , i64 r , i64 lq , i64 rq )
{
    if( l > rq or r < lq )
        return 0;
    if( l >= lq && r <= rq )
        return tam[x];
    i64 mid = ( l + r ) / 2;
    return qrySum( 2*x+1 , l , mid , lq , rq ) + qrySum( 2*x+2 , mid+1 , r , lq ,rq );
}

i64 bin( i64 x , i64 r )
{
    i64 ini = 1;
    i64 fin = r;
    while( ini < fin )
    {
        i64 mid = ( ini + fin ) / 2;
        if( qrySum( 0 , 1 , N , mid , r ) >= x )
            fin = mid;
        else
            ini = mid + 1;
    }
    if( qrySum( 0 , 1 , N , ini , r ) < x )
        return 2*N;
    return ini;
}

i64 qry( i64 x , i64 l , i64 r , i64 lq , i64 rq )
{
    if( l > rq or r < lq )
        return 0;
    if( l >= lq && r <= rq )
        return tree[x];
    i64 mid = ( l + r ) / 2;
    return max( qry( 2*x+1 , l , mid , lq , rq ) , qry( 2*x+2 , mid+1 , r , lq ,rq ) );
}

i64 bits( i64 x )
{
    i64 tmp = 0;
    while( x )
    {
        if( x & 1 ) tmp++;
        x /= 2;
    }
    return tmp;
}

int main()
{
    optimiza_io
    cin >> N;
    for( i64 i = 1; i <= N; i ++ )
    {
        cin >> a[i];
        a[i] = bits( a[i] );
        sum[i] = a[i] + sum[i - 1];
    }
    initTree( 0 , 1 , N );
    for( i64 i = 2; i <= N; i ++ )
    {
        if( a[i] & 1 )
            updPar( 0 , 1 , N , 1 , i - 1 );
        i64 r = i - 1;
        i64 l = i - 1;
        i64 mact = a[i];
        while( 1 )
        {
            i64 ini = 1;
            i64 fin = r;
            while( ini < fin )
            {
                i64 mid = ( ini + fin ) / 2;
                if( qry( 0 , 1 , N , mid , r ) == mact )
                    fin = mid;
                else
                    ini = mid + 1;
            }
            l = ini;

            i64 pos = bin( 2*mact , i );
            i64 lt = max( l , pos );
            if( lt <= r )
                ans += qryPar( 0 , 1 , N , lt , r );
            r = l - 1;
            l = r;
            if( l <= 1 )
                break;

        }
    }
    cout << ans;
    return 0;
}


//  Copyright © 2018 Diego Garcia Rodriguez del Campo. All rights reserved.

#include<bits/stdc++.h>
#define MAX 300005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
using namespace std;
typedef long long i64;

i64 N, ans;
i64 a[MAX];
i64 sum[MAX];
i64 par[MAX];
i64 impar[MAX];

i64 bits( i64 x )
{
    i64 tmp = 0;
    while( x )
    {
        if( x & 1 ) tmp++;
        x /= 2;
    }
    return tmp;
}

int main()
{
    optimiza_io
    cin >> N;
    par[0]++;
    for( i64 i = 1; i <= N; i ++ )
    {
        cin >> a[i];
        a[i] = bits( a[i] );
        sum[i] = ( a[i] + sum[i - 1] ) % 2;
        par[i] = par[i - 1];
        impar[i] = impar[i - 1];
        if( ! ( sum[i] & 1 ) )
            par[i]++;
        else
            impar[i]++;
    }
    for( i64 i = 2; i <= N; i ++ )
    {
        i64 cnt = a[i];
        i64 may = a[i];
        i64 j = i - 1;
        while( j >= 1 )
        {
            may = max( may , a[j] );
            cnt += a[j];
            if( ! ( cnt & 1 ) && cnt >= 2*may )
                ans++;
            j--;
            if( j < 1 or cnt > 126 )
                break;
        }
        if( j < 1 )
            continue;
        if( sum[i] & 1 )
            ans += impar[j];
        else
            ans += par[j];
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define N 300005

int n, a[N], c[2][N], p[N], s[N];

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		ll x; scanf("%lld", &x);
		for(int j = 0; j < 64; j++)
			if((1ll << j) & x) a[i]++;
		p[i] = a[i] & 1; s[i] = s[i - 1] + p[i], s[i] &= 1;
		c[0][i] = c[0][i - 1], c[0][i] = c[1][i - 1];
		c[p[i]][i]++;
	}
	ll ans = 0;
	for(int i = 1; i <= n; i++)
	{
		int pos = i, cnt = a[i], maxn = a[i];
		while(cnt <= 128 && pos - 1 >= 1)
		{
			pos--;
			cnt += a[pos], maxn = max(maxn, a[pos]);
			if(maxn * 2 <= cnt && s[pos - 1] == s[i]) ans++;
			// cout << i << ' ' << pos << ' ' << cnt << ' ' << maxn << ' ' << ans << endl;
		}
		pos--;
		if(pos == 0) continue;
		ans += c[p[i]][pos - 1];
	}
	printf("%lld\n", ans);
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define N 300005

int n, a[N], c[2][N], p[N], s[N];

int main()
{
	scanf("%d", &n);
	c[0][0] = 1;
	for(int i = 1; i <= n; i++)
	{
		ll x; scanf("%lld", &x);
		for(int j = 0; j < 64; j++)
			if((1ll << j) & x) a[i]++;
		p[i] = a[i] & 1; s[i] = s[i - 1] + p[i], s[i] &= 1;
		c[0][i] = c[0][i - 1], c[0][i] = c[1][i - 1];
		c[s[i]][i]++;
	}
	ll ans = 0;
	for(int i = 1; i <= n; i++)
	{
		int pos = i, cnt = a[i], maxn = a[i];
		while(cnt <= 128 && pos - 1 >= 1)
		{
			pos--;
			cnt += a[pos], maxn = max(maxn, a[pos]);
			if(maxn * 2 <= cnt && s[pos - 1] == s[i]) ans++;
			// cout << i << ' ' << pos << ' ' << cnt << ' ' << maxn << ' ' << ans << endl;
		}
		pos--;
		if(pos == 0) continue;
		ans += c[s[i]][pos - 1];
	}
	printf("%lld\n", ans);
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define N 300005

int n, a[N], c[2][N], p[N], s[N];

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		ll x; scanf("%lld", &x);
		for(int j = 0; j < 64; j++)
			if((1ll << j) & x) a[i]++;
		p[i] = a[i] & 1; s[i] = s[i - 1] + p[i], s[i] &= 1;
		c[0][i] = c[0][i - 1], c[0][i] = c[1][i - 1];
		c[s[i]][i]++;
	}
	ll ans = 0;
	for(int i = 1; i <= n; i++)
	{
		int pos = i, cnt = a[i], maxn = a[i];
		while(cnt <= 128 && pos - 1 >= 1)
		{
			pos--;
			cnt += a[pos], maxn = max(maxn, a[pos]);
			if(maxn * 2 <= cnt && s[pos - 1] == s[i]) ans++;
			// cout << i << ' ' << pos << ' ' << cnt << ' ' << maxn << ' ' << ans << endl;
		}
		pos--;
		if(pos == 0) continue;
		ans += c[s[i]][pos - 1];
	}
	printf("%lld\n", ans);
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define N 300005

int n, a[N], c[2][N], p[N], s[N];

int main()
{
	scanf("%d", &n);
	c[0][0] = 1;
	for(int i = 1; i <= n; i++)
	{
		ll x; scanf("%lld", &x);
		for(int j = 0; j < 64; j++)
			if((1ll << j) & x) a[i]++;
		p[i] = a[i] & 1; s[i] = s[i - 1] + p[i], s[i] &= 1;
		c[0][i] = c[0][i - 1], c[1][i] = c[1][i - 1];
		c[s[i]][i]++;
	}
	ll ans = 0;
	for(int i = 1; i <= n; i++)
	{
		int pos = i, cnt = a[i], maxn = a[i];
		while(cnt <= 128 && pos - 1 >= 1)
		{
			pos--;
			cnt += a[pos], maxn = max(maxn, a[pos]);
			if(maxn * 2 <= cnt && s[pos - 1] == s[i]) ans++;
			// cout << i << ' ' << pos << ' ' << cnt << ' ' << maxn << ' ' << ans << endl;
		}
		pos--;
		if(pos == 0) continue;
		ans += c[s[i]][pos - 1];
	}
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
main()
{
    //freopen("input.txt", "r", stdin);
    int n;
    cin>>n;
    int ar[n], suf[n+1][2], cu=0, an=0;
    for(int a=0; a<n; a++)
    {
        int x;
        scanf("%lld", &x);
        ar[a]=__builtin_popcountll(x);
    }
    suf[n][0]=1, suf[n][1]=0;
    for(int a=n-1; a>=0; a--)
    {
        suf[a][0]=suf[a+1][0], suf[a][1]=suf[a+1][1];
        cu=(cu+ar[a])%2;
        suf[a][cu]++;
        int r=min(a+65, n), su=0, ma=0;
        for(int b=a; b<r; b++)
        {
            su+=ar[b], ma=max(ma, ar[b]);
            if(ma<=su-ma and su%2==0) an++;
        }
        if(r<n) an+=suf[r+1][cu];
    }
    cout<<an;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
main()
{
    //freopen("input.txt", "r", stdin);
    int n;
    cin>>n;
    int ar[n], suf[n+1][2], cu=0, an=0;
    for(int a=0; a<n; a++)
    {
        int x;
        scanf("%lld", &x);
        ar[a]=__builtin_popcount(x);
    }
    suf[n][0]=1, suf[n][1]=0;
    for(int a=n-1; a>=0; a--)
    {
        suf[a][0]=suf[a+1][0], suf[a][1]=suf[a+1][1];
        cu=(cu+ar[a])%2;
        suf[a][cu]++;
        int r=min(a+65, n), su=0, ma=0;
        for(int b=a; b<r; b++)
        {
            su+=ar[b], ma=max(ma, ar[b]);
            if(ma<=su-ma and su%2==0) an++;
        }
        if(r<n) an+=suf[r+1][cu];
    }
    cout<<an;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
main()
{
    //freopen("input.txt", "r", stdin);
    int n;
    cin>>n;
    int ar[n], suf[n+1][2], cu=0, an=0;
    for(int a=0; a<n; a++)
    {
        int x;
        scanf("%lld", &x);
        ar[a]=__builtin_popcount(x);
    }
    suf[n][0]=1, suf[n][1]=0;
    for(int a=n-1; a>=0; a--)
    {
        suf[a][0]=suf[a+1][0], suf[a][1]=suf[a+1][1];
        cu=(cu+ar[a])%2;
        suf[a][cu]++;
        int r=min(a+65, n), su=0, ma=0;
        for(int b=a; b+1<r; b++)
        {
            su+=ar[b], ma=max(ma, ar[b]);
            if(ma<=su-ma and su%2==0) an++;
        }
        an+=suf[r][cu];
    }
    cout<<an;
}


#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 2*1e9
#define N 1000010
#define MAX_V 900010
using namespace std;
int count(ll x){
    int res=0;
    while(x){
        res+=x%2;
        x/=2;
    }
    return res;
}
main(){
    int n;
    cin>>n;
    ll a[N];
    a[0]=0;
    rep2(i,1,n)scanf("%d",&a[i]);
    rep2(i,1,n)a[i]=count(a[i]);
    ll s[N];
    s[0]=0;
    rep2(i,1,n){
        s[i]=s[i-1]+a[i];
    }
    ll odd=0,even=0;
    rep(i,n+1){
        if(s[i]%2)odd++;
        else even++;
    }
    ll ans=0;
    ans=odd*(odd-1)/2+even*(even-1)/2;
    int t[N];
    t[0]=0;
    rep2(i,1,n){
        t[i]=t[i-1]+s[i]%2;
    }

    rep2(i,1,n){
        rep(j,n){
            if(i-j<1)break;
            int sum=s[i]-s[i-j-1];
            if(sum>=a[i]*2)break;
            int p=(lower_bound(s,s+(n+1),s[i-j-1]+a[i]*2)-s)-1;
            if(sum%2^s[i]%2)ans-=t[p]-t[i-1];
            else ans-=(p-i+1)-t[p]+t[i-1];
        }
    }
    cout<<ans;
}


#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 2*1e9
#define N 1000010
#define MAX_V 900010
using namespace std;
ll int inv[N],comb[N],prd[N],invprd[N];
void calc_inv(){
    inv[1]=1;
    rep2(i,2,N){
        inv[i]=((-(MOD/i)*inv[MOD%i])%MOD+MOD)%MOD;
    }
    return;
}
void calc_comb(ll int n){
    comb[0]=1;
    rep2(i,1,n){
        comb[i]=comb[i-1]*(n+1-i)*inv[i]%MOD;
    }
    return;
}
void calc_product(){
    prd[0]=prd[1]=1;
    invprd[0]=invprd[1]=1;
    rep2(i,2,N){
        prd[i]=i*prd[i-1]%MOD;
        invprd[i]=inv[i]*invprd[i-1]%MOD;
    }
    return ;
}
ll cmb(int a,int b){
    return prd[a]*invprd[b]%MOD*invprd[a-b]%MOD;
}
ll modpow(ll x,ll n){
    if(n==0) return 1;
    ll res=modpow(x*x%MOD,n/2);
    if(n&1) res=res*x%MOD;
    return res;
}
gcd(ll a,ll b){
    return (a?gcd(b%a,a):b);
}
int count(ll x){
    int res=0;
    while(x){
        res+=x%2;
        x/=2;
    }
    return res;
}
main(){
    int n;
    cin>>n;
    ll a[N];
    rep(i,n)scanf("%d",&a[i]);
    rep(i,n)a[i]=count(a[i]);
    int s[N]={};
    s[0]=a[0];
    rep2(i,1,n-1){
        s[i]=s[i-1]+a[i];
    }
    ll odd=0,even=1;
    rep(i,n){
        if(s[i]%2)odd++;
        else even++;
    }
    ll ans=0;
    ans=odd*(odd-1)/2+even*(even-1)/2;
    rep(i,n){
        int sum=a[i];
        if(sum%2==0)ans--;
        rep2(j,1,n){
            if(i-j<0)break;
            if(a[i-j]>=a[i])break;
            sum+=a[i-j];
            if(sum>=2*a[i])break;
            if(sum%2==0)ans--;
            int sum2=sum;
            rep2(k,1,n){
                if(i+k>n-1)break;
                if(a[i+k]>a[i])break;
                sum2+=a[i+k];
                if(sum2>=2*a[i])break;
                if(sum%2==0)ans--;
            }
        }
    }
    cout<<ans;
}


#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 2*1e9
#define N 1000010
#define MAX_V 900010
using namespace std;
int count(ll x){
    int res=0;
    while(x){
        res+=x%2;
        x/=2;
    }
    return res;
}
main(){
    int n;
    cin>>n;
    ll a[N];
    a[0]=0;
    rep2(i,1,n)scanf("%lld",&a[i]);
    rep2(i,1,n)a[i]=count(a[i]);
    ll s[N];
    s[0]=0;
    rep2(i,1,n){
        s[i]=s[i-1]+a[i];
    }
    ll odd=0,even=0;
    rep(i,n+1){
        if(s[i]%2)odd++;
        else even++;
    }
    ll ans=0;
    ans=odd*(odd-1)/2+even*(even-1)/2;
    int t[N];
    t[0]=0;
    rep2(i,1,n){
        t[i]=t[i-1]+s[i]%2;
    }

    rep2(i,1,n){
        rep(j,n){
            if(i-j<1)break;
            int sum=s[i]-s[i-j-1];
            if(sum>=a[i]*2)break;
            int p=(lower_bound(s,s+(n+1),s[i-j-1]+a[i]*2)-s)-1;
            if(sum%2^s[i]%2)ans-=t[p]-t[i-1];
            else ans-=(p-i+1)-t[p]+t[i-1];
        }
    }
    cout<<ans;
}


#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 2*1e9
#define N 1000010
#define MAX_V 900010
using namespace std;
ll int inv[N],comb[N],prd[N],invprd[N];
void calc_inv(){
    inv[1]=1;
    rep2(i,2,N){
        inv[i]=((-(MOD/i)*inv[MOD%i])%MOD+MOD)%MOD;
    }
    return;
}
void calc_comb(ll int n){
    comb[0]=1;
    rep2(i,1,n){
        comb[i]=comb[i-1]*(n+1-i)*inv[i]%MOD;
    }
    return;
}
void calc_product(){
    prd[0]=prd[1]=1;
    invprd[0]=invprd[1]=1;
    rep2(i,2,N){
        prd[i]=i*prd[i-1]%MOD;
        invprd[i]=inv[i]*invprd[i-1]%MOD;
    }
    return ;
}
ll cmb(int a,int b){
    return prd[a]*invprd[b]%MOD*invprd[a-b]%MOD;
}
ll modpow(ll x,ll n){
    if(n==0) return 1;
    ll res=modpow(x*x%MOD,n/2);
    if(n&1) res=res*x%MOD;
    return res;
}
gcd(ll a,ll b){
    return (a?gcd(b%a,a):b);
}
int count(ll x){
    int res=0;
    while(x){
        res+=x%2;
        x/=2;
    }
    return res;
}
main(){
    int n;
    cin>>n;
    ll a[N];
    rep(i,n)scanf("%d",&a[i]);
    rep(i,n)a[i]=count(a[i]);
    ll s[N]={};
    s[0]=a[0];
    rep2(i,1,n-1){
        s[i]=s[i-1]+a[i];
    }
    ll odd=0,even=1;
    rep(i,n){
        if(s[i]%2)odd++;
        else even++;
    }
    ll ans=0;
    ans=odd*(odd-1)/2+even*(even-1)/2;
    rep(i,n){
        int sum=a[i];
        if(sum%2==0)ans--;
        int sum3=sum;
        rep2(k,1,n){
            if(i+k>n-1)break;
            sum3+=a[i+k];
            if(sum3>=2*a[i])break;
            if(sum3%2==0)ans--;
        }
        rep2(j,1,n){
            if(i-j<0)break;
            sum+=a[i-j];
            if(sum>=2*a[i])break;
            if(sum%2==0)ans--;
            int sum2=sum;
            rep2(k,1,n){
                if(i+k>n-1)break;
                sum2+=a[i+k];
                if(sum2>=2*a[i])break;
                if(sum2%2==0)ans--;
            }
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
  int evens = 1;
  int odds = 0;
  int n;
  cin >> n;
  int parity = 0;
  ll ans = 0;
  int prev = -1;
  for(int i = 0; i < n; ++i) {
    ll a;
    cin >> a;
    int x = __builtin_popcount(a) + __builtin_popcount(a >> 32);
    if (x % 2 == prev % 2 && x != prev) --ans;
    prev = x % 2;
    parity = (parity + x) % 2;
    if (parity) {
      ans += odds;
      ++odds;
    }
    else {
      ans += evens;
      ++evens;
    }
  }
  cout << ans << "\n";
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int pp(ll x) {
  int ans = 0;
  for (int i = 0; i < 64; ++i) {
    if (x %2) ++ans;
    x /= 2;
  }
  return ans;
}

const int MAXN = 300100;
int vals[MAXN];
int evens[MAXN];
int odds[MAXN];

int main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    ll a;
    cin >> a;
    int x = pp(a);
    vals[i] = x;
  }
  int parity = 0;
  ll ans = 0;
  evens[0] = 1;

  for (int i = 0; i < n; ++i) {
    int lft = max(0, i - 100);
    int mx = 0;
    int sm = 0;
    for(int j = i; j >= lft; --j) {
      mx = max(mx, vals[j]);
      sm += vals[j];
      if (sm % 2 == 0 && mx + mx <= sm) ++ans;
    }
    evens[i + 1] = evens[i];
    odds[i + 1] = odds[i];
    parity += vals[i];
    parity %= 2;
    if (parity) {
      if (lft > 0)
      ans += odds[lft - 1];
      odds[i + 1]++;
    } else {
      if (lft > 0)
      ans += evens[lft - 1];
      evens[i + 1]++;
    }
  }
  cout << ans << "\n";
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
  int evens = 1;
  int odds = 0;
  int n;
  cin >> n;
  int parity = 0;
  ll ans = 0;
  int prev = -1;
  for(int i = 0; i < n; ++i) {
    ll a;
    cin >> a;
    int x = __builtin_popcount(a) + __builtin_popcount(a >> 32);
    if (i > 0 && x % 2 == prev % 2 && x != prev) --ans;
    if (x % 2 == 0) --ans;
    prev = x;
    parity = (parity + x) % 2;
    if (parity) {
      ans += odds;
      ++odds;
    }
    else {
      ans += evens;
      ++evens;
    }
  }
  cout << ans << "\n";
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
  int evens = 1;
  int odds = 0;
  int n;
  cin >> n;
  int parity = 0;
  ll ans = 0;
  int prev = -1;
  for(int i = 0; i < n; ++i) {
    ll a;
    cin >> a;
    int x = __builtin_popcount(a) + __builtin_popcount(a >> 32);
    if (x % 2 == prev % 2 && x != prev) --ans;
    if (x % 2 == 0) --ans;
    prev = x % 2;
    parity = (parity + x) % 2;
    if (parity) {
      ans += odds;
      ++odds;
    }
    else {
      ans += evens;
      ++evens;
    }
  }
  cout << ans << "\n";
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
  int evens = 1;
  int odds = 0;
  int n;
  cin >> n;
  int parity = 0;
  ll ans = 0;
  int prev = -1;
  for(int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    int x = __builtin_popcount(a);
    if (x % 2 == prev % 2 && x != prev) --ans;
    prev = x % 2;
    parity = (parity + x) % 2;
    if (parity) {
      ans += odds;
      ++odds;
    }
    else {
      ans += evens;
      ++evens;
    }
  }
  cout << ans << "\n";
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int pp(ll x) {
  int ans = 0;
  for (int i = 0; i < 64; ++i) {
    if (x %2) ++ans;
    x /= 2;
  }
  return ans;
}

int main() {
  int evens = 1;
  int odds = 0;
  int n;
  cin >> n;
  int parity = 0;
  ll ans = 0;
  int prev = -1;
  for(int i = 0; i < n; ++i) {
    ll a;
    cin >> a;
    int x = pp(a);
    if (i > 0 && x % 2 == prev % 2 && x != prev) --ans;
    if (x % 2 == 0) --ans;
    prev = x;
    parity = (parity + x) % 2;
    if (parity) {
      ans += odds;
      ++odds;
    }
    else {
      ans += evens;
      ++evens;
    }
  }
  cout << ans << "\n";
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
  int evens = 1;
  int odds = 0;
  int n;
  cin >> n;
  int parity = 0;
  ll ans = 0;
  int prev = -1;
  for(int i = 0; i < n; ++i) {
    ll a;
    cin >> a;
    int x = __builtin_popcount(a);
    if (x % 2 == prev % 2 && x != prev) --ans;
    prev = x % 2;
    parity = (parity + x) % 2;
    if (parity) {
      ans += odds;
      ++odds;
    }
    else {
      ans += evens;
      ++evens;
    }
  }
  cout << ans << "\n";
}


#include <cstdio>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
typedef long long ll;

const int N = 300100;
int n, a[N], pref[N], parit[N];
ll answer;

int main() {
  scanf("%d",&n);
  REP(i,n) {
    ll ax;
    scanf("%lld",&ax);
    a[i] = __builtin_popcountll(ax);
    pref[i+1] = pref[i] + a[i];
    parit[i+1] = parit[i] + (pref[i+1] % 2 == 0);
  }
  REP(i,n) {
    int sum = 0, mx = 0, j;
    for (j = i; j < n; ++j) {
      if (sum >= 125) break;
      sum += a[j];
      mx = max(mx, a[j]);
      if (sum >= 2*mx && sum % 2 == 0) ++answer;
    }
    int rest = (pref[i] % 2 == 0) ? (parit[n] - parit[j]) : (n - j) - (parit[n] - parit[j]);
    answer += rest;
  }

  printf("%lld\n", answer);
}


#include <cstdio>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
typedef long long ll;

const int N = 300100;
int n, a[N], pref[N], parit[N];
ll answer;

int main() {
  scanf("%d",&n);
  REP(i,n) {
    ll ax;
    scanf("%lld",&ax);
    a[i] = __builtin_popcountll(ax);
    pref[i+1] = pref[i] + a[i];
    parit[i+1] = parit[i] + (a[i] % 2 == 0);
  }
  REP(i,n) {
    int sum = 0, mx = 0, j;
    for (j = i; j < min(n, i+20); ++j) {
      sum += a[j];
      mx = max(mx, a[j]);
      if (sum >= 2*mx && sum % 2 == 0) ++answer;
    }
    int rest = sum % 2 == 0 ? (parit[n] - parit[j]) : (n - j) - (parit[n] - parit[j]);
    answer += rest;
  }

  printf("%lld\n", answer);
}


#include <cstdio>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
typedef long long ll;

const int N = 300100;
int n, a[N], pref[N], parit[N];
ll answer;

int main() {
  scanf("%d",&n);
  REP(i,n) {
    ll ax;
    scanf("%lld",&ax);
    a[i] = __builtin_popcountll(ax);
    pref[i+1] = pref[i] + a[i];
    parit[i+1] = parit[i] + (a[i] % 2 == 0);
  }
  REP(i,n) {
    int sum = 0, mx = 0, j;
    for (j = i; j < min(n, i+40); ++j) {
      sum += a[j];
      mx = max(mx, a[j]);
      if (sum >= 2*mx && sum % 2 == 0) ++answer;
    }
    int rest = sum % 2 == 0 ? (parit[n] - parit[j]) : (n - j) - (parit[n] - parit[j]);
    answer += rest;
  }

  printf("%lld\n", answer);
}


#include <cstdio>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
typedef long long ll;

const int N = 300100;
int n, a[N], pref[N], parit[N];
ll answer;

int main() {
  scanf("%d",&n);
  REP(i,n) {
    ll ax;
    scanf("%lld",&ax);
    a[i] = __builtin_popcountll(ax);
    pref[i+1] = pref[i] + a[i];
    parit[i+1] = parit[i] + (a[i] % 2 == 0);
  }
  REP(i,n) {
    int sum = 0, mx = 0, j;
    for (j = i; j < min(n, i+120); ++j) {
      sum += a[j];
      mx = max(mx, a[j]);
      if (sum >= 2*mx && sum % 2 == 0) ++answer;
    }
    int rest = sum % 2 == 0 ? (parit[n] - parit[j]) : (n - j) - (parit[n] - parit[j]);
    answer += rest;
  }

  printf("%lld\n", answer);
}


#include <cstdio>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
typedef long long ll;

const int N = 300100;
int n, a[N], pref[N], parit[N];
ll answer;

int main() {
  scanf("%d",&n);
  REP(i,n) {
    ll ax;
    scanf("%lld",&ax);
    a[i] = __builtin_popcountll(ax);
    pref[i+1] = pref[i] + a[i];
    parit[i+1] = parit[i] + (a[i] % 2 == 0);
  }
  REP(i,n) {
    int sum = 0, mx = 0, j;
    for (j = i; j < n; ++j) {
      sum += a[j];
      mx = max(mx, a[j]);
      if (sum >= 2*mx && sum % 2 == 0) ++answer;
      if (sum >= 125) break;
    }
    int rest = sum % 2 == 0 ? (parit[n] - parit[j]) : (n - j) - (parit[n] - parit[j]);
    answer += rest;
  }

  printf("%lld\n", answer);
}


#include<cstdio>
typedef long long ll;
const int MAXN = 300000;
int a[MAXN + 5], S[MAXN + 5];
int seq[MAXN + 5][2], cnt[2], pos[2];
int Function(ll x) {
	int ret = 0;
	while( x ) {
		if( x & 1 ) ret++;
		x >>= 1;
	}
	return ret;
}
int main() {
	int n;
	scanf("%d", &n);
	for(int i=1;i<=n;i++) {
		ll x;
		scanf("%I64d", &x);
		a[i] = Function(x);
		S[i] = S[i-1] + a[i];
	}
	ll ans = 0;
	for(int i=64;i>=1;i--) {
		int lst = -1;
		cnt[0] = cnt[1] = 0;
		pos[0] = pos[1] = 0;
		for(int j=0;j<=n;j++) {
			if( a[j] > i ) {
				cnt[0] = cnt[1] = 0;
				pos[0] = pos[1] = 0;
			}
			else {
				if( a[j] == i ) lst = j;
				int t = (S[j]&1);
				seq[++cnt[t]][t] = j;
				while( pos[t]+1 <= cnt[t] && seq[pos[t]+1][t] <= lst && S[j] - S[seq[pos[t]+1][t]] >= 2*i )
					pos[t]++;
				ans += 1LL * pos[t];
			}
		}
	}
	printf("%I64d\n", ans);
}


#include<cstdio>
typedef long long ll;
const int MAXN = 300000;
int a[MAXN + 5], S[MAXN + 5];
int seq[MAXN + 5][2], cnt[2], pos[2];
int Function(ll x) {
	int ret = 0;
	while( x ) {
		if( x & 1 ) ret++;
		x >>= 1;
	}
	return ret;
}
int main() {
	int n;
	scanf("%d", &n);
	for(int i=1;i<=n;i++) {
		ll x;
		scanf("%I64d", &x);
		a[i] = Function(x);
		S[i] = S[i-1] + a[i];
	}
	ll ans = 0;
	for(int i=64;i>=1;i--) {
		int lst = -1;
		cnt[0] = cnt[1] = 0;
		pos[0] = pos[1] = 0;
		for(int j=1;j<=n;j++) {
			int t = (S[j]&1);
			if( a[j] > i ) {
				cnt[0] = cnt[1] = 0;
				pos[0] = pos[1] = 0;
			}
			else {
				seq[++cnt[S[j-1]&1]][S[j-1]&1] = j-1;
				if( a[j] == i ) lst = j-1;
				while( pos[t]+1 <= cnt[t] && seq[pos[t]+1][t] <= lst && S[j] - S[seq[pos[t]+1][t]] >= 2*i )
					pos[t]++;
				ans += pos[t];
			}
		}
	}
	printf("%I64d\n", ans);
}


#include<cstdio>
typedef long long ll;
const int MAXN = 300000;
int a[MAXN + 5], S[MAXN + 5];
int seq[MAXN + 5][2], cnt[2], pos[2];
int Function(ll x) {
	int ret = 0;
	while( x ) {
		if( x & 1 ) ret++;
		x >>= 1;
	}
	return ret;
}
int main() {
	int n;
	scanf("%d", &n);
	for(int i=1;i<=n;i++) {
		ll x;
		scanf("%I64d", &x);
		a[i] = Function(x);
		S[i] = S[i-1] + a[i];
	}
	ll ans = 0;
	for(int i=64;i>=1;i--) {
		int lst = -1;
		cnt[0] = cnt[1] = 0;
		pos[0] = pos[1] = 0;
		for(int j=0;j<=n;j++) {
			if( a[j] > i ) {
				cnt[0] = cnt[1] = 0;
				pos[0] = pos[1] = 0;
			}
			else {
				if( a[j] == i ) lst = j;
				int t = (S[j]&1);
				seq[++cnt[t]][t] = j;
				while( seq[pos[t] + 1][t] + 1 < j && pos[t] + 1 <= cnt[t] && seq[pos[t] + 1][t] <= lst && S[j] - S[seq[pos[t]+1][t]] >= 2*i )
					pos[t]++;
				ans += pos[t];
			}
		}
	}
	printf("%I64d\n", ans);
}


#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN = 300000;
int a[MAXN + 5], S[MAXN + 5];
int seq[MAXN + 5][2], cnt[2], pos[2];
int Function(ll x) {
	int ret = 0;
	while( x ) {
		if( x & 1 ) ret++;
		x >>= 1;
	}
	return ret;
}
int main() {
	int n;
	scanf("%d", &n);
	for(int i=1;i<=n;i++) {
		ll x;
		scanf("%I64d", &x);
		a[i] = Function(x);
		S[i] = S[i-1] + a[i];
	}
	ll ans = 0;
	for(int i=64;i>=1;i--) {
		for(int j=1;j<=n;j++) {
			int mx = a[j];
			for(int k=j;k<=n;k++) {
				mx = max(mx, a[k]);
				if( mx < i ) continue;
				if( mx > i ) break;
				if( (S[k] - S[j-1]) % 2 == 0 && (S[k] - S[j-1]) >= 2*i ) ans++;
			}
		}
	}
	printf("%I64d\n", ans);
}


#include<cstdio>
typedef long long ll;
const int MAXN = 300000;
int a[MAXN + 5], S[MAXN + 5];
int seq[MAXN + 5][2], cnt[2], pos[2];
int Function(ll x) {
	int ret = 0;
	while( x ) {
		if( x & 1 ) ret++;
		x >>= 1;
	}
	return ret;
}
int main() {
	int n;
	scanf("%d", &n);
	for(int i=1;i<=n;i++) {
		ll x;
		scanf("%I64d", &x);
		a[i] = Function(x);
		S[i] = S[i-1] + a[i];
	}
	ll ans = 0;
	for(int i=64;i>=1;i--) {
		int lst = -1;
		cnt[0] = cnt[1] = 0;
		pos[0] = pos[1] = 0;
		for(int j=1;j<=n;j++) {
			int t = (S[j]&1);
			if( a[j] > i ) {
				cnt[0] = cnt[1] = 0;
				pos[0] = pos[1] = 0;
			}
			else {
				seq[++cnt[S[j-1]&1]][S[j-1]&1] = j-1;
				if( a[j] == i ) lst = j;
				while( pos[t]+1 <= cnt[t] && seq[pos[t]+1][t] <= lst && S[j] - S[seq[pos[t]+1][t]] >= 2*i )
					pos[t]++;
				ans += 1LL * pos[t];
			}
		}
	}
	printf("%I64d\n", ans);
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N = 300005;

int n, v[N];
int even[N], odd[N];

ll f(int i, int b){
    if(i == n) return b == 0;
    return f(i+1, abs(b-v[i]));
    ll ans = 0;

    for(int in = 0; in <= v[i] && in <= b; in++){
        int j = v[i] + b - 2 * in;
        if(j < 0 || j >= 62) continue;
        ans |= f(i+1, j);
    }
    return ans;
}

int main(){

    ll x;

    scanf("%d", &n);

    for(int i = 0; i < n; i++){
        scanf("%lld", &x);
        v[i] = __builtin_popcountll(x);
    }

    for(int i = n-1; i >= 0; i--){
        even[i] = even[i+1];
        odd[i] = odd[i+1];
        if(v[i] % 2) odd[i]++;
        else even[i]++;
    }

    ll ans = 0;

    for(int i = n-1; i >= 0; i--){
        int j = i;
        int mx = 0;
        int s = 0;
        for(; j < n && j < i + 62*2; j++){
            mx = max(mx, v[j]);
            s += v[j];
            if(mx*2 <= s && s % 2 == 0) ans++;
        }
        if(s % 2) ans += odd[j];
        else ans += even[j];
    }

    printf("%lld\n", ans);

}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N = 300005;

int n, v[N];
int even[N], odd[N];

ll f(int i, int b){
    if(i == n) return b == 0;
    return f(i+1, abs(b-v[i]));
    ll ans = 0;

    for(int in = 0; in <= v[i] && in <= b; in++){
        int j = v[i] + b - 2 * in;
        if(j < 0 || j >= 62) continue;
        ans |= f(i+1, j);
    }
    return ans;
}

int main(){

    ll x;

    scanf("%d", &n);

    for(int i = 0; i < n; i++){
        scanf("%lld", &x);
        v[i] = __builtin_popcountll(x);
    }

    for(int i = n-1; i >= 0; i--){
        even[i] = even[i+1] + 1;
        odd[i] = odd[i+1];
        if(v[i] % 2) swap(even[i], odd[i]);
    }

    ll ans = 0;

    for(int i = n-1; i >= 0; i--){
        int j = i;
        int mx = 0;
        int s = 0;
        int lim = min(n, i + 200);
        for(; j < lim; j++){
            mx = max(mx, v[j]);
            s += v[j];
            if(mx*2 <= s && s % 2 == 0) ans++;
        }
        if(s % 2) ans += odd[j];
        else ans += even[j];
    }

    printf("%lld\n", ans);

}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N = 300005;

int n, v[N];
int even[N], odd[N];

ll f(int i, int b){
    if(i == n) return b == 0;
    return f(i+1, abs(b-v[i]));
    ll ans = 0;

    for(int in = 0; in <= v[i] && in <= b; in++){
        int j = v[i] + b - 2 * in;
        if(j < 0 || j >= 62) continue;
        ans |= f(i+1, j);
    }
    return ans;
}

int main(){

    ll x;

    scanf("%d", &n);

    for(int i = 0; i < n; i++){
        scanf("%lld", &x);
        v[i] = __builtin_popcountll(x);
    }

    for(int i = n-1; i >= 0; i--){
        even[i] = even[i+1];
        odd[i] = odd[i+1];
        if(v[i] % 2) odd[i]++;
        else even[i]++;
    }

    ll ans = 0;

    for(int i = n-1; i >= 0; i--){
        int j = i;
        int mx = 0;
        int s = 0;
        int lim = min(n, i + 200);
        for(; j < lim; j++){
            mx = max(mx, v[j]);
            s += v[j];
            if(mx*2 <= s && s % 2 == 0) ans++;
        }
        if(s % 2) ans += odd[j];
        else ans += even[j];
    }

    printf("%lld\n", ans);

}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N = 300005;

int n, v[N];
int even[N], odd[N];

ll f(int i, int b){
    if(i == n) return b == 0;
    return f(i+1, abs(b-v[i]));
    ll ans = 0;

    for(int in = 0; in <= v[i] && in <= b; in++){
        int j = v[i] + b - 2 * in;
        if(j < 0 || j >= 62) continue;
        ans |= f(i+1, j);
    }
    return ans;
}

int main(){

    ll x;

    scanf("%d", &n);

    for(int i = 0; i < n; i++){
        scanf("%lld", &x);
        v[i] = __builtin_popcountll(x);
    }

    for(int i = n-1; i >= 0; i--){
        even[i] = even[i+1];
        odd[i] = odd[i+1];
        if(v[i] % 2) odd[i]++;
        else even[i]++;
    }

    ll ans = 0;

    for(int i = n-1; i >= 0; i--){
        int j = i;
        int mx = 0;
        int s = 0;
        for(; j < n && j < i + 62; j++){
            mx = max(mx, v[j]);
            s += v[j];
            if(mx*2 <= s && s % 2 == 0) ans++;
        }
        if(s % 2) ans += odd[j];
        else ans += even[j];
    }

    printf("%lld\n", ans);

}


#include <sstream>
#include <fstream>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <utility>
#include <cassert>
#include <bitset>
using namespace std;
#define REP(I,N) for (I=0;I<N;I++)
#define rREP(I,N) for (I=N-1;I>=0;I--)
#define rep(I,S,N) for (I=S;I<N;I++)
#define rrep(I,S,N) for (I=N-1;I>=S;I--)
#define FOR(I,S,N) for (I=S;I<=N;I++)
#define rFOR(I,S,N) for (I=N;I>=S;I--)

#define DEBUG
#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define deputs(str) fprintf(stderr, "%s\n",str)
#else
#define debug(...)
#define deputs(str)
#endif // DEBUG
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long long LL;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF=0x3f3f3f3f;
const LL INFF=0x3f3f3f3f3f3f3f3fll;
const LL M=1e9+7;
const LL maxn=3e5+7;
const double pi=acos(-1.0);
const double eps=0.0000000001;
LL gcd(LL a, LL b) {return b?gcd(b,a%b):a;}
template<typename T>inline void pr2(T x,int k=64) {ll i; REP(i,k) debug("%d",(x>>i)&1); putchar(' ');}
template<typename T>inline void add_(T &A,int B,ll MOD=M) {A+=B; (A>=MOD) &&(A-=MOD);}
template<typename T>inline void mul_(T &A,ll B,ll MOD=M) {A=(A*B)%MOD;}
template<typename T>inline void mod_(T &A,ll MOD=M) {A%=MOD; A+=MOD; A%=MOD;}
template<typename T>inline void max_(T &A,T B) {(A<B) &&(A=B);}
template<typename T>inline void min_(T &A,T B) {(A>B) &&(A=B);}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
template<typename T>inline T powMM(T a, T b) {
	T ret=1;
	for (; b; b>>=1ll,a=(LL)a*a%M)
		if (b&1) ret=(LL)ret*a%M;
	return ret;
}
int n,m,q;
char str[maxn];
int startTime;
void startTimer() {startTime=clock();}
void printTimer() {debug("/--- Time: %ld milliseconds ---/\n",clock()-startTime);}

//okay: cnt_max*2<=sum
//popcnt!=0; brute force
int A[maxn],S[maxn],B[maxn][2];
int main() {
	int i,j;
	scanf("%d",&n);
	FOR(i,1,n) {
		ll k;
		scanf("%I64d",&k);
		while (k) A[i]+=k&1,k/=2;
		S[i]=A[i]+S[i-1];
		B[i][0]=B[i-1][0];
		B[i][1]=B[i-1][1];
		B[i][A[i]&1]++;
	} ll ans=0;
	// FOR(i,1,n) printf("%d ",A[i]);puts("");
	FOR(i,1,n) {
		int MAX=0;
		rFOR(j,max(i-200,1),i) {
			MAX=max(MAX,A[i]);
			if (!((S[i]^S[j-1])&1)&&S[i]-S[j-1]>=MAX*2) ans++;
			// printf("%d-%d : %d %d MAX=%d\n",j,i,S[i],S[j],MAX);
		} ans+=B[j][S[i]&1];
	} printf("%I64d\n",ans);
}
/*
3 3 3
*/


#include <sstream>
#include <fstream>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <utility>
#include <cassert>
#include <bitset>
using namespace std;
#define REP(I,N) for (I=0;I<N;I++)
#define rREP(I,N) for (I=N-1;I>=0;I--)
#define rep(I,S,N) for (I=S;I<N;I++)
#define rrep(I,S,N) for (I=N-1;I>=S;I--)
#define FOR(I,S,N) for (I=S;I<=N;I++)
#define rFOR(I,S,N) for (I=N;I>=S;I--)

#define DEBUG
#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define deputs(str) fprintf(stderr, "%s\n",str)
#else
#define debug(...)
#define deputs(str)
#endif // DEBUG
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long long LL;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF=0x3f3f3f3f;
const LL INFF=0x3f3f3f3f3f3f3f3fll;
const LL M=1e9+7;
const LL maxn=3e5+7;
const double pi=acos(-1.0);
const double eps=0.0000000001;
LL gcd(LL a, LL b) {return b?gcd(b,a%b):a;}
template<typename T>inline void pr2(T x,int k=64) {ll i; REP(i,k) debug("%d",(x>>i)&1); putchar(' ');}
template<typename T>inline void add_(T &A,int B,ll MOD=M) {A+=B; (A>=MOD) &&(A-=MOD);}
template<typename T>inline void mul_(T &A,ll B,ll MOD=M) {A=(A*B)%MOD;}
template<typename T>inline void mod_(T &A,ll MOD=M) {A%=MOD; A+=MOD; A%=MOD;}
template<typename T>inline void max_(T &A,T B) {(A<B) &&(A=B);}
template<typename T>inline void min_(T &A,T B) {(A>B) &&(A=B);}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
template<typename T>inline T powMM(T a, T b) {
    T ret=1;
    for (; b; b>>=1ll,a=(LL)a*a%M)
        if (b&1) ret=(LL)ret*a%M;
    return ret;
}
int n,m,q;
char str[maxn];
int startTime;
void startTimer() {startTime=clock();}
void printTimer() {debug("/--- Time: %ld milliseconds ---/\n",clock()-startTime);}

//okay: cnt_max*2<=sum
//popcnt!=0; brute force
int A[maxn],S[maxn],B[maxn][2];
int main() {
    int i,j;
    scanf("%d",&n);
    FOR(i,1,n) {
        ll k;
        scanf("%I64d",&k);
        while (k) A[i]+=k&1,k/=2;
        S[i]=A[i]+S[i-1];
        B[i][0]=B[i-1][0];
        B[i][1]=B[i-1][1];
        B[i][S[i-1]&1]++;//1->i
    } ll ans=0;
    // FOR(i,1,n) printf("%d(%d) ",A[i],S[i]);puts("");
    FOR(i,1,n) {
        int MAX=0;
        rFOR(j,max(i-200,1),i) {
            MAX=max(MAX,A[j]);
            if (!((S[i]^S[j-1])&1)&&S[i]-S[j-1]>=MAX*2) ans++;
            // printf("%d-%d : %d %d MAX=%d\n",j,i,S[i],S[j],MAX);
        } ans+=B[j][S[i]&1];
        // printf("%d : %d\n",i,ans);
    } printf("%I64d\n",ans);
}
/*
3 3 3
*/


#include <sstream>
#include <fstream>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <utility>
#include <cassert>
#include <bitset>
using namespace std;
#define REP(I,N) for (I=0;I<N;I++)
#define rREP(I,N) for (I=N-1;I>=0;I--)
#define rep(I,S,N) for (I=S;I<N;I++)
#define rrep(I,S,N) for (I=N-1;I>=S;I--)
#define FOR(I,S,N) for (I=S;I<=N;I++)
#define rFOR(I,S,N) for (I=N;I>=S;I--)

#define DEBUG
#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define deputs(str) fprintf(stderr, "%s\n",str)
#else
#define debug(...)
#define deputs(str)
#endif // DEBUG
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long long LL;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF=0x3f3f3f3f;
const LL INFF=0x3f3f3f3f3f3f3f3fll;
const LL M=1e9+7;
const LL maxn=3e5+7;
const double pi=acos(-1.0);
const double eps=0.0000000001;
LL gcd(LL a, LL b) {return b?gcd(b,a%b):a;}
template<typename T>inline void pr2(T x,int k=64) {ll i; REP(i,k) debug("%d",(x>>i)&1); putchar(' ');}
template<typename T>inline void add_(T &A,int B,ll MOD=M) {A+=B; (A>=MOD) &&(A-=MOD);}
template<typename T>inline void mul_(T &A,ll B,ll MOD=M) {A=(A*B)%MOD;}
template<typename T>inline void mod_(T &A,ll MOD=M) {A%=MOD; A+=MOD; A%=MOD;}
template<typename T>inline void max_(T &A,T B) {(A<B) &&(A=B);}
template<typename T>inline void min_(T &A,T B) {(A>B) &&(A=B);}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
template<typename T>inline T powMM(T a, T b) {
	T ret=1;
	for (; b; b>>=1ll,a=(LL)a*a%M)
		if (b&1) ret=(LL)ret*a%M;
	return ret;
}
int n,m,q;
char str[maxn];
int startTime;
void startTimer() {startTime=clock();}
void printTimer() {debug("/--- Time: %ld milliseconds ---/\n",clock()-startTime);}

//okay: cnt_max*2<=sum
//popcnt!=0; brute force
int A[maxn],S[maxn],B[maxn][2];
int main() {
	int i,j;
	scanf("%d",&n);
	FOR(i,1,n) {
		ll k;
		scanf("%I64d",&k);
		while (k) A[i]+=k&1,k/=2;
		S[i]=A[i]+S[i-1];
		B[i][0]=B[i-1][0];
		B[i][1]=B[i-1][1];
		B[i][S[i-1]&1]++;//1->i
	} ll ans=0;
	// FOR(i,1,n) printf("%d(%d) ",A[i],S[i]);puts("");
	FOR(i,1,n) {
		int MAX=0;
		rFOR(j,max(i-200,1),i) {
			MAX=max(MAX,A[i]);
			if (!((S[i]^S[j-1])&1)&&S[i]-S[j-1]>=MAX*2) ans++;
			// printf("%d-%d : %d %d MAX=%d\n",j,i,S[i],S[j],MAX);
		} ans+=B[j][S[i]&1];
		// printf("%d : %d\n",i,ans);
	} printf("%I64d\n",ans);
}
/*
3 3 3
*/


#include <sstream>
#include <fstream>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <utility>
#include <cassert>
#include <bitset>
using namespace std;
#define REP(I,N) for (I=0;I<N;I++)
#define rREP(I,N) for (I=N-1;I>=0;I--)
#define rep(I,S,N) for (I=S;I<N;I++)
#define rrep(I,S,N) for (I=N-1;I>=S;I--)
#define FOR(I,S,N) for (I=S;I<=N;I++)
#define rFOR(I,S,N) for (I=N;I>=S;I--)

#define DEBUG
#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define deputs(str) fprintf(stderr, "%s\n",str)
#else
#define debug(...)
#define deputs(str)
#endif // DEBUG
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef long long LL;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF=0x3f3f3f3f;
const LL INFF=0x3f3f3f3f3f3f3f3fll;
const LL M=1e9+7;
const LL maxn=3e5+7;
const double pi=acos(-1.0);
const double eps=0.0000000001;
LL gcd(LL a, LL b) {return b?gcd(b,a%b):a;}
template<typename T>inline void pr2(T x,int k=64) {ll i; REP(i,k) debug("%d",(x>>i)&1); putchar(' ');}
template<typename T>inline void add_(T &A,int B,ll MOD=M) {A+=B; (A>=MOD) &&(A-=MOD);}
template<typename T>inline void mul_(T &A,ll B,ll MOD=M) {A=(A*B)%MOD;}
template<typename T>inline void mod_(T &A,ll MOD=M) {A%=MOD; A+=MOD; A%=MOD;}
template<typename T>inline void max_(T &A,T B) {(A<B) &&(A=B);}
template<typename T>inline void min_(T &A,T B) {(A>B) &&(A=B);}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
template<typename T>inline T powMM(T a, T b) {
	T ret=1;
	for (; b; b>>=1ll,a=(LL)a*a%M)
		if (b&1) ret=(LL)ret*a%M;
	return ret;
}
int n,m,q;
char str[maxn];
int startTime;
void startTimer() {startTime=clock();}
void printTimer() {debug("/--- Time: %ld milliseconds ---/\n",clock()-startTime);}

//okay: cnt_max*2<=sum
//popcnt!=0; brute force
int A[maxn],S[maxn],B[maxn][2];
int main() {
	int i,j;
	scanf("%d",&n);
	FOR(i,1,n) {
		ll k;
		scanf("%I64d",&k);
		while (k) A[i]+=k&1,k/=2;
		S[i]=A[i]+S[i-1];
		B[i][0]=B[i-1][0];
		B[i][1]=B[i-1][1];
		B[i][A[i]&1]++;
	} ll ans=0;
	FOR(i,1,n) printf("%d ",A[i]);puts("");
	FOR(i,1,n) {
		int MAX=0;
		rFOR(j,max(i-200,1),i) {
			MAX=max(MAX,A[i]);
			if (!((S[i]^S[j-1])&1)&&S[i]-S[j-1]>=MAX*2) ans++;
			// printf("%d-%d : %d %d MAX=%d\n",j,i,S[i],S[j],MAX);
		} ans+=B[j][S[i]&1];
	} printf("%I64d\n",ans);
}
/*
3 3 3
*/


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define inf 1000000000
#define mod 234
#define N 300005
typedef long long ll;
using namespace std;
int n,t1,t2,ans,a[N],b[3];
ll a1;
ll gets(){
	ll v=0;bool f=0;char ch;
	while(!isdigit(ch)) { f|=ch=='-'; ch=getchar(); }
	while( isdigit(ch)) { v=(v<<3)+(v<<1)+ch-48; ch=getchar(); }
	return f?-v:v;
}
int main ()
{
	n=gets();
	for(int i=1;i<=n;i++){
		a1=gets();
		while(a1) a[i]^=a1%2, a1>>=1; // cout<<a[i]<<endl;
	}
	/*b[0]=1; if(!a[1]) ans--;
	for(int i=1;i<=n;i++) t1^=a[i], ans+=b[t1], b[t1]++; */
	t2=0;
	for(int i=1;i<=n;i++){
		t1^=a[i], ans+=b[t1], b[t2]++, t2=t1;

	}

	printf("%d\n",ans);
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define inf 1000000000
#define mod 234
#define N 300005
typedef long long ll;
using namespace std;
int n,t1,ans,a[N],b[3];
ll a1;
ll gets(){
	ll v=0;bool f=0;char ch;
	while(!isdigit(ch)) { f|=ch=='-'; ch=getchar(); }
	while( isdigit(ch)) { v=(v<<3)+(v<<1)+ch-48; ch=getchar(); }
	return f?-v:v;
}
int main ()
{
	n=gets();
	for(int i=1;i<=n;i++){
		a1=gets();
		while(a1) a[i]^=a1%2, a1>>=1; // cout<<a[i]<<endl;
	}
	b[0]=1; if(!a[1]) ans--;
	for(int i=1;i<=n;i++) t1^=a[i], ans+=b[t1], b[t1]++;
	printf("%d\n",ans);
	return 0;
}


#include<map>
#include<set>
#include<list>
#include<ctime>
#include<cmath>
#include<deque>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
#define _rep(i,s,t) for(register int i=s;i>=t;--i)
#define Rep(i,s,t) for(register int i=s;i<t;++i)
#define go(x) for(register int e=las[x];e;e=nxt[e])
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define is insert
#define es erase
#define pii pair<int,int>
#define ms(f,x) memset(f,x,sizeof f)
#define mc(f,x) memcpy(f,x,sizeof f)
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define gi(x) read(x)
#define gii(x,y) read(x),read(y)
#define giii(x,y,z) read(x),read(y),read(z)
namespace IO{
    #define gc getchar()
    #define pc(x) putchar(x)
    template<typename T>inline void read(T &x){
        x=0;int f=1;char ch=gc;while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=gc;}
        while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=gc;x*=f;return;
    }
    template<typename T>inline void write(T x=0){
        T wr[51];wr[0]=0;if(x<0)pc('-'),x=-x;if(!x)pc(48);
        while(x)wr[++wr[0]]=x%10,x/=10;while(wr[0])pc(48+wr[wr[0]--]);return;
    }
}
using IO::read;
using IO::write;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
#define int long long
const int N=3e5+11111;
int a[N],mx;
int n,h[3];
ll x,ans,t,S,sum[N];
main(){
	gi(n);
	rep(i,1,n){
		gi(x);
		for(;x;x>>=1)
			if(x&1)++a[i];
	}
	++h[0];
	rep(i,1,n){
		sum[i]=sum[i-1]+a[i];
		int e=(sum[i]&1);
		ans+=h[e];
		++h[e];
	}
	rep(i,1,n){
		mx=a[i],S=a[i];
		rep(j,1,60){
			if(i+j>n)break;
			mx=max(mx,a[i+j]);
			S+=a[i+j];
			if(mx+mx>S)
				--ans;
		}
	}
	printf("%lld\n",ans);
	return 0;
}
/*
3
7 31 3
*/


#include<map>
#include<set>
#include<list>
#include<ctime>
#include<cmath>
#include<deque>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
#define _rep(i,s,t) for(register int i=s;i>=t;--i)
#define Rep(i,s,t) for(register int i=s;i<t;++i)
#define go(x) for(register int e=las[x];e;e=nxt[e])
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define is insert
#define es erase
#define pii pair<int,int>
#define ms(f,x) memset(f,x,sizeof f)
#define mc(f,x) memcpy(f,x,sizeof f)
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define gi(x) read(x)
#define gii(x,y) read(x),read(y)
#define giii(x,y,z) read(x),read(y),read(z)
namespace IO{
    #define gc getchar()
    #define pc(x) putchar(x)
    template<typename T>inline void read(T &x){
        x=0;int f=1;char ch=gc;while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=gc;}
        while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=gc;x*=f;return;
    }
    template<typename T>inline void write(T x=0){
        T wr[51];wr[0]=0;if(x<0)pc('-'),x=-x;if(!x)pc(48);
        while(x)wr[++wr[0]]=x%10,x/=10;while(wr[0])pc(48+wr[wr[0]--]);return;
    }
}
using IO::read;
using IO::write;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
const int N=3e5+11;
int a[N],mx;
int n,h[3];
ll x,ans,t,S,sum[N];
int main(){
	gi(n);
	rep(i,1,n){
		gi(x);
		while(x){
			if(x&1)++a[i];
			x>>=1;
		}
	}
	++h[0];
	rep(i,1,n){
		sum[i]=sum[i-1]+a[i];
		int e=(sum[i]&1);
		ans+=h[e];
		++h[e];
	}
	rep(i,1,n){
		mx=a[i],S=a[i];
		rep(j,1,60){
			if(i+j>n)break;
			mx=max(mx,a[i+j]);
			S+=a[i+j];
			if(mx+mx>S)
				--ans;
		}
	}
	printf("%lld\n",ans);
	return 0;
}
/*
3
7 31 3
*/


#include<map>
#include<set>
#include<list>
#include<ctime>
#include<cmath>
#include<deque>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
#define _rep(i,s,t) for(register int i=s;i>=t;--i)
#define Rep(i,s,t) for(register int i=s;i<t;++i)
#define go(x) for(register int e=las[x];e;e=nxt[e])
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define is insert
#define es erase
#define pii pair<int,int>
#define ms(f,x) memset(f,x,sizeof f)
#define mc(f,x) memcpy(f,x,sizeof f)
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define gi(x) read(x)
#define gii(x,y) read(x),read(y)
#define giii(x,y,z) read(x),read(y),read(z)
namespace IO{
    #define gc getchar()
    #define pc(x) putchar(x)
    template<typename T>inline void read(T &x){
        x=0;int f=1;char ch=gc;while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=gc;}
        while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=gc;x*=f;return;
    }
    template<typename T>inline void write(T x=0){
        T wr[51];wr[0]=0;if(x<0)pc('-'),x=-x;if(!x)pc(48);
        while(x)wr[++wr[0]]=x%10,x/=10;while(wr[0])pc(48+wr[wr[0]--]);return;
    }
}
using IO::read;
using IO::write;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
const int N=3e5+11;
int a[N],mx;
int n,h[2];
ll x,ans,t,S,sum[N];
int main(){
	gi(n);
	rep(i,1,n){
		gi(x);
		while(x){
			if(x&1)++a[i];
			x>>=1;
		}
	}
	++h[0];
	rep(i,1,n){
		sum[i]=sum[i-1]+a[i];
		int e=sum[i]&1;
		ans+=h[e];
		++h[e];
	}
	rep(i,1,n){
		mx=a[i],S=a[i];
		rep(j,1,19){
			if(i+j>n)break;
			mx=max(mx,a[i+j]);
			S+=a[i+j];
			if(mx+mx>S)
				--ans;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


#include<map>
#include<set>
#include<list>
#include<ctime>
#include<cmath>
#include<deque>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
#define _rep(i,s,t) for(register int i=s;i>=t;--i)
#define Rep(i,s,t) for(register int i=s;i<t;++i)
#define go(x) for(register int e=las[x];e;e=nxt[e])
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define is insert
#define es erase
#define pii pair<int,int>
#define ms(f,x) memset(f,x,sizeof f)
#define mc(f,x) memcpy(f,x,sizeof f)
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define gi(x) read(x)
#define gii(x,y) read(x),read(y)
#define giii(x,y,z) read(x),read(y),read(z)
namespace IO{
    #define gc getchar()
    #define pc(x) putchar(x)
    template<typename T>inline void read(T &x){
        x=0;int f=1;char ch=gc;while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=gc;}
        while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=gc;x*=f;return;
    }
    template<typename T>inline void write(T x=0){
        T wr[51];wr[0]=0;if(x<0)pc('-'),x=-x;if(!x)pc(48);
        while(x)wr[++wr[0]]=x%10,x/=10;while(wr[0])pc(48+wr[wr[0]--]);return;
    }
}
using IO::read;
using IO::write;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
const int N=3e5+11;
int a[N],mx;
int n,h[2];
ll x,ans,t,S,sum[N];
int main(){
	gi(n);
	rep(i,1,n){
		gi(x);
		while(x){
			if(x&1)++a[i];
			x>>=1;
		}
	}
	++h[0];
	rep(i,1,n){
		sum[i]=sum[i-1]+a[i];
		int e=sum[i]&1;
		ans+=h[e];
		++h[e];
	}
	rep(i,1,n){
		mx=a[i],S=a[i];
		rep(j,1,19){
			if(i+j>n)break;
			mx=max(mx,a[i+j]);
			S+=a[i+j];
			if(a[i+j]+a[i+j]>S)
				--ans;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


#include<map>
#include<set>
#include<list>
#include<ctime>
#include<cmath>
#include<deque>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
#define _rep(i,s,t) for(register int i=s;i>=t;--i)
#define Rep(i,s,t) for(register int i=s;i<t;++i)
#define go(x) for(register int e=las[x];e;e=nxt[e])
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define is insert
#define es erase
#define pii pair<int,int>
#define ms(f,x) memset(f,x,sizeof f)
#define mc(f,x) memcpy(f,x,sizeof f)
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define gi(x) read(x)
#define gii(x,y) read(x),read(y)
#define giii(x,y,z) read(x),read(y),read(z)
namespace IO{
    #define gc getchar()
    #define pc(x) putchar(x)
    template<typename T>inline void read(T &x){
        x=0;int f=1;char ch=gc;while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=gc;}
        while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=gc;x*=f;return;
    }
    template<typename T>inline void write(T x=0){
        T wr[51];wr[0]=0;if(x<0)pc('-'),x=-x;if(!x)pc(48);
        while(x)wr[++wr[0]]=x%10,x/=10;while(wr[0])pc(48+wr[wr[0]--]);return;
    }
}
using IO::read;
using IO::write;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
#define int long long
const int N=3e5+11111;
int a[N],mx,t,S,sum[N],n,h[3];
ll x,ans;
main(){
	gi(n);
	rep(i,1,n){
		gi(x);
		for(;x;x>>=1)
			if(x&1)++a[i];
	}
	++h[0];
	rep(i,1,n){
		sum[i]=sum[i-1]+a[i];
		int e=(sum[i]&1);
		if(a[i]%2==0)--ans;
		ans+=h[e];
		++h[e];
	}
	rep(i,1,n){
		int ss=a[i],mx=a[i];
		rep(j,1,60){
			if(i+j>n)break;
			mx=max(mx,a[i+j]);
			ss+=a[i+j];
			if(ss%2==0&&mx+mx>ss)--ans;
			//cout<<ss<<" "<<mx<<endl;
		}
	}
	printf("%lld\n",ans);
	return 0;
}
/*
3
7 15 7
*/


#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b, c) for (int i = (a); i <= (b); i += (c))
#define FORD(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define FORl(i, a, b, c) for (ll i = (a); i <= (b); i += (c))
#define FORDl(i, a, b, c) for (ll i = (a); i >= (b); i -= (c))
using namespace std;
int freq[2];
int main () {
	int n;
	scanf("%d", &n);
	SET(freq, 0);
	ll ans = 0;
	int psum = 0;
	freq[0]++;
	FOR(i, 1, n, 1) {
		ll t, tt;
		scanf("%lld", &t); tt = t;
		int cnt = 0;
		while (t) {
			cnt += (t & 1);
			t >>= 1;
		}
		cnt &= 1;
		psum = (psum + cnt) & 1;
		ans += freq[psum];
		freq[psum]++;
		if (!cnt && tt != 0) ans--;
	}
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b, c) for (int i = (a); i <= (b); i += (c))
#define FORD(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define FORl(i, a, b, c) for (ll i = (a); i <= (b); i += (c))
#define FORDl(i, a, b, c) for (ll i = (a); i >= (b); i -= (c))
using namespace std;
int freq[2];
ll num[300005];
int bits[300005];
int main () {
	int n;
	scanf("%d", &n);
	SET(freq, 0); freq[0]++;

	ll ans = 0;
	int psum = 0;
	FOR(i, 1, n, 1) {
		ll t;
		scanf("%lld", &t);
		num[i] = t;

		int cnt = 0;
		while (t) {
			if (t % 2 == 1) cnt++;
			t /= 2;
		}
		bits[i] = cnt;

		cnt &= 1;
		psum = ((psum + cnt) & 1);
		ans += freq[psum]; freq[psum]++;

		int s = 0;
		int mx = 0;
		FORD(j, i, 1, 1) {
			s += bits[j];
			mx = max(mx, bits[j]);
			if (s > 128) break;
			if (s & 1) continue;
			if (mx * 2 > s) ans--;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b, c) for (int i = (a); i <= (b); i += (c))
#define FORD(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define FORl(i, a, b, c) for (ll i = (a); i <= (b); i += (c))
#define FORDl(i, a, b, c) for (ll i = (a); i >= (b); i -= (c))
using namespace std;
int freq[2];
ll num[300005];
int bits[300005];
int main () {
	int n;
	scanf("%d", &n);
	SET(freq, 0); freq[0]++;

	ll ans = 0;
	int psum = 0;
	FOR(i, 1, n, 1) {
		ll t;
		scanf("%lld", &t);
		num[i] = t;

		int cnt = 0;
		while (t) {
			if (t % 2 == 1) cnt++;
			t /= 2;
		}
		bits[i] = cnt;

		cnt &= 1;
		psum = ((psum + cnt) & 1);
		ans += freq[psum]; freq[psum]++;
		if (!cnt) ans--;

		int s = bits[i];
		int mx = bits[i];
		FORD(j, i - 1, 1, 1) {
			s += bits[j];
			if (s > 128) break;
			if (s & 1) continue;
			mx = max(mx, bits[j]);
			if (mx * 2 > s) ans--;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b, c) for (int i = (a); i <= (b); i += (c))
#define FORD(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define FORl(i, a, b, c) for (ll i = (a); i <= (b); i += (c))
#define FORDl(i, a, b, c) for (ll i = (a); i >= (b); i -= (c))
using namespace std;
int freq[2];
ll num[300005];
int bits[300005];
int main () {
	int n;
	scanf("%d", &n);
	SET(freq, 0);
	ll ans = 0;
	int psum = 0;
	freq[0]++;
	FOR(i, 1, n, 1) {
		ll t, tt;
		scanf("%lld", &t);
		num[i] = t;
		int cnt = 0;
		while (t) {
			cnt += (t & 1LL);
			t >>= 1;
		}
		bits[i] = cnt;

		cnt &= 1;
		psum += cnt; psum &= 1;
		ans += freq[psum]; freq[psum]++;
		if (!cnt) ans--;

		int s = bits[i];
		int mx = bits[i];
		FORD(j, i - 1, 1, 1) {
			s += bits[j];
			if (s > 128) break;
			if (s & 1) continue;
			mx = bits[j];
			if (mx * 2 > s) ans--;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b, c) for (int i = (a); i <= (b); i += (c))
#define FORD(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define FORl(i, a, b, c) for (ll i = (a); i <= (b); i += (c))
#define FORDl(i, a, b, c) for (ll i = (a); i >= (b); i -= (c))
using namespace std;
int freq[2];
ll num[300005];
int bits[300005];
int main () {
	int n;
	scanf("%d", &n);
	SET(freq, 0);
	ll ans = 0;
	int psum = 0;
	freq[0]++;
	FOR(i, 1, n, 1) {
		ll t, tt;
		scanf("%lld", &t);
		num[i] = t;
		int cnt = 0;
		while (t) {
			cnt += (t & 1LL);
			t >>= 1;
		}
		bits[i] = cnt;

		cnt &= 1;
		psum += cnt; psum &= 1;
		ans += freq[psum]; freq[psum]++;
		if (!cnt) ans--;

		int s = bits[i];
		int mx = bits[i];
		FORD(j, i - 1, 1, 1) {
			s += bits[j];
			if (s > 128) break;
			if (s & 1) continue;
			mx = max(mx, bits[j]);
			if (mx * 2 > s) ans--;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long

int n;

int main() {
    scanf("%d",&n);
    int sum = 0,even = 0,odd = 0,dou = 0;
    LL ret = 0;
    for (int i=0; i<n; i++) {
		LL xx;
		scanf("%I64d",&xx);
		int a = __builtin_popcount(xx);
		sum += a;
		if (a%2 == 0) ret--;
		if (sum % 2 == 0) {
			even++;
		}
		else {
			odd++;
		}
    }
	ret += (even*1LL*(even+1))/2+(odd*1LL*(odd-1))/2;
    printf("%I64d\n",ret);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long

int n,a[300005];

int main() {
    scanf("%d",&n);
    int sum = 0,even = 0,odd = 0,dou = 0;
    LL ret = 0;
    for (int i=0; i<n; i++) {
		LL xx;
		scanf("%I64d",&xx);
		a[i] = 0;
		while (xx) {
			a[i] += xx%2;
			xx /= 2;
		}
		//printf("%d ",a[i]);
		sum += a[i];
		if (a[i]%2 == 0) ret--;
		if (sum % 2 == 0) {
			even++;
		}
		else {
			odd++;
		}
		int mx = a[i],ts = a[i];
		for (int j=1; j<=60; j++) {
			if (i-j < 0) break;
			mx = max(a[i-j],mx);
			ts += a[i-j];
			if (ts % 2 == 0 && mx*2 > ts) {
				dou++;
			}
		}
    }
	ret += (even*1LL*(even+1))/2+(odd*1LL*(odd-1))/2;
    printf("%I64d\n",ret-dou);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long

int n;

int main() {
    scanf("%d",&n);
    int sum = 0,even = 0,odd = 0;
    LL ret = 0;
    for (int i=0; i<n; i++) {
		LL xx;
		scanf("%I64d",&xx);
		int a = __builtin_popcount(xx);
		sum += a;
		if (sum % 2 == 0) {
			even++;
		}
		else {
			odd++;
		}
		ret += even + odd/2;
    }
    printf("%I64d\n",ret-even);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define LL long long

int n;

int main() {
    scanf("%d",&n);
    int sum = 0,even = 0,odd = 0,dou = 0;
    LL ret = 0;
    for (int i=0; i<n; i++) {
		LL xx;
		scanf("%I64d",&xx);
		int a = 0;
		while (xx) {
			a += xx%2;
			xx /= 2;
		}
		sum += a;
		if (a%2 == 0) ret--;
		if (sum % 2 == 0) {
			even++;
		}
		else {
			odd++;
		}
    }
	ret += (even*1LL*(even+1))/2+(odd*1LL*(odd-1))/2;
    printf("%I64d\n",ret);
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int cnt[300005],s[300005],odd[300005],even[300005];
ll read() {
	char c=getchar(); ll x=0,f=1;
	while (c<'0' || c>'9') {
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
long long solve(int l,int r) {
	if (l>=r) return 0;
	int mx=0,j;
	for (int i=l; i<=r; i++) {
		if (mx<cnt[i]) {
			mx=cnt[i];
			j=i;
		}
	}
	long long res=solve(l,j-1)+solve(j+1,r);
	int k;
	if (j-l>=70) {
		k=j-70;
		res+=1LL*(odd[k]-odd[l-1])*(odd[r+1]-odd[j]);
		res+=1LL*(even[k]-even[l-1])*(even[r+1]-even[j]);
	}
	else k=l;
	int t=k,sum=cnt[k];
	for (int i=k; i<=j; i++) {
		while (t<j || (t<r && sum<mx*2)) {
			++t;
			sum+=cnt[t];
		}
		if (sum>=mx*2) {
			if (s[i-1]&1) res+=odd[r+1]-odd[t];
			else res+=even[r+1]-even[t];
		}
		sum-=cnt[i];
	}
	return res;
}
int main() {
	ll n=read();
	s[0]=0;
	for (int i=1; i<=n; i++) {
		ll a=read();
		cnt[i]=0;
		while (a>0) {
			if (a&1) ++cnt[i];
			a>>=1;
		}
		s[i]=s[i-1]+cnt[i];
	}
	odd[0]=even[0]=0;
	for (int i=0; i<=n; i++) {
		odd[i+1]=odd[i];
		even[i+1]=even[i];
		if (s[i]&1) ++odd[i+1];
		else ++even[i+1];
	}
	printf("%I64d\n", solve(1,n));
	return 0;
}