ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: c++17 

Solution 1 (runtime: 655 ms):
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ll long long
using namespace std;

ll n,m,t,d[200005],q,mn,sum,ans,indx,r,l,k,p[200005],pr[200005];

ll mx;

//pair <int,int> p[20005];

bool flag;

string s;

set <long long> st,st1;

set <long long> :: iterator it,it1;

vector <long long> v,edg[200005];

map <ll,ll> mp;

bool b[200005];

void treeDp(int a,int par){
    d[a] = 0;
    for(int i = 0; i < edg[a].size(); i++){
        if(edg[a][i] != par){
            treeDp(edg[a][i], a);
            mx = max((ll) mx,max((ll) (d[edg[a][i]] + edg[a].size() - 1),(ll) (edg[edg[a][i]].size() + edg[a].size() - 2)));

        }
    }
    v.clear();
    for(int i = 0; i < edg[a].size(); i++){
        if(edg[a][i] != par)
        v.pb(max((ll)d[edg[a][i]],(ll)edg[edg[a][i]].size()));
    }
    sort(v.begin(),v.end());
    if(v.size() >= 2){
        mx = max(mx,v[v.size() - 1] + v[v.size() - 2] + 1 - 2);
    }
    for(int i = 0; i < edg[a].size(); i++){
        if(edg[a][i] != par)
        d[a] = max(d[a],max(d[edg[a][i]],(ll) edg[edg[a][i]].size()));
    }
}

long long y,x,e,u;

int main(){
    cin >> t;
    while(t--){
        for(int i = 1; i <= n; i++){
            edg[i].clear();
        }
        cin >> n;
        for(int i = 1; i < n; i++){
            cin >> e >> u;
            edg[e].pb(u);
            edg[u].pb(e);
        }
        mx = 0;
        treeDp(1,0);
    //for(int i = 1; i <= n; i++) cout << d[i] << " ";
    //cout << endl;
        cout << mx << endl;
    }
}


Solution 2 (runtime: 640 ms):
#include <iostream>
#include <vector>
#include <set>
using namespace std;

const int MAXN = 2e5 + 5;
int t, n, deg[MAXN], ans;
vector<int> g[MAXN];
multiset<int> s1, s2;

int main() {
	ios :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	for (cin >> t; t --; ) {
		cin >> n; s1.clear(), ans = 0;
		for (int i = 1; i <= n; i ++) g[i].clear(), deg[i] = 0;
		for (int i = 1, u, v; i < n; i ++) {
			cin >> u >> v;
			g[u].push_back(v); deg[v] ++;
			g[v].push_back(u), deg[u] ++;
		}
		if (n == 2) { cout << 0 << '\n'; continue; }
		for (int i = 1; i <= n; i ++) s1.insert(deg[i]);
		for (int i = 1; i <= n; i ++) {
			s1.erase(s1.find(deg[i]));
			for (int j : g[i]) {
				s1.erase(s1.find(deg[j]));
				s2.insert(deg[j]);
			}
			if (!s1.empty()) ans = max(ans, deg[i] + (*s1.rbegin()) - 1);
			if (!s2.empty()) ans = max(ans, deg[i] + (*s2.rbegin()) - 2);
			s1.insert(deg[i]);
			for (int j : g[i]) s1.insert(deg[j]);
			s2.clear();
		}
		cout << ans << '\n';
	}
	return 0;
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 343 ms):
#include<bits/stdc++.h>
#define startt ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
#define loop(i,n) for(int i=0;i<n;i++)
#define vi vector<ll> 
#define pb(a) push_back(a);
#define pp  pop_back()
#define all(a)  a.begin(),a.end()
#define sc second
#define fr first
#define dbg  cout<<1234567890;
const int M=1e9+7;
typedef long long ll;
typedef long long intl;
typedef pair<int, int> pi;
void solve(int durgesh){
    int n;cin>>n;
    ll arr[n];
    loop(i,n)cin>>arr[i];
    ll mini=INT_MIN;
    int f=0;
    for(int i=1;i<n;i++){
        if(arr[i-1]<=arr[i]){
            arr[i]=arr[i]-arr[i-1];
            arr[i-1]=0;
            mini=max(mini,arr[i]);
        }else{
            f=1;
        }
    }
    if(f)cout<<"NO\n";
    else cout<<"YES\n";
}
int main() {
int TT=1;
cin>>TT;
for(int i=1;i<=TT;++i)
solve(i);
return 0;
}

