ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050B - Transfusion
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 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))) && (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") 
   
}

}

Submission (verdict: Accepted):
// #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;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define pb push_back

typedef long long ll;

ll arr[30];

void solve(){
    ll a,b,c,l,r;
    cin>>l>>r;
    
    if(r-l==2){
    cout<<l<<" "<<l+1<<" "<<r<<endl;
    }
    
    else{
    ll sum=0;
    
    ll lo,hi;
    lo=log2(l+1);
    hi=log2(r);
    
    if(pow(2,hi)==r){
     a=0;
     b=r;
     c=r-1;
    }
    
    else if(hi-lo>0){
        a=pow(2,hi)-1;
        b=pow(2,hi);
        c=pow(2,hi)+1;
    }
    
    else{
        for(int i=29;i>=0;i--){
            if(arr[i]<=l){
                // cout<<i<<endl;
                sum+=arr[i];
                l-=arr[i];
                r-=arr[i];
                
                lo=log2(l+1);
                hi=log2(r);
                
                // cout<<l<<" "<<r<<" "<<lo<<" "<<hi<<endl;
                
                if(pow(2,hi)==r){
                    a=sum;
                    b=r;
                    c=r-1+sum;
                    break;
                }
                
                if(hi-lo>0){
                    a=sum+pow(2,hi)-1;
                    b=sum+pow(2,hi);
                    c=sum+pow(2,hi)+1;
                    break;
                }
            }
        }
    }
    
    cout<<a<<" "<<b<<" "<<c<<endl;
    }
}

int main() {
    arr[0]=1;
    for(int i=1;i<30;i++)
    arr[i]=arr[i-1]*2;
    
    // for(int i=29;i>=0;i--)
    // cout<<arr[i]<<" ";
    // cout<<endl;
    
    ll t;
    cin>>t;
    while(t--)
    solve();
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define pb push_back

typedef long long ll;

ll arr[30];

void solve(){
    ll a,b,c,l,r;
    cin>>l>>r;
    
    if(r-l==2){
    cout<<l<<" "<<l+1<<" "<<r<<endl;
    }
    
    else{
    ll sum=0;
    
    ll lo,hi;
    lo=log2(l+1);
    hi=log2(r);
    
    if(pow(2,hi)==r){
     a=0;
     b=r;
     c=r-1;
    }
    
    else if(hi-lo>0){
        a=pow(2,hi)-1;
        b=pow(2,hi);
        c=pow(2,hi)+1;
    }
    
    else{
        for(int i=29;i>=0;i--){
            if(arr[i]<=l){
                // cout<<i<<endl;
                sum+=arr[i];
                l-=arr[i];
                r-=arr[i];
                
                lo=log2(l+1);
                hi=log2(r);
                
                // cout<<l<<" "<<r<<" "<<lo<<" "<<hi<<endl;
                
                if(pow(2,hi)==r){
                    a=sum;
                    b=r;
                    c=r-1+sum;
                    break;
                }
                
                if(hi-lo>0){
                    a=sum+pow(2,hi)-1;
                    b=sum+pow(2,hi);
                    c=sum+pow(2,hi)+1;
                    break;
                }
            }
        }
    }
    
    cout<<a<<" "<<b<<" "<<c<<endl;
    }
}

int main() {
    arr[0]=1;
    for(int i=1;i<30;i++)
    arr[i]=arr[i-1]*2;
    
    // for(int i=29;i>=0;i--)
    // cout<<arr[i]<<" ";
    // cout<<endl;
    
    ll t;
    cin>>t;
    while(t--)
    solve();
}


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define pb push_back

typedef long long ll;

ll arr[30];

void solve(){
    ll a,b,c,l,r;
    cin>>l>>r;
    
    if(r-l==2){
    cout<<l<<" "<<l+1<<" "<<r<<endl;
    }
    
    else{
    ll sum=0;
    
    ll lo,hi;
    lo=log2(l+1);
    hi=log2(r);
    
    if(pow(2,hi)==r){
     a=r-2;
     b=r;
     c=r-1;
    }
    
    else if(hi-lo>0){
        a=pow(2,hi)-1;
        b=pow(2,hi);
        c=pow(2,hi)+1;
    }
    
    else{
        for(int i=29;i>=0;i--){
            if(arr[i]<=l){
                // cout<<i<<endl;
                sum+=arr[i];
                l-=arr[i];
                r-=arr[i];
                
                lo=log2(l+1);
                hi=log2(r);
                
                // cout<<l<<" "<<r<<" "<<lo<<" "<<hi<<endl;
                
                if(pow(2,hi)==r){
                    a=r-2+sum;
                    b=r;
                    c=r-1+sum;
                    break;
                }
                
                if(hi-lo>0){
                    a=sum+pow(2,hi)-1;
                    b=sum+pow(2,hi);
                    c=sum+pow(2,hi)+1;
                    break;
                }
            }
        }
    }
    
    cout<<a<<" "<<b<<" "<<c<<endl;
    }
}

int main() {
    arr[0]=1;
    for(int i=1;i<30;i++)
    arr[i]=arr[i-1]*2;
    
    // for(int i=29;i>=0;i--)
    // cout<<arr[i]<<" ";
    // cout<<endl;
    
    ll t;
    cin>>t;
    while(t--)
    solve();
}
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

#define int long long

int t,n,l,r,a[100005],b[100005];

signed main(){

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	cin>>t;

	while(t--){

		int cnt=0,cnt1=0;

		memset(a,0,sizeof(a));

		memset(b,0,sizeof(b));

		cin>>n>>l>>r;

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

			cin>>a[i];

			b[i]=a[i];

		}

		sort(a+1,a+r);

		sort(b+l,b+n+1);

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

			cnt+=a[i];

		}

		for(int i=l;i<=r;i++){

			cnt1+=b[i];

		}

		cout<<min(cnt,cnt1)<<endl;

	}

	return 0;

}

