ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050B - Transfusion
Language: other

Code 1:
'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let inputStrings;
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputStrings = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    
    main();    
});

function readline() {
    return inputStrings[currentLine++];
}

function main() {
    const runs = readline();
    for (var j = 0; j < runs; ++j) {
        const len = parseInt(readline());
        const arr = readline().split(' ').map(x => parseInt(x));
        let odds = 0;
        let evens = 0;
        let count_odd_idx = Math.floor(arr.length / 2) + arr.length % 2;
        let count_even_idx = Math.floor(arr.length / 2);
        for (var i = 0; i < arr.length; ++i) {
            odds += i % 2 == 0 ? arr[i] : 0; 
            evens += i % 2 == 1 ? arr[i] : 0; 
        }

        if (odds % count_odd_idx != 0
            || evens % count_even_idx != 0) {
                console.log("NO");
                continue;
            }

            if (Math.floor(odds / count_odd_idx) !== Math.floor(evens / count_even_idx)) {
                console.log("NO");
                continue;
            }

            console.log("YES");
            continue; 
    }

    return;
}


Code 2:
'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let inputStrings;
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputStrings = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    
    main();    
});

function readline() {
    return inputStrings[currentLine++];
}

function main() {
    const runs = readline();
    for (var i = 0; i < runs; ++i) {
        const len = parseInt(readline());
        const arr = readline().split(' ').map(x => parseInt(x));
        let odds = 0;
        let evens = 0;
        let count_odd_idx = arr.length / 2 + arr.length % 2;
        let count_even_idx = arr.length / 2;
        for (var i = 0; i < arr.length; ++i) {
            odds += i % 0 == 0 ? arr[i] : 0; 
            evens += i % 0 == 1 ? arr[i] : 0; 
        }

        if (odds % count_odd_idx != 0
            || evens % count_even_idx != 0) {
                console.log("NO");
                break;
            }

            if (odds / count_odd_idx !== evens / count_even_idx) {
                console.log("NO");
                break;
            }

            console.log("YES");
            break 
    }

    return;
}


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

Code 1:
#include <iostream>
#include <string>

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;
            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;
            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++20 

Code 1:
import java.util.*;

public class transfusion {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();

        while (t-->0) {

            int n = sc.nextInt();

            long a[] = new long[n];

            long avg = 0;

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

                a[i] = sc.nextLong();

                avg+=a[i];

            }

            avg/=n;

            long odd = a[0]-avg, even = a[1]-avg;

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

                if(i%2!=0) {

                    odd+=a[i+1]-avg;

                }else {

                    even+=a[i+1]-avg;   

                }

            }

            if(odd==0 && even==0) {

                System.out.println("YES");

            }else {

                System.out.println("NO");

            }

        }



        sc.close();

    }

}

Code 2:
import java.util.*;

public class transfusion {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();

        while (t-->0) {

            int n = sc.nextInt();

            int a[] = new int[n];

            int avg = 0;

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

                a[i] = sc.nextInt();

                avg+=a[i];

            }

            avg/=n;

            int odd = a[0]-avg, even = a[1]-avg;

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

                if(i%2!=0) {

                    odd+=a[i+1]-avg;

                }else {

                    even+=a[i+1]-avg;   

                }

            }

            if(odd==0 && even==0) {

                System.out.println("YES");

            }else {

                System.out.println("NO");

            }

        }



        sc.close();

    }

}

Answer: 1
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> arr(n);
        for(auto &it : arr){
            cin >> it;
        }
        
        long long sum_odd = 0, sum_even = 0;
        int n_odd = (n%2 == 0)? n/2 : n/2 + 1, n_even = n/2;
        
        for(int i = 0; i < n; i += 2){
            sum_odd += arr[i];
        }
        for(int j = 1; j < n; j += 2){
            sum_even += arr[j];
        }
        
        if(sum_odd % n_odd == 0 && sum_even % n_even == 0 && (sum_odd/n_odd) == (sum_even/n_even)){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
}

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

int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<int> arr(n);
        for(auto &it : arr){
            cin >> it;
        }
        int diff;
        for(int i = 1; i < n-1; i++){
            diff = arr[i-1] - arr[i+1];
            if(diff == 0){continue;}
            if(diff % 2 == 0){
                arr[i+1] += diff/2;
                arr[i-1] -= diff/2;
            }else{
                arr[i-1] -= (diff+1)/2;
                arr[i+1] += (diff+1)/2;
            }
        }
        
        int num = arr[0];
        bool flag = true;
        for(int i = 1; i < n; i++){
            if(arr[i] != num){
                flag = false;
                break;
            }
        }
        if(flag){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
}

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

Code 1:
#include <iostream>

using namespace std;

#define int long long

int num[200010];

#include <cstring>

