ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


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

using namespace std;



void solve() {

    int n;

    cin >> n;

    int a[n + 1];

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

        cin >> a[i];

    }

    int x1 = a[1];

    int x2 = a[2];

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

        int x = min(x1, x2);

        x1 -= x;

        x2 -= x;

        x1 = x2;

        x2 = a[i + 1];

        if (x1 > x2) {

            cout << "no" << endl;

            return;

        }

    }

    cout << "yes" << endl;

}



int main() {

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

#define int long long



void solve() {

    int n;

    cin >> n;

    int a[n + 1];

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

        cin >> a[i];

    }

    int x1 = a[1];

    int x2 = a[2];

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

        int x = min(x1, x2);

        x1 -= x;

        x2 -= x;

        x1 = x2;

        x2 = a[i + 1];

        if (x1 > x2) {

            cout << "no" << endl;

            return;

        }

    }

    cout << "yes" << endl;

}



signed main() {

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

}







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

using namespace std;

#define int long long



void solve() {

    int n;

    cin >> n;

    int a[n + 1];

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

        cin >> a[i];

    }

    int x1 = a[1];

    int x2 = a[2];

    if(x1>x2) {

        cout << "no" << endl;

        return;

    }

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

        int x = min(x1, x2);

        x1 -= x;

        x2 -= x;

        x1 = x2;

        x2 = a[i + 1];

        if (x1 > x2) {

            cout << "no" << endl;

            return;

        }

    }

    cout << "yes" << endl;

}



signed main() {

    int t;

    cin >> t;

    while (t--) {

        solve();

    }

    return 0;

}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

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

//postmortem: break down: there's exactly one decomposition for each member of b. Put them into a stack and greedily break them down.
void solve(){
    int n, m;
    cin >> n >> m;

    int a;
    unordered_map<int, int> t;
    int nonzero_ct = 0;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(t[a]++ == 0)nonzero_ct++;
    }
    stack<int> st;
    for(int i = 0; i < m; i++){
        cin >> a;
        st.push(a);
    }

    while(!st.empty()){
        int b = st.top();
        st.pop();
        if(t[b] >= 1){
            t[b]--;
            if(t[b] == 0)nonzero_ct--;
        }
        else if(b != 1){
            st.push(b/2);
            st.push((b+1)/2);
        }else{
            cout << "NO" << endl;
            return;
        }
    }

    cout << (nonzero_ct == 0 ? "YES" : "NO") << endl;
}

int main(){
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;

    while(t--){
        solve();
    }

    return 0;
}

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

//postmortem: break down: there's exactly one decomposition for each member of b. Put them into a stack and greedily break them down.
void solve(){
    int n, m;
    cin >> n >> m;

    int a;
    map<int, int> t;
    int nonzero_ct = 0;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(t[a]++ == 0)nonzero_ct++;
    }
    stack<int> st;
    for(int i = 0; i < m; i++){
        cin >> a;
        st.push(a);
    }

    while(!st.empty()){
        int b = st.top();
        st.pop();
        if(t[b] >= 1){
            t[b]--;
            if(t[b] == 0)nonzero_ct--;
        }
        else if(b != 1){
            st.push(b/2);
            st.push((b+1)/2);
        }else{
            cout << "NO" << endl;
            return;
        }
    }

    cout << (nonzero_ct == 0 ? "YES" : "NO") << endl;
}

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

    while(t--){
        solve();
    }

    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)

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

//postmortem: break down: there's exactly one decomposition for each member of b. Put them into a stack and greedily break them down.
void solve(){
    int n, m;
    cin >> n >> m;

    int a;
    unordered_map<int, int> t;
    int nonzero_ct = 0;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(t[a]++ == 0)nonzero_ct++;
    }
    stack<int> st;
    for(int i = 0; i < m; i++){
        cin >> a;
        st.push(a);
    }

    while(!st.empty()){
        int b = st.top();
        st.pop();
        if(t[b] >= 1){
            t[b]--;
            if(t[b] == 0)nonzero_ct--;
        }
        else if(b != 1){
            st.push(b/2);
            st.push((b+1)/2);
        }else{
            cout << "NO" << endl;
            return;
        }
    }

    cout << (nonzero_ct == 0 ? "YES" : "NO") << endl;
}

