ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2057B - Gorilla and the Exam
Language: c++17 

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

#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

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() {
    fast_io;
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Solution 2 (runtime: 234 ms):
﻿#include "iostream"
#include "unordered_map"
#include "vector"
#include "algorithm"
#include "chrono"

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x ^= x << 13;
        x ^= x >> 7;
        x ^= x << 17;
        return x;
    }
    size_t operator () (uint64_t x) const {
        static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count(); // 时间戳
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main(int argc, char *argv[])
{
    using namespace std;
    int t;
    cin >> t;
    while (t --)
    {
        int n, k;
        cin >> n >> k;
        unordered_map<int, int, custom_hash> count;
        for (int i = 0; i < n; i ++)
        {
            int x;
            cin >> x;
            count[x] ++;
        }

        vector<pair<int, int>> vec;
        for (auto p : count)
        {
            vec.push_back(p);
        }

        sort(vec.begin(), vec.end(), [](auto a, auto b)
        {
            return a.second < b.second;
        });

        int cnt = vec.size();
        for (int i = 0; i < vec.size(); i ++)
        {
            if (vec[i].second > k) break;
            k -= vec[i].second;
            cnt --;
        }

        if (cnt == 0) cnt ++;

        cout << cnt << endl;
    }

    return 0;
}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

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


void solve()
{
    ll l,r;
    cin>>l>>r;

    ll a,b;
    a=b=0;
    
    int i = 29;

    while(i>0 && (((1<<i) & l) == ((1<<i) & r)))
    {
        if((1<<i) & l){
            a |= 1<<i;
            b |= 1<<i;
        }

        i--;
    }

    a |= 1<<i;
    i--;

    while(i>=0)
    {
        b |= 1<<i;
        i--;
    }

    ll c;

    if(b!=l) c = l;
    else if(a!=r) c= r;
    


    cout<<a<< " "<<b<< " "<<c<<endl;
}

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

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

    return 0;
}

Solution 2 (runtime: 77 ms):
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
// Including tree_order_statistics_node_update
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
// visit this link to study it in a proper way :
// https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds;
#define ordered_set  tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
// use less_equal for multiset and less for set ^
// Find by order and order of key
// cout<< *X.find_by_order(k)    <<endl;  //  K-th element in a set (counting from zero)
// cout<< X.order_of_key(k)   <<endl; //  Number of items strictly smaller than k.

using ll = long long;
#define int long long
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());


void solve() {
    int l,r;
    cin >> l >> r;
    int k = 31 - __builtin_clz( l ^ r );
    int a = ( l | ( (1 << k) - 1 ));
    int b = a + 1;
    int c = ( a == l ? r : l );
    cout << a << " " << b << " " << c << endl;
}

signed main() {
    auto begin = std::chrono::high_resolution_clock::now();

    // std::ifstream file("matrix.txt"); // Replace "input.txt" with your file name
    //     std::cerr << "Error opening file!" << std::endl;
    //     return 1;
    // }

    // std::string line;

    // while (std::getline(file, line)) { // Read the file line by line
    //     std::stringstream ss(line);    // Create a stringstream from the line
    //     std::string num;

    //     // Split the line by commas and extract integers
    //     while (std::getline(ss, num, ',')) {
    //         all.push_back(std::stoi(num)); // Convert the string to an integer and store it
    //     }
    // }

    // file.close();

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
        // cout << "-----" << endl;
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

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

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        string num;
        cin >> num;

        int twos_count = 0, threes_count = 0, sum = 0;

        // Process digits as a string to avoid overflow
        for (char digit : num)
        {
            int k = digit - '0';
            if (k == 2)
                twos_count++;
            else if (k == 3)
                threes_count++;
            sum += k;
        }

        if (sum % 9 == 0)
        {
            cout << "YES" << endl;
            continue;
        }

        // Limit effective counts based on problem constraints
        twos_count = min(twos_count, 8);
        threes_count = min(threes_count, 5);

        bool marker = false;
        int rem = sum % 9;

        for (int i = 0; i <= threes_count; i++)
        {
            for (int j = 0; j <= twos_count; j++)
            {
                if ((rem + i * 6 + j * 2) % 9 == 0)
                {
                    marker = true;
                    break;
                }
            }
            if (marker)
                break;
        }

        if (marker)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}


Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define pii pair<int,int>
const int maxn = 100005, MOD = 1e9 + 7;