Solution 2 (runtime: 328 ms):
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int a[N];
int main(){
	int t;cin>>t;
	while(t--){
		int n;cin>>n;
		bool flag=true;
		for(int i=1;i<=n;i++)cin>>a[i];
		for(int i=1;i<=n-1;i++){
			if(a[i]<=a[i+1]){
				a[i+1]-=a[i];
				a[i]=0;
			}
			else{
				flag=false;
				break;
			}
		}
		if(flag)cout<<"YES"<<"\n";
		else cout<<"NO"<<"\n";
	}
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 186 ms):
#include <bits/stdc++.h>
using namespace std;

#define pyes cout << "YES\n"
#define pno cout << "NO\n"
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x << " " << x << endl;
#else
#define debug(x)
#endif

int main()
{
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i)
    {
        int n, l, r;
        cin >> n >> l >> r;
        l--;
        r--;
        vector<int> v1;
        v1.reserve(n);
        int t1;
        string check = "checking\n";
        int x = max(0, l - (r - l + 1));
        int y = min(n - 1, r + (r - l + 1));
        debug(x) debug(y);
        for (int j = 0; j < n; ++j)
        {
            cin >> t1;
            v1.push_back(t1);
        }
        if (n == 1)
        {
            cout << t1 << endl;
            continue;
        }
        vector<int> v2(v1.begin(), v1.begin() + r + 1);
        sort(v2.begin(), v2.end());
        unsigned long long a1 = 0, a2 = 0;
        for (int i = 0; i < r - l + 1; ++i)
        {
            a1 += v2[i];
        }
        vector<int> v3(v1.begin() + l, v1.end());
        sort(v3.begin(), v3.end());
        for (int i = 0; i < r - l + 1; ++i)
        {
            a2 += v3[i];
        }
        cout << min(a1, a2) << endl;
        // debug(check)
        // cout << min(a1, a2) << endl;
    }
}

Solution 2 (runtime: 78 ms):
#include <bits/stdc++.h>

#define ll long long

#define W while

#define CI const int

#define RI int

#define Ms(a,x) memset((a), (x), sizeof(a)) 

using namespace std;

CI N = 1e5; int T, n, a[N + 5], l, r;

bool cmp (int x, int y) {return x > y;}

int main () {

	RI i, j; scanf ("%d", &T); W (T --) {

		scanf ("%d%d%d", &n, &l, &r); for (i = 1; i <= n; ++ i) scanf ("%d", &a[i]);

		sort (a + 1, a + l); sort (a + l, a + r + 1, cmp); sort (a + r + 1, a + n + 1); ll sum = 0, now = 0, ans = 0;

		for (i = l; i <= r; ++ i) sum += a[i]; now = sum; for (i = 1; i <= min (l - 1, r - l + 1); ++ i) {

			if (a[i] <= a[i + l - 1]) now = now - a[i + l - 1] + a[i]; else break;

		} ans = now; now = sum; for (i = 1; i <= min (r - l + 1, n - r); ++ i) {

			if (a[i + r] <= a[i + l - 1]) now = now - a[i + l - 1] + a[i + r];

		} ans = min (ans, now); printf ("%lld\n", ans);

	}

	return 0;

}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 186 ms):
#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    long long n,l,r;
	    cin>>n>>l>>r;
	    vector<long long> v(n);
	    for(long long i=0;i<n;i++){
	        cin>>v[i];
	    }
	    sort(v.begin()+l-1,v.begin()+r);
	    sort(v.begin(),v.begin()+l-1);
	    sort(v.begin()+r,v.end());
	    long long ans=0;
	    for(long long i=l-1;i<r;i++){
	        ans+=v[i];
	    }
	    long long ans1=0,ans2=0;
	    for(long long i=r-1;i>=l-1;i--){
	        if(r-1-i<l-1&&v[i]>v[r-1-i]){
	            ans1+=v[i]-v[r-1-i];
	        }
	        else{
	            break;
	        }
	    }
	    for(long long i=r-1;i>=l-1;i--){
	        if(2*r-i-1<n&&v[i]>v[2*r-i-1]){
	            ans2+=v[i]-v[2*r-i-1];
	        }
	        else{
	            break;
	        }
	    }
	    ans-=max(ans1,ans2);
	    cout<<ans<<endl;
	    
	}

}


