ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

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

using namespace std;
using ll = long long;

// https://codeforces.com/blog/entry/62393
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

void solve() {
	int n;
	cin >> n;
	vector<vector<int>> adjList(n);
	vector<int> deg(n);
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		adjList[u].push_back(v);
		adjList[v].push_back(u);
		deg[u]++;
		deg[v]++;
	}
	vector<int> p(n);
	iota(p.begin(), p.end(), 0);
	sort(p.begin(), p.end(), [&](int i, int j) { return deg[i] > deg[j]; });
	int first = p[0], firstCnt = deg[p[0]];
	multiset<int> s;
	for (int x : adjList[first]) {
		deg[x]--;
	}
	for (int i = 0; i < n; i++) {
		if (i != first) {
			s.insert(deg[i]);
		}
	}
	int secondCnt = *s.rbegin();
	cout << firstCnt + secondCnt - 1 << endl;
}

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



Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

// https://codeforces.com/blog/entry/62393
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

void solve() {
	int n;
	cin >> n;
	vector<vector<int>> adjList(n);
	vector<int> deg(n);
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		adjList[u].push_back(v);
		adjList[v].push_back(u);
		deg[u]++;
		deg[v]++;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		vector<int> cnt(deg);
		for (int x : adjList[i]) {
			cnt[x]--;
		}
		int can = cnt[i];
		cnt[i] = 0;
		can += *max_element(cnt.begin(), cnt.end());
		ans = max(ans, can);
	}
	cout << ans - 1 << endl;
}

int main() {
	ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tt;
	cin >> tt;
	while (tt--) {
		solve();
	}
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t, n, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    unordered_map<int, int> nums;
    int num;
    for (int i = 0; i < n; ++i) {
      cin >> num;
      ++nums[num];
    }
    if (k > n - 1) {
      cout << 1 << endl;
      continue;
    }
    vector<vector<int>> data(nums.size());
    int index = 0;
    for (auto &[k, v]: nums) {
      data[index++] = {v, k};
    }
    sort(data.begin(), data.end());
    int ans = data.size();
    for (int i = 0; i < data.size(); ++i) {
      if (k < 1) break;
      int sub = min(data[i][0], k);
      data[i][0] -= sub;
      if (data[i][0] == 0) {
	--ans;
	k -= sub;
      } else {
	break;
      }
    }
    cout << max(ans, 1) << endl;
  }
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t, n, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    vector<int> nums(n);
    for (int &i: nums) {
      cin >> i;
    }
    if (k > n - 1) {
      cout << 1 << endl;
      continue;
    }
    sort(nums.begin(), nums.end());
    vector<int> cnt{1};
    int ans = 0;
    for (int i = 1; i < n; ++i) {
      if (nums[i] == nums[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) {
	ans = m - i;
	break;
      }
      k -= cnt[i];
    }
    cout << max(ans, 1) << endl;
  }
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t, n, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    unordered_map<int, int> nums;
    int num;
    for (int i = 0; i < n; ++i) {
      cin >> num;
      ++nums[num];
    }
    if (k > n - 1) {
      cout << 1 << endl;
      continue;
    }
    vector<vector<int>> data;
    for (auto &[k, v]: nums) {
      data.push_back({v, k});
    }
    sort(data.begin(), data.end());
    int ans = data.size();
    for (int i = 0; i < data.size(); ++i) {
      if (k < 1) break;
      int sub = min(data[i][0], k);
      data[i][0] -= sub;
      if (data[i][0] == 0) {
	--ans;
	k -= sub;
      } else {
	break;
      }
    }
    cout << max(ans, 1) << endl;
  }
}


Submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t, n, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    unordered_map<int, int> nums;
    int num;
    for (int i = 0; i < n; ++i) {
      cin >> num;
      ++nums[num];
    }
    if (k > n - 1) {
      cout << 1 << endl;
      continue;
    }
    vector<vector<int>> data(nums.size());
    int index = 0;
    for (auto &[k, v]: nums) {
      data[index++] = {v, k};
    }
    sort(data.begin(), data.end());
    int ans = data.size();
    for (int i = 0; i < data.size(); ++i) {
      if (k < 1) break;
      int sub = min(data[i][0], k);
      data[i][0] -= sub;
      if (data[i][0] == 0) {
	--ans;
	k -= sub;
      } else {
	break;
      }
    }
    cout << max(ans, 1) << endl;
  }
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>