void fast_io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
}

// bool prime[1001];

// void SieveOfEratosthenes(int n)
// {
//     memset(prime, true, sizeof(prime));
//     for (int p = 2; p * p <= n; p++) {
//         if (prime[p] == true) {
//             for (int i = p * p; i <= n; i += p)prime[i] = false;
//         }
//     }
// }


void solve(){
    string n; cin >> n; 
    int twos = 0, threes = 0, md = 0;
    int x = n.size();
    bool ans = 0;
    for(int i = 0; i<x ; ++i){
        int temp = (int)(n[i]) - 48;
        md += temp; 
        md = (md % 9);
        // cout << temp << " ";
        if(temp == 2) twos++;
        if(temp == 3) threes++;

    }
    twos = min((int)8, twos);
    threes = min((int)2, threes);
    for(int i = 0; i<=twos; ++i){
        for(int j = 0; j<=threes; ++j){
            int temp = (2*i) + (6*j);
            if((md+temp) % 9 == 0) {
                ans = 1;
                break;
            }
        }
        if(ans) break;
    }
    if(ans) cout << "YES";
    else cout << "NO";
    
}

signed main() {
    fast_io();
    int t = 1;
    cin >> t;
    while(t--){
        solve();
        cout << endl;
    }
}
Problem: 2062C - Cirno and Operations
Language: c++17 

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<long long> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }

        int now = n;
        long long ans = LLONG_MIN;

        for (int i = 0; i < n; i++) {
            long long sum = accumulate(a.begin(), a.end(), 0LL);
            if (i == 0) ans = max(ans, sum);
            else ans = max(ans, max(sum, -sum));

            if (a.size() > 1) {
                vector<long long> b(a.size() - 1);
                for (int j = 0; j < a.size() - 1; j++) {
                    b[j] = a[j + 1] - a[j];
                }
                a = b;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

#define ll long long

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    
    int now = n;
    while (now > 1)  {
        ll currentSum = 0;
        for (int i = 0; i < now - 1; i++) {
            a[i] = a[i + 1] - a[i];
            currentSum += a[i];
        } 
        sum = max (sum, max (currentSum, -currentSum));
        now--;
    }
    cout << sum << endl;
}

int main() {
    int test; 
    cin >> test;
    while (test --) 
        solve();
}
Problem: 2050C - Uninteresting Number
Language: c++17 

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

using namespace std;

bool canConvert(int digitSum, int occurance, int value) {
    if (digitSum % 9 == 0) {
        return true;
    }
    for (int i = 0; i < occurance; i++) {
        digitSum += value;
        if (digitSum % 9 == 0) {
            return true;
        }
    }
    return false;
}

void solve() {
    string number;
    cin >> number;

    int digitSum = 0;
    for (const auto c : number) {
        digitSum += c - '0';
    }

    if (digitSum % 9 == 0) {
        cout << "YES" << endl;
        return;
    }
    // 0 => 0
    // 1 => 1
    // 2 => 4 +2
    // 3 => 9 +6
    int twos = 0, threes = 0;
    for (const auto c : number) {
        if (c == '2') {
            twos++;
        } else if (c == '3') {
            threes++;
        }
    }

    if (canConvert(digitSum, threes, 6)) {
        cout << "YES" << endl;
        return;
    }

    if (twos >= 1) {
        if (canConvert(digitSum+2, threes, 6)) {
            cout << "YES" << endl;
            return;
        }
    }

    if (twos >= 2) {
        if (canConvert(digitSum+4, threes, 6)) {
            cout << "YES" << endl;
            return;
        }

        twos += (3*threes);
        if (canConvert(digitSum, twos, 2)) {
            cout << "YES" << endl;
            return;
        }
    }

    cout << "NO" << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        solve();
    }

    return 0;
}

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

