import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxis {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos%2==0 && dos >0){
			taxis = taxis + dos/2;
			dos = 0;
		}
		else if(dos%2!=0 && dos>1){
			taxis = taxis + (dos-1)/2;
			dos = dos - (dos-1)/2;
		}
		if(dos==1 && unos==0){
			taxis++;
		}
		else if(dos==1 && unos>=2){
			taxis++;
			dos=0;
			unos = unos - 2;
		}
		else if(dos ==1 && unos == 1){
			taxis++;
			dos=0;
			unos=0;
		}
		if (unos>3 && unos%4==0){
			taxis = taxis + unos/4;
			unos = 0;
		}
		else if (unos>3 && unos%4!=0){
			int resto = unos%4;
			taxis = taxis + (unos-resto)/4 + 1;
			unos = unos - (unos-resto)/4;
		}

		System.out.println(taxis);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxis {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos%2==0 && dos >0){
			taxis = taxis + dos/2;
			dos = 0;
		}
		else if(dos%2!=0 && dos>1){
			taxis = taxis + (dos-1)/2;
			dos = dos - (dos-1)/2;
		}
		if(dos==1 && unos==0){
			taxis++;
		}
		else if(dos==1 && unos>=2){
			taxis++;
			dos=0;
			unos = unos - 2;
		}
		else if(dos ==1 && unos == 1){
			taxis++;
			dos=0;
			unos=0;
		}
		if (unos>=4 && unos%4==0){
			taxis = taxis + unos/4;
		}
		else if (unos>4 && unos%4 !=0){
			int resto = unos%4;
			taxis = taxis + (unos-resto)/4;
			unos = unos - (unos-resto)/4;
		}
		if (unos>0 && unos<4){
			taxis++;
		}

		System.out.println(taxis);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxis {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos%2==0 && dos >0){
			taxis = taxis + dos/2;
			dos = dos - dos/2;
		}
		else if(dos%2!=0 && dos>0){
			taxis = taxis + (dos-1)/2;
			dos = dos - (dos-1)/2;
		}
		if(dos==1 && unos==0){
			taxis++;
		}
		else if(dos==1 && unos>=2){
			taxis++;
			dos=0;
			unos = unos - 2;
		}
		else if(dos ==1 && unos == 1){
			taxis++;
			dos=0;
			unos=0;
		}
		if (unos>3 && unos%4==0){
			taxis = taxis + unos/4;
			unos = 0;
		}
		else if (unos>3 && unos%4!=0){
			int resto = unos%4;
			taxis = taxis + (unos-resto)/4;
			unos = unos - (unos-resto)/4;
		}
		else if (unos>0 && unos<4){
			taxis++;
		}
		System.out.println(taxis);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxis {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos%2==0 && dos >0){
			taxis = taxis + dos/2;
			dos = 0;
		}
		else if(dos%2!=0 && dos>1){
			taxis = taxis + (dos-1)/2;
			dos = 1;
		}
		if(dos==1 && unos==0){
			taxis++;
		}
		else if(dos==1 && unos>0 && unos<3){
			taxis++;
			dos=0;
			unos = 0;
		}
		if (unos>4 && unos%4==0){
			taxis = taxis + unos/4;
		}
		else if (unos>4 && unos%4 !=0){
			int resto = unos%4;
			taxis = taxis + (unos-resto)/4;
			unos = unos - (unos-resto)/4;
		}
		if (unos>0 && unos<4){
			taxis++;
		}

		System.out.println(taxis);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxis {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos%2==0 && dos >0){
			taxis = taxis + dos/2;
			dos = 0;
		}
		else if(dos%2!=0 && dos>1){
			taxis = taxis + (dos-1)/2;
			dos = 1;
		}
		if(dos==1 && unos==0){
			taxis++;
		}
		else if(dos==1 && unos>=2){
			taxis++;
			dos=0;
			unos = unos - 2;
		}
		else if(dos ==1 && unos == 1){
			taxis++;
			dos=0;
			unos=0;
		}
		if (unos>=4 && unos%4==0){
			taxis = taxis + unos/4;
		}
		else if (unos>4 && unos%4 !=0){
			int resto = unos%4;
			taxis = taxis + (unos-resto)/4;
			unos = unos - (unos-resto)/4;
		}
		if (unos>0 && unos<4){
			taxis++;
		}

		System.out.println(taxis);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxi {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos%2==0){
			taxis = taxis + dos/2;
		}
		else{
			taxis = taxis + (dos-1)/2;
			if (unos >=2){
				taxis++;
				unos = unos-2;
			}
		}
		if (unos>=4 && unos%4==0){
			taxis = taxis + unos/4;
		}
		else if (unos>=4 && unos%4 != 0){
			int resto = unos%4;
			taxis = taxis + (unos-resto)/4 +1;
		}
		else if (unos<4 && unos>0){
			taxis++;
		}
		System.out.println(taxis);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxis {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos%2==0){
			taxis = taxis + dos/2;
			dos = dos - dos/2;
		}
		else if(dos%2!=0){
			taxis = taxis + (dos-1)/2;
			dos = dos - (dos-1)/2;
		}
		while (dos>0 && unos >=2){
			taxis++;
			dos--;
			unos = unos -2;
		}
		if(dos==1 && unos==0){
			taxis++;
		}
		if (unos>4 && unos%4==0){
			taxis = taxis + unos/4;
		}
		else if (unos>4 && unos%4 !=0){
			int resto = unos%4;
			taxis = taxis + (unos-resto)/4;
			unos = unos - (unos-resto)/4;
		}
		if (unos>0 && unos<4){
			taxis++;
		}

		System.out.println(taxis);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxis {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos%2==0 && dos >0){
			taxis = taxis + dos/2;
			dos = dos - dos/2;
		}
		else if(dos%2!=0 && dos>0){
			taxis = taxis + (dos-1)/2;
			dos = dos - (dos-1)/2;
		}
		if(dos==1 && unos==0){
			taxis++;
		}
		else if(dos==1 && unos>=2){
			taxis++;
			dos=0;
			unos = unos - 2;
		}
		else if(dos==1 && unos==1){
			taxis++;
			dos--;
			unos--;
		}
		if (unos>=4 && unos%4==0){
			taxis = taxis + unos/4;
			unos = 0;
		}
		else if (unos>4 && unos%4 !=0){
			int resto = unos%4;
			taxis = taxis + (unos-resto)/4;
			unos = unos - (unos-resto)/4;
		}
		if (unos>0 && unos<4){
			taxis++;
		}

		System.out.println(taxis);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxis {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos%2==0 && dos >0){
			taxis = taxis + dos/2;
			dos = 0;
		}
		else if(dos%2!=0 && dos>1){
			taxis = taxis + (dos-1)/2;
			dos = dos - (dos-1)/2;
		}
		if(dos==1 && unos==0){
			taxis++;
		}
		else if(dos==1 && unos>=2){
			taxis++;
			dos=0;
			unos = unos - 2;
		}
		else if(dos ==1 && unos == 1){
			taxis++;
			dos=0;
			unos=0;
		}
		if (unos>=4 && unos%4==0){
			taxis = taxis + unos/4;
			unos = 0;
		}
		else if (unos>4 && unos%4 !=0){
			int resto = unos%4;
			taxis = taxis + (unos-resto)/4;
			unos = unos - (unos-resto)/4;
		}
		if (unos>0 && unos<4){
			taxis++;
		}

		System.out.println(taxis);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxi {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos%2==0){
			taxis = taxis + dos/2;
		}
		else{
			taxis = taxis + (dos-1)/2;
			if (unos >=2){
				taxis++;
				unos = unos-2;
			}
		}
		if (unos%4==0 && unos>4){
			taxis = taxis + unos/4;
		}
		else{
			taxis = taxis + (unos/4) +1;
		}
		System.out.println(taxis);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxis {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos%2==0){
			taxis = taxis + dos/2;
			dos = 0;
		}
		else if (dos%2!=0){
			taxis = taxis + (dos-1)/2;
			dos = 1;
		}
		if (unos <= 1 && dos==1){
			taxis++;
			unos = 0;
			dos = 0;
		}
		else if(unos>1 && dos==1){
			taxis++;
			dos = 0;
			unos = unos -2;
		}
		if (unos>=4 && unos%4==0){
			taxis = taxis + unos/4;
		}
		else if (unos>4 && unos%4!=0){
			int resto = unos%4;
			taxis = taxis + (unos-resto)/4;
			unos = unos-resto;
		}
		if (unos>0 && unos<4){
			taxis++;
			unos=0;
		}
		System.out.println(taxis);
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxis {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos%2==0 && dos >0){
			taxis = taxis + dos/2;
			dos = 0;
		}
		else if(dos%2!=0 && dos>1){
			taxis = taxis + (dos-1)/2;
			dos = 1;
		}
		if(dos==1 && unos==0){
			taxis++;
		}
		else if(dos==1 && unos>0 && unos<3){
			taxis++;
			dos=0;
			unos = 0;
		}
		if (unos>=4 && unos%4==0){
			taxis = taxis + unos/4;
		}
		else if (unos>4 && unos%4 !=0){
			int resto = unos%4;
			taxis = taxis + (unos-resto)/4;
			unos = unos - (unos-resto)/4;
		}
		if (unos>0 && unos<4){
			taxis++;
		}

		System.out.println(taxis);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Taxi {

	public static void main(String[] args) throws IOException{

		BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
		int grupos = Integer.parseInt(entrada.readLine());
		String cantidad = entrada.readLine();
		int le = cantidad.length();
		int unos = 0;
		int dos =0;
		int tres = 0;
		int cuatros=0;
		for (int i=0;i<le;i++){
			if (cantidad.charAt(i)=='1'){
				unos++;
			}
			else if (cantidad.charAt(i)=='2'){
				dos++;
			}
			else if (cantidad.charAt(i)=='3'){
				tres++;
			}
			else if (cantidad.charAt(i)=='4'){
				cuatros++;
			}
		}
		int taxis = cuatros;
		while (unos >0 && tres >0){	//llena con combinaciones de 3 y 1 si es posible
			taxis++;
			unos--;
			tres--;
		}
		taxis = taxis + tres; //llena con los grupos de tres que queden, si es que quedan
		if (dos>=2 && dos%2==0){
			taxis = taxis + dos/2;
		}
		else if (dos%2!=0 && dos>1){
			taxis = taxis + (dos-1)/2;
			if (unos >=2){
				taxis++;
				unos = unos-2;
			}
		}
		else if (dos==1 && unos==0){
			taxis = taxis +1;
		}
		if (unos>=4 && unos%4==0){
			taxis = taxis + unos/4;
		}
		else if (unos>=4 && unos%4 != 0){
			int resto = unos%4;
			taxis = taxis + (unos-resto)/4 +1;
		}
		else if (unos<4 && unos>0){
			taxis++;
		}
		System.out.println(taxis);

	}

}


import java .util.* ;

public class Coding {
    public static int checking(ArrayList <Integer>x){
        int s =0;

        for (int i = x.size()-1; i >= 0; i--) {
            if(x.get(i)<4)  {
                s= i ;
                break ;
            }
        }
        return s ;
}
     public static int seeif(ArrayList<Integer> x, int num1 , int num2 ){
         for (int i = num2; i >= 1; i--) {
             if(num1+x.get(i)<= 4)return i ;
         }
         return 0 ;
     }
 public static void main(String[] args) {
      Scanner in = new Scanner (System.in);
      int taxi =0;
      ArrayList<Integer> l2=new ArrayList();
      int a=in.nextInt();

     for (int i = 0; i < a; i++) {
        l2.add(in.nextInt());

     }

          Collections.sort(l2);
          int z ;
                    int q ;
          while(!l2.isEmpty()){
              z= l2.get(0) ;
             if(z==4){
                 taxi++ ;
                 l2.remove(0) ;
             } else{
             if(seeif(l2,z,checking(l2))!=0){

                 l2.add(0 , l2.remove(0) +l2.remove(seeif(l2,z,checking(l2))));

             }else{
                 taxi++;
                 l2.remove(0);

             }

          }
          }
          System.out.println(taxi );
    }
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package coding;

import java.util.Scanner;

public class Coding {

