ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

#include <sstream>

#include <queue>

#include <deque>

#include <bitset>

#include <iterator>

#include <list>

#include <stack>

#include <map>

#include <set>

#include <functional>

#include <numeric>

#include <utility>

#include <limits>

#include <time.h>

#include <math.h>

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <assert.h>

using namespace std;



typedef long long ll;

typedef pair<ll,ll> pll;

typedef vector<ll> vll;

typedef vector<bool> vb;

typedef vector<pair<ll,ll>> vpll;

typedef vector<vector<ll>> vvll;



#define fi first

#define se second

#define pb push_back

#define mod 1000000007



#define f(i,s,e) for( ll i=s; i<e; i++)

#define fa(i,a) for( auto i: a)

#define fe(i,s,e) for( ll i=s; i<=e; i++)

#define fr(i,e,s) for( ll i=e; i>=s; i--)

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

#define rall(a) a.rbegin(), a.rend()



#define get(a) cin >> a

#define get2(a,b) cin >> a >> b

#define get3(a,b,c) cin >> a >> b >> c



#define pnl cout << "\n"

#define print(a) cout << a << " "

#define print2(a,b) cout << a << " " << b << " "

#define print3(a,b,c) cout << a << " " << b << " " << c << " "



ll vmax(vll a) { ll mx=a[0]; fa(i,a) mx=max( i, mx); return mx; }

ll vmin(vll a) { ll mi=a[0]; fa(i,a) mi=min( i, mi); return mi; }

ll vsum(vll a) { ll sm=0; fa(i,a) sm+=i; return sm; }



ll add( ll x, ll y) { ll res=x+y; return ( res>mod ? res-mod:res ); }

ll mult( ll x, ll y) { ll res=x*y; return ( res>mod ? res%mod:res ); }

ll sub( ll x, ll y) { ll res=x-y; return ( res<0 ? res+mod:res ); }

ll pow( ll x, ll y) { ll res=1; x%=mod; while(y){ if(y&1) res=mult(res,x); y>>=1; x=mult(x,x);} return res; }



void getv(vll &a) { f(i,0,a.size()) get(a[i]); }

void getvp(vpll &a) { f(i,0,a.size()) get(a[i].fi), get(a[i].se); }

void getvv(vvll &a) { f(i,0,a.size()) f(j,0,a[0].size()) get(a[i][j]); }

void printv(vll a) { fa(i,a) print(i); pnl; }

void printvp(vpll a) { fa(i,a) print2(i.fi, i.se), pnl; }

void printvv(vvll a) { fa(i,a) { fa(j,i) print(j); pnl; }}



void yes() { print("YES"); }

void no() { print("NO"); }



void solve() {

	ll n, l, r; 

    get3( n, l, r);



    vll a(n);

    getv(a);



    vll s1=a, s2=a;

    sort( s1.begin(), s1.begin()+r);

    sort( s2.begin()+l-1, s2.end());



    ll ans1=0, ans2=0;

    for( ll i=0; i<r-l+1; i++) 

        ans1+=s1[i], ans2+=s2[i];



    print(min(ans1, ans2)); pnl;

}



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0); cout.tie(0);



    ll t; get(t);

    while(t--) 

		solve();



    return 0;

}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <algorithm>
#include<bits/stdc++.h>
#include <climits>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <string>
#include <unordered_map>
#define nl "\n"
#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

void dfs(vector<set<int>> &adj_list, vector<bool> &vis, int u)
{
    vis[u]=1;
    for(auto v: adj_list[u])
    {
        if(!vis[v]) dfs(adj_list, vis, v);
    }
}