using namespace std;

#define int long long



signed main()

{

	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

	int t;

	cin>>t;

	while(t--)

	{

		string n;

		cin>>n;

		int cnt2=0,cnt3=0,sum=0;

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

		{

			sum=sum+n[i]-'0';

			if(n[i]=='3')

			{

				cnt3++;

			}

			else if(n[i]=='2')

			{

				cnt2++;

			}

		}

		int flag=0;

		for(int i=0;i<=min(cnt2,9ll);i++)

		{

			for(int j=0;j<=min(cnt3,3ll);j++)

			{

				if((i*2+j*6+sum)%9==0)

				{

					flag=1;

					break;

				}

			}

		}

		if(!flag)

		{

			cout<<"NO";

		}

		else

		{

			cout<<"YES";

		}

		cout<<endl;

	}

	return 0;

}
Problem: 2060D - Subtract Min Sort
Language: c++17 

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



static void solve(void)

{

	int n;

	std::cin >> n;

	std::vector<int> v(n);

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

		std::cin >> v[i];

	}

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

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

		{

			std::cout << "NO" << std::endl;

			return;

		}

		int d = std::min(v[i + 1], v[i]);

		while (d)

		{

			v[i + 1] -= d;

			v[i] -= d;

			d = std::min(v[i], v[i + 1]);

		}

	}

	std::cout << "YES" << std::endl;

}



int main()

{

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	std::cout.tie(0);

	int t;

	std::cin >> t;

	while (t--)

	{

		solve();

	}

	return 0;

}



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

using namespace std;

#define int long long



const int N = 200005;

int a[N];



signed main(){

ios::sync_with_stdio(false);

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

int t;

cin >> t;

while(t --){

int n;

cin >> n;

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

cin >> a[i];

bool ok = 0;

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

if(a[i] <= a[i - 1] + a[i + 1]){

int x = min(a[i] , a[i - 1]);

a[i - 1] -= x;

a[i] -= x;

}else{

ok = 1;

break;

}

}

if(ok)

cout << "NO" << '\n';

else

cout << "YES" << '\n';

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

a[i] = 0;

}

return 0;

}
Problem: 2050B - Transfusion
Language: c++17 

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

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    vector<int> a(n);
    array<int64_t, 2> sum = {0, 0};
    array<int64_t, 2> cnt = {0, 0};
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      sum[i % 2] += a[i];
      cnt[i % 2] += 1;
    }
    if (sum[0] % cnt[0] == 0 && sum[1] % cnt[1] == 0 && sum[0] / cnt[0] == sum[1] / cnt[1]) {
      cout << "YES" << '\n';
    } else {
      cout << "NO" << '\n';
    }
  }
  return 0;
}


Solution 2 (runtime: 312 ms):
#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: 2049C - MEX Cycle
Language: c++17 

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

#include<iomanip>

#include<climits>

// INT_MAX LLONG_MAX

#include <vector>

#include<array>

#include<queue>

#include<stack>

#include<set>

#include<unordered_set>

#include<map>

#include<unordered_map>

#include<cstring>

#include<cmath>

#include <algorithm>

using namespace std;

#define endl "\n"

#define rep(i,a,b) for(int i=(a);i<(b);i++)

#define ffor(i,a,b) for(int i=(a);i<=(b);i++)

#define rfor(i,a,b) for(int i=(a);i>=(b);i--)

#define fios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define int long long

#define yes cout<<"Yes"<<endl;

#define no cout<<"No"<<endl;

#define DEBUG cout<<">>>>"<<endl;

using vi=vector<int>;

template<size_t N>

