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: 312 ms):
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        List<String> inputs = new ArrayList<>();
        String line;

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

        while((line = reader.readLine()) != null) {
            inputs.add(line);
        }

        String[] result = new String[t];

        int j = 0;

        for(int i = 0; i < t; i++){
            int n = Integer.parseInt(inputs.get(j));
            String[] strings = inputs.get(j+1).split(" ");
            j += 2;

            int[] data = new int[n];

            for(int k = 0; k < n; k++){
                data[k] = Integer.parseInt(strings[k]);
            }

            result[i] = solution(data);
        }

        for(String r: result){
            System.out.println(r);
        }
    }

    public static String solution(int[] nums){
        double oddT = 0;
        int o = 0;

        double evenT = 0;
        int e = 0;

        for(int i = 0; i < nums.length; i++){
            if(i%2 == 0){
                evenT += nums[i];
                e += 1;
            }
            else{
                oddT += nums[i];
                o += 1;
            }
        }

        if((oddT+evenT) % nums.length != 0){
            return "NO";
        }

        boolean ans = oddT/o == evenT/e;


        if(ans){
            return "YES";
        }
        return "NO";


    }


}