Solution 2 (runtime: 202 ms):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef vector<ll> vll;

typedef set<int> si;

typedef map<int, int> mii;

typedef map<int, char> mic;

typedef map<char, int> mci;



#define f(i, l, h) for(int i = l; i < h; i++)

#define cf(i, l, h) for(int i = l; i <= h; i++)

#define rf(i, h, l) for(int i = h - 1; i >= l; i--)

#define pb push_back



void solution() {

	int n, l, r;

	cin >> n >> l >> r;

	vll a, b;



	f(i, 0, n) {

		int x;

		cin >> x;



		if(i >= l-1) a.pb(x);

		if(i < r) b.pb(x);

	}



	sort(a.begin(), a.end());

	sort(b.begin(), b.end());



	ll ans1 = 0, ans2 = 0;



	cf(i, 0, r-l) ans1 += a[i];

	cf(i, 0, r-l) ans2 += b[i];



	cout << min(ans1, ans2) << endl;

}



int main() {

	int t = 1;

	cin >> t;

	while(t--) {

		solution();

	}

}
Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 1421 ms):
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 1e5 + 5;
vector<int> g[N];
int vis[N]={0};
int c = 0;
void dfs(int node, int par, int n){
    // vis[node] = 1;
    if(node == n){
        c++;
        return;
    }
    for(int i : g[node]){
        dfs(i,node,n);
    }
}
void solve(){
    int n;
    cin >> n;
    vector<pair<int,int>> v;
    int arr[n];
    for(int i = 0; i < n; i++){
        cin >> arr[i];
    }
    if(n == 1){
        cout << 0 << endl;
        return;
    }
    for(int i = n; i >=2; i--){
        for(int j = i-1; j >= 1; j--){
            v.push_back({i,j});
        }
    }
    int rarr[n+1]={0};
    for(int i = 1; i <= n; i++){
        rarr[i] = n-i+1;
    } 
    for (int i = 0; i < n; i++) {
    while (rarr[i + 1] != arr[i]) {
        int pos = 0;
        for (int k = i + 1; k <= n; k++) {
            if (rarr[k] == arr[i]) {
                pos = k;
                break;
            }
        }
        swap(rarr[pos - 1], rarr[pos]);
        v.push_back({rarr[pos - 1], rarr[pos]});
    }
    }

    // for(int i = 1; i <= n; i++){
    //     cout << rarr[i] << endl;
    // }
    cout << v.size() << endl;
    for(int i = 0; i < v.size(); i++){
        cout << v[i].first <<" " << v[i].second << endl; 
    }
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("opp.txt", "w", stdout);
#endif
    solve();
    return 0;
}


Solution 2 (runtime: 1327 ms):
#include <bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL)
#define int long long
#define mod 1000000007

signed main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i=0; i<n; i++) {
        cin>>v[i];
    }
    bool arr[n+1] = {false};
    vector<pair<int,int>> ans;
    for(int i=n-1; i>=0; i--) {
        arr[v[i]] = true;
        for(int j=v[i]-1; j>0; j--) {
            if(!arr[j]) ans.push_back({v[i],j});
        }
        for(int j=1; j<=n; j++) {
            if(!arr[j]) ans.push_back({j,v[i]});
        }
        
    }
    cout<<ans.size()<<endl;
    for(auto x : ans) {
        cout<<x.first<<" "<<x.second<<endl;
    }
    return 0;
}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
 
/*                                             सम्भवामि युगे युगे ॥                                      */

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define inf std::numeric_limits<int>::max();
#define yup cout<<"YES"<<endl;
#define nope cout<<"NO"<<endl;
const int MOD = 1e9+7;
ll binaryExpo(ll base, ll e)
{
    ll res=1;
    while (e)
    {
        if(e&1) (res *= base)%=MOD;
        (base *= base)%=MOD; e/=2;
    } return res;
}