using ai = array<int, N>;

using pii=pair<int,int>;

typedef long long LL;

const int inf=1e18;

const int CJR=998244353;

const int HY_Spark=1e9+7;





void solve(){

	int n,x,y;

	cin>>n>>x>>y;

	vi a (n+1,0);

	ffor(i,2,n-1){

		a[i]=a[i-1]^1;

	}

	if(n%2){

		a[n]=2;

	}else{

		a[n]=1;

	}

	if(a[x]==a[y]){

		if(x==1 && a[n]==2){

			swap(a[1],a[n]);

		}else{

			a[x]=2;

		}

	}

	ffor(i,1,n){

		cout<<a[i]<<" ";

	}

	cout<<endl;

}





signed main(){

    fios;

    int _=1;

    cin>>_;

    while(_--){

        solve();

    }

}

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

#define int long long int

using namespace std;



signed main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    int t=1;

    cin>>t;

    while(t--)

    {

       int n,x,y;

       cin>>n>>x>>y;

       vector<int>ans(n);

       if(n%2==0)

       {

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

        {

            if(i%2==0)ans[i]=0;

            else ans[i]=1;

        }

        if(ans[x-1]==ans[y-1])ans[x-1]=2;

        for(auto ele:ans)cout<<ele<<" ";

        cout<<endl;

       }

       else

       {

        for(int i=0;i<x-1;i++)

        {

            if(i%2==0)ans[i]=0;

            else ans[i]=1;

        }

        ans[x-1]=2;

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

        {

            if(i%2==0)ans[i]=1;

            else ans[i]=0;

        }

        for(auto ele:ans)cout<<ele<<" ";

        cout<<endl;

       }

    }

    return 0;

}
Problem: 2050C - Uninteresting Number
Language: c++17 

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
std::set<ll> generateSums(int count2, int count3) {
    std::set<ll> sums;

    // Iterate through all possible numbers of 2s (0 to count2)
    for (int i = 0; i <= count2; ++i) {
        // Iterate through all possible numbers of 3s (0 to count3)
        for (int j = 0; j <= count3; ++j) {
            // Calculate the sum for the current combination
            ll sum =(ll)i * 2 + (ll)j * 6;
            sums.insert(sum);
        }
    }

    return sums;
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    // Log output to console
    int t;
         cin >> t;

 while(t--){
    string s;
    cin >> s;
   
    int c2=0;
    int c3=0;
    rep(i,0,s.size()){
       if(s[i]=='2') c2++;
       if(s[i]=='3') c3++;
    }
    auto x = generateSums(min(8,c2),min(8,c3));
    ll os=0;
    rep(i,0,s.size()){
        int y=s[i]-'0';
        os+=y;
    }
    // cout << os << endl;
    bool f=false;  
    // if(os%9==0){
    //  cout << "YES" << endl;
    //  f=true;
    // }
    for(auto sum: x){
        if((sum+os)%9==0){
            // cout << os <<" " << sum;
            cout << "YES" << endl;
            f=true;
            break;
        }
    }
    if(not f){
        cout << "NO" << endl;
    }
     

 }
    return (ll)0;
}

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

using namespace std;



#define ll long long

const int N = 2e5 + 5;



#define mod 1000000007



int main() {

#ifndef ONLINE_JUDGE

    freopen("out.out", "w", stdout);

    freopen("in.in", "r", stdin);

#else

#endif



    int t;

    cin >> t;

    while (t--) {

        string s;

        cin >> s;

        ll sum = 0;

        map<ll, ll> mp;

        for (auto i : s) {

            sum += (i - '0');

            if (i - '0' == 2) mp[2]++;

            if (i - '0' == 3) mp[3]++;

        }

        if (sum % 9 == 0) {

            cout << "YES\n";

            continue;

        }

        int p = 0;

        for (int i = 0; i <= min(mp[2], 8ll); i++) {

            for (int j = 0; j <= min(mp[3], 20ll); j++) {

                ll ans = 0;

                ans = sum + (i * 2 + j * 6);

                if (ans % 9 == 0) {

                    p = 1;

                    break;

                }

            }

        }

        cout << (p ? "YES" : "NO") << "\n";

    }



    return 0;

}
Problem: 2050C - Uninteresting Number
Language: c++17 

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