 public static void main(String[] args) {
       Scanner in=new Scanner(System.in);
      int taxi =0;
      int x;
      int c1 =0 , c2 = 0,  c3 =0 ,c4=0 ;

      int a=in.nextInt();

     for (int i = 0; i < a; i++) {
        x= in.nextInt();
        if(x==1) c1 ++ ;
         if(x==2) c2 ++ ;
          if(x==3) c3 ++ ;
           if(x==4) c4 ++ ;

     }
     taxi +=c4 ;
     if(c1!=0 &&c3!=0){
         int t = Math.min(c1,c3 ) ;
         c1 -=t ;
         c3-= t;
         taxi += t ;
         if(c3!=0){ taxi +=c3 ;
         c3 = 0 ;

         }
     }
     if(c1!=0&&c2!=0){
          if(c1==1){
             c1-=1 ;
             c2-=1 ;
             c3++ ;
            // System.out.println("*");
          }else{
          int t = c1/2 ;
          int t1 = c1%2 ;
         int m=  Math.min(t,c2 ) ;
          c2-= m ;
          c1+=t1 ;
          c1-= m*2 ;
         // System.out.println("*");
          taxi +=m ;
          ///System.out.println(taxi );
     }}
     if(c1==0&&c2!=0){
         int t = c2 /2 ;
         int t1 = c2%2 ;
         c2 -=t;
         taxi+= t+t1 ;

     }
     if(c1!=0&&c2==0&&c3==0&&c4==0){
        int t = c1 /4 ;
         int t1 = c1%4 ;

          taxi+= t+t1 ;
           c1 -=t;

     }
      if(c1==0&&c2!=0&&c3==0&&c4==0){

         int t = c2 /2 ;
         int t1 = c2%2 ;
         c2 -=t;
         taxi+= t+t1 ;

     }
       if(c1==0&&c2==0&&c3!=0&&c4==0){

         taxi+= c3 ;

     }
     System.out.println(taxi);
    }
}


import java.util.Scanner;

public class Coding {

 public static void main(String[] args) {
       Scanner in=new Scanner(System.in);
      long taxi =0;
    int x;

      int c1 =0 , c2 = 0,  c3 =0 ,c4=0 ;

     long a=in.nextInt();

     for (int i = 0; i < a; i++) {
        x= in.nextInt();
        if(x==1) c1 ++ ;
         if(x==2) c2 ++ ;
          if(x==3) c3 ++ ;
           if(x==4) c4 ++ ;

     }
     taxi +=c4 ;
     if(c1!=0 &&c3!=0){
         int t = Math.min(c1,c3 ) ;
         c1 -=t ;
         c3-= t;
         taxi += t ;
//         if(c3!=0){ taxi +=c3 ;
//         c3 = 0 ;
//         b= false ;
//         }
     }
     if(c1!=0&&c2!=0){
          if(c1==1){
             c1-=1 ;
             c2-=1 ;
             taxi++ ;
            // System.out.println("*");
          }else{
          int t = c1/2 ;
          int t1 = c1%2 ;
         int m=  Math.min(t,c2 ) ;
          c2-= m ;
          if(c1<4)c1+=t1 ;

          c1-= m*2 ;
         // System.out.println("*");
          taxi +=m ;
          ///System.out.println(taxi );
     }}
     if(c1!=0&&c2!=0){
         int t = c2 /2 ;
         int t1 = c2%2 ;
         c2 -=t;
         taxi+= t+t1 ;

     }
      if(c3!=0){
         taxi+= c3 ;
      }

     if(c2!=0){
          int t = c2 /2 ;
          int t1 = c2%2 ;
        // c2 -=t;
         // System.out.println(t1);
         taxi+= t+t1 ;
      }

     if(c1!=0){
          if(c1<4){
         taxi++;
          }else{
          int t = c1 /4 ;
        int t1 = c1%4 ;
         // System.out.println("*");

          taxi+= t+t1 ;
           c1 -=t;
      }}

     System.out.println(taxi);
    }
}


import java .util.ArrayList ;
import java.util.Collections;
import java.util.Scanner;

public class Coding {

     public static int seeif(ArrayList<Integer> x, int num1  ){
         if(num1 == 4 ){
             return 0 ;
         }else{
         for (int i = x.size()-1; i >= 1; i--) {
             if(num1+x.get(i)<= 4)return i ;
         }}
         return 0 ;
     }
 public static void main(String[] args) {
       Scanner in=new Scanner(System.in);
      int taxi =0;
      ArrayList<Integer> l2=new ArrayList();
      int a=in.nextInt();

     for (int i = 0; i < a; i++) {
        l2.add(in.nextInt());

     }

          Collections.sort(l2);
          int z ;
          int t ;

          while(!l2.isEmpty()){
              z= l2.get(0) ;
             t=  seeif(l2,z) ;

             if(t!=0){
                     l2.set(0, z+l2.remove(t));

             }else{
                 taxi++;
                 l2.remove(0);

          }
          }
          System.out.println(taxi );
    }
}


import java.util.Scanner;

public class Coding {

 public static void main(String[] args) {
       Scanner in=new Scanner(System.in);
 long taxi =0;
     long x;

      long c1 =0 , c2 = 0,  c3 =0 ,c4=0 ;

     long a=in.nextInt();

     for (int i = 0; i < a; i++) {
        x= in.nextInt();
        if(x==1) c1 ++ ;
         if(x==2) c2 ++ ;
          if(x==3) c3 ++ ;
           if(x==4) c4 ++ ;

     }
     taxi +=c4 ;
     if(c1!=0 &&c3!=0){
        long t = Math.min(c1,c3 ) ;
         c1 -=t ;
         c3-= t;
         taxi += t ;

     }
     if(c1!=0&&c2!=0){
          if(c1==1){
             c1-=1 ;
             c2-=1 ;
             taxi++ ;

          }else{
          long t = c1/2 ;
          long t1 = c1%2 ;
         long m=  Math.min(t,c2 ) ;
          c2-= m ;
          if(c1>4)c1+=t1 ;

          c1-= m*2 ;

          taxi +=m ;

     }}
     if(c1!=0&&c2!=0){
         long t = c2 /2 ;
         long t1 = c2%2 ;
         c2 -=t;
         taxi+= t+t1 ;

     }
      if(c3!=0){
         taxi+= c3 ;
      }

     if(c2!=0){
          long t = c2 /2 ;
          long t1 = c2%2 ;

         taxi+= t+t1 ;
      }

     if(c1!=0){
          if(c1<4){
         taxi++;
          }else{
         long t = c1 /4 ;
        long t1 = c1%4 ;
         // System.out.println("*");

          taxi+= t+t1 ;
           c1 -=t;
      }}

     System.out.println(taxi);
    }
}


import java .util.ArrayList ;
import java.util.Collections;
import java.util.Scanner;

public class Coding {

     public static int seeif(ArrayList<Integer> x, int num1  ){
         for (int i = x.size()-1; i >= 1; i--) {
             if(num1+x.get(i)<= 4)return i ;
         }
         return 0 ;
     }
 public static void main(String[] args) {
       Scanner in=new Scanner(System.in);
      int taxi =0;
      ArrayList<Integer> l2=new ArrayList();
      int a=in.nextInt();

     for (int i = 0; i < a; i++) {
        l2.add(in.nextInt());

     }

          Collections.sort(l2);
          int z ;
          int t ;

          while(!l2.isEmpty()){
              z= l2.get(0) ;
              t=seeif(l2,z) ;
             if(z==4){
                 taxi++ ;
                 l2.remove(0) ;
             } else{
             if(t!=0){

                 l2.add(0 , l2.remove(0) +l2.remove(t));

             }else{
                 taxi++;
                 l2.remove(0);

             }

          }
          }
          System.out.println(taxi );
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+50;
ll sum[N],odd[N],even[N];
ll a[N],b[N];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        b[i]=0;
        for(int j=0;j<64;j++){
            if(a[i]&(1LL<<j)){
                b[i]++;
            }
        }
        a[i]=b[i];
    }
    ll res=0;
    for(int i=1;i<=n;i++){
        sum[i]=sum[i-1]+a[i];
        ll maxn=a[i];
        for(int j=i-1;j>=max(i-64,1);j--){
            maxn=max(a[j],maxn);
            ll tmp=sum[i]-sum[j-1];
            if(!(tmp&1LL)&&maxn*2<=tmp){
                res++;
            }
           // cout<<tmp<<' '<<maxn<<endl;
        }
        if(i>64){
            if(sum[i]&1) res+=odd[i-64];
            else res+=even[i-64];
        }
        odd[i]=odd[i-1];
        even[i]=even[i-1];
        if(sum[i]&1LL) odd[i]++;
        else even[i]++;
    }
    printf("%lld\n",res);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+50;
ll dp2[65],dp1[65],pre[150];
ll a[N],b[N];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        b[i]=0;
        for(int j=0;j<64;j++){
            if(a[i]&(1LL<<j)){
                b[i]++;
            }
        }
    }
    //memset(dp,0,sizeof(dp));
    memset(pre,0,sizeof(pre));
    ll res=0;
    /*for(int i=1;i<=n;i++) cout<<b[i]<<' ';
    cout<<endl;*/
    for(int i=1;i<=n;i++){
        for(int j=b[i];j<=64;j+=2)res+=dp2[j];
        res+=dp1[b[i]];
        for(int j=0;j<=64;j++){
            if(dp1[j]+dp2[j]==0) continue;
            ll r=(b[i]+j);
            if(r>64) {
                if(r%2==0)
                    r=64;
                else r=63;
            }
            pre[r]+=dp1[j]+dp2[j];
        }
        for(int j=0;j<=64;j++) dp2[j]=pre[j],pre[j]=0,dp1[j]=0;
        dp1[b[i]]++;
        /*for(int j=0;j<64;j++) if(dp[i][j]!=0)cout<<j<<' ';
        cout<<endl;*/
    }
    //cout<<endl;
    printf("%lld\n",res);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+50;
ll dp[N][64],pre[80];
ll a[N],b[N];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        b[i]=0;
        for(int j=0;j<64;j++){
            if(a[i]&(1LL<<j)){
                b[i]++;
            }
        }
    }
    memset(dp,0,sizeof(dp));
    dp[0][0]=0;
    memset(pre,0,sizeof(pre));
    ll res=0;
    /*for(int i=1;i<=n;i++) cout<<b[i]<<' ';
    cout<<endl;*/
    for(int i=1;i<=n;i++){
        for(int j=b[i];j<64;j+=2)res+=dp[i-1][j];
        for(int j=0;j<64;j++){
            if(dp[i-1][j]==0) continue;
            ll r=(b[i]+j);
            if(r>=64) r=r-(63-r);
            pre[r]+=dp[i-1][j];
        }
        for(int j=0;j<64;j++) dp[i][j]=pre[j],pre[j]=0;
        dp[i][b[i]]++;
       /* for(int j=0;j<64;j++) cout<<dp[i][j]<<' ';
        cout<<endl;*/
      //  cout<<dp[i][0]<<endl;
        res+=dp[i][0];
        //cout<<dp[i][0]<<' ';
    }
    //cout<<endl;
    printf("%lld\n",res);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+50;
ll sum[N],odd[N],even[N];
ll a[N],b[N];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        b[i]=0;
        for(int j=0;j<64;j++){
            if(a[i]&(1LL<<j)){
                b[i]++;
            }
        }
        a[i]=b[i];
    }
    ll res=0;sum[0]=odd[0]=0;even[0]=1;
    for(int i=1;i<=n;i++){
        sum[i]=sum[i-1]+a[i];
        ll maxn=a[i];
        for(int j=i-1;j>=max(i-128,1);j--){
            maxn=max(a[j],maxn);
            ll tmp=sum[i]-sum[j-1];
            if(!(tmp&1LL)&&maxn*2<=tmp){
                res++;
            }
           // cout<<tmp<<' '<<maxn<<endl;
        }
        if(i>129){
            if(sum[i]&1) res+=odd[i-130];
            else res+=even[i-130];
        }
        odd[i]=odd[i-1];
        even[i]=even[i-1];
        if(sum[i]&1LL) odd[i]++;
        else even[i]++;
    }
    printf("%lld\n",res);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+50;