void solutioN()
{
    ll n; cin>> n;
    vector<ll> v(n), anotherV;
    ll sum = 0;
    for(int i=0; i<n; i++)
    {
        cin>> v[i];
        anotherV.push_back(v[i]);
        sum += v[i];
    }


    while ((anotherV.size())>=1)
    {
        ll ss = 0;
        for(auto it : anotherV) 
        {
            ss += it; 
            // cout<< it << " "; 
        }
        // cout<<endl;
        sum = max(sum, ss);

        for(int i=1; i<anotherV.size(); i++)
        {
            if(anotherV[i]<anotherV[i-1])
            {
                reverse(anotherV.begin(),anotherV.end());
                break;
            }
        }


        vector<ll> tempV;
        for(int i=1; i<anotherV.size(); i++)
        {
            tempV.push_back(anotherV[i]-anotherV[i-1]);
        }
        anotherV.clear();
        anotherV = tempV;
    }
    cout<< sum <<endl;
}

void solve_mul()
{ ll test; cin>>test; while (test--) {solutioN();} }

void solve_single(){solutioN();}

int main()
{
    ios_base::sync_with_stdio(false);
    solve_mul();
    //solve_single();
}






/*                                Ⓒ All rights reserved to Prnc                              */

Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
#include <algorithm>
#include <string>

using namespace std;
typedef long long ll;
 

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    ll sum=0,ans=0;
    for(int i=0;i<n;i++) {cin >> a[i];ans+=a[i];}
    while(a.size()>1){
    sum=0;
    if(a.back()<a.front())
     reverse(a.begin(),a.end());
    vector<ll> diff;
    for(int i=1;i<a.size();i++){
      diff.push_back(a[i]-a[i-1]);
      sum+=a[i]-a[i-1];
     }
     a=diff;
     ans=max(ans,sum);
            }
    cout << ans << "\n";
                }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t; 
    cin >> t;
    while(t--) solve();
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 343 ms):
#include<bits/stdc++.h>
using namespace std;
bool func(vector<int>& arr){
    auto func=[&](int i){
        int mini=min(arr[i],arr[i+1]);
        arr[i]-=mini;
        arr[i+1]-=mini;
    };
    for(int i=0;i<arr.size()-1;i++){
        func(i);
    }
    return is_sorted(arr.begin(),arr.end());
}
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> arr(n);
        for(int &i:arr){
            cin>>i;
        }
        if(func(arr)){
            cout<<"YES\n";
        }else{
            cout<<"NO\n";
        }
    }
}

Solution 2 (runtime: 140 ms):
#include <bits/stdc++.h>

#define int long long

#define endl '\n'

#define MAXN 200005

using namespace std;

int read()

{

	int fh=1;

	char ch;

	while((ch=getchar())<'0'||ch>'9')

		if(ch=='-')

			fh=-1;

	int res=ch-'0';

	while((ch=getchar())>='0'&&ch<='9')

		res=res*10+ch-'0';

	return res*fh;

}

int a[MAXN];

void solve()

{

	int n=read();

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

		a[i]=read();

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

	{

		if(a[i]>=a[i-1])

		{

			a[i]-=a[i-1],a[i-1]=0;

			continue;

		}

		break;

	}

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

	{

		if(a[i]>a[i+1])

		{

			cout << "NO" << endl;

			return;

		}

	}

	cout << "YES" << endl;

}

int T;

signed main()

