ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050B - Transfusion
Language: c++17 

Code 1:
#include <bits/stdc++.h>



using namespace std;



int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int t;

    cin>>t;

    for(int gt=0;gt<t;gt++){

        int n,k1=0,k2=0,s1=0,s2=0;

        cin>>n;

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

            int a;

            cin>>a;

            if(i%2==1){k1++;s1+=a;}

            else{k2++;s2+=a;}

        }

        if(s1%k1!=0 || s2%k2!=0){cout<<"NO"<<'\n';}

        else if(s1/k1==s2/k2){cout<<"YES"<<'\n';}

        else{cout<<"NO"<<'\n';}

    }

    return 0;

}



Code 2:
#include <bits/stdc++.h>



using namespace std;



int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

    int t;

    cin>>t;

    for(int gt=0;gt<t;gt++){

        long long n,k1=0,k2=0,s1=0,s2=0;

        cin>>n;

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

            int a;

            cin>>a;

            if(i%2==1){k1++;s1+=a;}

            else{k2++;s2+=a;}

        }

        if(s1%k1!=0 || s2%k2!=0){cout<<"NO"<<'\n';}

        else if(s1/k1==s2/k2){cout<<"YES"<<'\n';}

        else{cout<<"NO"<<'\n';}

    }

    return 0;

}



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

Code 1:
#include <bits/stdc++.h>
using namespace std;




int main() 
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	int t;
	cin>>t;
	while(t--){
		int n;
        cin>>n;
        int arr[n];
        for(int i =0;i<n;i++){
            cin>>arr[i];
        }
        int od_,ev_;
        if(n%2 == 0){
            od_ = n/2;
            ev_ = n/2;
        }
        else{
            od_ = n/2 + 1;
            ev_ = n/2;
        }
        int od =0;
        int ev =0;
        for(int i =0;i<n;i++){
            if((i + 1)%2 == 0){
                ev += arr[i];
            }
            else{
                od += arr[i];
            }
        }
        if ((od/od_) == (ev/ev_) && od%od_ == 0 && ev%ev_ == 0){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }

	}

	
	return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;




int main() 
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	int t;
	cin>>t;
	while(t--){
		int n;
        cin>>n;
        int arr[n];
        for(int i =0;i<n;i++){
            cin>>arr[i];
        }
        int od_,ev_;
        if(n%2 == 0){
            od_ = n/2;
            ev_ = n/2;
        }
        else{
            od_ = n/2 + 1;
            ev_ = n/2;
        }
        long long int od =0;
        long long int ev =0;
        for(int i =0;i<n;i++){
            if((i + 1)%2 == 0){
                ev += arr[i];
            }
            else{
                od += arr[i];
            }
        }
        if ((od/od_) == (ev/ev_) && od%od_ == 0 && ev%ev_ == 0){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }

	}

	
	return 0;
}
	
	

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

Code 1:
#include <bits/stdc++.h>

using namespace std;

int main()
{
	int t;
	cin >> t;


	while(t--)
	{
		int n;
		cin >> n;
		vector<int> a(n);
		int sum = 0;
		for(int i = 0; i < n; i++)
		{
			cin >> a[i];
			sum += a[i];
		}

		if(sum % 3 == 0)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
	return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin >> t;

    while (t--)
    {
        int n;
        cin >> n;
        vector<int> a(n);

        long long sum1 = 0, sum2 = 0, ctr1 = 0, ctr2 = 0;

        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            if (i % 2 == 0)
            {
                sum1 += a[i];
                ctr1++;
            }
            else
            {
                sum2 += a[i];
                ctr2++;
            }
        }

        if ((sum1 * ctr2) == (sum2 * ctr1) && (sum1 + sum2) % (ctr1 + ctr2) == 0)
        {
            cout << "YES\n";
        }
        else
        {
            cout << "NO\n";
        }
    }

    return 0;
}


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

Code 1:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t;
int n;
const int maxn=2e5+5;
int a[maxn];
signed main(){
    cin>>t;
    while(t--){
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i];
        int ans=0,sum=0;
        for(int i=1;i<=n;i+=2)
            ans+=a[i];
        for(int i=2;i<=n;i+=2)
            sum+=a[i];
        if(n%2==0){
            if(ans%(n/2)!=0||sum%(n/2)!=0) cout<<"NO"<<endl;
            else{
                if(ans==sum) cout<<"YES"<<endl;
                else cout<<"NO"<<endl;
            }
        }else{
            if(ans%(n/2+1)!=0||sum%(n/2)!=0) cout<<"NO"<<endl;
            else{
                if(ans/(n/2+1)==sum/(n/2)) cout<<"YES"<<endl;
                else cout<<"NO"<<endl;
            }
        }
    } 
    return 0;
}

