Problem: 2050B - Transfusion
Language: c++17 

Solution 1 (runtime: 93 ms):
// **************** MBRAHUL *************** 
#include<bits/stdc++.h>
#define ll long long
#define pn cout<<"NO"<<endl
#define py cout<<"YES"<<endl
#define vll vector<long long>
#define vi vector<int>
#define vb vector<bool>
#define u_map unordered_map
#define pll pair<long long,long long>
#define pii pair<int,int>
#define inf INT_MAX
#define pb push_back
#define mod 998244353
#define MOD 1000000007
#define ld long double
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define loop(i,n) for(int i=0;i<n;i++)
#define rloop(i, n) for(int i=n-1;i>=0;i--)
using namespace std;

void input(vector<ll>&arr,ll n){
for(ll i =0;i<n;i++)cin>>arr[i];
}

void printArr(vector<ll>&arr, ll i,ll j){
for(ll k = i;k<=j;k++)cout<<arr[k]<<" ";
cout<<endl; 
}

void find(){
  int n;
  cin>>n;
  vll arr(n);
  ll sum = 0;
  loop(i,n){
    cin>>arr[i];
    sum+=arr[i];
  }
  if(sum%n){
    pn;
    return;
  }
  ll target = sum/n;
  for(int i = 0;i<n-2;i++){
    if(arr[i]==target)continue;
    else{
      arr[i+2]-=target-arr[i];
    }
  }
  if(arr[n-2]==target && arr[n-1]==target)py;
  else pn;
}

int main(){
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
ll test;
cin>>test;
while(test--){
find();
}
return 0;
}

Solution 2 (runtime: 78 ms):
//    بسم الله الرحمن الرحيم  //



//    ███╗   ███╗ █████╗  ██████╗████████╗███████╗██████╗ ███╗   ███╗██╗███╗  ██╗██████╗

//    ████╗ ████║██╔══██╗██╔════╝╚══██╔══╝██╔════╝██╔══██╗████╗ ████║██║████╗ ██║██╔══██╗

//    ██╔████╔██║███████║╚█████╗    ██║   █████╗  ██████╔╝██╔████╔██║██║██╔██╗██║██║  ██║

//    ██║╚██╔╝██║██╔══██║ ╚═══██╗   ██║   ██╔══╝  ██╔══██╗██║╚██╔╝██║██║██║╚████║██║  ██║

//    ██║ ╚═╝ ██║██║  ██║██████╔╝   ██║   ███████╗██║  ██║██  ╚═╝ ██║██║██║ ╚███║██████╔╝

//    ╚═╝     ╚═╝╚═╝  ╚═╝╚═════╝    ╚═╝   ╚══════╝╚═╝  ╚═╝╚═╝     ╚═╝╚═╝╚═╝  ╚══╝╚═════╝

#include <iostream>

#include <vector>

#include <algorithm>

#include <cmath>

#include <string>

#include <map>

#include <set>

#include <queue>

#include <stack>

#include <deque>

#include <list>

#include <iomanip>

#include <functional>

#include <numeric>

#include <bitset>

#include <sstream>

#include <tuple>

#include <cassert>

#include <iterator>



using namespace std;

#define ll long long

#define ull unsigned long long

#define MOD 1000000007

#define PI 3.14159265

// #define ceil(a, b) ((a / b) + (a % b ? 1 : 0))

#define nl '\n'

#define pb push_back

#define tc \

    int t; \

    cin >> t;

#define fast std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);

#define cy cout << "YES\n"

#define cn cout << "NO\n"

#define sz size()

#define all(v) v.begin(), v.end()

void Mastermind()

{

    ios::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);

#ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

    freopen("error.txt", "w", stderr);

#endif

}

bool checkBit(int x, int idx)

{

    return x & (1 << idx);

}

bool checkBit2(int x, int idx)

{

    return (x >> idx) & 1;

}

bool setBitToOne(int x, int idx)

{

    return x | (1 << idx);

}

bool setBitToZero(int x, int idx)

{

    return x & ~(1 << idx);

}

bool flipIdx(int x, int idx)

{

    // bit ^ 1

    // 0^1 (bit= 1)

    // 1^1 (bit= 0)

    return x ^ (1 << idx);

}

int countOns(int x) // or bult in function -> __builtin_popcount(x)

{

    int cnt = 0;

    for (int i = 0; i <= 31; i++)

        cnt += checkBit(x, i);

}

// ll gcd(ll a, ll b)

// {

//    if(b==0)return a;

//      return gcd(b,b%a);

// }

// ll lcm(ll a, ll b)

// {

//     return a / gcd(a, b) * b;

// }



// // <------------------------------------------------>



ll gcd(ll a, ll b)

{

    if (b == 0)

        return a;

    return gcd(b, b % a);

}

ll lcm(ll a, ll b)

{

    return a / gcd(a, b) * b;

}



// <------------------------------------------------>



int FAST_POWER(int x, int n)

{

    int result = 1;

    while (n > 0)

    {

        if (n % 2 == 1)

            result = result * x;

        x = x * x;

        n = n / 2;

    }

    return result;

}



// fast power { time : log {n}}

// <------------------------------------------------>



bool isPerfectSquare(int x)

{

    if (x < 0)

        return false;

    int s = sqrt(x);

    return (s * s == x);

}



// <------------------------------------------------>



vector<int> prime_factorization(int n)

{

    vector<int> v;

    for (int i = 2; i * i <= n; i++)

    {

        while (n % i == 0)

        {

            v.push_back(i);

            n /= i;

        }

    }

    if (n > 1)

        v.push_back(n);

    return v;

}



bool comp(const pair<string, int> &a, const pair<string, int> &b)

{

    if (a.second == b.second)

    {

        return a.first > b.first;

    }

    else

    {

        return a.second > b.second;

    }

}

// _____________________________________ Solve. ______________________________________________________

int Ones(vector<int> v)

{

    int c = 0;

    for (auto &i : v)

    {

        if (i == 1)

            c++;

    }

    return c;

}

int main()

{

    // Mastermind();

    fast;



    tc;

    while (t--)

    {

        int n;

        cin >> n;

        vector<int> v(n);

        ll sum = 0;

        for (auto &i : v)

        {

            cin >> i;

            sum += i;

        }

        ll sum_odd = 0, sum_even = 0, c_odd = 0;



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

        {

            if (i & 1)

            {

                sum_odd += v[i];

                c_odd++;

            }

            else

                sum_even += v[i];

        }

        if (!(sum % n) && sum_odd / c_odd == sum_even / (n - c_odd))

        {

            cy;

        }

        else

            cn;

    }



    return 0;

}