int main(){
    //freopen("input.txt", "r", stdin);
    int t;
    cin >> t;

    while(t--){
        solve();
    }

    return 0;
}

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

//postmortem: break down: there's exactly one decomposition for each member of b. Put them into a stack and greedily break them down.
void solve(){
    int n, m;
    cin >> n >> m;

    int a;
    unordered_map<int, int> t;
    int nonzero_ct = 0;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(t[a]++ == 0)nonzero_ct++;
    }
    stack<int> st;
    for(int i = 0; i < m; i++){
        cin >> a;
        st.push(a);
    }

    while(!st.empty()){
        int b = st.top();
        st.pop();
        if(t[b] >= 1){
            t[b]--;
            if(t[b] == 0)nonzero_ct--;
        }
        else if(b != 1){
            st.push(b/2);
            st.push((b+1)/2);
        }else{
            cout << "NO" << endl;
            return;
        }
    }

    cout << (nonzero_ct == 0 ? "YES" : "NO") << endl;
}

int main(){
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;

    while(t--){
        solve();
    }

    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: C++17 (GCC 7-32)


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

//postmortem: break down: there's exactly one decomposition for each member of b. Put them into a stack and greedily break them down.
void solve(){
    int n, m;
    cin >> n >> m;

    int a;
    unordered_map<int, int> t;
    int nonzero_ct = 0;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(t[a]++ == 0)nonzero_ct++;
    }
    stack<int> st;
    for(int i = 0; i < m; i++){
        cin >> a;
        st.push(a);
    }

    while(!st.empty()){
        int b = st.top();
        st.pop();
        if(t[b] >= 1){
            t[b]--;
            if(t[b] == 0)nonzero_ct--;
        }
        else if(b != 1){
            st.push(b/2);
            st.push((b+1)/2);
        }else{
            cout << "NO" << endl;
            return;
        }
    }

    cout << (nonzero_ct == 0 ? "YES" : "NO") << endl;
}