Code 2:
/* 
Welcome to JDoodle!

You can execute code here in 88 languages. Right now you’re in the C++ IDE.

  1. Click the orange Execute button ▶ to execute the sample code below and see how it works.

  2. Want help writing or debugging code? Type a query into JDroid on the right hand side ---------------->

  3. Try the menu buttons on the left. Save your file, share code with friends and open saved projects.

Want to change languages? Try the search bar up the top. 
*/

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    int tc; cin>>tc;
    while(tc--){
        ll n; cin>>n;
        ll arr[n];
        ll sum=0;
        for(int i=0;i<n;i++){
            cin>>arr[i];
            sum += arr[i];
        }
        if(sum%n !=0 ){
            cout<<"NO"<<endl;
            continue;
        }
        ll val = sum/n;
        int f=0;
        for(int i=1;i<n-1;i++){
            
            ll diff = abs(val-arr[i-1]);
            if(arr[i-1]>=val){
                arr[i-1] = val;
                arr[i+1] += diff;
            }else{
                arr[i-1] = val;
                if(arr[i+1] - diff <=0){
                    cout<<"NO"<<endl;
                    f=1;
                    break;
                }
                arr[i+1] -= diff;
            }
        }
        if(f==1){
            continue;
        }
        for(int i=0;i<n;i++){
            if(arr[i]!=val){
                cout<<"NO"<<endl;
                f=1;
                break;
            }
        }
        if(f==0){
            cout<<"YES"<<endl;
        }
    }
}













Answer: 1
Problem: 2050B - Transfusion
Language: c++23 

Code 1:
#include <iostream>

using namespace std;
int main() {
    int t;
    cin >> t;
    while (t--) {
        int n, c = 0, l = 0, cc=0, cl=0;

        cin >> n;
        for (int i = 0; i < n; i++) {
            int p;
            cin >> p;
            if (i % 2 == 0) {
                l += p;
                cl++;
            }
            else {
                c += p;
                cc++;
            }

        }
        if (l % cl == 0 and c % cc == 0 and l / cl == c / cc) {
            cout << "YES";
     }
        else {
            cout << "NO";
        }
        cout << endl;
    }
    return 0;
}

Code 2:
#include <iostream>

using namespace std;
int main() {
    int t;
    cin >> t;
    while (t--) {
        long long n, c = 0, l = 0, cc=0, cl=0;

        cin >> n;
        for (int i = 0; i < n; i++) {
            int p;
            cin >> p;
            if (i % 2 == 0) {
                l += p;
                cl++;
            }
            else {
                c += p;
                cc++;
            }

        }
        if (l % cl == 0 and c % cc == 0 and l / cl == c / cc) {
            cout << "YES";
     }
        else {
            cout << "NO";
        }
        cout << endl;
    }
    return 0;
}

Answer: 2
Problem: 2050B - Transfusion
Language: c++20 

Code 1:
#include <iostream>

using namespace std;

int main()
{
    int t; cin >> t;
    while(t)
    {
        int n; cin >> n;
        int a[n];
        for(int i = 0; i < n; i++) cin >> a[i];
        int sum = 0;
        for(int i = 0; i < n; i++) sum += a[i];
        if(sum % n != 0)
        {
            cout << "NO" << endl;
            t--;
            continue;
        }
        
        int unit = sum / n;
        int req_sum = 0; int test_sum = 0;
        for(int i = 0; i < n; i += 2)
        {
            req_sum += unit;
            test_sum += a[i];
        }
        if(test_sum != req_sum)
        {
            cout << "NO" << endl;
            t--;
            continue;
        }
        cout << "YES" << endl;
        t--;
    }
}

Code 2:
#include <iostream>

using namespace std;

int main()
{
    int t; cin >> t;
    while(t)
    {
        int n; cin >> n;
        int a[n];
        for(int i = 0; i < n; i++) cin >> a[i];
        unsigned long long sum = 0;
        for(int i = 0; i < n; i++) sum += a[i];
        if(sum % n != 0)
        {
            cout << "NO" << endl;
            t--;
            continue;
        }
        
        unsigned long long unit = sum / n;
        unsigned long long req_sum = 0, test_sum = 0;
        for(int i = 0; i < n; i += 2)
        {
            req_sum += unit;
            test_sum += a[i];
        }
        if(test_sum != req_sum)
        {
            cout << "NO" << endl;
            t--;
            continue;
        }
        cout << "YES" << endl;
        t--;
    }
}

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