{

	ios::sync_with_stdio(false);

	cin.tie(0);

	T=read();

	while(T--)

		solve();

	return 0;

}
Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 765 ms):
#include <bits/stdc++.h>
using namespace std;
#define F first
void solve(){
    int n,m; cin>>n>>m;
    vector < int > a(n),b(m);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<m;i++)cin>>b[i];
    map < int , int > mp1,mp2;
    for(int i=0;i<n;i++)mp1[a[i]]++;
    for(int i=0;i<m;i++)mp2[b[i]]++;
    int x = prev(mp2.end())->F;
    while(mp2.size()!=0 and mp1.size()!=0){
        if(mp1[x]>mp2[x]){
            // cout<<x<<"\n";
            cout<<"NO\n";
            return;
        }
        int y = min(mp1[x],mp2[x]);
        mp1[x]-=y; mp2[x]-=y;
        if(mp2[x]!=0){
            mp2[x/2]+=mp2[x];
            mp2[x-x/2]+=mp2[x];
        }
       
        mp1.erase(x); mp2.erase(x);
        if(mp2.size()!=0)x = prev(mp2.end())->F;
    }
    if((mp1.size()!=0)or(mp2.size()!=0)){
        cout<<"NO\n";
        return;
    }
    cout<<"YES\n";
}
int main(){
    int t; cin>>t;
    for(int i=0;i<t;i++){
        solve();
    }
}

Solution 2 (runtime: 390 ms):
#include <bits/stdc++.h>



using namespace std;

priority_queue<int> q;

map<int, int> M;



int main()

{   ios::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    int t, n, m, a, ok;

    cin>>t;



    while(t)

    {cin>>n>>m;

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

     {cin>>a;

      M[a]--;

     }



     for(int i=1;i<=m;i++)

     {cin>>a;

      M[a]++;

      if(M[a]==1)q.push(a);

     }



     ok=1;

     while(q.empty()!=1)

     {a=q.top();

      q.pop();



      if(a!=1 && M[a]>0)

      {int a1=a/2, b1=a/2;

       if(a%2==1)a1++;



       int v1=M[a1], v2=M[b1], v3=M[a];



       if(a1!=b1)

       {if(v1<=0 && v1+v3>0)q.push(a1);

        if(v2<=0 && v2+v3>0)q.push(b1);

       }

       else if(v1<=0 && v2+v3*2>0)q.push(a1);





       M[a1]+=v3, M[b1]+=v3;

       M[a]=0;

      }

     }



     map<int, int>:: iterator I;

     for(I=M.begin();I!=M.end() && ok;I++)

     if(I->second!=0)ok=0;

     M.clear();



     if(ok)cout<<"YES\n";

     else cout<<"NO\n";

     t--;

    }



    return 0;

}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 234 ms):
#include <bits/stdc++.h>
using namespace std;

int main() {
    int t, n, k;
    const int MAX_N = 100000;
    // count numbers
    cin >> t;
    for (int i = 0; i < t; ++i) {
        int key;
        map<int, int> mem{};
        cin >> n >> k;
        for (int i = 0; i < n; ++i) {
            cin >> key;
            ++mem[key];
        }
        vector<int> values{};
        transform(begin(mem), end(mem), back_inserter(values), [](auto elem) { return elem.second;});
        sort(begin(values), end(values), [](auto a, auto b){return a < b;});
        int answer = values.size();
        for (auto i: values) {
            if (i <= k) {
                k -= i;
                --answer;
            } else {
                break;
            }
        }
        if (answer == 0) {
            answer = 1;
        }
        cout << answer << endl;
    }
}

Solution 2 (runtime: 280 ms):
#include <bits/stdc++.h>
#define vi vector<int>
#define ll long long int
#define lb long double
#define vii vector<long long int>
#define vs vector<string>
#define f(i, vec) for (auto i : vec)
#define fr(i, n) for (int i = 0; i < n; i++)
#define frs(i,j,n) for(int i =j;i<n;i++)
#define srt(arr) sort(arr.begin(),arr.end())
using namespace std;

int mod(int a){
   if(a<0) return -1*a;
   return a;
}

bool cmp(pair<int,int>x,pair<int,int>y){
    return x.second<y.second;
}

void solve()
{  
   map<ll,ll>mp;
   vii freq;
   ll n,k;
   cin>>n>>k;
   fr(i,n) {
      ll t;
      cin>>t;
      mp[t]++;
   }

   f(i,mp){
     freq.push_back(i.second);
   }

   srt(freq);
   
   ll len = freq.size();
   fr(i,len-1){
      if(freq[i]>k) break;
      else if(freq[i]==k){
         freq[i] = 0;
         break;
      }
      else{
         k -= freq[i];
         freq[i] = 0;
      }
   }
   ll count = 0;
   f(i,freq) if(i!=0) count++;
   cout<<count<<"\n";
}
int main()
{

   int t;
   cin >> t;
   while (t--)
   {
      solve();
   }
//    solve();
}
Problem: 2060D - Subtract Min Sort
Language: c++17 