//1 1 4 5 1 4

//1 1 4 5 1 4 1 9 1 9 8 1 0

Submission (verdict: Accepted):
#include<bits/stdc++.h>

using namespace std;

#define int long long

int t,n,l,r,a[100005],b[100005];

signed main(){

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	cin>>t;

	while(t--){

		int cnt=0,cnt1=0;

		memset(a,0,sizeof(a));

		memset(b,0,sizeof(b));

		cin>>n>>l>>r;

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

			cin>>a[i];

			b[i]=a[i];

		}

		sort(a+1,a+r+1);

		sort(b+l,b+n+1);

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

			cnt+=a[i];

		}

		for(int i=l;i<=r;i++){

			cnt1+=b[i];

		}

		cout<<min(cnt,cnt1)<<endl;

	}

	return 0;

}

//1 1 4 5 1 4

//1 1 4 5 1 4 1 9 1 9 8 1 0
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

#define int long long

int t,n,l,r,a[100005];

signed main(){

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	cin>>t;

	while(t--){

		int ans=0;

		memset(a,0,sizeof(a));

		cin>>n>>l>>r;

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

			cin>>a[i];

		}

		sort(a+1,a+n+1);

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

			ans+=a[i];

		}

		cout<<ans<<endl;

	}

	return 0;

}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

#define int long long

int t,n,l,r,a[100005],b[100005];

signed main(){

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	cin>>t;

	while(t--){

		int cnt=0,cnt1=0;

		memset(a,0,sizeof(a));

		memset(b,0,sizeof(b));

		cin>>n>>l>>r;

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

			cin>>a[i];

			b[i]=a[i];

		}

		sort(a+1,a+r);

		sort(b+l,b+n+1);

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

			cnt+=a[i];

		}

		for(int i=l;i<=r;i++){

			cnt1+=b[i];

		}

		cout<<min(cnt,cnt1)<<endl;

	}

	return 0;

}

