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: 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";


    }


}