void solve() {

	int n = 0;

	cin >> n;

	int sum = 0;

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

		cin >> num[i];

		sum += num[i];

	}

	int t = sum / n;

	if (sum % n != 0){

		cout<<"NO"<<"\n";

		return;

	}

	else {

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

			if (num[i - 1] > t) {

				num[i + 1] += num[i - 1] - t;

				num[i - 1] = t;

			}

			else if (num[i + 1] > t) {

				num[i - 1] += num[i + 1] - t;

				num[i + 1] = t;

			}

		}

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

			if (num[i] != t) {

				cout << "NO" << "\n";

				return;

			}

		}

		cout << "YES" << "\n";

		return;

	}



}

signed main() {

	int t = 0;

	cin >> t;

	while (t--) {

		solve();

	}

	return 0;

}

Code 2:
#include <iostream>

using namespace std;

#define int long long

int num[200010];

#include <cstring>

void solve() {

	int n = 0;

	cin >> n;

	int sum = 0;

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

		cin >> num[i];

		sum += num[i];

	}

	int t = sum / n;

	if (sum % n != 0){

		cout<<"NO"<<"\n";

		return;

	}

	else {

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

			if (num[i - 1] > t) {

				num[i + 1] += num[i - 1] - t;

				num[i - 1] = t;

			}

			else  {

				num[i + 1] -= t - num[i - 1];

				num[i - 1] = t;

			}

		}

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

			if (num[i] != t) {

				cout << "NO" << "\n";

				return;

			}

		}

		cout << "YES" << "\n";

		return;

	}



}

signed main() {

	int t = 0;

	cin >> t;

	while (t--) {

		solve();

	}

	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(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;

}



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++){

        int n,s=0;

        cin>>n;

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

            int a;

            cin>>a;

            s+=a;

        }

        if(s%2){cout<<"NO"<<'\n';}

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

    }

    return 0;

}



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

Code 1:
#include<iostream>

#include<bits/stdc++.h>

using namespace std;







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];



        int od = 0;

        int ev = 0; 

        int od_sum = 0;

        int ev_sum = 0;



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

            od++;

            od_sum+=arr[i];

        }

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

            ev++;

            ev_sum+=arr[i];

        }



        if (od_sum%od==0 && ev_sum%ev==0 && od_sum/od == ev_sum/ev)

        cout << "YES" << endl;

        else 

        cout << "NO" << endl;

    }

}



Code 2:
#include<iostream>

#include<bits/stdc++.h>

using namespace std;







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];



        int od = 0;

        int ev = 0; 

        long long int od_sum = 0;

        long long int ev_sum = 0;



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

            od++;

            od_sum+=arr[i];

        }

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

            ev++;

            ev_sum+=arr[i];

        }



        if (od_sum%od==0 && ev_sum%ev==0 && od_sum/od == ev_sum/ev)

        cout << "YES" << endl;

        else 

        cout << "NO" << endl;

    }

}



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

Code 1:
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

using namespace std;

#define int long long
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define read(x,a,b) rep(i, a, b) cin>>x[i];
#define vi vector<int>
#define all(l) l.begin(), l.end()

typedef long long ll;
constexpr int N=1e6, mod=1e9+7, INF=1e18+5;

void solve()
{
    int n; cin >> n;
    vi a(n); read(a,0,n-1)
    int sum{0},even{0},odd{0};
    rep(i,0,n-1)
    {
        if (i&1) odd+=a[i];
        else even+=a[i];
    }
    int e{n/2},o{n/2};
    if (n&1) e++;
    if (odd%o || even%e || odd/o!=even/e) cout << "NO\n";
    else cout << "YES\n";
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int t{1};
    cin >> t;
    while (t--) solve();
}

Code 2:
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

using namespace std;

#define int long long
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define read(x,a,b) rep(i, a, b) cin>>x[i];
#define vi vector<int>
#define all(l) l.begin(), l.end()

typedef long long ll;
constexpr int N=1e6, mod=1e9+7, INF=1e18+5;

void solve()
{
    int n; cin >> n;
    vi a(n); read(a,0,n-1)
    int sum{accumulate(all(a),0)};
    if (sum/n!=(sum+n-1)/n) {cout << "NO\n"; return;}
    int target{sum/n};
    rep(i,1,n-2)
    {
        int diff{target-a[i-1]};
        a[i-1]+=diff,a[i+1]-=diff;
    }
    rep(i,0,n-1)
    {
        if (a[i]!=target) {cout << "NO\n"; return;}
    }
    cout << "YES\n";
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int t{1};
    cin >> t;
    while (t--) solve();
}

Answer: 1
Problem: 2050B - Transfusion
Language: python