//1 1 4 5 1 4

//1 1 4 5 1 4 1 9 1 9 8 1 0
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>

using namespace std;

#define int long long

int t,n,l,r,a[100005];

signed main(){

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	cin>>t;

	while(t--){

		int ans=0;

		memset(a,0,sizeof(a));

		cin>>n>>l>>r;

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

			cin>>a[i];

		}

		sort(a+1,a+n+1);

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

			ans+=a[i];

		}

		cout<<ans<<endl;

	}

	return 0;

}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


Submission (verdict: Time limit exceeded on test 27):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;


bool dfs(int x, unordered_map<int,int> &mp, int &n)
{
    if(!x) return 0;
    if(mp[x]>0)
    {
        mp[x]--;
        n--;
        return 1;
    }
    return dfs(x/2, mp, n) && dfs(x-x/2, mp, n);
}
int main()
{
    int test;
    cin >> test;

    while(test--)
    {
		int n, m;
		cin >> n >> m;

        unordered_map<int,int> mp;

        for(int i=0; i<n; i++)
        {
            int x;
            cin >> x;
            mp[x]++;
        }

        bool flag = false;

        for(int i=0; i<m; i++)
        {
            int x;
            cin >> x;

            if(!flag && !dfs(x, mp, n)) flag = true;
        }

        if(flag || n) cout << "NO";
        else cout << "YES";

        if(test) cout << '\n';
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 27):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;


bool dfs(int x, unordered_map<int,int> &mp, int &n)
{
    if(!x) return 0;
    if(mp[x]>0)
    {
        mp[x]--;
        n--;
        return 1;
    }
    return dfs(x/2, mp, n) && dfs(x-x/2, mp, n);
}
int main()
{
    int test;
    cin >> test;

    while(test--)
    {
		int n, m;
		cin >> n >> m;

        unordered_map<int,int> mp;

        for(int i=0; i<n; i++)
        {
            int x;
            cin >> x;
            mp[x]++;
        }

        bool flag = false;

        for(int i=0; i<m; i++)
        {
            int x;
            cin >> x;

            if(!flag && !dfs(x, mp, n)) flag = true;
        }

        if(flag || n) cout << "NO";
        else cout << "YES";

        if(test) cout << '\n';
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 27):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;


bool dfs(int x, unordered_map<int,int> &mp, int &n)
{
    if(!x) return 0;
    if(mp[x]>0)
    {
        mp[x]--;
        n--;
        return 1;
    }
    return dfs(x/2, mp, n) && dfs(x-x/2, mp, n);
}
int main()
{
    int test;
    cin >> test;

    while(test--)
    {
		int n, m;
		cin >> n >> m;

        unordered_map<int,int> mp;

        for(int i=0; i<n; i++)
        {
            int x;
            scanf("%d",&x);
            // cin >> x;
            mp[x]++;
        }

        bool flag = false;

        for(int i=0; i<m; i++)
        {
            int x;
            scanf("%d",&x);

            if(!flag && !dfs(x, mp, n)) flag = true;
        }

        if(flag || n) cout << "NO";
        else cout << "YES";

        if(test) cout << '\n';
    }
    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 27):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;


bool dfs(int x, unordered_map<int,int> &mp, int &n)
{
    if(!x) return 0;
    if(mp[x]>0)
    {
        mp[x]--;
        n--;
        return 1;
    }
    return dfs(x/2, mp, n) && dfs(x-x/2, mp, n);
}
int main()
{
    int test;
    cin >> test;

    while(test--)
    {
		int n, m;
		cin >> n >> m;

        unordered_map<int,int> mp;

        for(int i=0; i<n; i++)
        {
            int x;
            scanf("%d",&x);
            // cin >> x;
            mp[x]++;
        }

        bool flag = false;

        for(int i=0; i<m; i++)
        {
            int x;
            scanf("%d",&x);

            if(!flag && !dfs(x, mp, n)) flag = true;
        }

        if(flag || n) cout << "NO";
        else cout << "YES";

        if(test) cout << '\n';
    }
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;


bool dfs(int x, map<int,int> &mp, int &n)
{
    if(!x) return 0;
    if(mp[x]>0)
    {
        mp[x]--;
        n--;
        return 1;
    }
    return dfs(x/2, mp, n) && dfs(x-x/2, mp, n);
}
int main()
{
    int test;
    cin >> test;

    while(test--)
    {
		int n, m;
		cin >> n >> m;

        map<int,int> mp;

        for(int i=0; i<n; i++)
        {
            int x;
            scanf("%d",&x);
            // cin >> x;
            mp[x]++;
        }

        bool flag = false;

        for(int i=0; i<m; i++)
        {
            int x;
            scanf("%d",&x);

            if(!flag && !dfs(x, mp, n)) flag = true;
        }

        if(flag || n) cout << "NO";
        else cout << "YES";

        if(test) cout << '\n';
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

class DSU {
public: 
    vector<int> rank, par; 
    DSU(int n) 
    {
        rank.resize(n+1, 0); 
        par.resize(n+1);
        for(int i=0; i<=n; i++) par[i] = i;
    }

    int findUPar(int node) 
    {
        if(node==par[node]) return node; 
        return par[node] = findUPar(par[node]); 
    }

    void unionByRank(int u, int v) 
    {
        int ulp_u = findUPar(u); 
        int ulp_v = findUPar(v); 

        if(ulp_u==ulp_v) return;

        if(rank[ulp_u]<rank[ulp_v]) par[ulp_u] = ulp_v; 
        else if(rank[ulp_v]<rank[ulp_u])  par[ulp_v] = ulp_u;
        else 
        {
            par[ulp_v] = ulp_u; 
            rank[ulp_u]++; 
        }
    }
}; 

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

    while(test--)
    {
		int n;
		cin >> n;
		vector<pair<int,int>> g1;
        vector<pair<int,int>> indegree(n+1);

        for(int i=1; i<=n; i++) indegree[i].second = i;

		for(int i=0; i<n-1; i++)
		{
			int u,v;
			cin >> u >> v;
			g1.push_back({u,v});
            indegree[u].first++;
            indegree[v].first++;
		}

        if(n==2) cout << 0;
        else
        {
            sort(indegree.begin(), indegree.end());
            int v1 = indegree[n].second;

            vector<pair<int,int>> g2;
            vector<pair<int,int>> indegree1(n+1);
            for(int i=1; i<=n; i++) indegree1[i].second = i;

            for(auto it:g1)
            {
                int u = it.first;
                int v = it.second;

                if(u==v1 || v==v1) continue;
                else 
                {
                    g2.push_back({u,v});
                    indegree1[u].first++;
                    indegree1[v].first++;
                }
            }

            sort(indegree1.begin(), indegree1.end());
            int v2 = indegree1[n].second;

            int ans=0;
            DSU ds1(n);
            for(auto it:g2)
            {
                int u = it.first;
                int v = it.second;

                if(u==v2 || v==v2) continue;
                else ds1.unionByRank(u,v);
            }

            for(int i=1; i<=n; i++)
            {
                if(!(i==v1 || i==v2) && ds1.par[i]==i) ans++;
            }
            cout << ans;
        }
        if(test) cout << '\n';
    }
    return 0;
}
Problem: 2050B - Transfusion
Language: Node.js


Submission (verdict: Wrong answer on test 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 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");
        return;
    }

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

    console.log("YES");
    return 
}
Problem: 2050B - Transfusion
Language: Node.js

Previous submission (verdict: Wrong answer on test 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 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;
}


Submission (verdict: Accepted):
'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;
}
Problem: 2050B - Transfusion
Language: Node.js

Previous submission (verdict: Wrong answer on test 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 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");
        return;
    }

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

    console.log("YES");
    return 
}


Submission (verdict: Wrong answer on test 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 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;
}