ll sum[N],odd[N],even[N];
ll a[N],b[N];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        b[i]=0;
        for(int j=0;j<64;j++){
            if(a[i]&(1LL<<j)){
                b[i]++;
            }
        }
        a[i]=b[i];
    }
    ll res=0;
    for(int i=1;i<=n;i++){
        sum[i]=sum[i-1]+a[i];
        ll maxn=a[i];
        for(int j=i-1;j>=max(i-64,1);j--){
            maxn=max(a[j],maxn);
            ll tmp=sum[i]-sum[j-1];
            if((tmp&1LL)&&maxn*2<=tmp){
                res++;
            }
          //  cout<<j<<' '<<maxn<<endl;
        }
        if(i>64){
            if(sum[i]&1) res+=odd[i-64];
            else res+=even[i-64];
        }
        odd[i]=odd[i-1];
        even[i]=even[i-1];
        if(sum[i]&1LL) odd[i]++;
        else even[i]++;
    }
    printf("%lld\n",res);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+50;
ll sum[N],odd[N],even[N];
ll a[N],b[N];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        b[i]=0;
        for(int j=0;j<64;j++){
            if(a[i]&(1LL<<j)){
                b[i]++;
            }
        }
        a[i]=b[i];
    }
    ll res=0;sum[0]=odd[0]=0;even[0]=1;
    for(int i=1;i<=n;i++){
        sum[i]=sum[i-1]+a[i];
        ll maxn=a[i];
        for(int j=i-1;j>=max(i-64,1);j--){
            maxn=max(a[j],maxn);
            ll tmp=sum[i]-sum[j-1];
            if(!(tmp&1LL)&&maxn*2<=tmp){
                res++;
            }
           // cout<<tmp<<' '<<maxn<<endl;
        }
        if(i>64){
            if(sum[i]&1) res+=odd[i-65];
            else res+=even[i-65];
        }
        odd[i]=odd[i-1];
        even[i]=even[i-1];
        if(sum[i]&1LL) odd[i]++;
        else even[i]++;
    }
    printf("%lld\n",res);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+50;
ll sum[N],odd[N],even[N];
ll a[N],b[N];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        b[i]=0;
        for(int j=0;j<64;j++){
            if(a[i]&(1LL<<j)){
                b[i]++;
            }
        }
        a[i]=b[i];
    }
    ll res=0;sum[0]=odd[0]=even[0]=0;
    for(int i=1;i<=n;i++){
        sum[i]=sum[i-1]+a[i];
        ll maxn=a[i];
        for(int j=i-1;j>=max(i-128,1);j--){
            maxn=max(a[j],maxn);
            ll tmp=sum[i]-sum[j-1];
            if(!(tmp&1LL)&&maxn*2<=tmp){
                res++;
            }
           // cout<<tmp<<' '<<maxn<<endl;
        }
        if(i>129){
            if(sum[i]&1) res+=odd[i-130];
            else res+=even[i-130];
        }
        odd[i]=odd[i-1];
        even[i]=even[i-1];
        if(sum[i]&1LL) odd[i]++;
        else even[i]++;
    }
    printf("%lld\n",res);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+50;
ll sum[N],odd[N],even[N];
ll a[N],b[N];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        b[i]=0;
        for(int j=0;j<64;j++){
            if(a[i]&(1LL<<j)){
                b[i]++;
            }
        }
        a[i]=b[i];
    }
    ll res=0;sum[0]=odd[0]=0;even[0]=1;
    for(int i=1;i<=n;i++){
        sum[i]=sum[i-1]+a[i];
        ll maxn=a[i];
        for(int j=i-1;j>=max(i-61,1);j--){
            maxn=max(a[j],maxn);
            ll tmp=sum[i]-sum[j-1];
            if(!(tmp&1LL)&&maxn*2<=tmp){
                res++;
            }
           // cout<<tmp<<' '<<maxn<<endl;
        }
        if(i>62){
            if(sum[i]&1) res+=odd[i-63];
            else res+=even[i-63];
        }
        odd[i]=odd[i-1];
        even[i]=even[i-1];
        if(sum[i]&1LL) odd[i]++;
        else even[i]++;
    }
    printf("%lld\n",res);
}


#include <iostream>
#include <algorithm>
#include <set>
#include <cmath>
#include <string>
#include <unordered_map>
#include <vector>
#include <bitset>

using namespace std;

bool check(string x){
    int res = 0;
    for(char i : x)
        if(i == '1')
            res ++;
    return res % 2 != 0;
}

int main () {
    bool data[300003] = {};
    long long n, a, res = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a;
        bitset<61> bit = a;
        data[i] = check(bit.to_string());
    }
    for(int i = 0; i < n - 1; i++){
        int k = data[i];
        for(int j = i + 1; j < n; j++){
            k += data[j];
            if(k % 2 == 0)
                res++;
        }
    }
    cout << res;
}


#include <iostream>
#include <algorithm>
#include <set>
#include <cmath>
#include <string>
#include <unordered_map>
#include <vector>
#include <bitset>

using namespace std;

unsigned long long check(unsigned long long x){
    unsigned long long res = 1;
    while (x > 2){
        res += x % 2;
        x /= 2;
    }
    return res;
}

const int M = int(3e5+3);
unsigned long long a[M], b[M], res = 0, S0, S1;
int n;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        b[i] = check(a[i]);
    }
    for (int i = 0; i < n; i++){
        S0 = b[i];
        for (int j = i + 1; j < n; j++){
            S0 += b[j];
            if(S0 % 2 == 0)
                res ++;
        }
    }
    for (int i = 0; i < n; i++){
        S0 = b[i]; S1 = b[i];
        for (int j = i + 1; j < n && j - i < 65; j++){
            S0 += b[j]; S1 = max(S1, b[j]);
            if(S0 % 2 == 0 && 2*S1 > S0)
                res --;
        }
    }
    cout << res;
}


#include <iostream>
#include <algorithm>
#include <set>
#include <cmath>
#include <string>
#include <unordered_map>
#include <vector>
#include <bitset>

using namespace std;

unsigned long long check(unsigned long long x){
    unsigned long long res = 1;
    while (x > 2){
        res += x % 2;
        x /= 2;
    }
    return res;
}

const int M = int(3e5+3);
unsigned long long a[M], b[M], res = 0, S0, S1;
int n;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        b[i] = check(a[i]);
        cout << a[i] << " " << b[i] << endl;
    }
    for (int i = 0; i < n; i++){
        S0 = b[i]; S1 = b[i];
        for (int j = i + 1; j < n; j++){
            S0 += b[j]; S1 = max(S1, b[j]);
            if(S0 % 2 == 0 && 2*S1 < S0)
                res ++;
        }
    }
    cout << res;
}


#include <iostream>
#include <algorithm>
#include <set>
#include <cmath>
#include <string>
#include <unordered_map>
#include <vector>
#include <bitset>

using namespace std;

unsigned long long check(unsigned long long x){
    unsigned long long res = 1;
    while (x > 2){
        res += x % 2;
        x /= 2;
    }
    return res;
}

const int M = int(3e5+3);
unsigned long long a[M], b[M], res = 0, S0, S1;
int n;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        b[i] = check(a[i]);
    }
    for (int i = 0; i < n; i++){
        S0 = b[i]; S1 = b[i];
        for (int j = i + 1; j < n; j++){
            S0 += b[j]; S1 = max(S1, b[j]);
            if(S0 % 2 == 0 && 2*S1 <= S0)
                res ++;
        }
    }
    cout << res;
}


#include <bits/stdc++.h>
#define endl '\n'
#define ll int64_t
#define ull uint64_t
using namespace std;

const int N = int(3e5) + 9;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, res{}, s1 = 1, s2{}, sufSum{};
    cin >> n;
    long long a[N];
    int b[N];
    for(int i = 0; i <n; ++i){
        cin >> a[i];
        b[i] = __builtin_popcountll(a[i]);
    }
    for(int i = n - 1; i >= 0; --i){
        int sum = 0, mx = 0;
        for(int j = i; j < n && j - i < 65; ++j){
            sum += b[j];
            mx = max(mx, b[j]);
            if(mx > sum - mx && sum % 2 == 0) --res;
        }

        sufSum += b[i];
        if (sufSum % 2 == 0)
            res += s1;
        else
            res += s2;

        if(sufSum & 1) ++s2;
        else ++s1;
    }
    cout << res << endl;
    return 0;
};


#include <iostream>
#include <algorithm>
#include <set>
#include <cmath>
#include <string>
#include <unordered_map>
#include <vector>
#include <bitset>

using namespace std;

int check(int x){
    int res = 1;
    while (x > 2){
        res += x % 2;
        x /= 2;
    }
    return res;
}

const int M = int(3e5+3);

int n, a[M], b[M], res = 0, S0, S1;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        b[i] = check(a[i]);
    }
    for (int i = 0; i < n; i++){
        S0 = b[i];
        for (int j = i + 1; j < n; j++){
            S0 += b[j];
            if(S0 % 2 == 0)
                res ++;
        }
    }
    for (int i = 0; i < n; i++){
        S0 = b[i];
        for (int j = i + 1; j < min(n, i + 63); j++){
            S1 += b[j];
            if(S0 > S1)
                res--;
        }
    }
    cout << res;
}


#include <bits/stdc++.h>
#define endl '\n'
#define ll int64_t
#define ull uint64_t
using namespace std;

const int N = int(3e5) + 9;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, res{}, s1 = 1, s2{}, sufSum{};
    cin >> n;
    long long a[N];
    int b[N];
    for(int i = 0; i <n; ++i){
        cin >> a[i];
        b[i] = __builtin_popcountll(a[i]);
    }
    for(int i = n - 1; i >= 0; --i){
        int sum = 0, mx = 0;
        for(int j = i; j < n && j - i < 65; ++j){
            sum += b[j];
            mx = max(mx, b[j]);
            if(mx > sum - mx && sum % 2 == 0) --res;
        }

        sufSum += b[i];
        if (sufSum % 2 == 0)
            res += s1;
        else
            res += s2;

        if(sufSum & 1) ++s2;
        else ++s1;
    }
    cout << res << endl;
    return 0;
};


#include <bits/stdc++.h>
#define endl '\n'
#define ll int64_t
#define ull uint64_t
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, temp;
    cin >> n;
    vector<int> b;
    for (int i = 0; i < n; ++i) {
        cin >> temp;
        b.push_back(__builtin_popcount(temp));
    }
    int res, s{}, sum{};
    for (int i = n - 2; i >= 0; --i) {
        sum += b[i + 1];
        if (sum % 2 == 0)
            ++s;
        if (sum % 2)
            res += n - i - 1 - s;
        else
            res += s;
    }
    for (ll l = 0; l < n; ++l) {
        sum = b[l];
        s = b[l];
        for (ll r = l + 1; r < min(l + 61, n); ++r) {
            sum += b[r];
            s = max(s, b[r]);
            if (sum < 2 * s && sum % 2 == 0)
                --res;
        }
    }
    cout << res << endl;
    return 0;
};


#include <bits/stdc++.h>
#define endl '\n'
#define ll int64_t
#define ull uint64_t
using namespace std;

const int N = int(3e5) + 9;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, res{}, s1 = 1, s2{}, sufSum{}, temp;
    cin >> n;
    vector<int> b;
    for(int i = 0; i <n; ++i){
        cin >> temp;
        b.push_back(__builtin_popcountll(temp));
    }
    for(int i = n - 1; i >= 0; --i){
        int sum = 0, mx = 0;
        for(int j = i; j < n && j - i < 65; ++j){
            sum += b[j];
            mx = max(mx, b[j]);
            if(mx > sum - mx && sum % 2 == 0) --res;
        }

        sufSum += b[i];
        if (sufSum % 2 == 0)
            res += s1;
        else
            res += s2;

        if(sufSum & 1) ++s2;
        else ++s1;
    }
    cout << res << endl;
    return 0;
};


#include <iostream>
#include <algorithm>
#include <set>
#include <cmath>
#include <string>
#include <unordered_map>
#include <vector>
#include <bitset>

using namespace std;

