Problem: 2050B - Transfusion
Language: java

Solution 1 (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";


    }


}


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));

//     }



// }