void solve()
{
    int t=1;
    cin>>t;
    while(t--)
    {
        int n; cin>>n;
        vector<set<int>> adj_list(n);
        for(int i=0;i<n-1;i++)
        {
            int u, v; cin>>u>>v;
            adj_list[u-1].insert(v-1);
            adj_list[v-1].insert(u-1);
        }

        int mu, m2u;
        int m=0;
        for(int i=0;i<n;i++)
        {
            if(adj_list[i].size()>m)
            {
                m=adj_list[i].size();
                mu=i;
            }
        }
        m=0;
        for(int i=0;i<n;i++)
        {
            if(adj_list[i].size()>m && i!=mu)
            {
                m=adj_list[i].size();
                m2u=i;
            }
        }

        for(int i=0;i<n;i++)
        {
            if(i!=mu && i!=m2u)
            {
                if(adj_list[i].count(mu)) adj_list[i].erase(mu);
                if(adj_list[i].count(m2u)) adj_list[i].erase(m2u);
            }
        }

        vector<bool> vis(n, 0);
        vis[mu]=1, vis[m2u]=1;
        int result=0;
        for(int i=0;i<n;i++)
        {
            if(!vis[i])
            {
                result++;
                dfs(adj_list, vis, i);
            }
        }
        cout<<result<<nl;

    }
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    solve();
    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define E 1e-9
#define PI 3.141592653589793238462
#define PB push_back
#define F find
#define S second
#define EB emplace_back
#define MP make_pair
#define INF 1e18
#define MOD 1000000007
#define SZ(a) int((a).size())
#define setbits(a) (__builtin_popcountll(a))
#define right(a) (__builtin_ctzll(a))
#define left(a) (__builtin_clzll(a))
#define parity(a) (__builtin_parityll(a))
#define msb(a) (__lg(a))
#define lsb(a) ((ll)(log2(a & -a)))
typedef std::numeric_limits<double> dbl;
typedef long long ll;
#define REP(i, a, b) for (ll i = a; i < b; i++)
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;

ll power(ll a, ll n)
{
    ll ans = 1ll;
    while (n > 0)
    {
        int last_bit = (n & 1ll);
        if (last_bit)
        {
            ans = ans * a;
        }
        a = a * a;
        n = n >> 1ll;
    }
    return ans;
}

class DSU
{
private:
    vector<ll> Parent, Rank;

public:
    DSU(int n)
    {
        Parent.resize(n);
        Rank.resize(n, 0);
        for (int i = 0; i < n; i++)
        {
            Parent[i] = i;
            Rank[i] = 1;
        }
    }

    void Init(ll n)
    {
        REP(i, 0, n)
        {
            Parent[i] = i;
            Rank[i] = 1;
        }
    }

    ll Root(ll x)
    {
        if (Parent[x] != x)
            Parent[x] = Root(Parent[x]);
        return Parent[x];
    }

    void Union(ll x, ll y)
    {
        ll rx = Root(x), ry = Root(y);
        if (rx == ry)
            return;
        if (Rank[rx] > Rank[ry])
        {
            Parent[ry] = rx;
            Rank[rx] += Rank[ry];
        }
        else
        {
            Parent[rx] = ry;
            Rank[ry] += Rank[rx];
        }
    }

    ll getRank(ll x)
    {
        return this->Rank[x];
    }
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin >> t;
    while (t--)
    {
        ll l, r;
        cin >> l >> r;
        ll x = 0ll, flag = 0ll;
        for (ll i = msb(r); i >= 0; i--)
        {
            if ((l & (1ll << i)) && (r & (1ll << i)))
            {
                if (!flag)
                    x += (1ll << i);
            }
            else if ((r & (1ll << i)))
            {
                if (!flag)
                {
                    x += (1ll << i);
                    flag = 1ll;
                }
            }
            else if(!(l & (1ll << i)))
            {
                if (flag)
                    x += (1ll << i);
            }
        }
        cout << l << " " << x << " " << r << '\n';
    }
    return 0;
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
 
using i64 = long long;
 
void solve() {
    int l, r;
    std::cin >> l >> r;
    int k = 31 - __builtin_clz(l ^ r);
    int a = l | ((1 << k) - 1), b = a + 1, c = (a == l ? r : l);
    std::cout << a << " " << b << " " << c << "\n";
}
 
signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
 
    int t = 1;
    std::cin >> t;
 
    while (t--) {
        solve();
    }
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define E 1e-9
#define PI 3.141592653589793238462
#define PB push_back
#define F find
#define S second
#define EB emplace_back
#define MP make_pair
#define INF 1e18
#define MOD 1000000007
#define SZ(a) int((a).size())
#define setbits(a) (__builtin_popcountll(a))
#define right(a) (__builtin_ctzll(a))
#define left(a) (__builtin_clzll(a))
#define parity(a) (__builtin_parityll(a))
#define msb(a) (__lg(a))
#define lsb(a) ((ll)(log2(a & -a)))
typedef std::numeric_limits<double> dbl;
typedef long long ll;
#define REP(i, a, b) for (ll i = a; i < b; i++)
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;

ll power(ll a, ll n)
{
    ll ans = 1ll;
    while (n > 0)
    {
        int last_bit = (n & 1ll);
        if (last_bit)
        {
            ans = ans * a;
        }
        a = a * a;
        n = n >> 1ll;
    }
    return ans;
}

class DSU
{
private:
    vector<ll> Parent, Rank;

public:
    DSU(int n)
    {
        Parent.resize(n);
        Rank.resize(n, 0);
        for (int i = 0; i < n; i++)
        {
            Parent[i] = i;
            Rank[i] = 1;
        }
    }

    void Init(ll n)
    {
        REP(i, 0, n)
        {
            Parent[i] = i;
            Rank[i] = 1;
        }
    }

    ll Root(ll x)
    {
        if (Parent[x] != x)
            Parent[x] = Root(Parent[x]);
        return Parent[x];
    }

    void Union(ll x, ll y)
    {
        ll rx = Root(x), ry = Root(y);
        if (rx == ry)
            return;
        if (Rank[rx] > Rank[ry])
        {
            Parent[ry] = rx;
            Rank[rx] += Rank[ry];
        }
        else
        {
            Parent[rx] = ry;
            Rank[ry] += Rank[rx];
        }
    }

    ll getRank(ll x)
    {
        return this->Rank[x];
    }
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin >> t;
    while (t--)
    {
        ll l, r;
        cin >> l >> r;
        ll x = 0ll, flag = 0ll;
        for (ll i = msb(r); i >= 0; i--)
        {
            if ((l & (1ll << i)) && (r & (1ll << i)))
            {
                if (!flag)
                    x += (1ll << i);
            }
            else if ((l & (1ll << i)) || (r & (1ll << i)))
            {
                if (flag)
                    x += (1ll << i);
                else
                    flag = 1ll;
            }
            else
            {
                if (flag)
                    x += (1ll << i);
            }
        }
        cout << l << " " << x << " " << r << '\n';
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 4):
import sys


def readline(type):
    return list(map(type, sys.stdin.readline().split(' ')))


def add_ans(a, b, ans, check):
    if check[a - 1][b - 1] != 0:
        return

    ans.append((a, b))
    check[a - 1][b - 1] = 1

# 1 2 3
# 2 3 1

def main():
    n, = readline(int)
    order = readline(int)

    ans = []
    check = [0] * n

    for i in range(n):
        check[i] = [0]*n

    for i in range(n -1, -1, -1):
        for prev_i in range(n - 1, i, -1):
            a, b = order[i], order[prev_i]
            if a > b:
                add_ans(a, b, ans, check)
                continue

            add_ans(a, b, ans, check)
            add_ans(b, a, ans, check)

    print(len(ans))
    for a, b in reversed(ans):
        print(a, b, sep=' ')




if __name__ == '__main__':
    main()


Submission (verdict: Wrong answer on test 4):
import sys


def readline(type):
    return list(map(type, sys.stdin.readline().split(' ')))


def add_ans(a, b, ans, check):
    if check[a - 1][b - 1] != 0:
        return

    ans.append((a, b))
    check[a - 1][b - 1] = 1

# 1 2 3 4
# 1 2 3 4


def apply_stacked(stacked, ans, check):
    for a, b in reversed(stacked):
        add_ans(b, a, ans, check)

def main():
    n, = readline(int)
    order = readline(int)

    ans = []
    check = [0] * n

    for i in range(n):
        check[i] = [0]*n
# 2 1 3 4
    for i in range(n - 1, -1, -1):
        stacked = []
        for prev_i in range(n - 1, i, -1):
            a, b = order[i], order[prev_i]
            if a > b:
                apply_stacked(stacked, ans, check)
                add_ans(a, b, ans, check)
                continue

            add_ans(a, b, ans, check)
            stacked.append((a, b))

        apply_stacked(stacked, ans, check)
    print(len(ans))
    for a, b in reversed(ans):
        print(a, b, sep=' ')




if __name__ == '__main__':
    main()
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 4):
import sys


def readline(type):
    return list(map(type, sys.stdin.readline().split(' ')))


def add_ans(a, b, ans, check):
    if check[a - 1][b - 1] != 0:
        return

    ans.append((a, b))
    check[a - 1][b - 1] = 1

# 1 2 3 4
# 1 2 3 4


def apply_stacked(stacked, ans, check):
    for a, b in reversed(stacked):
        add_ans(b, a, ans, check)

def main():
    n, = readline(int)
    order = readline(int)

    ans = []
    check = [0] * n

    for i in range(n):
        check[i] = [0]*n
# 2 1 3 4
    for i in range(n - 1, -1, -1):
        stacked = []
        for prev_i in range(n - 1, i, -1):
            a, b = order[i], order[prev_i]
            if a > b:
                apply_stacked(stacked, ans, check)
                add_ans(a, b, ans, check)
                continue

            add_ans(a, b, ans, check)
            stacked.append((a, b))

        apply_stacked(stacked, ans, check)
    print(len(ans))
    for a, b in reversed(ans):
        print(a, b, sep=' ')




if __name__ == '__main__':
    main()


Submission (verdict: Wrong answer on test 7):
import sys


def readline(type):
    return list(map(type, sys.stdin.readline().split(' ')))


def add_ans(a, b, ans, check):
    if check[a - 1][b - 1] != 0:
        return

    ans.append((a, b))
    check[a - 1][b - 1] = 1

# 1 2 3 4
# 1 2 3 4


def apply_stacked(stacked, ans, check):
    for a, b in reversed(stacked):
        add_ans(b, a, ans, check)


def useless_swaps(i_a, i_b, order, ans, check):
    if i_a == i_b:
        return

    for i in range(i_a, i_b):
        first = []
        last = []

        for next_i in range(i + 1, i_b + 1):
            a = order[i]
            b = order[next_i]

            if (
                check[a - 1][b - 1] + check[b - 1][a - 1] == 0
            ):
                first.append((a, b))
                last.append((a, b))
            else:
                break

        for a, b in first:
            ans.append((a, b))
            check[a - 1][b - 1] = 1
        for b, a in reversed(last):
            ans.append((a, b))
            check[a - 1][b - 1] = 1


def main():
    n, = readline(int)
    order = readline(int)

    check = [[0] * n for _ in range(n)]
    ans = []

    flag = True

    while (flag):
        i_a = 0
        i_b = 0
        flag = False

        for i in range(1, n):
            a = order[i - 1]
            b = order[i]

            if a < b:
                i_b = i
            else:
                useless_swaps(i_a, i_b, order, ans, check)
                flag = True
                order[i - 1] = b
                order[i] = a
                ans.append((a, b))
                check[a - 1][b - 1] = 1
                break
        if not flag:
            useless_swaps(i_a, i_b, order, ans, check)

    print(len(ans))
    for a, b in reversed(ans):
        print(a, b, sep=' ')

if __name__ == '__main__':
    main()
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 4):
import sys


def readline(type):
    return list(map(type, sys.stdin.readline().split(' ')))


def add_ans(a, b, ans, check):
    if check[a - 1][b - 1] != 0:
        return

    ans.append((a, b))
    check[a - 1][b - 1] = 1

# 1 2 3
# 2 3 1

def main():
    n, = readline(int)
    order = readline(int)

    ans = []
    check = [0] * n

    for i in range(n):
        check[i] = [0]*n

    for i in range(n -1, -1, -1):
        for prev_i in range(n - 1, i, -1):
            a, b = order[i], order[prev_i]
            if a > b:
                add_ans(a, b, ans, check)
                continue

            add_ans(a, b, ans, check)
            add_ans(b, a, ans, check)

    print(len(ans))
    for a, b in reversed(ans):
        print(a, b, sep=' ')




if __name__ == '__main__':
    main()
Problem: 2050B - Transfusion
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vpll = vector<pair<long long, long long>>;
using vpii = vector<pair<int, int>>;
using vvll = vector<vector<long long>>;
using vbl = vector<bool>;
using pll = pair<ll, ll>;

#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define F                first
#define S                second 
#define pb               push_back
#define endl             '\n'
//------------------------------------
int ar[100100];
void solve(){
    int n;
    cin>>n;
    int sum = 0;
    int sum1 = 0;
    int ct1 = 0;
    int ct2 = 0;
    int sum2 = 0;
    for(int i = 0;i<n;i++){
        cin>>ar[i];
        if(i%2==0){
            sum1+=ar[i];
            ct1++;
        }
        else{
            sum2+=ar[i];
            ct2++;
        }
        sum+=ar[i];
    }
    if(sum%n!=0){
        cout<<"NO"<<endl;
    }
    else{
        if(sum1%ct1==0&&sum2%ct2==0&&sum1/ct1==sum/n&&sum2/ct2==sum/n){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }



    }







}




int main(){
    speed;
    int T;
    cin>>T;
    while(T--){
        solve();
    }
    
    return 0;
}
Problem: 2050B - Transfusion
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vpll = vector<pair<long long, long long>>;
using vpii = vector<pair<int, int>>;
using vvll = vector<vector<long long>>;
using vbl = vector<bool>;
using pll = pair<ll, ll>;

#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define F                first
#define S                second 
#define pb               push_back
#define endl             '\n'
//------------------------------------
int ar[100100];
void solve(){
    int n;
    cin>>n;
    int sum = 0;
    int sum1 = 0;
    int ct1 = 0;
    int ct2 = 0;
    int sum2 = 0;
    for(int i = 0;i<n;i++){
        cin>>ar[i];
        if(i%2==0){
            sum1+=ar[i];
            ct1++;
        }
        else{
            sum2+=ar[i];
            ct2++;
        }
        sum+=ar[i];
    }
    if(sum%n!=0){
        cout<<"NO"<<endl;
    }
    else{
        if(sum1%ct1==0&&sum2%ct2==0&&sum1/ct1==sum/n&&sum2/ct2==sum/n){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }



    }







}




int main(){
    speed;
    int T;
    cin>>T;
    while(T--){
        solve();
    }
    
    return 0;
}

Submission (verdict: Runtime error on test 4):
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vpll = vector<pair<long long, long long>>;
using vpii = vector<pair<int, int>>;
using vvll = vector<vector<long long>>;
using vbl = vector<bool>;
using pll = pair<ll, ll>;

#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define F                first
#define S                second 
#define pb               push_back
#define endl             '\n'
//------------------------------------
int ar[100100];
void solve(){
    int n;
    cin>>n;
    ll sum = 0;
    ll sum1 = 0;
    int ct1 = 0;
    int ct2 = 0;
    ll sum2 = 0;
    for(int i = 0;i<n;i++){
        cin>>ar[i];
        if(i%2==0){
            sum1+=ar[i];
            ct1++;
        }
        else{
            sum2+=ar[i];
            ct2++;
        }
        sum+=ar[i];
    }
    if(sum%n!=0){
        cout<<"NO"<<endl;
    }
    else{
        if(sum1%ct1==0&&sum2%ct2==0&&sum1/ct1==sum/n&&sum2/ct2==sum/n){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }



    }







}




int main(){
    speed;
    int T;
    cin>>T;
    while(T--){
        solve();
    }
    
    return 0;
}
Problem: 2050B - Transfusion
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Runtime error on test 4):
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vpll = vector<pair<long long, long long>>;
using vpii = vector<pair<int, int>>;
using vvll = vector<vector<long long>>;
using vbl = vector<bool>;
using pll = pair<ll, ll>;