int count(long long x){
    int res = 1;
    while(x > 2){
        res += x % 2 != 0;
        x /= 2;
    }
    return res;
}

const int N = int(3e5 + 3);
int n, res = 0, b[N] = {};
long long a;
int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a;
        b[i] = count(a);
    }
    for(int i = 0; i < n - 1; i++){
        int cnt = b[i], max = cnt;
        for(int j = i + 1; j < n; j++){
            cnt += b[j];
            if(max<b[j])
                max = b[j];
            if(2*max<=cnt&&cnt%2==0)
                res++;
        }
    }
    cout << res;
}


#include <bits/stdc++.h>
#define endl '\n'
#define ll int64_t
#define ull uint64_t
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, temp;
    cin >> n;
    vector<int> b;
    for (int i = 0; i < n; ++i) {
        cin >> temp;
        b.push_back(__builtin_popcount(temp));
    }
    int res{}, s{}, sum{};
    for (int i = n - 2; i >= 0; --i) {
        sum += b[i + 1];
        if (sum % 2 == 0)
            ++s;
        if (sum % 2)
            res += n - i - 1 - s;
        else
            res += s;
    }
    for (ll l = 0; l < n; ++l) {
        sum = b[l];
        s = b[l];
        for (ll r = l + 1; r < min(l + 61, n); ++r) {
            sum += b[r];
            s = max(s, b[r]);
            if (sum < 2 * s && sum % 2 == 0)
                --res;
        }
    }
    cout << res << endl;
    return 0;
};


#include <bits/stdc++.h>
#define endl '\n'
#define ll int64_t
#define ull uint64_t
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, temp;
    cin >> n;
    vector<int> b;
    for (int i = 0; i < n; ++i) {
        cin >> temp;
        b.push_back(__builtin_popcount(temp));
    }
    int res{}, s1 = 1, s2{}, sum{};
    for (int i = n - 1; i >= 0; --i) {
        sum += b[i];
        if (sum % 2) res += s2;
        else res += s1;
        if (sum % 2) ++s2;
        else ++s1;
    }
    for (ll l = 0; l < n; ++l) {
        sum = 0;
        s1 = 0;
        for (ll r = l; r < min(l + 61, n); ++r) {
            sum += b[r];
            s1 = max(s1, b[r]);
            if (sum < 2 * s1 && sum % 2 == 0)
                --res;
        }
    }
    cout << res << endl;
    return 0;
};


#include <iostream>
#include <algorithm>
#include <set>
#include <cmath>
#include <string>
#include <unordered_map>
#include <vector>
#include <bitset>

using namespace std;

unsigned long long check(unsigned long long x){
    unsigned long long res = 1;
    while (x > 2){
        res += x % 2;
        x /= 2;
    }
    return res;
}

const int M = int(3e5+3);
unsigned long long a[M], b[M], res = 0, S0, S1;
int n;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        b[i] = check(a[i]);
    }
    for (int i = 0; i < n; i++){
        S0 = b[i]; S1 = b[i];
        for (int j = i + 1; j < n; j++){
            S0 += b[j]; S1 = max(S1, b[j]);
            if(S0 % 2 == 0 && (j >= i + 63 || 2*S1 <= S0))
                res ++;
        }
    }
    cout << res;
}


#include <iostream>
#include <algorithm>
#include <set>
#include <cmath>
#include <string>
#include <unordered_map>
#include <vector>
#include <bitset>

using namespace std;

bool check(string x){
    int res = 0;
    for(char i : x)
        if(i == '1')
            res ++;
    return res % 2 != 0;
}

int main () {
    bool data[300003] = {};
    int n, a, res = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a;
        bitset<61> bit = a;
        data[i] = check(bit.to_string());
    }
    for(int i = 0; i < n - 1; i++){
        int k = data[i];
        for(int j = i + 1; j < n; j++){
            k += data[j];
            if(k % 2 == 0)
                res++;
        }
    }
    cout << res;
}


#include <iostream>
#include <algorithm>
#include <set>
#include <cmath>
#include <string>
#include <unordered_map>
#include <vector>
#include <bitset>

using namespace std;

unsigned long long check(unsigned long long x){
    unsigned long long res = 1;
    while (x > 2){
        res += x % 2;
        x /= 2;
    }
    return res;
}

const int M = int(3e5+3);

unsigned long long a[M], b[M], res = 0, S0, S1;
int n;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        b[i] = check(a[i]);
    }
    for (int i = 0; i < n; i++){
        S0 = b[i];
        for (int j = i + 1; j < n; j++){
            S0 += b[j];
            if(S0 % 2 == 0)
                res ++;
        }
    }
    for (int i = 0; i < n; i++){
        S0 = b[i];
        for (int j = i + 1; j < min(n, i + 63); j++){
            S1 += b[j];
            if(S0 > S1)
                res--;
        }
    }
    cout << res;
}


#include <bits/stdc++.h>
#define sz(x) (long long)x.size()

using namespace std;

//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 5, M = 1e6 + 7, SM = 1e3 + 5, logN = 20;
const long long MOD = 1e9 + 7, INF = 1e18 + 9;
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Head, typename... Tail>
void debug(Head a, Tail... b) {
    cerr << a << " ";
    debug(b...);
}

long long a[N * 3], pref[N * 3], L[N * 3], R[N * 3], sign[N * 3][2];

long long sum(long long l, long long r) {
	return pref[r] - pref[l - 1];
}

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	long long n; cin >> n;

	for(long long i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] = __builtin_popcountll(a[i]);
	}

	stack<long long> s;

	for(long long i = 1; i <= n; i++) {
		while(!s.empty() && a[i] >= a[s.top()]) s.pop();
		if(s.empty()) L[i] = 1;
		else L[i] = s.top() + 1;
		s.push(i);
	}

	while(!s.empty()) s.pop();

	for(long long i = n; i >= 1; i--) {
		while(!s.empty() && a[i] > a[s.top()]) s.pop();
		if(s.empty()) R[i] = n;
		else R[i] = s.top() - 1;
		s.push(i);
	}

	for(long long i = 1; i <= n; i++) {
		pref[i] = pref[i - 1] + a[i];
		sign[i][0] = sign[i - 1][0];
		sign[i][1] = sign[i - 1][1];
		if(pref[i] & 1) sign[i][1]++;
		else sign[i][0]++;
	}

	long long ans = 0;

	for(long long i = 1; i <= n; i++) {
		for(long long l = L[i]; l <= i; l++) {
			long long low = i, high = R[i], r = 0;
			while(low <= high) {
				long long mid = low + (high - low) / 2;
				if(sum(l, mid) - a[i] >= a[i]) {
					high = mid - 1;
					r = mid;
				}
				else {
					low = mid + 1;
				}
			}
			if(!r) continue;
			ans += (sign[R[i]][pref[l - 1] & 1] - sign[r - 1][pref[l - 1] & 1]);
		}
	}

	cout << ans;

	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
#define sz(x) (long long)x.size()

using namespace std;

//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 5, M = 1e6 + 7, SM = 1e3 + 5, logN = 20;
const long long MOD = 1e9 + 7, INF = 1e18 + 9;
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Head, typename... Tail>
void debug(Head a, Tail... b) {
    cerr << a << " ";
    debug(b...);
}

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	long long n; cin >> n;

	vector<long long> a(n + 1), pref(n + 1), L(n + 1), R(n + 1);
	vector<vector<long long>> sign(n + 1, vector<long long>(2));

	for(long long i = 1; i <= n; i++) {
		cin >> a[i];
	}

	stack<long long> s;

	for(long long i = 1; i <= n; i++) {
		while(!s.empty() && a[i] >= s.top()) s.pop();
		if(s.empty()) L[i] = 1;
		else L[i] = s.top() + 1;
		s.push(i);
	}

	while(!s.empty()) s.pop();

	for(long long i = n; i >= 1; i--) {
		while(!s.empty() && a[i] > a[s.top()]) s.pop();
		if(s.empty()) R[i] = n;
		else R[i] = s.top() - 1;
		s.push(i);
	}

	for(long long i = 1; i <= n; i++) {
		pref[i] = pref[i - 1] + a[i];
		sign[i][0] = sign[i - 1][0];
		sign[i][1] = sign[i - 1][1];
		if(pref[i] & 1) sign[i][1]++;
		else sign[i][0]++;
	}

	auto sum = [&](long long l, long long r) {
		return pref[r] - pref[l - 1];
	};

	long long ans = 0;

	for(long long i = 1; i <= n; i++) {
		for(long long l = L[i]; l < i; l++) {
			long long low = i, high = R[i], r = i;
			while(low <= high) {
				long long mid = low + (high - low) / 2;
				if(sum(l, mid) - a[i] <= a[i]) {
					low = mid + 1;
					r = mid;
				}
				else {
					high = mid - 1;
				}
			}
			ans += (sign[r][pref[l - 1] & 1] - sign[l - 1][pref[l - 1] & 1]);
		}
	}

	cout << ans;

	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
#define sz(x) (long long)x.size()

using namespace std;

//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 5, M = 1e6 + 7, SM = 1e3 + 5, logN = 20;
const long long MOD = 1e9 + 7, INF = 1e18 + 9;
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Head, typename... Tail>
void debug(Head a, Tail... b) {
    cerr << a << " ";
    debug(b...);
}

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	long long n; cin >> n;

	vector<long long> a(n + 1), pref(n + 1), L(n + 1), R(n + 1);
	vector<vector<long long>> sign(n + 1, vector<long long>(2));

	auto bits = [&](long long x) {
		long long ans = 0;
		while(x) {
			ans += (x & 1ll);
			x >>= 1ll;
		}
		return ans;
	};

	for(long long i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] = bits(a[i]);
	}

	stack<long long> s;

	for(long long i = 1; i <= n; i++) {
		while(!s.empty() && a[i] >= a[s.top()]) s.pop();
		if(s.empty()) L[i] = 1;
		else L[i] = s.top() + 1;
		s.push(i);
	}

	while(!s.empty()) s.pop();

	for(long long i = n; i >= 1; i--) {
		while(!s.empty() && a[i] > a[s.top()]) s.pop();
		if(s.empty()) R[i] = n;
		else R[i] = s.top() - 1;
		s.push(i);
	}

	for(long long i = 1; i <= n; i++) {
		pref[i] = pref[i - 1] + a[i];
		sign[i][0] = sign[i - 1][0];
		sign[i][1] = sign[i - 1][1];
		if(pref[i] & 1) sign[i][1]++;
		else sign[i][0]++;
	}

	auto sum = [&](long long l, long long r) {
		return pref[r] - pref[l - 1];
	};

	long long ans = 0;

	for(long long i = 1; i <= n; i++) {
		for(long long l = L[i]; l <= i; l++) {
			long long low = i, high = R[i], r = 0;
			while(low <= high) {
				long long mid = low + (high - low) / 2;
				if(sum(l, mid) - a[i] >= a[i]) {
					high = mid - 1;
					r = mid;
				}
				else {
					low = mid + 1;
				}
			}
			if(!r) continue;
			ans += (sign[R[i]][pref[l - 1] & 1] - sign[r - 1][pref[l - 1] & 1]);
		}
	}

	cout << ans;

	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
#define sz(x) (long long)x.size()

using namespace std;

//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 5, M = 1e6 + 7, SM = 1e3 + 5, logN = 20;
const long long MOD = 1e9 + 7, INF = 1e18 + 9;
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Head, typename... Tail>
void debug(Head a, Tail... b) {
    cerr << a << " ";
    debug(b...);
}

long long n, a[N * 3], pref[N * 3], L[N * 3], R[N * 3], sign[N * 3][2];

long long sum(long long l, long long r) {
	return pref[r] - pref[l - 1];
}