Solution 1 (runtime: 359 ms):
#include <bits/stdc++.h>

#define int long long 

using namespace std;

const int N = 2 * 1e5 + 10;

int n;
int a[N];
int t;

signed main() {
    cin >> t;
    while (t--) {
        cin >> n;
        for (int i = 1;i <= n;++i) {
            cin >> a[i];
        }
        for (int i = 2;i <= n;++i) {
            int t = min(a[i - 1],a[i]);
            a[i - 1] -= t;
            a[i] -= t;
        }
        bool flg = false;
        for (int i = 2;i <= n;++i) {
            if (a[i] < a[i - 1]) {
                cout << "NO\n";
                flg = true;
            }
            if (flg) break;
        }
        if (flg) continue;
        cout << "Yes\n";
    }
    return 0;
}

Solution 2 (runtime: 328 ms):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl
int main() {
    ll t;
    cin >> t;   
    while(t--) {
        ll n;
        cin>>n;
        vector<ll> v(n);
        for(ll i=0;i<n;i++){
            cin>>v[i];
        }
        ll d=v[0],f=0;
        for(int i=0;i<n-2;i++){
            d=v[i+1]-d;
            if(d<0) f++;
           if( (d)>v[i+2]) f++;
        }
        if(n==2&&v[1]<v[0] ) f++;
        if(f) cno;
        else cyes;
    }
    return 0;
}
Problem: 2050B - Transfusion
Language: c++17 

Solution 1 (runtime: 93 ms):
#include <iostream>

#include <fstream>

#include <algorithm>

using namespace std;



int main() {

#ifdef DEBUG_INPUT

    ifstream inFile("input.txt");

    if (!inFile) {

        cerr << "Failed to open input.txt" << endl;

        return 1;

    }

    cin.rdbuf(inFile.rdbuf());  // Redirect std::cin to read from input.txt

#endif

    int num_tests;

    cin>>num_tests;

    //collect each test

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

        int num_ints;

        cin>>num_ints;



        int sum_even = 0;

        int sum_odd =0;

        int n_even = 0;

        int n_odd = 0;

        for(int j = 0; j<num_ints; j++){

            int current_int;

            cin>>current_int;

            //check if we're on the odd index

            if(((j + 1) % 2) == 0){

                sum_even = sum_even + current_int;

                n_even++;

            }

            else{

                sum_odd = sum_odd + current_int;

                n_odd++;

            }

        }



        bool total_feas = ((sum_even + sum_odd) % (n_even + n_odd)) == 0;

        bool even_feas = (sum_odd % n_odd) == 0;

        bool odd_feas = (sum_even % n_even) == 0;



        if(total_feas && even_feas && odd_feas){

            cout<<"YES"<<endl;

        }

        else{

            cout<<"NO"<<endl;

        }

    }

    return 0;

}



Solution 2 (runtime: 109 ms):
#include<bits/stdc++.h>

#define ll          long long

#define ld 			long double

#define hell        1000000007

#define debug(x) cerr<<"DEBUG -> "<<#x<<" = "<<x<<"\n";

#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

using namespace std;



#define N 100005

const ll nax = 200005;



/*



sum % n != 0 -> NO







1 2 5 4

3 2 3 4

3 3 3 3





YES

NO

YES

NO

YES

NO

NO

NO

*/







void solve() {

    int n;

    cin>>n;

    long long odd = 0;

    long long even = 0;



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

        long long x;

        cin>>x;      

        if(i%2 == 1) odd += x;

        if(i%2 == 0) even += x;

    }



    long long total = odd + even;



    if(total % n != 0) {

        cout<<"no\n";

        return;

    }



    int req = total / n;

    if(n % 2 == 1) odd -= req;



    if(odd == even) cout<<"yes\n";

    else cout<<"no\n";

}



int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);

    #ifndef ONLINE_JUDGE

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

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

    #endif

    int t=1;

    cin>>t;

    while(t--) {

        solve();

    }

    time

    return 0;

}