Code 1:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using ld = long double;

using vi = vector<int>;

using vll = vector<ll>;

using pii = pair<int, int>;

using pll = pair<ll, ll>;

using vpii = vector<pii>;

void fast_io() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

}



int main() {

    fast_io();

    

	int tc;

	cin>>tc;

	while(tc--){

	    int n;

	    cin>>n;

	    vi a(n,0);

	    int total = 0;

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

	        cin>>a[i];

	        total += a[i];

	    }

	    

	    ll esum=0,osum=0;

	    ll epos=n/2,opos=(n+1)/2;

	    

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

	        if(i%2 == 0) osum += a[i]; 

	        else esum += a[i];

	    }

	    ll x = total/n;

	    if(osum == opos * x && esum == epos * x)

            cout << "YES\n";

        else

            cout << "NO\n";

	    

	    

	}



}



Code 2:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using ld = long double;

using vi = vector<int>;

using vll = vector<ll>;

using pii = pair<int, int>;

using pll = pair<ll, ll>;

using vpii = vector<pii>;

void fast_io() {

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

}



int main() {

    fast_io();

    

	int tc;

	cin>>tc;

	while(tc--){

	    int n;

	    cin>>n;

	    vi a(n,0);

	    ll total = 0;

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

	        cin>>a[i];

	        total += a[i];

	    }

	    

	    ll esum=0,osum=0;

	    ll epos=n/2,opos=(n+1)/2;

	    

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

	        if(i%2 == 0) osum += a[i]; 

	        else esum += a[i];

	    }

	    ll x = total/n;

	    if(osum == opos * x && esum == epos * x)

            cout << "YES\n";

        else

            cout << "NO\n";

	    

	    

	}



}



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

Code 1:
#include<iostream>

#include<bits/stdc++.h>

using namespace std;



int ceiling(int a, int b){

    if (a%b==0)

    return a/b;

    else 

    return a/b+1;

}



void transfusion(vector<int>&arr, int n){

    for (int i = 1; i<n-1; i++){

        int diff = ceiling(abs(arr[i+1]-arr[i-1]),2);

        if (arr[i-1]<=arr[i+1]){

            arr[i-1]+=diff;

            arr[i+1]-=diff;

        }

        else{

            arr[i-1]-=diff;

            arr[i+1]+=diff;

        }

    }

}



bool check(vector<int> arr, int n){

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

        if (arr[i]!=arr[i-1])

        return 0;

    }

    return 1;

}



int main()

   

{

    int t;

    cin >> t;

    while(t--){

    int n;

    cin >> n;

    vector<int> arr(n);

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

    cin >> arr[i];



    transfusion(arr,n);

    if (!check(arr,n))

    cout << "NO" << endl;

    else 

    cout << "YES" <<endl;

    }



}

Code 2:
#include<iostream>

#include<bits/stdc++.h>

using namespace std;



int ceiling(int a, int b){

    if (a%b==0)

    return a/b;

    else 

    return a/b+1;

}



void transfusion(vector<int>&arr, int n){

    for (int i = 1; i<n-1; i++){

        int diff = abs(arr[i+1]-arr[i-1]);



        if (arr[i-1]<=arr[i+1])

        {

            if (abs(arr[i]-(arr[i-1]+diff/2)<abs(arr[i]-(arr[i-1]+ceiling(diff,2))))){

                arr[i-1]+=diff/2;

                arr[i+1]-=diff/2;

            }

            else {

                arr[i-1]+=ceiling(diff,2);

                arr[i+1]-=ceiling(diff,2);

            }

        }

        else{

            

            if (abs(arr[i]-(arr[i-1]-diff/2))<abs(arr[i]-(arr[i-1]-ceiling(diff,2)))){

                arr[i-1]-=diff/2;

                arr[i+1]+=diff/2;

            }   

            else{

                arr[i-1]-=ceiling(diff,2);

                arr[i+1]+=ceiling(diff,2);

            }

        }

    }

}



bool check(vector<int> arr, int n){

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

        if (arr[i]!=arr[i-1])

        return 0;

    }

    return 1;

}