Code 1:
def process_array():
    _size = int(input())
    a =list(map(int, input().split()))
    sum1 = 0 
    odd= (_size+1)//2
    sum2 = 0 
    even = _size-odd
    for i in range(_size):
        if i%2==0 :
           sum1+=a[i]
           
        else :
           sum2+=a[i] 
   # print(sum1, sum2, odd ,even)
    if (sum1+sum2)%_size==0 :
       if sum1 == odd*((sum1+sum2)/_size) and sum2== even*((sum1+sum2)/_size):
          print("YES")
          return
       else:
          print("NO")
          return   
    else:
      print("NO")

t = int(input())    
for _ in range(t): 
       process_array()


Code 2:
def process_array():
    _size = int(input())
    a =list(map(int, input().split()))
    sum1 = 0 
    odd= (_size+1)/2
    sum2 = 0 
    even = _size-odd
    for i in range(_size):
        if i%2==0 :
           sum1+=a[i]
        else :
           sum2+=a[i] 
    if (sum1+sum2)%_size==0 :
       if sum1 == odd*((sum1+sum2)/_size) and sum2== even*((sum1+sum2)/_size):
          print("YES")
          return
       else:
          print("NO")
          return   
    else:
      print("NO")

t = int(input())    
for _ in range(t): 
       process_array()


Answer: 1
Problem: 2050B - Transfusion
Language: python

Code 1:


OUT=[]
for i in range(int(input())):
    n=int(input())
    L=list(map(int,input().split()))
    s=sum(L)
    if s%n==0 :
        p=s//n
        k=1
        b=True
        while k<n-1 and b:
            if L[k-1]!= p:
                if L[k+1]-(p-L[k-1])<0:
                    b=False
                else:
                    L[k+1]-=p-L[k-1]
                    L[k-1]=p
                
            k+=1
        if b and L[-1]==p and L[-2]==p:
            OUT.append('YES')
        else:
            OUT.append('NO')
        
    else:
        OUT.append('NO')

for i in OUT:
    print(i)

Code 2:


OUT=[]
for i in range(int(input())):
    n=int(input())
    L=list(map(int,input().split()))
    s=sum(L)
    if s%n==0 :
        p=s//n
        k=1
        b=True
        while k<n-1 and b:
            if L[k-1]!= p:
                
                L[k+1]-=p-L[k-1]
                L[k-1]=p
                
            k+=1
        if b and L[-1]==p and L[-2]==p:
            OUT.append('YES')
        else:
            OUT.append('NO')
        
    else:
        OUT.append('NO')

for i in OUT:
    print(i)

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

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define f(i,a,b) for(int i=a; i<b; i++)
#define fr(i,a,b) for(int i=a; i>=b; i--)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define w(t) int t; cin>>t; while(t--)
#define ll long long


int main(){
w(t){
    int n ; cin>>n;
    vector<int> arr(n);
    long long even=0,odd=0;
    f(i,0,n) {
        int x; cin>>x;
        if(i%2) odd+=x;
        else even+=x;
    }
    bool z=false;
    if(n%2 ) {
        if(odd/(n/2) == even/(n/2 + 1) && (odd/(n/2) == ceil((double) odd/(n/2)))) z=true;
        }

    else {
            if(odd/(n/2) == even/(n/2) && (odd/(n/2) == ceil((double) odd/(n/2)))) z=true;
            }
    if(z) print("YES")
    else print("NO") 
   
}

}

Code 2:
// #include <bits/stdc++.h>
// using namespace std;
// #define print(x) cout<<x<<endl;
// #define f(i,a,b) for(int i=a; i<b; i++)
// #define fr(i,a,b) for(int i=a; i>=b; i--)
// #define all(v) v.begin(),v.end()
// #define pb(x) push_back(x)
// #define w(t) int t; cin>>t; while(t--)
// #define ll long long


// int main(){
// w(t){
//     int n ; cin>>n;
//     vector<int> arr(n);
//     long long even=0,odd=0;
//     f(i,0,n) {
//         int x; cin>>x;
//         if(i%2) odd+=x;
//         else even+=x;
//     }
//     bool z=false;
//     if(n%2 ) {
//         if(odd/(n/2) == even/(n/2 + 1) && (odd/(n/2) == ceil((double) odd/(n/2))) && (even/(n/2) == ceil((double) even/(n/2 + 1)))) z=true;
//         }

//     else {
//             if(odd/(n/2) == even/(n/2) && (odd/(n/2) == ceil((double) odd/(n/2))) &&(even/(n/2) == ceil((double) even/(n/2)))) 
//             z=true;
//             }
//     if(z) print("YES")
//     else print("NO") 
   
// }

// }
#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n; cin >> n;
    vector<int> a(n);
    for (int &x : a) cin >> x;
    
    long long ods = 0, evs = 0;
    for (int i = 0; i < n; i++) {
        if (i & 1) ods += a[i];
        else evs += a[i];
    }
    int odc = n / 2, evc = n / 2;
    if (n & 1) evc++;

    if (ods % odc != 0 || evs % evc != 0 || ods / odc != evs / evc) {
        cout << "NO";
        return;
    }
    cout << "YES";
}