using namespace std;

int main() {
  int t, n, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    unordered_map<int, int> nums;
    int num;
    for (int i = 0; i < n; ++i) {
      cin >> num;
      ++nums[num];
    }
    if (k > n - 1) {
      cout << 1 << endl;
      continue;
    }
    vector<vector<int>> data;
    for (auto &[k, v]: nums) {
      data.push_back({v, k});
    }
    sort(data.begin(), data.end());
    int ans = data.size();
    for (int i = 0; i < data.size(); ++i) {
      if (k < 1) break;
      int sub = min(data[i][0], k);
      data[i][0] -= sub;
      if (data[i][0] == 0) {
	--ans;
	k -= sub;
      } else {
	break;
      }
    }
    cout << max(ans, 1) << endl;
  }
}


Submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t, n, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    unordered_map<int, int> nums;
    int num;
    for (int i = 0; i < n; ++i) {
      cin >> num;
      ++nums[num];
    }
    if (k > n - 1) {
      cout << 1 << endl;
      continue;
    }
    vector<vector<int>> data;
    for (auto &[k, v]: nums) {
      data.push_back({v, k});
    }
    sort(data.begin(), data.end());
    int ans = data.size();
    for (int i = 0; i < data.size(); ++i) {
      if (k < 1) break;
      int sub = min(data[i][0], k);
      data[i][0] -= sub;
      if (data[i][0] == 0) {
	--ans;
	k -= sub;
      } else {
	break;
      }
    }
    cout << max(ans, 1) << endl;
  }
}
Problem: 2057B - Gorilla and the Exam
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Time limit exceeded on test 11):
#include <bits/stdc++.h>

using namespace std;

int main() {
  int t, n, k;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    unordered_map<int, int> nums;
    int num;
    for (int i = 0; i < n; ++i) {
      cin >> num;
      ++nums[num];
    }
    if (k > n - 1) {
      cout << 1 << endl;
      continue;
    }
    vector<vector<int>> data;
    for (auto &[k, v]: nums) {
      data.push_back({v, k});
    }
    sort(data.begin(), data.end());
    int ans = data.size();
    for (int i = 0; i < data.size(); ++i) {
      if (k < 1) break;
      int sub = min(data[i][0], k);
      data[i][0] -= sub;
      if (data[i][0] == 0) {
	--ans;
	k -= sub;
      } else {
	break;
      }
    }
    cout << max(ans, 1) << endl;
  }
}
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
#define MAXN 1010
#define nt long long 
int a[MAXN],cnt = 0;
int ans[MAXN][2];
int p=1;

void solve(){
    int n;
    std::cin>>n;
    for(int i=1;i<=n;i++)std::cin>>a[i];
    for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++){
            if(a[i]>a[j]){
                ans[p][0]=a[i];
                ans[p][1]=a[j];
                p++;
                cnt++;
            }
        }
    for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++){
            if(a[i]<a[j]){
                ans[p][0]=a[j];
                ans[p][1]=a[i];
                p++;
                ans[p][0]=a[i];
                ans[p][1]=a[j];
                p++;
                cnt+=2;
            }
        }
    std::cout<<cnt<<std::endl;
    for(int i=1;i<p;i++){
        std::cout<<ans[i][0]<<" "<<ans[i][1]<<std::endl;
    }
}

signed main(){
    std::cin.tie(0)->std::ios::sync_with_stdio(false);
    solve();
    return 0;
}

Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
#define MAXN 1010
#define int long long 
int a[MAXN],cnt = 0;
int ans[MAXN][2];
int p=1;

void solve(){
    int n;
    std::cin>>n;
    for(int i=1;i<=n;i++)std::cin>>a[i];
    for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++){
            if(a[i]>a[j]){
                ans[p][0]=a[i];
                ans[p][1]=a[j];
                p++;
                cnt++;
            }
        }
    for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++){
            if(a[i]<a[j]){
                ans[p][0]=a[j];
                ans[p][1]=a[i];
                p++;
                ans[p][0]=a[i];
                ans[p][1]=a[j];
                p++;
                cnt+=2;
            }
        }
    std::cout<<cnt<<std::endl;
    for(int i=1;i<p;i++){
        std::cout<<ans[i][0]<<" "<<ans[i][1]<<std::endl;
    }
}

