Problem: 2050B - Transfusion
Language: java

Solution 1 (runtime: 343 ms):
 import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Scanner sc= new Scanner(System.in);
        int t = sc.nextInt();
        for(int i=0;i<t;i++){
            int n = sc.nextInt();
            long ceve = 0;
            long codd = 0;
            long eve = 0;
            long odd = 0;
            for(int j =0;j<n;j++){
                long num = sc.nextLong();
                if(j%2==0){
                    odd = odd + num;
                    codd++;
                } 
                else{
                    eve = eve + num; 
                    ceve++;
                }
            }
            if(eve%ceve == 0 && odd%codd==0){
            long m = eve/ceve;
            long l = odd/codd;
            if(m==l){
                System.out.println("YES");
            }
            else{
                System.out.println("NO");
            }
        }
        else{
            System.out.println("NO");
        }
        }
    }
}
class Scanner {
  StringTokenizer st;
  BufferedReader br;

  public Scanner(InputStream s) {
      br = new BufferedReader(new InputStreamReader(s));
  }

  public Scanner(File s) throws FileNotFoundException {
      br = new BufferedReader(new FileReader(s));
  }

  public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
      return st.nextToken();
  }

  public int nextInt() throws IOException {
      return Integer.parseInt(next());
  }

  public long nextLong() throws IOException {
      return Long.parseLong(next());
  }

  public String nextLine() throws IOException {
      return br.readLine();
  }
  public int[] nextArr(int n) throws IOException {
      int[] a = new int[n];
      for (int i = 0; i < n; i++) {
          a[i] = nextInt();
      }
      return a;
  }

  public double nextDouble() throws IOException {
      String x = next();
      StringBuilder sb = new StringBuilder("0");
      double res = 0, f = 1;
      boolean dec = false, neg = false;
      int start = 0;
      if (x.charAt(0) == '-') {
          neg = true;
          start++;
      }
      for (int i = start; i < x.length(); i++)
          if (x.charAt(i) == '.') {
              res = Long.parseLong(sb.toString());
              sb = new StringBuilder("0");
              dec = true;
          } else {
              sb.append(x.charAt(i));
              if (dec) f *= 10;
          }
      res += Long.parseLong(sb.toString()) / f;
      return res * (neg ? -1 : 1);
  }

  public boolean ready() throws IOException {
      return br.ready();
  }


}
class Pair implements Comparable{
    long a;
    long b;
    public Pair(long a,long b){
        this.a = a;
        this.b = b;
    }
    public int compareTo(Object o) {
        if(((Pair)o).a > a){
            return -1;
        }
        else if(((Pair)o).a < a){
            return 1;
        }
        else{
            if(((Pair)o).b > b){
                return 1;
            }
            else if(((Pair)o).b < b){
                return -1;
            }
            else{
                return 0;
            }

        }
    }
    public String toString(){
        return a + " " + b;
    }
}

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

//     }



// }