#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define F                first
#define S                second 
#define pb               push_back
#define endl             '\n'
//------------------------------------
int ar[100100];
void solve(){
    int n;
    cin>>n;
    ll sum = 0;
    ll sum1 = 0;
    int ct1 = 0;
    int ct2 = 0;
    ll sum2 = 0;
    for(int i = 0;i<n;i++){
        cin>>ar[i];
        if(i%2==0){
            sum1+=ar[i];
            ct1++;
        }
        else{
            sum2+=ar[i];
            ct2++;
        }
        sum+=ar[i];
    }
    if(sum%n!=0){
        cout<<"NO"<<endl;
    }
    else{
        if(sum1%ct1==0&&sum2%ct2==0&&sum1/ct1==sum/n&&sum2/ct2==sum/n){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }



    }







}




int main(){
    speed;
    int T;
    cin>>T;
    while(T--){
        solve();
    }
    
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vpll = vector<pair<long long, long long>>;
using vpii = vector<pair<int, int>>;
using vvll = vector<vector<long long>>;
using vbl = vector<bool>;
using pll = pair<ll, ll>;

#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define F                first
#define S                second 
#define pb               push_back
#define endl             '\n'
//------------------------------------
int ar[1001000];
void solve(){
    int n;
    cin>>n;
    ll sum = 0;
    ll sum1 = 0;
    int ct1 = 0;
    int ct2 = 0;
    ll sum2 = 0;
    for(int i = 0;i<n;i++){
        cin>>ar[i];
        if(i%2==0){
            sum1+=ar[i];
            ct1++;
        }
        else{
            sum2+=ar[i];
            ct2++;
        }
        sum+=ar[i];
    }
    if(sum%n!=0){
        cout<<"NO"<<endl;
    }
    else{
        if(sum1%ct1==0&&sum2%ct2==0&&sum1/ct1==sum/n&&sum2/ct2==sum/n){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }



    }







}




int main(){
    speed;
    int T;
    cin>>T;
    while(T--){
        solve();
    }
    
    return 0;
}