int main() {
    int TESTS; cin >> TESTS;
    while (TESTS --> 0) {
        solve();
        cout << '\n';
    }
    return 0;
}

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

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

using namespace std;

int main()

{

  double t, n, a;

  cin >> t;

  while (t--)

  {

    cin >> n;

    double sum = 0, sum1 = 0, sum2 = 0;

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

    {

      cin >> a;

      sum += a;

      if (i % 2 == 0)

        sum1 += a;

      else

        sum2 += a;

    }

    double test = sum / (float)n;

    if ((int)sum % (int)n == 0 && sum1 == test * ceil(n / 2) && sum2 == test * int(n / 2))

      cout << "YES\n";

    else

      cout << "NO\n";

  }

}

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

using namespace std;

int main()

{

  long long t, n, a, b;

  cin >> t;

  while (t--)

  {

    cin >> n;

    long long sum = 0, sum1 = 0, sum2 = 0;

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

    {

      cin >> a;

      sum += a;

      if (i % 2 == 0)

        sum1 += a;

      else

        sum2 += a;

    }

    if (n % 2 == 0)

    {

      a = n / 2;

      b = n / 2;

    }

    else

    {

      a = n / 2 + 1;

      b = n / 2;

    }

    if (sum % n == 0 && sum1 == a * sum / n && sum2 == b * sum / n)

      cout << "YES\n";

    else

      cout << "NO\n";

  }

}

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

Code 1:
#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define _test int _TEST; cin >> _TEST; while (_TEST--)
#define ll long long
#define all(a) (a).begin(), (a).end()



void solve() {
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i = 0; i < n; i++)
  {
    cin>>a[i];
  }
  int even=0,odd=0;
  int n1=0,n2=0;
  for(int i = 0; i < n; i++)
  {
    if(i&1){
      even+=a[i];
      n1++;
    }else{
      odd+=a[i];
      n2++;
    }
  }
  if(even%n1==0 && odd%n2==0 && even/n1==odd/n2) cout<<"YES\n";
  else cout<<"NO\n";
}
int main() {
  _test { 
solve();
 }
  return 0;
}

Code 2:
#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define _test int _TEST; cin >> _TEST; while (_TEST--)
#define ll long long
#define all(a) (a).begin(), (a).end()



void solve() {
  ll n;
  cin>>n;
  vector<ll>a(n);
  for(int i = 0; i < n; i++)
  {
    cin>>a[i];
  }
  ll even=0,odd=0;
  ll n1=0,n2=0;
  for(int i = 0; i < n; i++)
  {
    if(i&1){
      even+=a[i];
      n1++;
    }else{
      odd+=a[i];
      n2++;
    }
  }
  if(even%n1==0 && odd%n2==0 && even/n1==odd/n2) cout<<"YES\n";
  else cout<<"NO\n";
}
int main() {
  _test { 
solve();
 }
  return 0;
}

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

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

using namespace std;

void gotoo(){

    long long n;

    cin>>n;

    long long a[n],i,sum=0;

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

        cin>>a[i];

        sum+=a[i];

    }

    if(sum%n!=0){

        cout<<"NO"<<endl;

        return;

    }

    long long ch=sum/n;

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

        if(a[i-1]>ch){

            long long ne1=a[i-1]-ch;

            a[i-1]=a[i-1]-ne1;

            a[i+1]=a[i+1]+ne1;

        }

        else if(a[i-1]<ch){

            long long nee=ch-a[i-1];

            a[i+1]=a[i+1]-nee;

            a[i-1]=a[i-1]+nee;

        }

    }

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

        cout<<"YES"<<endl;

    else

        cout<<"NO"<<endl;

        

}

int main(){

    int t;

    cin>>t;

    while(t--){

        gotoo();

    }

}

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

using namespace std;

void gotoo(){

    int n;

    cin>>n;

    int a[n],i,sum=0;

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

        cin>>a[i];

        sum+=a[i];

    }

    if(sum%n!=0){

        cout<<"NO"<<endl;

        return;

    }

    int ch=sum/n;

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

        if(a[i-1]>ch){

            int ne1=a[i-1]-ch;

            a[i-1]=a[i-1]-ne1;

            a[i+1]=a[i+1]+ne1;

        }

        else if(a[i-1]<ch){

            int nee=ch-a[i-1];

            a[i+1]=a[i+1]-nee;

            a[i-1]=a[i-1]+nee;

        }

    }

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

        cout<<"YES"<<endl;

    else

        cout<<"NO"<<endl;

        

}

int main(){

    int t;

    cin>>t;

    while(t--){

        gotoo();

    }

}

Answer: 1