using namespace std;

void solve()
{
    string s;
    cin >> s;
    int sum = 0;
    int two_sum = 0;
    int three_sum = 0;
    for (int i = 0; i < s.length(); i++)
    {
        sum += s[i] - '0';
        if (s[i] - '0' == 2)
        {
            two_sum += 2;
        }
        if (s[i] - '0' == 3)
        {
            three_sum += 6;
        }
    }
    if (sum % 9 == 0)
    {
        cout << "YES" << endl;
        return;
    }
    int fire = 9 - (sum % 9);
    while (fire <= two_sum + three_sum)
    {
        if (fire % 2 != 0)
        {
            fire += 9;
            continue;
        }
        int temp_fire = fire;
        int temp_two = two_sum;
        int temp_three = three_sum;
        while (temp_three >= 6 && temp_fire >= 6)
        {
            temp_fire -= 6;
            temp_three -= 6;
        }
        while (temp_two >= 2 && temp_fire >= 2)
        {
            temp_fire -= 2;
            temp_two -= 2;
        }
        if (temp_fire == 0)
        {
            cout << "YES" << endl;
            return;
        }
        fire += 18;
    }
    cout << "NO" << endl;
    return;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int INP;
    cin >> INP;
    while (INP--)
    {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 61 ms):
#include <iostream>
#include <string>
using namespace std;

void solve() {
    string n;
    cin >> n;

    int sm = 0, twos = 0, threes = 0;

    // Compute sum and count 2s and 3s
    for (char c : n) {
        int digit = c - '0';
        sm += digit;
        if (digit == 2) twos++;
        if (digit == 3) threes++;
    }

    // Check combinations of transformations
    for (int i = 0; i <= min(10, twos); i++) {
        for (int j = 0; j <= min(10, threes); j++) {
            if ((sm + i * 2 + j * 6) % 9 == 0) {
                cout << "YES" << endl;
                return;
            }
        }
    }

    cout << "NO" << endl;
}

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

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

    return 0;
}
Problem: 2050C - Uninteresting Number
Language: c++17 

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

void solve() {
    string s;
    cin >> s;
    map<char,int> mp;
    mp['2']=0;
    mp['3']=0;
    ll sum=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='2') mp['2']++;
        if(s[i]=='3') mp['3']++;
        sum += (s[i]-'0');
        sum %= 9;
    }
     for (int i = 0; i <= min(10, mp['2']); i++) {
        for (int j = 0; j <= min(10, mp['3']); j++) {
            if ((sum + i * 2 + j * 6) % 9 == 0) {
                cout << "YES" << endl;
                return;
            }
        }
    }

    cout << "NO" << endl;
}

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


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

using namespace std;

#define nl '\n'

#define int long long

#define sp ' '

#define PI 3.14159265358979323846



int32_t main(){

    cin.tie(0)->sync_with_stdio(0);

    int t;cin>>t;

    while(t--)

    {

        string s;cin>>s;

        int c2 =count(s.begin(),s.end(),'2'),c3 = count(s.begin(),s.end(),'3');

        int sum=0;

        for(int i = 0;i<s.size();i++)

        {

            sum+=s[i]-'0';

        }

        bool ok = false;

        for(int i = 0;i<=min(10ll,c2);i++)

        {

            for(int j = 0;j<=min(10ll,c3);j++)

            {

             if((sum + 2*i + 6*j)%9 ==0)

             {

                 ok = true;

                 break;

             }

            }

        }

        if(ok)

            cout<<"YES"<<nl;

        else cout<<"NO"<<nl;

    }

}