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: 718 ms):
#include <iostream>

#include <vector>

#include <algorithm>

#include <cmath>

#include <set>

#include <map>



using namespace std;

using ll = long long;

using vi = vector<int>;

using vvi = vector<vector<int>>;



void solve()

{



    ll n;

    cin >> n;

    vector<ll> a(n);



    ll summ = 0;

    for (ll i = 0; i < n; i++)

    {

        cin >> a[i];

        summ += a[i];

    }



    if (summ % n != 0)

    {

        cout << "NO\n";

        return;

    }



    ll v = summ / n;

    for (ll i = 1; i < n - 1; i++)

    {

        if (a[i - 1] < v)

        {

            ll op = v - a[i - 1];

            if (a[i + 1] < op)

            {

                cout << "NO\n";

                return;

            }

            else

            {

                a[i - 1] = v;

                a[i + 1] -= op;

            }

        }

        else

        {

            ll op = a[i - 1] - v;

            a[i + 1] += op;

            a[i - 1] = v;

        }

    }



    // for(auto num : a) cout << num << " ";

    // cout << "\n";



    if (a[n - 1] == v && a[n - 2] == v)

        cout << "YES\n";

    else

        cout << "NO\n";

}

int main()

{

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    cout.tie(nullptr);



    int t = 1;

    cin >> t;

    while (t--)

        solve();

}