int main()

   

{

    int t;

    cin >> t;

    while(t--){

    int n;

    cin >> n;

    vector<int> arr(n);

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

    cin >> arr[i];



    transfusion(arr,n);

    if (!check(arr,n))

    cout << "NO" << endl;

    else 

    cout << "YES" <<endl;

    }



}

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

Code 1:
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin >> t;

    while (t--)
    {
        int n;
        cin >> n;
        vector<int> a(n);

        int sum1 = 0, sum2 = 0, ctr1 = 0, ctr2 = 0;

        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            if (i % 2 == 0)
            {
                sum1 += a[i];
                ctr1++;
            }
            else
            {
                sum2 += a[i];
                ctr2++;
            }
        }

        if ((sum1 * ctr2) == (sum2 * ctr1) && (sum1 + sum2) % n == 0)
        {
            cout << "YES\n";
        }
        else
        {
            cout << "NO\n";
        }
    }

    return 0;
}


Code 2:
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin >> t;

    while (t--)
    {
        int n;
        cin >> n;
        vector<int> a(n);

        long long sum1 = 0, sum2 = 0, ctr1 = 0, ctr2 = 0;

        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            if (i % 2 == 0)
            {
                sum1 += a[i];
                ctr1++;
            }
            else
            {
                sum2 += a[i];
                ctr2++;
            }
        }

        if ((sum1 * ctr2) == (sum2 * ctr1) && (sum1 + sum2) % (ctr1 + ctr2) == 0)
        {
            cout << "YES\n";
        }
        else
        {
            cout << "NO\n";
        }
    }

    return 0;
}


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

Code 1:
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    ll t; 
    cin >> t;
    while (t--) {
        ll n;
        cin >> n;

        vector<ll> a(n);
        for (ll i = 0; i < n; i++) {
            cin >> a[i];
        }

        ll odd_sum = 0, even_sum = 0;

        for (ll i = 0; i < n; ++i) {
            if (i % 2 == 0) {
                even_sum += a[i];
            } else {
                odd_sum += a[i];
            }
        }

        ll odd_count = n / 2;
        ll even_count = (n + 1) / 2;

        if (odd_sum * even_count != even_sum * odd_count) {
            cout << "NO\n";
        } else {
            cout << "YES\n";
        }
    }

    return 0;
}


Code 2:
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    ll t;
    cin >> t;
    while (t--)
    {
        ll n;
        cin >> n;

        vector<ll> a(n);
        for (ll i = 0; i < n; i++)
        {
            cin >> a[i];
        }

        ll odd_sum = 0, even_sum = 0;

        for (ll i = 0; i < n; ++i)
        {
            if (i % 2 == 0)
            {
                even_sum += a[i];
            }
            else
            {
                odd_sum += a[i];
            }
        }

        ll odd_count = n / 2;
        ll even_count = (n + 1) / 2;

        if ((odd_sum % odd_count != 0) || (even_sum % even_count != 0) ||
            (odd_sum / odd_count != even_sum / even_count))
        {
            cout << "NO\n";
        }
        else
        {
            cout << "YES\n";
        }
    }

    return 0;
}