long long bits(long long x) {
	long long ans = 0;
	while(x) {
		ans += (x & 1);
		x >>= 1;
	}
	return ans;
};

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n;

	for(long long i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] = bits(a[i]);
	}

	stack<long long> s;

	for(long long i = 1; i <= n; i++) {
		while(!s.empty() && a[i] >= a[s.top()]) s.pop();
		if(s.empty()) L[i] = 1;
		else L[i] = s.top() + 1;
		s.push(i);
	}

	while(!s.empty()) s.pop();

	for(long long i = n; i >= 1; i--) {
		while(!s.empty() && a[i] > a[s.top()]) s.pop();
		if(s.empty()) R[i] = n;
		else R[i] = s.top() - 1;
		s.push(i);
	}

	for(long long i = 1; i <= n; i++) {
		pref[i] = pref[i - 1] + a[i];
		sign[i][0] = sign[i - 1][0];
		sign[i][1] = sign[i - 1][1];
		sign[i][pref[i] & 1]++;
	}

	long long ans = 0;

	for(long long i = 1; i <= n; i++) {
		for(long long l = L[i]; l <= i; l++) {
			long long low = i, high = R[i], r = 0;
			while(low <= high) {
				long long mid = low + (high - low) / 2;
				if(sum(l, mid) - a[i] >= a[i]) {
					high = mid - 1;
					r = mid;
				}
				else {
					low = mid + 1;
				}
			}
			if(!r) continue;
			ans += (sign[R[i]][pref[l - 1] & 1] - sign[r - 1][pref[l - 1] & 1]);
		}
	}

	cout << ans;

	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
#define sz(x) (long long)x.size()

using namespace std;

//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 5, M = 1e6 + 7, SM = 1e3 + 5, logN = 20;
const long long MOD = 1e9 + 7, INF = 1e18 + 9;
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Head, typename... Tail>
void debug(Head a, Tail... b) {
    cerr << a << " ";
    debug(b...);
}

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	long long n; cin >> n;

	vector<long long> a(n + 1), pref(n + 1), L(n + 1), R(n + 1);
	vector<vector<long long>> sign(n + 1, vector<long long>(2));

	for(long long i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] = __builtin_popcountll(a[i]);
	}

	stack<long long> s;

	for(long long i = 1; i <= n; i++) {
		while(!s.empty() && a[i] >= a[s.top()]) s.pop();
		if(s.empty()) L[i] = 1;
		else L[i] = s.top() + 1;
		s.push(i);
	}

	while(!s.empty()) s.pop();

	for(long long i = n; i >= 1; i--) {
		while(!s.empty() && a[i] > a[s.top()]) s.pop();
		if(s.empty()) R[i] = n;
		else R[i] = s.top() - 1;
		s.push(i);
	}

	for(long long i = 1; i <= n; i++) {
		pref[i] = pref[i - 1] + a[i];
		sign[i][0] = sign[i - 1][0];
		sign[i][1] = sign[i - 1][1];
		if(pref[i] & 1) sign[i][1]++;
		else sign[i][0]++;
	}

	auto sum = [&](long long l, long long r) {
		return pref[r] - pref[l - 1];
	};

	long long ans = 0;

	for(long long i = 1; i <= n; i++) {
		for(long long l = L[i]; l <= i; l++) {
			long long low = i, high = R[i], r = 0;
			while(low <= high) {
				long long mid = low + (high - low) / 2;
				if(sum(l, mid) - a[i] >= a[i]) {
					high = mid - 1;
					r = mid;
				}
				else {
					low = mid + 1;
				}
			}
			if(!r) continue;
			ans += (sign[R[i]][pref[l - 1] & 1] - sign[r - 1][pref[l - 1] & 1]);
		}
	}

	cout << ans;

	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
#define sz(x) (long long)x.size()

using namespace std;

//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 5, M = 1e6 + 7, SM = 1e3 + 5, logN = 20;
const long long MOD = 1e9 + 7, INF = 1e18 + 9;
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Head, typename... Tail>
void debug(Head a, Tail... b) {
    cerr << a << " ";
    debug(b...);
}

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	long long n; cin >> n;

	vector<long long> a(n + 1), pref(n + 1), L(n + 1), R(n + 1);
	vector<vector<long long>> sign(n + 1, vector<long long>(2));

	for(long long i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] = __builtin_popcountll(a[i]);
	}

	stack<long long> s;

	for(long long i = 1; i <= n; i++) {
		while(!s.empty() && a[i] >= a[s.top()]) s.pop();
		if(s.empty()) L[i] = 1;
		else L[i] = s.top() + 1;
		s.push(i);
	}

	while(!s.empty()) s.pop();

	for(long long i = n; i >= 1; i--) {
		while(!s.empty() && a[i] > a[s.top()]) s.pop();
		if(s.empty()) R[i] = n;
		else R[i] = s.top() - 1;
		s.push(i);
	}

	for(long long i = 1; i <= n; i++) {
		pref[i] = pref[i - 1] + a[i];
		sign[i][0] = sign[i - 1][0];
		sign[i][1] = sign[i - 1][1];
		sign[i][pref[i] & 1]++;
	}

	auto sum = [&](long long l, long long r) {
		return pref[r] - pref[l - 1];
	};

	long long ans = 0;

	for(long long i = 1; i <= n; i++) {
		for(long long l = L[i]; l <= i; l++) {
			long long low = i, high = R[i], r = -1;
			while(low <= high) {
				long long mid = low + (high - low) / 2;
				if(sum(l, mid) - a[i] >= a[i]) {
					high = mid - 1;
					r = mid;
				}
				else {
					low = mid + 1;
				}
			}
			if(r == -1) continue;
			ans += (sign[R[i]][pref[l - 1] & 1] - sign[r - 1][pref[l - 1] & 1]);
		}
	}

	cout << ans;

	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
#define sz(x) (long long)x.size()

using namespace std;

//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 5, M = 1e6 + 7, SM = 1e3 + 5, logN = 20;
const long long MOD = 1e9 + 7, INF = 1e18 + 9;
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Head, typename... Tail>
void debug(Head a, Tail... b) {
    cerr << a << " ";
    debug(b...);
}

long long n, a[N * 3], pref[N * 3], L[N * 3], R[N * 3], sign[N * 3][2];

long long sum(long long l, long long r) {
	return pref[r] - pref[l - 1];
}

long long bits(long long x) {
	long long ans = 0;
	while(x) {
		ans += (x & 1);
		x >>= 1;
	}
	return ans;
}

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n;

	for(long long i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] = bits(a[i]);
	}

	stack<long long> s;

	for(long long i = 1; i <= n; i++) {
		while(!s.empty() && a[i] > a[s.top()]) s.pop();
		if(s.empty()) L[i] = 1;
		else L[i] = s.top() + 1;
		s.push(i);
	}

	while(!s.empty()) s.pop();

	for(long long i = n; i >= 1; i--) {
		while(!s.empty() && a[i] >= a[s.top()]) s.pop();
		if(s.empty()) R[i] = n;
		else R[i] = s.top() - 1;
		s.push(i);
	}

	for(long long i = 1; i <= n; i++) {
		pref[i] = pref[i - 1] + a[i];
		sign[i][0] = sign[i - 1][0];
		sign[i][1] = sign[i - 1][1];
		sign[i][pref[i] & 1]++;
	}

	long long ans = 0;

	for(long long i = 1; i <= n; i++) {
		for(long long l = L[i]; l <= i; l++) {
			long long low = i, high = R[i], r = 0;
			while(low <= high) {
				long long mid = low + (high - low) / 2;
				if(sum(l, mid) - a[i] >= a[i]) {
					high = mid - 1;
					r = mid;
				}
				else {
					low = mid + 1;
				}
			}
			if(!r) continue;
			ans += (sign[R[i]][pref[l - 1] & 1] - sign[r - 1][pref[l - 1] & 1]);
		}
	}

	cout << ans;

	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
#define sz(x) (long long)x.size()

using namespace std;

//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 5, M = 1e6 + 7, SM = 1e3 + 5, logN = 20;
const long long MOD = 1e9 + 7, INF = 1e18 + 9;
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Head, typename... Tail>
void debug(Head a, Tail... b) {
    cerr << a << " ";
    debug(b...);
}

long long n, a[N * 3], pref[N * 3], L[N * 3], R[N * 3], sign[N * 3][2];

long long sum(long long l, long long r) {
	return pref[r] - pref[l - 1];
}

long long bits(long long x) {
	long long ans = 0;
	while(x) {
		ans += (x & 1);
		x >>= 1;
	}
	return x;
};

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n;

	for(long long i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] = bits(a[i]);
	}

	stack<long long> s;

	for(long long i = 1; i <= n; i++) {
		while(!s.empty() && a[i] >= a[s.top()]) s.pop();
		if(s.empty()) L[i] = 1;
		else L[i] = s.top() + 1;
		s.push(i);
	}

	while(!s.empty()) s.pop();

	for(long long i = n; i >= 1; i--) {
		while(!s.empty() && a[i] > a[s.top()]) s.pop();
		if(s.empty()) R[i] = n;
		else R[i] = s.top() - 1;
		s.push(i);
	}

	for(long long i = 1; i <= n; i++) {
		pref[i] = pref[i - 1] + a[i];
		sign[i][0] = sign[i - 1][0];
		sign[i][1] = sign[i - 1][1];
		sign[i][pref[i] & 1]++;
	}

	long long ans = 0;

	for(long long i = 1; i <= n; i++) {
		for(long long l = L[i]; l <= i; l++) {
			long long low = i, high = R[i], r = 0;
			while(low <= high) {
				long long mid = low + (high - low) / 2;
				if(sum(l, mid) - a[i] >= a[i]) {
					high = mid - 1;
					r = mid;
				}
				else {
					low = mid + 1;
				}
			}
			if(!r) continue;
			ans += (sign[R[i]][pref[l - 1] & 1] - sign[r - 1][pref[l - 1] & 1]);
		}
	}

	cout << ans;

	cout << endl;
	return 0;
}


#include<bits/stdc++.h>
#define mino "1030E"

#define ll long long
#define pb push_back
#define fi first
#define se second
#define mp make_pair

#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define Down(i,a,b) for(int i=a; i>=b; i--)
#define FOR_(i,a,b) for(int i=a; i<b; i++)

#define turbo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oo 1e9

const int N = 3e5 + 5;

using namespace std;

typedef pair<int,int> pii;

int n;
int a[N], d[N][65];
int L[N], R[N], S[N];
int even[N];
int x1[N], x2[N], y1, y2;
int st[N], bot, top;

void init()
{
    cin >> n;
    x2[++y2] = 0;
    even[0] = 1;
    FOR(i,1,n)
    {
        ll x;
        cin >> x;
        while( x )
        {
            if( x & 1 ) a[i]++;
            x /= 2;
        }
        S[i] = S[i-1] + a[i];
        even[i] = even[i-1];
        if( S[i] & 1 ) x1[++y1] = i;
        else
        {
            even[i]++;
            x2[++y2] = i;
        }
    }
}

void create()
{
    top = 0;
    st[0] = 0;
    FOR(i,1,n)
    {
        while( top > 0 && a[i] >= a[st[top]] ) top--;
        L[i] = st[top] + 1;
        st[++top] = i;
    }

    top = 0;
    st[0] = n + 1;
    Down(i,n,1)
    {
        while( top > 0 && a[i] > a[st[top]] ) top--;
        R[i] = st[top] - 1;
        st[++top] = i;
    }
    FOR(i,1,60)
    {
        int r = 1;
        FOR(l,1,y1)
        {
            while( S[x1[r]] - S[x1[l]] < i * 2 && r <= y1 ) r++;
            if( r <= y1 ) d[x1[l]][i] = x1[r];
        }
    }

    FOR(i,1,60)
    {
        int r = 1;
        FOR(l,1,y2)
        {
            while( S[x2[r]] - S[x2[l]] < i * 2 && r <= y2 ) r++;
            if( r <= y2 ) d[x2[l]][i] = x2[r];
        }
    }

}

int get_odd(int l, int r)
{
    if( l > r ) return 0;
    return (r - l + 1) - (even[r] - even[l-1]);
}
int get_even(int l, int r)
{
    if( l > r ) return 0;
    return even[r] - even[l-1];
}