signed main(){
    std::cin.tie(0)->std::ios::sync_with_stdio(false);
    solve();
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
#define MAXN 1010
#define nt long long 
int a[MAXN],cnt = 0;
int ans[MAXN][2];
int p=1;

void solve(){
    int n;
    std::cin>>n;
    for(int i=1;i<=n;i++)std::cin>>a[i];
    for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++){
            if(a[i]>a[j]){
                ans[p][0]=a[i];
                ans[p][1]=a[j];
                p++;
                cnt++;
            }
        }
    for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++){
            if(a[i]<a[j]){
                ans[p][0]=a[j];
                ans[p][1]=a[i];
                p++;
                ans[p][0]=a[i];
                ans[p][1]=a[j];
                p++;
                cnt+=2;
            }
        }
    std::cout<<cnt<<std::endl;
    for(int i=1;i<p;i++){
        std::cout<<ans[i][0]<<" "<<ans[i][1]<<std::endl;
    }
}

signed main(){
    std::cin.tie(0)->std::ios::sync_with_stdio(false);
    solve();
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
#define MAXN 1010
#define int long long 
int a[MAXN],cnt = 0;
int ans[MAXN][2];
int p=1;

void solve(){
    int n;
    std::cin>>n;
    for(int i=1;i<=n;i++)std::cin>>a[i];
    for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++){
            if(a[i]>a[j]){
                ans[p][0]=a[i];
                ans[p][1]=a[j];
                p++;
                cnt++;
            }
        }
    for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++){
            if(a[i]<a[j]){
                ans[p][0]=a[j];
                ans[p][1]=a[i];
                p++;
                ans[p][0]=a[i];
                ans[p][1]=a[j];
                p++;
                cnt+=2;
            }
        }
    std::cout<<cnt<<std::endl;
    for(int i=1;i<p;i++){
        std::cout<<ans[i][0]<<" "<<ans[i][1]<<std::endl;
    }
}