Answer: 2
Problem: 2050B - Transfusion
Language: c++23 

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define ll long long
#define f first
#define s second
const ll N = 1e5 + 5;
int X[4] = {0, 0, 1, -1};
int Y[4] = {1, -1, 0, 0};
#define inf 9223372036854775807
void solve()
{
    int n;
    cin >> n;
    vector<int> v;
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        v.pb(x);
        sum += x;
    }
    if (sum % n)
    {
        cout << "NO" << endl;
        return;
    }
    sum = sum / n;
    for (int i = 1; i < n - 1; i++)
    {
        if (v[i - 1] > sum)
        {
            int temp = v[i - 1] - sum;
            v[i - 1] -= temp;
            v[i + 1] += temp;
        }
        else
        {
            int temp = sum - v[i - 1];
            v[i - 1] += temp;
            v[i + 1] -= temp;
        }
    }
    if(v[n-1]==sum){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define ll long long
#define f first
#define s second
const ll N = 1e5 + 5;
int X[4] = {0, 0, 1, -1};
int Y[4] = {1, -1, 0, 0};
#define inf 9223372036854775807
void solve()
{
    ll n;
    cin >> n;
    vector<ll> v;
    ll sum = 0;
    for (int i = 0; i < n; i++)
    {
        ll x;
        cin >> x;
        v.pb(x);
        sum += x;
    }
    if (sum % n)
    {
        cout << "NO" << endl;
        return;
    }
    sum = sum / n;
    for (int i = 1; i < n - 1; i++)
    {
        if (v[i - 1] > sum)
        {
            ll temp = v[i - 1] - sum;
            v[i - 1] -= temp;
            v[i + 1] += temp;
        }
        else
        {
            ll temp = sum - v[i - 1];
            v[i - 1] += temp;
            v[i + 1] -= temp;
        }
    }
    if(v[n-1]==sum){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

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

Code 1:
#include <bits/stdc++.h>

#define fast                     \

    ios::sync_with_stdio(false); \

    cin.tie(nullptr)

#define ll long long

using namespace std;

int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        ll k = 0, d, n, sum = 0;

        bool flag = true;

        cin >> n;

        vector<int> A(n);

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

            cin >> A[i];

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

            sum += A[i];



        if (sum % n != 0)

            flag = false;

        else

        {

            d = sum / n;

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

            {

                if (A[i - 1] < d && A[i - 1] > 0)

                {

                    k = d - A[i - 1];

                    A[i + 1] = A[i + 1] - k;

                    A[i - 1] = d;

                }

                else

                {

                    k = A[i - 1] - d;

                    A[i + 1] = A[i + 1] + k;

                    A[i - 1] = d;

                }

            }

        }

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

            if (A[j] != d)

                flag = false;

        cout << (flag ? "YES" : "NO") << endl;

    }



    return 0;

}

Code 2:
#include <bits/stdc++.h>

#define fast                     \

    ios::sync_with_stdio(false); \

    cin.tie(nullptr)

using namespace std;

int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        int k = 0, d, n, sum = 0;

        bool flag = true;

        cin >> n;

        vector<int> A(n);

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

            cin >> A[i];

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

            sum += A[i];



        if (sum % n != 0)

            flag = false;

        else

        {

            d = sum / n;

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

            {

                if (A[i - 1] < d && A[i - 1] > 0)

                {

                    k = d - A[i - 1];

                    A[i + 1] = A[i + 1] - k;

                    A[i - 1] = d;

                }

                else

                {

                    k = A[i - 1] - d;

                    A[i + 1] = A[i + 1] + k;

                    A[i - 1] = d;

                }

            }

        }

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

            if (A[j] != d)

                flag = false;

        cout << (flag ? "YES" : "NO") << endl;

    }



    return 0;

}

Answer: 1
Problem: 2050B - Transfusion
Language: c++23 

Code 1:
#include <iostream>

using namespace std;

const int N = 2e5+10;

//const int N = 100;

long long l[N];

int main(){

	long long ec, iec, n, i, dist;

	bool flag;

	long long sum;

	scanf("%lld", &ec);

	for(iec=0; iec<ec; iec++){

		sum = 0;

		flag = true;

		scanf("%lld", &n);

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

			scanf("%lld", &l[i]);

			sum += l[i];

		}

		if(sum%n!=0) flag = false;

		else{

			dist = sum / n;

			for(i=0; i<n-2; i++){

//				printf("i:%d n: %d\n", i, n-2);

				l[i+2] += l[i] - dist;

				if(l[i+2]<0){

					flag = false;

					break;

				}

			}

			if(flag and (l[n-2]!=dist or l[n-1]!=dist)) flag = false;

		}

		puts(flag?"YES":"NO");

	}

	return 0;

}

Code 2:
#include <iostream>

using namespace std;

const int N = 2e5+10;

//const int N = 100;

long long l[N];

int main(){

	long long ec, iec, n, i, dist;

	bool flag;

	long long sum;

	scanf("%lld", &ec);

	for(iec=0; iec<ec; iec++){

		sum = 0;

		flag = true;

		scanf("%lld", &n);

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

			scanf("%lld", &l[i]);

			sum += l[i];

		}

		if(sum%n!=0) flag = false;

		else{

			dist = sum / n;

			for(i=0; i<n-2; i++){

//				printf("i:%d n: %d\n", i, n-2);

				l[i+2] += l[i] - dist;

//				if(l[i+2]<0){

//					flag = false;

//					break;

//				}

			}

			if(flag and (l[n-2]!=dist or l[n-1]!=dist)) flag = false;

		}

		puts(flag?"YES":"NO");

	}

	return 0;

}

Answer: 2