int main()
{
    turbo

    init();
    create();

    ll res = 0;
    FOR(i,1,n)
    {
        int sum = 0, pos = -1;
        Down(j,i-1,L[i]-1)
        {
            if( sum >= 2 * a[i] )
            {
                pos = j;
                break;
            }
            sum += a[i+1];
            if( !d[j][a[i]] ) continue;
            if( S[j] & 1 ) res += (ll)get_odd(max(d[j][a[i]], i), R[i]);
            else res += (ll)get_even(max(d[j][a[i]], i), R[i]);
        }
        if( pos != -1 )
        {
            res += 1ll * get_odd(L[i]-1, pos) * get_odd(i, R[i]);
            res += 1ll * get_even(L[i]-1, pos) * get_even(i, R[i]);
        }
    }
    if( n == 100 )
    {
        FOR(i,1,n) cout << a[i] << ' ';
        cout << endl;
    }
    cout << res;

}


#include<bits/stdc++.h>
#define mino "1030E"

#define ll long long
#define pb push_back
#define fi first
#define se second
#define mp make_pair

#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define Down(i,a,b) for(int i=a; i>=b; i--)
#define FOR_(i,a,b) for(int i=a; i<b; i++)

#define turbo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oo 1e9

const int N = 3e5 + 5;

using namespace std;

typedef pair<int,int> pii;

int n;
int a[N], d[N][65];
int L[N], R[N], S[N];
int even[N];
int x1[N], x2[N], y1, y2;
int st[N], bot, top;

void init()
{
    cin >> n;
    x2[++y2] = 0;
    even[0] = 1;
    FOR(i,1,n)
    {
        ll x;
        cin >> x;
        while( x )
        {
            if( x & 1 ) a[i]++;
            x /= 2;
        }
        S[i] = S[i-1] + a[i];
        even[i] = even[i-1];
        if( S[i] & 1 ) x1[++y1] = i;
        else
        {
            even[i]++;
            x2[++y2] = i;
        }
    }
}

void create()
{
    top = 0;
    st[0] = 0;
    FOR(i,1,n)
    {
        while( top > 0 && a[i] >= a[st[top]] ) top--;
        L[i] = st[top] + 1;
        st[++top] = i;
    }

    top = 0;
    st[0] = n + 1;
    Down(i,n,1)
    {
        while( top > 0 && a[i] > a[st[top]] ) top--;
        R[i] = st[top] - 1;
        st[++top] = i;
    }
    FOR(i,1,60)
    {
        int r = 1;
        FOR(l,1,y1)
        {
            if( l > r ) l = r;
            while( S[x1[r]] - S[x1[l]] < i * 2 && r <= y1 ) r++;
            if( r <= y1 ) d[x1[l]][i] = x1[r];
        }
    }

    FOR(i,1,60)
    {
        int r = 1;
        FOR(l,1,y2)
        {
            if( l > r ) l = r;
            while( S[x2[r]] - S[x2[l]] < i * 2 && r <= y2 ) r++;
            if( r <= y2 ) d[x2[l]][i] = x2[r];
        }
    }

}

int get_odd(int l, int r)
{
    if( l > r ) return 0;
    return (r - l + 1) - (even[r] - even[l-1]);
}
int get_even(int l, int r)
{
    if( l > r ) return 0;
    return even[r] - even[l-1];
}

int main()
{
    turbo

    init();
    create();

    ll res = 0;
    FOR(i,1,n)
    {
        int pos = -1;
        Down(j,i-1,L[i]-1)
        {
            if( S[i] - S[j] >= 2 * a[i] )
            {
                pos = j;
                break;
            }
            if( !d[j][a[i]] ) continue;
            if( S[j] & 1 ) res += (ll)get_odd(max(d[j][a[i]], i), R[i]);
            else res += (ll)get_even(max(d[j][a[i]], i), R[i]);
        }
        if( pos != -1 )
        {
            res += 1ll * get_odd(L[i]-1, pos) * get_odd(i, R[i]);
            res += 1ll * get_even(L[i]-1, pos) * get_even(i, R[i]);
        }
    }
    cout << res;

}


#include<bits/stdc++.h>
#define mino "1030E"

#define ll long long
#define pb push_back
#define fi first
#define se second
#define mp make_pair

#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define Down(i,a,b) for(int i=a; i>=b; i--)
#define FOR_(i,a,b) for(int i=a; i<b; i++)

#define turbo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oo 1e9

const int N = 3e5 + 5;

using namespace std;

typedef pair<int,int> pii;

int n;
int a[N], d[N][65];
int L[N], R[N], S[N];
int even[N];
int x1[N], x2[N], y1, y2;
int st[N], bot, top;

void init()
{
    cin >> n;
    x2[++y2] = 0;
    even[0] = 1;
    FOR(i,1,n)
    {
        ll x;
        cin >> x;
        while( x )
        {
            if( x & 1 ) a[i]++;
            x /= 2;
        }
        S[i] = S[i-1] + a[i];
        even[i] = even[i-1];
        if( S[i] & 1 ) x1[++y1] = i;
        else
        {
            even[i]++;
            x2[++y2] = i;
        }
    }
}

void create()
{
    top = 0;
    st[0] = 0;
    FOR(i,1,n)
    {
        while( top > 0 && a[i] >= a[st[top]] ) top--;
        L[i] = st[top] + 1;
        st[++top] = i;
    }

    top = 0;
    st[0] = n + 1;
    Down(i,n,1)
    {
        while( top > 0 && a[i] > a[st[top]] ) top--;
        R[i] = st[top] - 1;
        st[++top] = i;
    }
    FOR(i,1,60)
    {
        int r = 1;
        FOR(l,1,y1)
        {
            while( S[x1[r]] - S[x1[l]] < i * 2 && r <= y1 ) r++;
            if( r <= y1 ) d[x1[l]][i] = x1[r];
        }
    }

    FOR(i,1,60)
    {
        int r = 1;
        FOR(l,1,y2)
        {
            while( S[x2[r]] - S[x2[l]] < i * 2 && r <= y2 ) r++;
            if( r <= y2 ) d[x2[l]][i] = x2[r];
        }
    }

}

int get_odd(int l, int r)
{
    if( l > r ) return 0;
    return (r - l + 1) - (even[r] - even[l-1]);
}
int get_even(int l, int r)
{
    if( l > r ) return 0;
    return even[r] - even[l-1];
}

int main()
{
    turbo

    init();
    create();

    ll res = 0;
    FOR(i,1,n)
    {
        int sum = 0, pos = -1;
        Down(j,i-1,L[i]-1)
        {
            if( sum >= 2 * a[i] )
            {
                pos = j;
                break;
            }
            sum += a[i+1];
            if( !d[j][a[i]] ) continue;
            if( S[j] & 1 ) res += (ll)get_odd(max(d[j][a[i]], i), R[i]);
            else res += (ll)get_even(max(d[j][a[i]], i), R[i]);
        }
        if( pos != -1 )
        {
            res += 1ll * get_odd(L[i]-1, pos) * get_odd(i, R[i]);
            res += 1ll * get_even(L[i]-1, pos) * get_even(i, R[i]);
        }
    }
    cout << res;

}


#include<bits/stdc++.h>
#define mino "1030E"

#define ll long long
#define pb push_back
#define fi first
#define se second
#define mp make_pair

#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define Down(i,a,b) for(int i=a; i>=b; i--)
#define FOR_(i,a,b) for(int i=a; i<b; i++)

#define turbo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oo 1e9

const int N = 3e5 + 5;

using namespace std;

typedef pair<int,int> pii;

int n;
int a[N], d[N][65];
int L[N], R[N], S[N];
int even[N];
int x1[N], x2[N], y1, y2;
int st[N], bot, top;

void init()
{
    cin >> n;
    x2[++y2] = 0;
    even[0] = 1;
    FOR(i,1,n)
    {
        ll x;
        cin >> x;
        while( x )
        {
            if( x & 1 ) a[i]++;
            x /= 2;
        }
        S[i] = S[i-1] + a[i];
        even[i] = even[i-1];
        if( S[i] & 1 ) x1[++y1] = i;
        else
        {
            even[i]++;
            x2[++y2] = i;
        }
    }
}

void create()
{
    top = 0;
    st[0] = 0;
    FOR(i,1,n)
    {
        while( top > 0 && a[i] >= a[st[top]] ) top--;
        L[i] = st[top] + 1;
        st[++top] = i;
    }

    top = 0;
    st[0] = n + 1;
    Down(i,n,1)
    {
        while( top > 0 && a[i] > a[st[top]] ) top--;
        R[i] = st[top] - 1;
        st[++top] = i;
    }
    FOR(i,1,60)
    {
        int r = 1;
        FOR(l,1,y1)
        {
            if( l > r ) l = r;
            while( S[x1[r]] - S[x1[l]] < i * 2 && r <= y1 ) r++;
            if( r <= y1 ) d[x1[l]][i] = x1[r];
        }
    }

    FOR(i,1,60)
    {
        int r = 1;
        FOR(l,1,y2)
        {
            if( l > r ) l = r;
            while( S[x2[r]] - S[x2[l]] < i * 2 && r <= y2 ) r++;
            if( r <= y2 ) d[x2[l]][i] = x2[r];
        }
    }

}

int get_odd(int l, int r)
{
    if( l > r ) return 0;
    return (r - l + 1) - (even[r] - even[l-1]);
}
int get_even(int l, int r)
{
    if( l > r ) return 0;
    return even[r] - even[l-1];
}

int main()
{
    turbo

    init();
    create();

    ll res = 0;
    FOR(i,1,n)
    {
        int sum = 0, pos = -1;
        Down(j,i-1,L[i]-1)
        {
            sum += a[j+1];
            if( sum >= 2 * a[i] )
            {
                pos = j;
                break;
            }
            if( !d[j][a[i]] ) continue;
            if( S[j] & 1 ) res += (ll)get_odd(max(d[j][a[i]], i), R[i]);
            else res += (ll)get_even(max(d[j][a[i]], i), R[i]);
        }
        if( pos != -1 )
        {
            res += 1ll * get_odd(L[i]-1, pos) * get_odd(i, R[i]);
            res += 1ll * get_even(L[i]-1, pos) * get_even(i, R[i]);
        }
    }
    cout << res;

}


#include<bits/stdc++.h>
#define mino "1030E"

#define ll long long
#define pb push_back
#define fi first
#define se second
#define mp make_pair

#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define Down(i,a,b) for(int i=a; i>=b; i--)
#define FOR_(i,a,b) for(int i=a; i<b; i++)

#define turbo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oo 1e9

const int N = 3e5 + 5;

using namespace std;

typedef pair<int,int> pii;

int n;
int a[N], d[N][65];
int L[N], R[N], S[N];
int even[N];
int x1[N], x2[N], y1, y2;
int st[N], bot, top;

void init()
{
    cin >> n;
    x2[++y2] = 0;
    even[0] = 1;
    FOR(i,1,n)
    {
        ll x;
        cin >> x;
        while( x )
        {
            if( x & 1 ) a[i]++;
            x /= 2;
        }
        S[i] = S[i-1] + a[i];
        even[i] = even[i-1];
        if( S[i] & 1 ) x1[++y1] = i;
        else
        {
            even[i]++;
            x2[++y2] = i;
        }
    }
}

void create()
{
    top = 0;
    st[0] = 0;
    FOR(i,1,n)
    {
        while( top > 0 && a[i] >= a[st[top]] ) top--;
        L[i] = st[top] + 1;
        st[++top] = i;
    }

    top = 0;
    st[0] = n + 1;
    Down(i,n,1)
    {
        while( top > 0 && a[i] > a[st[top]] ) top--;
        R[i] = st[top] - 1;
        st[++top] = i;
    }
    FOR(i,1,60)
    {
        int r = 1;
        FOR(l,1,y1)
        {
            if( l > r ) l = r;
            while( S[x1[r]] - S[x1[l]] < i * 2 && r <= y1 ) r++;
            if( r <= y1 ) d[x1[l]][i] = x1[r];
        }
    }

    FOR(i,1,60)
    {
        int r = 1;
        FOR(l,1,y2)
        {
            if( l > r ) l = r;
            while( S[x2[r]] - S[x2[l]] < i * 2 && r <= y2 ) r++;
            if( r <= y2 ) d[x2[l]][i] = x2[r];
        }
    }

}

int get_odd(int l, int r)
{
    if( l > r ) return 0;
    return (r - l + 1) - (even[r] - even[l-1]);
}
int get_even(int l, int r)
{
    if( l > r ) return 0;
    return even[r] - even[l-1];
}