signed main(){
    std::cin.tie(0)->std::ios::sync_with_stdio(false);
    solve();
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
vector<int>ansv[2];
int a[1000],c[1000];
int main(){
	ios::sync_with_stdio(false),cin.tie(0);
	int n,i,j;
	cin>>n;
	for(i=0;i<n;i++)
	{
		a[i]=i+1;
		cin>>c[i];
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<n-i-1;j++)
		{
			ansv[0].push_back(a[j+1]);
			ansv[1].push_back(a[j]);
			swap(a[j],a[j+1]);
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=i;j<n;j++)
		{
			if(a[j]==c[i])break;
		}
		for(;j>i;j--)
		{
			ansv[0].push_back(a[j]);
			ansv[1].push_back(a[j-1]);
			swap(a[j],a[j-1]);
		}
	}
	cout<<ansv[0].size()<<'\n';
	for(i=0;i<ansv[0].size();i++)cout<<ansv[0][i]<<' '<<ansv[1][i]<<'\n';
	return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--) {
        int freq2=0,freq3=0,sum=0;
        string s;
        cin>>s;
        int n = s.size();
        vector<int >v(n);
        for(int i=0;i<n;i++){
            v[i]=s[i]-'0';
            sum+=v[i];
            if(v[i]==2){
                freq2++;
            }else if(v[i]==3){
                freq3++;
            }
        }
        int x =9-sum%9;
        if(x==9){
            yes;
            continue;
        }
        if(x==1 and (freq2>=5 or (freq2 >=2 and freq3>= 1))){yes;}
        else if (x==2 and freq2>=1){yes;}
        else if(x==3  and (freq2 >=6 or freq3>=2)){yes;}
        else if(x==4  and freq2>=2 ){yes;}
        else if(x==5  and (freq2>=7 or (freq2>=1 and freq3 >=2))){yes;}
        else if(x==6  and (freq2>=3 or freq3>=1)){yes; }
        else if(x==7  and (freq2>=8 or (freq2>=2 and freq3 >=2))){yes;}
        else if(x==8  and (freq2>=4 or (freq2>=1 and freq3>=1) or (freq3>=1 and freq2>=5))){yes;}
        else{
            no;
        }
    }

    return 0;
}


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--) {
        int freq2=0,freq3=0,sum=0;
        string s;
        cin>>s;
        int n = s.size();
        vector<int >v(n);
        for(int i=0;i<n;i++){
            v[i]=s[i]-'0';
            sum+=v[i];
            if(v[i]==2){
                freq2++;
            }else if(v[i]==3){
                freq3++;
            }
        }
        int x =9-sum%9;
        if(x==9){
            yes;
            continue;
        }
        if(x==1 and (freq2>=5 or (freq2 >=2 and freq3>= 1))){yes;}
        else if (x==2 and freq2>=1){yes;}
        else if(x==3  and (freq2 >=6 or freq3>=2)){yes;}
        else if(x==4  and freq2>=2 ){yes;}
        else if(x==5  and (freq2>=7 or (freq2>=1 and freq3 >=2))){yes;}
        else if(x==6  and (freq2>=3 or freq3>=1)){yes; }
        else if(x==7  and ((freq3>=1 and freq2>=5) or freq2>=8 or (freq2>=2 and freq3 >=2) )){yes;}
        else if(x==8  and (freq2>=4 or (freq2>=1 and freq3>=1))){yes;}
        else{
            no;
        }
    }

    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--) {
        int freq2=0,freq3=0,sum=0;
        string s;
        cin>>s;
        int n = s.size();
        vector<int >v(n);
        for(int i=0;i<n;i++){
            v[i]=s[i]-'0';
            sum+=v[i];
            if(v[i]==2){
                freq2++;
            }else if(v[i]==3){
                freq3++;
            }
        }
        int x =9-sum%9;
        if(x==9){
            yes;
            continue;
        }
        if(x==1 and (freq2>=5 or (freq2 >=2 and freq3>= 1))){yes;}
        else if (x==2 and freq2>=1){yes;}
        else if(x==3  and (freq2 >=6 or freq3>=2)){yes;}
        else if(x==4  and freq2>=2 ){yes;}
        else if(x==5  and (freq2>=7 or (freq2>=1 and freq3 >=2) or(freq2>=4 and freq3>=1))){yes;}
        else if(x==6  and (freq2>=3 or freq3>=1)){yes; }
        else if(x==7  and ((freq3>=1 and freq2>=5) or freq2>=8 or (freq2>=2 and freq3 >=2) )){yes;}
        else if(x==8  and (freq2>=4 or (freq2>=1 and freq3>=1))){yes;}
        else{
            no;
        }
    }

    return 0;
}


Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--) {
        int freq2=0,freq3=0,sum=0;
        string s;
        cin>>s;
        int n = s.size();
        vector<int >v(n);
        for(int i=0;i<n;i++){
            v[i]=s[i]-'0';
            sum+=v[i];
            if(v[i]==2){
                freq2++;
            }else if(v[i]==3){
                freq3++;
            }
        }
        int x =9-sum%9;
        if(x==9){
            yes;
            continue;
        }
        if(x==1 and (freq2>=5 or (freq2 >=2 and freq3>= 1))){yes;}
        else if (x==2 and freq2>=1){yes;}
        else if(x==3  and (freq2 >=6 or freq3>=2 or (freq2>=3 and freq3>=1))){yes;}
        else if(x==4  and freq2>=2 ){yes;}
        else if(x==5  and (freq2>=7 or (freq2>=1 and freq3 >=2) or(freq2>=4 and freq3>=1))){yes;}
        else if(x==6  and (freq2>=3 or freq3>=1)){yes; }
        else if(x==7  and ((freq3>=1 and freq2>=5) or freq2>=8 or (freq2>=2 and freq3 >=2) )){yes;}
        else if(x==8  and (freq2>=4 or (freq2>=1 and freq3>=1))){yes;}
        else{
            no;
        }
    }

    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--) {
        int freq2=0,freq3=0,sum=0;
        string s;
        cin>>s;
        int n = s.size();
        vector<int >v(n);
        for(int i=0;i<n;i++){
            v[i]=s[i]-'0';
            sum+=v[i];
            if(v[i]==2){
                freq2++;
            }else if(v[i]==3){
                freq3++;
            }
        }
        int x =9-sum%9;
        if(x==9){
            yes;
            continue;
        }
        if(x==1 and (freq2>=5 or (freq2 >=2 and freq3>= 1))){yes;}
        else if (x==2 and freq2>=1){yes;}
        else if(x==3  and (freq2 >=6 or freq3>=2)){yes;}
        else if(x==4  and freq2>=2 ){yes;}
        else if(x==5  and (freq2>=7 or (freq2>=1 and freq3 >=2))){yes;}
        else if(x==6  and (freq2>=3 or freq3>=1)){yes; }
        else if(x==7  and (freq2>=8 or (freq2>=2 and freq3 >=2))){yes;}
        else if(x==8  and (freq2>=4 or (freq2>=1 and freq3>=1) or (freq3>=1 and freq2>=5))){yes;}
        else{
            no;
        }
    }

    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--) {
        int freq2=0,freq3=0,sum=0;
        string s;
        cin>>s;
        int n = s.size();
        vector<int >v(n);
        for(int i=0;i<n;i++){
            v[i]=s[i]-'0';
            sum+=v[i];
            if(v[i]==2){
                freq2++;
            }else if(v[i]==3){
                freq3++;
            }
        }
        int x =9-sum%9;
        if(x==9){
            yes;
            continue;
        }
        if(x==1 and (freq2>=5 or (freq2 >=2 and freq3>= 1))){yes;}
        else if (x==2 and freq2>=1){yes;}
        else if(x==3  and (freq2 >=6 or freq3>=2)){yes;}
        else if(x==4  and freq2>=2 ){yes;}
        else if(x==5  and (freq2>=7 or (freq2>=1 and freq3 >=2))){yes;}
        else if(x==6  and (freq2>=3 or freq3>=1)){yes; }
        else if(x==7  and ((freq3>=1 and freq2>=5) or freq2>=8 or (freq2>=2 and freq3 >=2) )){yes;}
        else if(x==8  and (freq2>=4 or (freq2>=1 and freq3>=1))){yes;}
        else{
            no;
        }
    }

    return 0;
}


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while (t--) {
        int freq2=0,freq3=0,sum=0;
        string s;
        cin>>s;
        int n = s.size();
        vector<int >v(n);
        for(int i=0;i<n;i++){
            v[i]=s[i]-'0';
            sum+=v[i];
            if(v[i]==2){
                freq2++;
            }else if(v[i]==3){
                freq3++;
            }
        }
        int x =9-sum%9;
        if(x==9){
            yes;
            continue;
        }
        if(x==1 and (freq2>=5 or (freq2 >=2 and freq3>= 1))){yes;}
        else if (x==2 and freq2>=1){yes;}
        else if(x==3  and (freq2 >=6 or freq3>=2)){yes;}
        else if(x==4  and freq2>=2 ){yes;}
        else if(x==5  and (freq2>=7 or (freq2>=1 and freq3 >=2) or(freq2>=4 and freq3>=1))){yes;}
        else if(x==6  and (freq2>=3 or freq3>=1)){yes; }
        else if(x==7  and ((freq3>=1 and freq2>=5) or freq2>=8 or (freq2>=2 and freq3 >=2) )){yes;}
        else if(x==8  and (freq2>=4 or (freq2>=1 and freq3>=1))){yes;}
        else{
            no;
        }
    }

    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: PyPy 3-64

