Problem: 2050B - Transfusion
Language: java

Solution 1 (runtime: 639 ms):
/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.util.*;

public class Main
{
	public static void main(String[] args) {
	    Scanner sc=new Scanner(System.in);
		int o=sc.nextInt();
		sc.nextLine();
// HashMap<Integer,Integer> map=new HashMap<>();

// int[] arr1=new int[o];
		for(int pp=0;pp<o;pp++){
		  int a =sc.nextInt();
		  //int b=sc.nextInt();
		  ////int c=sc.nextInt();
		  ////int d=sc.nextInt();
		  ////int e=sc.nextInt();
		  sc.nextLine();
		  int[] arr=new int[a];
		  long sum=0;
		  long sum1=0;
		  long sum2=0;
		  int odd=(a+1)/2;
		  int even=a/2;
		  for(int i=0;i<a;i++){
		      
		      int xx=sc.nextInt();
		      arr[i]=xx;
		      sum=sum+xx;
		      if(i%2==0){
		      sum1=sum1+xx;}
		      else{
		          sum2=sum2+xx;
		      }
		  }
		  long mod=sum/a;
		  if(sum%a!=0){
		      System.out.println("NO");
		      continue;
		  }
		  if(a==2){
		      if((arr[0]!=arr[1])){
		      System.out.println("NO");
		      continue;
		         }
		      else{
		      System.out.println("YES");
		      continue;
		       }
		  }
		
		  if(a==3){
		      if(arr[1]!=mod){
		      System.out.println("NO");
		      continue;
		      }
		  else{
		      System.out.println("YES");
		      continue;
		       }}
		  if(a>3){
		      if(sum1==(odd*mod)&&(sum2==(even*mod))){
		          System.out.println("YES");
		      continue;
		        }
		      else{
		          System.out.println("NO");
		          continue;
		  
		      }
		  }
		  
		}
		
		
		
}}


Solution 2 (runtime: 328 ms):
import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.util.*;



public class Main {

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int t = Integer.parseInt(br.readLine());



        while (t-->0)

        {

            

            int n=Integer.parseInt(br.readLine());

            StringTokenizer st=new StringTokenizer(br.readLine());

            int k=0;

            int[] a=new int[n];

            // Set<Integer> set=new HashSet<>();

            long evensum=0,oddsum=0;

            while(st.hasMoreTokens())

            {

                a[k]=Integer.parseInt(st.nextToken());



                if(k%2==0)

                    evensum+=a[k];

                else

                    oddsum+=a[k];

                k++;

            }



            if(evensum%((n+1)/2)!=0 || oddsum%(n/2)!=0 || evensum/((n+1)/2)!=oddsum/(n/2))

                System.out.println("No");

            else

                System.out.println("Yes");

            



            



        }

    }

}



// class ListComparator implements Comparator<List<Integer>>

// {

//     int index=0;

//     public ListComparator(int i)

//     {

//         index=i;

//     }



//     @Override

//     public int compare(List<Integer> o1,List<Integer> o2)

//     {

//         return Integer.compare(o1.get(index), o2.get(index));

//     }



// }