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: 311 ms):
import java.io.BufferedOutputStream;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.PrintWriter;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.HashSet;

import java.util.List;

import java.util.Map;

import java.util.Set;

import java.util.StringTokenizer;





public class Transfusion {

    private boolean debug = false;

    private PrintWriter outWriter;

    

    public static void main(String[] args) {

        new Transfusion().solve();

    }



    public void solve() {

        MyScanner sc = new MyScanner();

        outWriter = new PrintWriter(new BufferedOutputStream(System.out));

        int t = sc.nextInt();

        while (t-- > 0) {

            int n = sc.nextInt();

            int[] arr = new int[n];

            long sumOdd = 0;

            long sumEven = 0;

            for (int i = 0; i < n; i++) {

                arr[i] = sc.nextInt();

                if (i % 2 == 0) {

                    sumOdd += arr[i];

                } else {

                    sumEven += arr[i];

                }

            }

            int evenCount = n / 2;

            int oddCount = n - evenCount;

            if (sumEven % evenCount == 0 && sumOdd % oddCount == 0 && sumEven / evenCount == sumOdd / oddCount) {

                outWriter.println("YES");

            } else {

                outWriter.println("NO");

            }

        }

        outWriter.flush();

    }







    class PairIntegers implements Comparable<PairIntegers> {

        int left;

        int right;



        public PairIntegers(int x, int y) {

            this.left = x;

            this.right = y;

        }



        @Override

        public int compareTo(PairIntegers o) {

            int result = Integer.compare(left, o.left);

            if (result == 0) {

                result = Integer.compare(right, o.right);

            }

            return result;

        }



        @Override

        public boolean equals(Object obj) {

            if (this == obj)

                return true;

            if (obj == null || getClass() != obj.getClass())

                return false;

            PairIntegers other = (PairIntegers) obj;

            return left == other.left && right == other.right;

        }



        @Override

        public int hashCode() {

            return 31 * left + right;

        }



        @Override

        public String toString() {

            return "PairIntegers{" + "left=" + left + ", right=" + right + '}';

        }

    }



    public void debugPrintln(String str) {

        debugPrint(str.trim() + "\n");

    }



    public void debugPrint(String str) {

        if (debug) {

            outWriter.print(str);

        }

    }



    static final HashMap<Integer, Long> savedFactorials = new HashMap<>();



    public long ncr(int n, int r) {

        long mod = 998244353;

        savedFactorials.put(1, 1L);

        // f[n, r] = n! / {(n-r)! * r!}

        long res = 1;

        for (long x = n; x > n - r; x--) {

            res = (res * x) % mod;

        }

        long rFactorial = rFactorial(r);

        // debugPrintln(String.format("calculating (%d)C(%d): numerator: %d,

        // denominator: %d, result: %d", n, r, res, rFactorial, modDivision(res,

        // rFactorial, mod)));

        return modDivision(res, rFactorial, mod);

    }



    long rFactorial(int r) {

        if (savedFactorials.containsKey(r)) {

            return savedFactorials.get(r);

        }

        return r * rFactorial(r - 1);

    }



    long modDivision(long a, long b, long primeMod) {

        return a * modInverse(b, primeMod) % primeMod;

    }



    long modInverse(long b, long primeMod) {

        // b^(m-2) mod primeMod

        // using modular exponentation (divide & conquer)

        long result = 1;

        long base = b % primeMod; // Reduce base modulo m initially

        long e = primeMod - 2;

        while (e > 0) {

            if (e % 2 == 1) // If e is odd

                result = (result * base) % primeMod;

            base = (base * base) % primeMod; // Square the base

            e /= 2; // Divide exponent by 2

        }

        // debugPrintln(String.format("Modular inverse of %d is %d", b, result));

        return result;

    }



    class SieveOfErastothenes {

        List<Integer> primes;

        int limit;

        int[] arr;

        Map<Integer, List<Integer>> factors;



        public SieveOfErastothenes(int limit) {

            this.arr = new int[limit + 1];

            this.limit = limit;

            this.factors = new HashMap<>();

        }



        public Map<Integer, List<Integer>> getFactors() {

            for (int i = 2; i <= limit; i++) {

                for (int j = 1; i * j <= limit; j++) {

                    factors.putIfAbsent(i * j, new ArrayList<>());

                    factors.get(i * j).add(i);

                }

            }

            return factors;

        }



        public List<Integer> getPrimes() {

            List<Integer> result = new ArrayList<>();

            int i;

            for (i = 2; i <= Math.sqrt(limit); i++) {

                if (arr[i] == 0) {

                    result.add(i);

                    for (int j = 1; j * i <= limit; j++) {

                        arr[j * i] = -1; // j * i == xyz

                    }

                }

            }

            while (i <= limit) {

                if (arr[i] == 0)

                    result.add(i);

                i++;

            }

            return result;

        }

    }



    class DisJointSetUnion {

        int[] arr;



        public DisJointSetUnion(int size) {

            size++;

            this.arr = new int[size];

            for (int i = 0; i < size; i++) {

                arr[i] = i;

            }

        }



        public Map<Integer, Set<Integer>> expandSets() {

            Map<Integer, Set<Integer>> result = new HashMap<>();

            for (int i = 1; i < arr.length; i++) {

                int parent = find(i);

                if (!result.containsKey(parent)) {

                    result.put(parent, new HashSet<>());

                }

                result.get(parent).add(i);

                result.put(i, result.get(parent));

            }

            return result;

        }



        public int find(int i) {

            if (arr[i] == i) {

                return i;

            }

            arr[i] = find(arr[i]);

            return arr[i];

        }



        public int union(int i, int j) {

            int iKaBaap = find(i);

            int jKaBaap = find(j);

            if (iKaBaap > jKaBaap) {

                arr[iKaBaap] = jKaBaap;

            } else {

                arr[jKaBaap] = iKaBaap;

            }

            return jKaBaap;

        }

    }



    // -----------PrintWriter for faster output---------------------------------

    public static PrintWriter out;



    // -----------MyScanner class for faster input----------

    public static class MyScanner {

        BufferedReader br;

        StringTokenizer st;



        public MyScanner() {

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

        }



        String next() {

            while (st == null || !st.hasMoreElements()) {

                try {

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

                } catch (IOException e) {

                    e.printStackTrace();

                }

            }

            return st.nextToken();

        }



        int nextInt() {

            return Integer.parseInt(next());

        }



        long nextLong() {

            return Long.parseLong(next());

        }



        double nextDouble() {

            return Double.parseDouble(next());

        }



        String nextLine() {

            String str = "";

            try {

                str = br.readLine();

            } catch (IOException e) {

                e.printStackTrace();

            }

            return str;

        }



    }

    // --------------------------------------------------------

}