int main(){
    //freopen("input.txt", "r", stdin);
    int t;
    cin >> t;

    while(t--){
        solve();
    }

    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


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

using namespace std;

int main () {
    int cases;
    cin >> cases;
    while(cases--) {
        map<int,vector<int>> connections;
        int nodes;
        cin >> nodes;
        for (int i = 0; i < nodes - 1; i++) {
            int a,b;
            cin >> a >> b;
            connections[a].push_back(b);
            connections[b].push_back(a);
        }
        int best = 1;
        int count = 0;
        for (auto i : connections) {
            if (i.second.size() > count) {
                best = i.first;
                count = 1;
            } else if (i.second.size() == connections[best].size()) {
                count++;
            }
        }
        if (nodes == 2) cout << 0 << endl;
        else if (nodes == 3) cout << 1 << endl;
        else if (count >= 3) cout << (connections[best].size() * 2) - 1;
        else {
            int res = connections[best].size();
            for (auto i : connections[best]) {
                connections[i].pop_back();
            }
            connections[best].clear();
            int second = 0;
            for (auto i : connections) {
                second = max(second, int(i.second.size()));
            }
            cout << res + second - 1 << endl;
        }
    }
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

int main () {
    int cases;
    cin >> cases;
    while(cases--) {
        map<int,vector<int>> connections;
        int nodes;
        cin >> nodes;
        for (int i = 0; i < nodes - 1; i++) {
            int a,b;
            cin >> a >> b;
            connections[a].push_back(b);
            connections[b].push_back(a);
        }
        int best = 1;
        int count = 0;
        for (auto i : connections) {
            if (i.second.size() > count) {
                best = i.first;
                count = 1;
            } else if (i.second.size() == connections[best].size()) {
                count++;
            }
        }
        if (nodes == 2) cout << 0 << endl;
        else if (nodes == 3) cout << 1 << endl;
        else if (count >= 3) cout << (connections[best].size() * 2) - 1;
        else {
            int res = connections[best].size();
            for (auto i : connections[best]) {
                connections[i].pop_back();
            }
            connections[best].clear();
            int second = 0;
            for (auto i : connections) {
                second = max(second, int(i.second.size()));
            }
            cout << res + second - 1 << endl;
        }
    }
    return 0;
}

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

int main () {
    int cases;
    cin >> cases;
    while(cases--) {
        map<int,vector<int>> connections;
        int nodes;
        cin >> nodes;
        for (int i = 0; i < nodes - 1; i++) {
            int a,b;
            cin >> a >> b;
            connections[a].push_back(b);
            connections[b].push_back(a);
        }
        int best = 1;
        int count = 0;
        for (auto i : connections) {
            if (i.second.size() > count) {
                best = i.first;
                count = 1;
            } else if (i.second.size() == connections[best].size()) {
                count++;
            }
        }
        if (nodes == 2) cout << 0 << endl;
        else if (nodes == 3) cout << 1 << endl;
        // else if (count >= 3) cout << (connections[best].size() * 2) - 1;
        else {
            int res = connections[best].size();
            for (auto i : connections[best]) {
                connections[i].pop_back();
            }
            connections[best].clear();
            int second = 0;
            for (auto i : connections) {
                second = max(second, int(i.second.size()));
            }
            cout << res + second - 1 << endl;
        }
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<map>
using namespace std;
int main() {
    int t;
    cin>>t;
    while(t-- > 0) {
        int n, k;
        cin>>n>>k;
        map<int, int> freq;
        for(int i = 0; i < n; i++) {
            int num;
            cin>>num;
            freq[num]++;
        }
        while (k > 0 && !freq.empty()) {
            auto it = freq.begin();
            if (k >= it -> second) {
                k -= it -> second;
                freq.erase(it);
            } else {break;}
        }
        cout<<freq.size()<<endl;
    }
    return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 1):
#include <iostream>
#include <map>
#include <set>
using namespace std;
int main() {
    int t;
    cin>>t;
    while(t-- > 0) {
        int n, k;
        cin>>n>>k;
        map<int, int> freq;
        for(int i = 0; i < n; i++) {
          int num;
          cin>>num;
          freq[num]++;
        }
        int distinct_count = freq.size();
        if(k >= n) {
            cout<<1<<endl;
            continue;
        }
        set<int> freq_values;
        for(auto &entry : freq) {freq_values.insert(entry.second);}
        while (k > 0 && distinct_count > 1) {
            auto it = freq_values.begin(); 
            if (*it <= k) {
                k -= *it;
                freq_values.erase(it);
                distinct_count--;
            } else {
                break;
            }
        }
        cout<<distinct_count<<endl;
    }
    return 0;
}

Submission (verdict: Accepted):
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void solve()
{
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  vector<int> cnt = {1};
  for (int i = 1; i < n; i++)
  {
    if (a[i] == a[i - 1])
    {
      cnt.back()++;
    }
    else
    {
      cnt.emplace_back(1);
    }
  }
  sort(cnt.begin(), cnt.end());
  int m = cnt.size();
  for (int i = 0; i < m - 1; i++)
  {
    if (cnt[i] > k)
    {
      cout << m - i << "\n";
      return;
    }
    k -= cnt[i];
  }
  cout << 1 << "\n";
}

int main()
{
  int t;
  cin >> t;
  while (t--)
  {
    solve();
  }
  return 0;
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include<iostream>
#include<map>
using namespace std;
int main() {
    int t;
    cin>>t;
    while(t-- > 0) {
        int n, k;
        cin>>n>>k;
        map<int, int> freq;
        for(int i = 0; i < n; i++) {
            int num;
            cin>>num;
            freq[num]++;
        }
        while (k > 0 && !freq.empty()) {
            auto it = freq.begin();
            if (k >= it -> second) {
                k -= it -> second;
                freq.erase(it);
            } else {break;}
        }
        cout<<freq.size()<<endl;
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 1):
#include <iostream>
#include <map>
#include <set>
using namespace std;
int main() {
    int t;
    cin>>t;
    while(t-- > 0) {
        int n, k;
        cin>>n>>k;
        map<int, int> freq;
        for(int i = 0; i < n; i++) {
          int num;
          cin>>num;
          freq[num]++;
        }
        int distinct_count = freq.size();
        if(k >= n) {
            cout<<1<<endl;
            continue;
        }
        set<int> freq_values;
        for(auto &entry : freq) {freq_values.insert(entry.second);}
        while (k > 0 && distinct_count > 1) {
            auto it = freq_values.begin(); 
            if (*it <= k) {
                k -= *it;
                freq_values.erase(it);
                distinct_count--;
            } else {
                break;
            }
        }
        cout<<distinct_count<<endl;
    }
    return 0;
}
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)


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

using namespace std;



int main(){

  int t;

  cin>>t;

  while(t--){

    int n;

    cin>>n;

    vector<int> vec(n);

    int sum = 0;

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

    {

       cin>>vec[i];

       sum += vec[i];

    }

    if(sum%n != 0){cout<<"NO"<<endl;continue;;}

    int sum0 = 0;

    int sum1 = 0;

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

    {

      sum0 += vec[i];

    }

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

    {

      sum1 += vec[i];

    }

    int u = n/2;

    int beta = sum/n;

    if(u%2 == 0){if(sum0/u == beta && sum1/u == beta){cout<<"YES"<<endl;}continue;}

    else if(u%2 != 0){if(sum0/(u+1) == beta && sum1/u == beta){cout<<"YES"<<endl;}continue;}

    else{cout<<"NO"<<endl;}

  }

  return 0 ;

}
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)

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

using namespace std;



int main(){

  int t;

  cin>>t;

  while(t--){

    int n;

    cin>>n;

    vector<int> vec(n);

    int sum = 0;

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

    {

       cin>>vec[i];

       sum += vec[i];

    }

    if(sum%n != 0){cout<<"NO"<<endl;continue;}

    int sum0 = 0;

    int sum1 = 0;

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

    {

      sum0 += vec[i];

    }

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

    {

      sum1 += vec[i];

    }

    int u = n/2;

    int beta = sum/n;

    if(n%2 == 0){if(sum0/u == beta && sum1/u == beta){cout<<"YES"<<endl;continue;}}

    else if(n%2 != 0){if(sum0/(u+1) == beta && sum1/u == beta){cout<<"YES"<<endl;continue;}}

    cout<<"NO"<<endl;

  }

  return 0 ;

}

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

using namespace std;



int main(){

  int t;

  cin>>t;

  while(t--){

    int n;

    cin>>n;

    vector<int> vec(n);

    long long sum = 0;

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

    {

       cin>>vec[i];

       sum += vec[i];

    }

    if(sum%n != 0){cout<<"NO"<<endl;continue;}

    long long sum0 = 0;

    long long sum1 = 0;

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

    {

      sum0 += vec[i];

    }

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

    {

      sum1 += vec[i];

    }

    int u = n/2;

    int beta = sum/n;

    if(n%2 == 0){if(sum0/u == beta && sum1/u == beta){cout<<"YES"<<endl;continue;}}

    else if(n%2 != 0){if(sum0/(u+1) == beta && sum1/u == beta){cout<<"YES"<<endl;continue;}}

    cout<<"NO"<<endl;

  }

  return 0 ;

}
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)

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

using namespace std;



int main(){

  int t;

  cin>>t;

  while(t--){

    int n;

    cin>>n;

    vector<int> vec(n);

    int sum = 0;

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

    {

       cin>>vec[i];

       sum += vec[i];

    }

    if(sum%n != 0){cout<<"NO"<<endl;continue;}

    int sum0 = 0;

    int sum1 = 0;

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

    {

      sum0 += vec[i];

    }

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

    {

      sum1 += vec[i];

    }

    int u = n/2;

    int beta = sum/n;

    if(n%2 == 0){if(sum0/u == beta && sum1/u == beta){cout<<"YES"<<endl;continue;}}

    else if(n%2 != 0){if(sum0/(u+1) == beta && sum1/u == beta){cout<<"YES"<<endl;continue;}}

    else{cout<<"NO"<<endl;}

  }

  return 0 ;

}

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

using namespace std;



int main(){

  int t;

  cin>>t;

  while(t--){

    int n;

    cin>>n;

    vector<int> vec(n);

    int sum = 0;

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

    {

       cin>>vec[i];

       sum += vec[i];

    }

    if(sum%n != 0){cout<<"NO"<<endl;continue;}

    int sum0 = 0;

    int sum1 = 0;

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

    {

      sum0 += vec[i];

    }

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

    {

      sum1 += vec[i];

    }

    int u = n/2;

    int beta = sum/n;

    if(n%2 == 0){if(sum0/u == beta && sum1/u == beta){cout<<"YES"<<endl;continue;}}

    else if(n%2 != 0){if(sum0/(u+1) == beta && sum1/u == beta){cout<<"YES"<<endl;continue;}}

    cout<<"NO"<<endl;

  }

  return 0 ;

}
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)

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

using namespace std;



int main(){

  int t;

  cin>>t;

  while(t--){

    int n;

    cin>>n;

    vector<int> vec(n);

    int sum = 0;

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

    {

       cin>>vec[i];

       sum += vec[i];

    }

    if(sum%n != 0){cout<<"NO"<<endl;continue;;}

    int sum0 = 0;

    int sum1 = 0;

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

    {

      sum0 += vec[i];

    }

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

    {

      sum1 += vec[i];

    }

    int u = n/2;

    int beta = sum/n;

    if(n%2 == 0){if(sum0/u == beta && sum1/u == beta){cout<<"YES"<<endl;}continue;}

    else if(n%2 != 0){if(sum0/(u+1) == beta && sum1/u == beta){cout<<"YES"<<endl;}continue;}

    else{cout<<"NO"<<endl;}

  }

  return 0 ;

}

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

using namespace std;



int main(){

  int t;

  cin>>t;

  while(t--){

    int n;

    cin>>n;

    vector<int> vec(n);

    int sum = 0;

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

    {

       cin>>vec[i];

       sum += vec[i];

    }

    if(sum%n != 0){cout<<"NO"<<endl;continue;}

    int sum0 = 0;

    int sum1 = 0;

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

    {

      sum0 += vec[i];

    }

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

    {

      sum1 += vec[i];

    }

    int u = n/2;

    int beta = sum/n;

    if(n%2 == 0){if(sum0/u == beta && sum1/u == beta){cout<<"YES"<<endl;continue;}}

    else if(n%2 != 0){if(sum0/(u+1) == beta && sum1/u == beta){cout<<"YES"<<endl;continue;}}

    else{cout<<"NO"<<endl;}

  }

  return 0 ;

}
Problem: 2050B - Transfusion
Language: C++17 (GCC 7-32)

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

using namespace std;



int main(){

  int t;

  cin>>t;

  while(t--){

    int n;

    cin>>n;

    vector<int> vec(n);

    int sum = 0;

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

    {

       cin>>vec[i];

       sum += vec[i];

    }

    if(sum%n != 0){cout<<"NO"<<endl;continue;;}

    int sum0 = 0;

    int sum1 = 0;

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

    {

      sum0 += vec[i];

    }

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

    {

      sum1 += vec[i];

    }

    int u = n/2;

    int beta = sum/n;

    if(u%2 == 0){if(sum0/u == beta && sum1/u == beta){cout<<"YES"<<endl;}continue;}

    else if(u%2 != 0){if(sum0/(u+1) == beta && sum1/u == beta){cout<<"YES"<<endl;}continue;}

    else{cout<<"NO"<<endl;}

  }

  return 0 ;

}

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

using namespace std;



int main(){

  int t;

  cin>>t;

  while(t--){

    int n;

    cin>>n;

    vector<int> vec(n);

    int sum = 0;

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

    {

       cin>>vec[i];

       sum += vec[i];

    }

    if(sum%n != 0){cout<<"NO"<<endl;continue;;}

    int sum0 = 0;

    int sum1 = 0;

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

    {

      sum0 += vec[i];

    }

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

    {

      sum1 += vec[i];

    }

    int u = n/2;

    int beta = sum/n;

    if(n%2 == 0){if(sum0/u == beta && sum1/u == beta){cout<<"YES"<<endl;}continue;}

    else if(n%2 != 0){if(sum0/(u+1) == beta && sum1/u == beta){cout<<"YES"<<endl;}continue;}

    else{cout<<"NO"<<endl;}

  }

  return 0 ;

}