Previous submission (verdict: Time limit exceeded on test 26):
import random

for _ in range(int(input())):

	x,y = [int(t) for t in input().split()]

	a = [int(t) for t in input().split()]



	C = {}

	for e in a:

		C[e] = C[e]+1 if e in C else 1



	b = [int(t) for t in input().split()]

	if sum(a)^sum(b): print("NO"); continue



	flag = 1

	while b:

		e = b.pop()

		if e in C:

			C[e] -= 1

			if C[e] == 0: del C[e]

			continue

		

		if e == 1: flag = 0; break

		b.append( e//2 )

		b.append( (e+1)//2 )

	

	print( "YES" if flag else "NO" )

Submission (verdict: Accepted):
import sys

input = sys.stdin.readline

from collections import Counter



from random import getrandbits



RANDOM = getrandbits(32)



class Int(int):

    def __init__(self, x):

        int.__init__(x)

    def __hash__(self):

        return super(Int, self).__hash__() ^ RANDOM



def find(x):

    if cnt[Int(x)]:

        cnt[Int(x)] -= 1

        return True

    if x == 0 or x == 1: return False

    

    return find((x + 1) // 2) and find(x // 2)



def solve():

    global cnt

    n, m = map(int, input().split())

    a = list(map(Int, input().split()))

    b = list(map(int, input().split()))

    b.sort(reverse=True)



    if sum(a) != sum(b):

        return False

    

    cnt = Counter(a)

    for i in range(m):

        if cnt[Int(b[i])]:

            cnt[Int(b[i])] -= 1

            continue

        if not find(b[i]):

            return False



    return max(cnt.values()) == 0



for _ in range(int(input())):

    print("Yes" if solve() else "No")