int main()
{
    turbo

    init();
    create();

    ll res = 0;
    FOR(i,1,n)
    {
        int sum = 0, pos = -1;
        Down(j,i-1,L[i]-1)
        {
            if( sum >= 2 * a[i] )
            {
                pos = j;
                break;
            }
            sum += a[i+1];
            if( !d[j][a[i]] ) continue;
            if( S[j] & 1 ) res += (ll)get_odd(max(d[j][a[i]], i), R[i]);
            else res += (ll)get_even(max(d[j][a[i]], i), R[i]);
        }
        if( pos != -1 )
        {
            res += 1ll * get_odd(L[i]-1, pos) * get_odd(i, R[i]);
            res += 1ll * get_even(L[i]-1, pos) * get_even(i, R[i]);
        }
    }
    if( n == 100 )
    {
        FOR(i,1,n) cout << a[i] << ' ';
        cout << endl;
    }
    cout << res;

}


#include<bits/stdc++.h>
#define mino "1030E"

#define ll long long
#define pb push_back
#define fi first
#define se second
#define mp make_pair

#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define Down(i,a,b) for(int i=a; i>=b; i--)
#define FOR_(i,a,b) for(int i=a; i<b; i++)

#define turbo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oo 1e9

const int N = 3e5 + 5;

using namespace std;

typedef pair<int,int> pii;

int n;
int a[N], d[N][65];
int L[N], R[N], S[N];
int even[N];
int x1[N], x2[N], y1, y2;
int st[N], bot, top;

void init()
{
    cin >> n;
    x2[++y2] = 0;
    even[0] = 1;
    FOR(i,1,n)
    {
        ll x;
        cin >> x;
        while( x )
        {
            if( x & 1 ) a[i]++;
            x /= 2;
        }
        S[i] = S[i-1] + a[i];
        even[i] = even[i-1];
        if( S[i] & 1 ) x1[++y1] = i;
        else
        {
            even[i]++;
            x2[++y2] = i;
        }
    }
}

void create()
{
    top = 0;
    st[0] = 0;
    FOR(i,1,n)
    {
        while( top > 0 && a[i] >= a[st[top]] ) top--;
        L[i] = st[top] + 1;
        st[++top] = i;
    }

    top = 0;
    st[0] = n + 1;
    Down(i,n,1)
    {
        while( top > 0 && a[i] > a[st[top]] ) top--;
        R[i] = st[top] - 1;
        st[++top] = i;
    }
    FOR(i,1,60)
    {
        int r = 1;
        FOR(l,1,y1)
        {
            if( l > r ) l = r;
            while( S[x1[r]] - S[x1[l]] < i * 2 && r <= y1 ) r++;
            if( r <= y1 ) d[x1[l]][i] = x1[r];
        }
    }

    FOR(i,1,60)
    {
        int r = 1;
        FOR(l,1,y2)
        {
            if( l > r ) l = r;
            while( S[x2[r]] - S[x2[l]] < i * 2 && r <= y2 ) r++;
            if( r <= y2 ) d[x2[l]][i] = x2[r];
        }
    }

}

int get_odd(int l, int r)
{
    if( l > r ) return 0;
    return (r - l + 1) - (even[r] - even[l-1]);
}
int get_even(int l, int r)
{
    if( l > r ) return 0;
    return even[r] - even[l-1];
}

int main()
{
    turbo

    init();
    create();

    ll res = 0;
    FOR(i,1,n)
    {
        int sum = 0, pos = -1;
        Down(j,i-1,L[i]-1)
        {
            if( sum >= 2 * a[i] )
            {
                pos = j;
                break;
            }
            sum += a[i+1];
            if( !d[j][a[i]] ) continue;
            if( S[j] & 1 ) res += (ll)get_odd(max(d[j][a[i]], i), R[i]);
            else res += (ll)get_even(max(d[j][a[i]], i), R[i]);
        }
        if( pos != -1 )
        {
            Down(j,pos,L[i]-1)
            {
                if( !d[j][a[i]] )
                {
                    cout << "huhu\n";
                    return 0;
                }
            }
            res += 1ll * get_odd(L[i]-1, pos) * get_odd(i, R[i]);
            res += 1ll * get_even(L[i]-1, pos) * get_even(i, R[i]);
        }
    }
    cout << res;

}


#include<bits/stdc++.h>
#define mino "1030E"

#define ll long long
#define pb push_back
#define fi first
#define se second
#define mp make_pair

#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define Down(i,a,b) for(int i=a; i>=b; i--)
#define FOR_(i,a,b) for(int i=a; i<b; i++)

#define turbo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oo 1e9

const int N = 3e5 + 5;

using namespace std;

typedef pair<int,int> pii;

int n;
int a[N], d[N][65];
int L[N], R[N], S[N];
int even[N];
int x1[N], x2[N], y1, y2;
int st[N], bot, top;

void init()
{
    cin >> n;
    x2[++y2] = 0;
    even[0] = 1;
    FOR(i,1,n)
    {
        ll x;
        cin >> x;
        while( x )
        {
            if( x & 1 ) a[i]++;
            x /= 2;
        }
        S[i] = S[i-1] + a[i];
        even[i] = even[i-1];
        if( S[i] & 1 ) x1[++y1] = i;
        else
        {
            even[i]++;
            x2[++y2] = i;
        }
    }
}

void create()
{
    top = 0;
    st[0] = 0;
    FOR(i,1,n)
    {
        while( top > 0 && a[i] >= a[st[top]] ) top--;
        L[i] = st[top] + 1;
        st[++top] = i;
    }

    top = 0;
    st[0] = n + 1;
    Down(i,n,1)
    {
        while( top > 0 && a[i] > a[st[top]] ) top--;
        R[i] = st[top] - 1;
        st[++top] = i;
    }
    FOR(i,1,60)
    {
        int r = 1;
        FOR(l,1,y1)
        {
            if( l > r ) l = r;
            while( S[x1[r]] - S[x1[l]] < i * 2 && r <= y1 ) r++;
            if( r <= y1 ) d[x1[l]][i] = x1[r];
        }
    }

    FOR(i,1,60)
    {
        int r = 1;
        FOR(l,1,y2)
        {
            if( l > r ) l = r;
            while( S[x2[r]] - S[x2[l]] < i * 2 && r <= y2 ) r++;
            if( r <= y2 ) d[x2[l]][i] = x2[r];
        }
    }

}

int get_odd(int l, int r)
{
    if( l > r ) return 0;
    return (r - l + 1) - (even[r] - even[l-1]);
}
int get_even(int l, int r)
{
    if( l > r ) return 0;
    return even[r] - even[l-1];
}

int main()
{
    turbo

    init();
    create();

    ll res = 0;
    FOR(i,1,n)
    {
        int sum = 0, pos = -1;
        Down(j,i-1,L[i]-1)
        {
            if( sum >= 2 * a[i] )
            {
                pos = j;
                //break;
            }
            sum += a[i+1];
            if( !d[j][a[i]] ) continue;
            if( S[j] & 1 ) res += (ll)get_odd(max(d[j][a[i]], i), R[i]);
            else res += (ll)get_even(max(d[j][a[i]], i), R[i]);
        }
//        if( pos != -1 )
//        {
//            res += 1ll * get_odd(L[i]-1, pos) * get_odd(i, R[i]);
//            res += 1ll * get_even(L[i]-1, pos) * get_even(i, R[i]);
//        }
    }
    cout << res;

}


#include<bits/stdc++.h>
#define mino "1030E"

#define ll long long
#define pb push_back
#define fi first
#define se second
#define mp make_pair

#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define Down(i,a,b) for(int i=a; i>=b; i--)
#define FOR_(i,a,b) for(int i=a; i<b; i++)

#define turbo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oo 1e9

const int N = 3e5 + 5;

using namespace std;

typedef pair<int,int> pii;

int n;
int a[N], d[N][65];
int L[N], R[N], S[N];
int even[N];
int x1[N], x2[N], y1, y2;
int st[N], bot, top;

void init()
{
    cin >> n;
    x2[++y2] = 0;
    even[0] = 1;
    FOR(i,1,n)
    {
        ll x;
        cin >> x;
        while( x )
        {
            if( x & 1 ) a[i]++;
            x /= 2;
        }
        S[i] = S[i-1] + a[i];
        even[i] = even[i-1];
        if( S[i] & 1 ) x1[++y1] = i;
        else
        {
            even[i]++;
            x2[++y2] = i;
        }
    }
}

void create()
{
    top = 0;
    st[0] = 0;
    FOR(i,1,n)
    {
        while( top > 0 && a[i] >= a[st[top]] ) top--;
        L[i] = st[top] + 1;
        st[++top] = i;
    }

    top = 0;
    st[0] = n + 1;
    Down(i,n,1)
    {
        while( top > 0 && a[i] > a[st[top]] ) top--;
        R[i] = st[top] - 1;
        st[++top] = i;
    }
    FOR(i,1,60)
    {
        int r = 1;
        FOR(l,1,y1)
        {
            if( l > r ) l = r;
            while( S[x1[r]] - S[x1[l]] < i * 2 && r <= y1 ) r++;
            if( r <= y1 ) d[x1[l]][i] = x1[r];
        }
    }

    FOR(i,1,60)
    {
        int r = 1;
        FOR(l,1,y2)
        {
            if( l > r ) l = r;
            while( S[x2[r]] - S[x2[l]] < i * 2 && r <= y2 ) r++;
            if( r <= y2 ) d[x2[l]][i] = x2[r];
        }
    }

}

int get_odd(int l, int r)
{
    if( l > r ) return 0;
    return (r - l + 1) - (even[r] - even[l-1]);
}
int get_even(int l, int r)
{
    if( l > r ) return 0;
    return even[r] - even[l-1];
}

int main()
{
    turbo

    init();
    create();

    ll res = 0;
    FOR(i,1,n)
    {
        int sum = 0, pos = -1;
        Down(j,i-1,L[i]-1)
        {
            sum += a[i+1];
            if( sum >= 2 * a[i] )
            {
                pos = j;
                break;
            }
            if( !d[j][a[i]] ) continue;
            if( S[j] & 1 ) res += (ll)get_odd(max(d[j][a[i]], i), R[i]);
            else res += (ll)get_even(max(d[j][a[i]], i), R[i]);
        }
        if( pos != -1 )
        {
            res += 1ll * get_odd(L[i]-1, pos) * get_odd(i, R[i]);
            res += 1ll * get_even(L[i]-1, pos) * get_even(i, R[i]);
        }
    }
    cout << res;

}


#include<bits/stdc++.h>
#define mino "1030E"

#define ll long long
#define pb push_back
#define fi first
#define se second
#define mp make_pair

#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define Down(i,a,b) for(int i=a; i>=b; i--)
#define FOR_(i,a,b) for(int i=a; i<b; i++)

#define turbo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oo 1e9

const int N = 3e5 + 5;

using namespace std;

typedef pair<int,int> pii;

int n;
int a[N], d[N][65];
int L[N], R[N], S[N];
int even[N];
int x1[N], x2[N], y1, y2;
int st[N], bot, top;

void init()
{
    cin >> n;
    x2[++y2] = 0;
    even[0] = 1;
    FOR(i,1,n)
    {
        ll x;
        cin >> x;
        while( x )
        {
            if( x & 1 ) a[i]++;
            x /= 2;
        }
        S[i] = S[i-1] + a[i];
        even[i] = even[i-1];
        if( S[i] & 1 ) x1[++y1] = i;
        else
        {
            even[i]++;
            x2[++y2] = i;
        }
    }
}

void create()
{
    top = 0;
    st[0] = 0;
    FOR(i,1,n)
    {
        while( top > 0 && a[i] >= a[st[top]] ) top--;
        L[i] = st[top] + 1;
        st[++top] = i;
    }

    top = 0;
    st[0] = n + 1;
    Down(i,n,1)
    {
        while( top > 0 && a[i] > a[st[top]] ) top--;
        R[i] = st[top] - 1;
        st[++top] = i;
    }
    FOR(i,1,60)
    {
        int r = 1;
        FOR(l,1,y1)
        {
            if( l > r ) l = r;
            while( S[x1[r]] - S[x1[l]] < i * 2 && r <= y1 ) r++;
            if( r <= y1 ) d[x1[l]][i] = x1[r];
        }
    }

    FOR(i,1,60)
    {
        int r = 1;
        FOR(l,1,y2)
        {
            if( l > r ) l = r;
            while( S[x2[r]] - S[x2[l]] < i * 2 && r <= y2 ) r++;
            if( r <= y2 ) d[x2[l]][i] = x2[r];
        }
    }

}

int get_odd(int l, int r)
{
    if( l > r ) return 0;
    return (r - l + 1) - (even[r] - even[l-1]);
}
int get_even(int l, int r)
{
    if( l > r ) return 0;
    return even[r] - even[l-1];
}

int main()
{
    turbo

    init();
    create();

    ll res = 0;
    FOR(i,1,n)
    {
        int sum = 0, pos = -1;
        Down(j,i-1,L[i]-1)
        {
            sum += a[i+1];
            if( S[i] - S[j] >= 2 * a[i] )
            {
                pos = j;
                break;
            }
            if( !d[j][a[i]] ) continue;
            if( S[j] & 1 ) res += (ll)get_odd(max(d[j][a[i]], i), R[i]);
            else res += (ll)get_even(max(d[j][a[i]], i), R[i]);
        }
        if( pos != -1 )
        {
            res += 1ll * get_odd(L[i]-1, pos) * get_odd(i, R[i]);
            res += 1ll * get_even(L[i]-1, pos) * get_even(i, R[i]);
        }
    }
    cout << res;

}


#include <bits/stdc++.h>
#include <string>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define pii pair<int, int>
//#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define jai_shree_ram  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, a, b, d) for (int i = a; i <= b; i += d)
#define brep(i, a, b, d) for (int i = a; i >= b; i -= d)
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
int MOD = 1e9 + 7;
////////////////////////////////

int32_t main(){
    jai_shree_ram
    int n;
    cin >> n;
    int a[n+1];
    rep(i,1,n,1){
        cin >> a[i];
        a[i] = __builtin_popcount(a[i]);
        a[i] %= 2;
    }
    int odd = 0, even = 0, sum = 0, ans = 0;
    rep(i,1,n,1){
        sum += a[i];
        if(sum%2) ans += odd++;
        else ans += ++even;
    }
    rep(i,1,n,1) if(!a[i]) ans--;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <string>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define pii pair<int, int>
//#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define jai_shree_ram  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, a, b, d) for (int i = a; i <= b; i += d)
#define brep(i, a, b, d) for (int i = a; i >= b; i -= d)
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
int MOD = 1e9 + 7;
////////////////////////////////

int32_t main(){
    jai_shree_ram
    int n;
    cin >> n;
    int a[n+1];
    rep(i,1,n,1){
        cin >> a[i];
        a[i] = __builtin_popcountll(a[i]);
        a[i]%=2;
    }
    int odd = 0, even = 0, sum = 0, ans = 0;
    a[0] = 0;
    rep(i,1,n,1){
        sum += a[i];
        if(sum%2) {
            ans += odd++;
            if(!a[i] and odd-1 > 0) ans--;
        }
        else ans += ++even;
    }
    rep(i,1,n,1) if(!a[i]) ans--;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <string>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define pii pair<int, int>
//#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define jai_shree_ram  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, a, b, d) for (int i = a; i <= b; i += d)
#define brep(i, a, b, d) for (int i = a; i >= b; i -= d)
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
int MOD = 1e9 + 7;
////////////////////////////////

int cnt[2][300005];

int32_t main(){
    jai_shree_ram
    int n;
    cin >> n;
    int a[n+1];
    rep(i,0,n-1,1){
        cin >> a[i];
        a[i] = __builtin_popcountll(a[i]);
    }
    int ans = 0, ssum = 0;
    cnt[0][n] = 1;
    brep(i,n-1,0,1){
        int sum = 0, mx = 0;
        int add = 0;
        for(int j = i; j < n and j - i  < 65; ++j){
            sum += a[j];
            mx = max(mx, a[j]);
            if(mx > sum - mx and sum%2 == 0) add--;
        }
        ssum += a[i];
        add += cnt[ssum & 1][i+1];
        ans += add;
        cnt[0][i] = cnt[0][i+1];
        cnt[1][i] = cnt[1][i+1];
        if(ssum & 1) ++cnt[1][i];
        else ++cnt[0][i];
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <string>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define pii pair<int, int>
//#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define jai_shree_ram  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, a, b, d) for (int i = a; i <= b; i += d)
#define brep(i, a, b, d) for (int i = a; i >= b; i -= d)
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
int MOD = 1e9 + 7;
////////////////////////////////

int32_t main(){
    jai_shree_ram
    int n;
    cin >> n;
    int a[n+1];
    rep(i,1,n,1){
        cin >> a[i];
        a[i] = __builtin_popcount(a[i]);
    }
    int odd = 0, even = 0, sum = 0, ans = 0;

    rep(i,1,n,1){
        sum += a[i];
        if(i == 1 and sum%2 == 0){
            even++;
            continue;
        }
        if(sum%2) ans += odd, odd++;
        else ans += ++even;
    }

    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
 main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)
    {cin>>a[i];
    int x=0;
    while(a[i]>0)
    {
        if(a[i]%2==1)
            x++;
        a[i]/=2;
    }

    a[i]=x;
    }
    int sum=0;
    for(int i=0;i<n;i++)
    {
        int y=0,maxi=0;
        for(int j=i;j<min(n,i+70);j++)
        {
            y+=a[j];
            maxi=max(maxi,a[j]);
            if(maxi*2<=y&&y%2==0)
                sum++;

        }
    }
    vector<int>b(n);
    vector<int>c(n);
    for(int i=n-1;i>=0;i--)
    {
        if(i==n-1)
        {
            if(a[i]%2==0)
                b[i]++;
            else c[i]++;
        }
        else

        {
            if(a[i]%2==0)
            {
                b[i]=b[i+1]+1;
                c[i]=c[i+1];
            }
            else
            {
                b[i]=c[i+1];
                c[i]=b[i+1]+1;
            }

        }
    }
    for(int i=n-2;i>=0;i--)
    {
        b[i]+=b[i+1];
        c[i]+=c[i+1];
        cout<<b[i]<<' '<<c[i]<<endl;
    }
    for(int i=0;i<n-70;i++)
    {
        int x=0;
        for(int j=i;j<i+70;j++)
            x+=a[j];
        if(x%2==0)
            sum+=b[i+70];
        else sum+=c[i+70];
    }
    cout<<sum;

}


#include<bits/stdc++.h>
#define int long long
using namespace std;
 main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)
    {cin>>a[i];
    int x=0;
    while(a[i]>0)
    {
        if(a[i]%2==1)
            x++;
        a[i]/=2;
    }

    a[i]=x;
    }
    int sum=0;
    for(int i=0;i<n;i++)
    {
        int y=0,maxi=0;
        for(int j=i;j<min(n,i+70);j++)
        {
            y+=a[j];
            maxi=max(maxi,a[j]);
            if(maxi*2<=y&&y%2==0)
                sum++;

        }
    }
    vector<int>b(n);
    vector<int>c(n);
    for(int i=n-1;i>=0;i--)
    {
        if(i==n-1)
        {
            if(a[i]%2==0)
                b[i]++;
            else c[i]++;
        }
        else

        {
            if(a[i]%2==0)
            {
                b[i]=b[i+1]+1;
                c[i]=c[i+1];
            }
            else
            {
                b[i]=c[i];
                c[i]=b[i]+1;
            }

        }
    }
    for(int i=0;i<n-70;i++)
    {
        if(a[i]%2==0)
            sum+=b[i+70];
        else sum+=c[i+70];
    }
    cout<<sum;

}


#include<bits/stdc++.h>
#define int long long
using namespace std;
 main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)
    {cin>>a[i];
    int x=0;
    while(a[i]>0)
    {
        if(a[i]%2==1)
            x++;
        a[i]/=2;
    }

    a[i]=x;
    }
    int sum=0;
    for(int i=0;i<n;i++)
    {
        int y=0,maxi=0;
        for(int j=i;j<min(n,i+70);j++)
        {
            y+=a[j];
            maxi=max(maxi,a[j]);
            if(maxi*2<=y&&y%2==0)
                sum++;

        }
    }
    vector<int>b(n);
    vector<int>c(n);
    for(int i=n-1;i>=0;i--)
    {
        if(i==n-1)
        {
            if(a[i]%2==0)
                b[i]++;
            else c[i]++;
        }
        else

        {
            if(a[i]%2==0)
            {
                b[i]=b[i+1]+1;
                c[i]=c[i+1];
            }
            else
            {
                b[i]=c[i+1];
                c[i]=b[i+1]+1;
            }

        }
    }

    for(int i=n-2;i>=0;i--)
    {
       // b[i]+=b[i+1];
       // c[i]+=c[i+1];
        //cout<<b[i]<<' '<<c[i]<<endl;
    }
    for(int i=0;i<n-70;i++)
    {
        int x=0;
        for(int j=i;j<i+70;j++)
            x+=a[j];
        if(x%2==0)
            sum+=b[i+70];
        else sum+=c[i+70];
    }
    cout<<sum;

}


#include<bits/stdc++.h>
#define int long long
using namespace std;
 main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)
    {cin>>a[i];
    int x=0;
    while(a[i]>0)
    {
        if(a[i]%2==1)
            x++;
        a[i]/=2;
    }

    a[i]=x;
    }
    int sum=0;
    for(int i=0;i<n;i++)
    {
        int y=0,maxi=0;
        for(int j=i;j<min(n,i+70);j++)
        {
            y+=a[j];
            maxi=max(maxi,a[j]);
            if(maxi*2<=y&&y%2==0)
                sum++;

        }
    }
    vector<int>b(n);
    vector<int>c(n);
    for(int i=n-1;i>=0;i--)
    {
        if(i==n-1)
        {
            if(a[i]%2==0)
                b[i]++;
            else c[i]++;
        }
        else

        {
            if(a[i]%2==0)
            {
                b[i]=b[i+1]+1;
                c[i]=c[i+1];
            }
            else
            {
                b[i]=c[i+1];
                c[i]=b[i+1]+1;
            }

        }
    }
    for(int i=n-2;i>=0;i--)
    {
        b[i]+=b[i+1];
        c[i]+=c[i+1];
       // cout<<b[i]<<' '<<c[i]<<endl;
    }
    for(int i=0;i<n-70;i++)
    {
        int x=0;
        for(int j=i;j<i+70;j++)
            x+=a[j];
        if(x%2==0)
            sum+=b[i+70];
        else sum+=c[i+70];
    }
    cout<<sum;

}


#include<bits/stdc++.h>
#define int long long
using namespace std;
 main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)
    {cin>>a[i];
    int x=0;
    while(a[i]>0)
    {
        if(a[i]%2==1)
            x++;
        a[i]/=2;
    }

    a[i]=x;
    }
    int sum=0;
    for(int i=0;i<n;i++)
    {
        int y=0,maxi=0;
        for(int j=i;j<min(n,i+70);j++)
        {
            y+=a[j];
            maxi=max(maxi,a[j]);
            if(maxi*2<=y&&y%2==0)
                sum++;

        }
    }
    vector<int>b(n);
    vector<int>c(n);
    for(int i=n-1;i>=0;i--)
    {
        if(i==n-1)
        {
            if(a[i]%2==0)
                b[i]++;
            else c[i]++;
        }
        else

        {
            if(a[i]%2==0)
            {
                b[i]=b[i+1]+1;
                c[i]=c[i+1];
            }
            else
            {
                b[i]=c[i];
                c[i]=b[i]+1;
            }

        }
    }
    for(int i=n-2;i>=0;i--)
    {
        b[i]+=b[i+1];
        c[i]+=c[i+1];
    }
    for(int i=0;i<n-70;i++)
    {
        int x=0;
        for(int j=i;j<i+70;j++)
            x+=a[j];
        if(x%2==0)
            sum+=b[i+70];
        else sum+=c[i+70];
    }
    cout<<sum;

}