ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<stack>
#include<map>
#include<queue>
#include<algorithm>
#include<set>
#define ll long long
using namespace std;

ll max(ll a,ll b)
{
    return a>=b?a:b;
}
ll min(ll a,ll b)
{
    return a<=b?a:b;
}
ll divi(ll a,ll b)
{
    if(a%b)
    {
        return a/b+1;
    }
    return a/b;
}



void solve()
{
  ll n,i;
  string str;
  cin>>str;
  n=str.length();
  vector<ll>dp(n,-1);
  ll count2=0,count3=0;
  ll sum=0;
  for(i=0;i<n;++i)
  {
    sum+=str.at(i)-'0';
    if(str.at(i)=='2')
   { count2++;
    continue;}
    if(str.at(i)=='3')
    {
      count3++;
    }
  }
  if(sum%9==0)
  {
    cout<<"Yes\n";
    return;
  }
  ll temp=0;

 for(temp=0;temp<=min(8,count2);++temp)
 {
  ll sum2;
  sum2=sum+(temp)*2;
  for(ll temp2=0;temp2<=min(8,count3);++temp2)
  {
    ll sum3;
  sum3=sum2+6*temp2;
    if(sum3%9==0)
    {
      cout<<"Yes\n";
      return;
    }
  }
  
 }
 cout<<"No\n";


}
int main()
{
    ll cases;
    cin>>cases;
    while(cases--)
    solve();

}

/*
1
3 10
4 8 4
2 9 10


10
1 14 30 1 16 25 2 32 4 44 

1 8 16 24 32 40 48 56 64 72 80 88 96 104 112 120 128
*/

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

using namespace std;

int main()

{

    int n,i,t,th,sum,p,j,d,b,s;

    char str[100005];

    cin>>s;while(s--){

    cin>>str;

    t=0;th=0;sum=0;

    for(i=0;i<strlen(str);i++)

    {

       // cout<<str[i]-'a'+49<<"\n";

        if((str[i]-'a'+49)==2)

        {

                t=t+1;

        }

          if((str[i]-'a'+49)==3)

        {

            th=th+1;

        }

        sum=sum+str[i]-'a'+49;



    }



    p=0;

    if(sum%9==0)

    {

        p=p+1;

    }

    else

    {



        for(i=0;i<t+1;i++)

        for(j=0;j<th+1;j++)

        {

            d=2*i+6*j;

            b=sum+d;



            if(b%9==0)

            {

                p=p+1;

                i=t+1;

                j=th+1;

            }



        }

    }

    if(p>=1)

    {

        cout<<"YES";

    }else{cout<<"NO";}

    cout<<"\n";

    }

    return 0;

}
Problem: 2050D - Digital string maximization
Language: c++17 

Solution 1 (runtime: 92 ms):
#include <bits/stdc++.h>
#define f(i,a,b) for(ll i=a; i<b; i++)
#define rf(i,a,b) for(ll i=a; i>=b; i--)
#define inar(a,n) for(ll i=0; i<n; i++) cin >> a[i]
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define go(x,m) for(auto &x:m)
#define F first
#define S second
#define andd &&
#define orr ||
#define mo 1000000007
#define a(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define next cout << "\n"
using namespace std;
using ll = long long;
using vl = vector <long long>;
using vll = vector <pair<long long,long long>>;
using vlb = vector <pair<long long,bool>>;
using mll = map <long long,long long>;
using mcl = map <char,long long>;
void operation(string &s){
    int n=s.length();
    for(int i=1; i<n; i++){
        if((s[i-1]-'0')<(s[i]-'0')-1){
            int d=s[i]-'0';
            s[i]=s[i-1];
            s[i-1]=('0'+(d-1));
        }
    }
}
void solve(){
    string s;
    cin >> s;
    int n=s.length();
    for(int i=0; i<10; i++){
        operation(s);
    }
    cout << s << endl;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
    ios::sync_with_stdio(0); cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

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

using namespace std;

#define int long long



int32_t main(){

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

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

            while(i>0&&s[i]-s[i-1]>1){

                s[i]--;

                swap(s[i],s[i-1]);

                i--;

            }



           }

        

        cout<<s<<endl;

            

        }

              



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

Solution 1 (runtime: 656 ms):
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
void solve(){
    int n,m;
    cin>>n>>m;
    vector<int>a(n),b(m);
    priority_queue<int>pq_a,pq_b;
    for(auto & i : a){
        cin>>i;
        pq_a.push(i);
    } 
    for(auto & i : b) {
        cin>>i;
        pq_b.push(i);
    }
    if(n<m){
        cout<<"NO"<<endl;
        return;
    }
    if(n==m){
        sort(a.begin(),a.end());
        sort(b.begin(),b.end());
        if(a==b){
            cout<<"YES"<<endl;
            return;
        }
        else{
            cout<<"NO"<<endl;
            return;
        }
    }
    while( (pq_b.size() < pq_a.size()) and (!pq_a.empty()) and (!pq_b.empty()) ){
        int mxa = pq_a.top();
        int mxb = pq_b.top();
        if(mxa>mxb){
            cout<<"NO"<<endl;
            return;
        }
        if(mxa==mxb){
            pq_a.pop();
            pq_b.pop();
            
        }
        if(mxa<mxb){
            pq_b.pop();
            pq_b.push((mxb/2));
            pq_b.push((mxb/2)+(mxb%2));
        }
    }
    vector<int>temp_a , temp_b;
    while(!pq_a.empty()){
        temp_a.push_back(pq_a.top());
        pq_a.pop();
    }
    while(!pq_b.empty()){
        temp_b.push_back(pq_b.top());
        pq_b.pop();
    }
    if(temp_a==temp_b){
        cout<<"YES"<<endl;
        return;
        
    }
    cout<<"NO"<<endl;
    return;
    
    
    
}
int32_t main(){
    int t; cin>>t;
    while(t--)  solve();
}

Solution 2 (runtime: 890 ms):
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define  nl "\n"
#define forn(a, c) for (int a = 0; a < c; a++) 
#define forl(a, b, c) for (int a = b; a <= c; a++) 
#define forr(a, b, c) for (int a = b; a >= c; a--)
#define cin(v) for(auto &i:v){cin>>i;}
#define cout(v) for(auto &i:v){cout<<i<<" ";}cout<<nl;
#define all(a) a.begin(),a.end()
#define fast() (ios_base::sync_with_stdio(false), cin.tie(NULL));
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

bool func(int x, multiset<int> &s){
    if(x == 1){
        if(s.find(x) == s.end())return false;
        else {
            s.erase(s.find(x));
            return true;
        }
    }
    if(s.find(x) != s.end()){
        s.erase(s.find(x));
        return true;
    }
    else {
        if(func(x/2,s) && func((x+1)/2,s))return true;
        return false;
    }
    // return false;
}

void solve(){
    int n,k;cin>>n>>k;
    // std::vector<int> v(n);
    multiset<int> s;
    forn(i,n){
        int x;cin>>x;s.insert(x);
    }
    std::vector<int> v2(k);
    forn(i,k)cin>>v2[i];
    forn(i,k){
        if(!func(v2[i],s)){cout<<"No\n";return;}
    }
    if(!s.empty())cout<<"No\n";
    else cout<<"Yes\n";

}

signed main()
{
    auto begin = std::chrono::high_resolution_clock::now();
    fast();
    int tt;cin>>tt;
    while(tt--){
        solve();
    }
    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";
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 390 ms):
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int dp[1001][1001];
string a, b, c;

int f(int i, int j)
{
    int va = 1000, vb = 1000;
    if (dp[i][j] != -1)
        return dp[i][j];
    if (i == a.length() && j == b.length())
    {
        dp[i][j] = 0;
        return dp[i][j];
    }
    if (i != a.length())
        va = (a[i] == c[i + j] ? 0 : 1) + f(i + 1, j);
    if (j != b.length())
        vb = (b[j] == c[i + j] ? 0 : 1) + f(i, j + 1);
    dp[i][j] = min({va, vb});
    return dp[i][j];
}

int main()
{
    int t, q, i, j;
    cin >> t;
    for (q = 0; q < t; q++)
    {
        cin >> a >> b >> c;
        for (i = 0; i < 1001; i++)
            for (j = 0; j < 1001; j++)
                dp[i][j] = -1;
        cout << f(0, 0) << '\n';
    }
    return 0;
}

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

int main(){
    ll t;
    cin>>t;
    while(t--){
   
    string a,b,c;
    cin>>a;
    cin>>b;
    cin>>c;
    vector<vector<ll> > dp(b.size()+1,vector<ll>(a.size()+1));
    dp[0][0]=0;
    for(ll i=1;i<=b.size();i++){
        dp[i][0]=dp[i-1][0];
            if(b[i-1]!=c[i-1]){
              dp[i][0]++;
            }
    }
    for(ll j=1;j<=a.size();j++){
        dp[0][j]=dp[0][j-1];

            if(a[j-1]!=c[j-1]){
              dp[0][j]++;
            }
    }
    for(ll i=1;i<=b.size();i++){
      for(ll j=1;j<=a.size();j++){
         
            ll k=i+j;
            ll x=dp[i-1][j],y=dp[i][j-1];
            if(a[j-1]!=c[k-1]){
               y++;
            }
            if(b[i-1]!=c[k-1]){
               x++;
            }
            dp[i][j]=min(x,y);
         
        //   cout<<dp[i][j]<<" ";
      }
    //   cout<<endl;
    }
   //  for(ll i=0;i<=b.size();i++){
   //    for(ll j=0;j<=a.size();j++){
   //       cout<<dp[i][j]<<" ";
   //    }
   //    cout<<endl;
   //  }
    cout<<dp[b.size()][a.size()]<<"\n";


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

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

int32_t main() 
{
    int t;
    cin>>t;
    while(t--){
      int l,r;
      cin>>l>>r;
      if(r-l==2){
        cout<<l<<" "<<l+1<<" "<<r<<endl;
        continue;
      }
      int val=pow(2,30);
      int ans=-1;
      while(ans==-1){
        int x=l/val;
        int y=r/val;
        if(x==y){
          if(y-x+1>val){
          int a=(x+1)*val;
            if(a-2>=l){
              cout<<a<<" "<<a-1<<" "<<a-2;
            }
            else{
              cout<<a<<" "<<a-1<<" "<<a+1;
            }
            break;
          }  
        }
        else{
         int a=(x+1)*val;
            if(a-2>=l){
              cout<<a<<" "<<a-1<<" "<<a-2;
            }
            else{
              cout<<a<<" "<<a-1<<" "<<a+1;
            }
            break;
        }
        val=val/2;
      }
      cout<<endl;
      
    }
}

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

const int N = 1e5 + 10;

ll l, r, a[2];

ll calc(ll x) {
    if (x < l || x > r) {
        return -1;
    }
    return (x ^ l) + (x ^ r);
}

void solve() {
    cin >> l >> r;
    a[0] = l, a[1] = r;
    for (int i = 31; i >= 0; i--) {
        for (int j = 0; j < 2; j++) {
            ll tmp1 = calc(a[j]);
            ll tmp2 = calc(a[j] ^ (1ll << i));
            if (tmp2 >= tmp1) {
                a[j] ^= 1ll << i;
            }
        }
    }
    for (int i = 0; i < 2; i++) {
        if (a[i] == l) a[i]++;
        if (a[i] == r) a[i]--;
    }
    cout << l << " " << r << " " << (calc(a[0]) > calc(a[1]) ? a[0] : a[1]) << endl;
}

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

    int T; cin >> T;
    while (T--) {
        solve();
    }
}
Problem: 2061D - Kevin and Numbers
Language: c++17 

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


int main() {
     int t;
     cin>>t;
     while(t--){
        int n,m;
        cin>>n>>m;

        vector<int>a(n);
        vector<int>b(m);

         map<int,int>req;

        for(int i=0;i<n;i++) {
            cin>>a[i];
            req[a[i]]--;
        }

        for(int i=0;i<m;i++){
             cin>>b[i];

             req[b[i]]++;

        }

        bool f=1;

        bool g=1;

        int x,freq;
        for(auto it=req.rbegin();it!=req.rend();it++){
        
           x=it->first;
           freq=it->second;

           if(x<=0) break;

           if(freq<0) {
            f=0;
            break;
           }
             g=1;
           if(freq>0) g=0;

           if(x%2==0){
             req[x/2]+=freq*2;
           }else{
            req[x/2]+=freq;
            req[x/2+1]+=freq;
           }

        }

        if(!g || !f){
            cout<<"no"<<endl;
        }else{
            cout<<"yes"<<endl;
        }


     }
    return 0;
}

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

using namespace std;

#define int long long



int32_t main(){

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);



    int t = 1;

    cin >> t;

    while(t--){

        int n, m;

        cin >> n >> m;

        vector<int> a(n), b(m);

        multiset<int>sa,sb;

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

            cin>>a[i];

            sa.insert(a[i]);

        }

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

            cin>>b[i];

            sb.insert(b[i]);

        }

        bool flag=true;

        while(!sa.empty()&&!sb.empty()&&flag){

            int x=*sb.begin();

            if(sa.find(x)!=sa.end()){

                sa.erase(sa.find(x));

                sb.erase(sb.begin());

                continue;

            }

            else{

                if(x==1||x==0){

                    flag=false;

                    break;

                }

                if(x%2==0){

                sb.insert(x/2);

                  sb.insert(x/2);

                }

                else{

                    sb.insert(x/2);

                    sb.insert(x/2+1);

                }

                sb.erase(sb.find(x));

            }

        }

          if(flag&&sb.empty()&&sa.empty())cout<<"Yes"<<endl;

           else cout<<"No"<<endl;

    }

 



    return 0;

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

Solution 1 (runtime: 359 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<ll> v(n);
        for(int i = 0; i < n; i++){
            cin >> v[i];
        }
        bool flag = false;
        int i = 0;
        while(i < n - 1){
            int min_val = min(v[i], v[i + 1]);
            v[i] -= min_val;
            v[i + 1] -= min_val;
            i++;
        }
        for(int i = 0; i < n - 1; i++){
            if(v[i] > v[i + 1]){
                flag = true;
                break;
            }
        }
        // for(int i = 0; i < n; i++){
        //     cout << v[i] << " ";
        // }
        // cout << "\n";
        if(flag) cout << "NO" << endl;
        else cout << "YES" << endl;
    }
    return 0;
}

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

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

        for (int k = 0; k < n - 1; k++)
        {
            int p = a[k];
            a[k] = a[k] - min(p, a[k + 1]);
            a[k + 1] = a[k + 1] - min(p, a[k + 1]);
        }

        if (is_sorted(a.begin(), a.end()))
        {
            cout << "Yes\n";
        }
        else
        {
            cout << "No\n";
        }
    }

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

Solution 1 (runtime: 187 ms):
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,l,r;
        cin>>n>>l>>r;
        vector<int>a(n,0);
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        vector<int>b =a;
        vector<int>c=a;
        sort(b.begin(),b.begin()+r,greater<>());
        sort(c.begin()+l-1,c.end());
        long long min1=0,min2=0;
        for(int i=l-1;i<r;i++)
        {
            min1+=b[i];
            min2+=c[i];
        }
        cout<<min(min1,min2)<<endl;
    }
}

Solution 2 (runtime: 77 ms):
/******************************************************************************
 * Filename: sol.cpp
 * Problem: CF - 2063B - Subsequence Update
 *****************************************************************************/
#include <iostream>
#include <algorithm>

using namespace std;

using ll = long long;

const int kMaxN = (int)1e5;

int a[kMaxN], b[kMaxN];

ll kthMinSum(int k, int *begin, int *end) {
	ll ret = 0;
	int len = end - begin;
	copy(begin, end, b);
	sort(b, b+len);
	for (int i = 0; i < k; i++) ret += b[i];
	return ret;
}

ll solve(int n, int l, int r) {
	return min(kthMinSum(r-l+1, a, a+r), kthMinSum(r-l+1, a+l-1, a+n));
}

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

	int t;
	cin >> t;
	while (t--) {
		int n, l, r;
		cin >> n >> l >> r;
		for (int i = 0; i < n; i++) cin >> a[i];
		cout << solve(n, l, r) << endl;
	}

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

Solution 1 (runtime: 202 ms):
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int t;
    cin >> t;
    for(int z=1; z<=t; z++){
        long long n, l, r;
        cin>>n>>l>>r;
        vector<long long> v(n);
        for(int i=0; i<n; i++)
            cin>>v[i];
        long long seql=r-l+1;
        r = min(r, n);
        l = max(l, 1LL);
        long long start=l-1;
        seql=min(seql, r);
        seql=min(seql, n-start);
        vector<long long> st, dr;
        for(int i=0; i<r; i++)
            st.push_back(v[i]);
        for(int i=start; i<n; i++)
            dr.push_back(v[i]);
        sort(st.begin(), st.end());
        sort(dr.begin(), dr.end());
        long long s1=0, s2=0;
        for (int i=0; i<seql; i++) {
            if(i<st.size())
                s1+=st[i];
            if(i<dr.size())
                s2+=dr[i];
        }
        cout<<min(s1, s2)<<'\n';
    }

    return 0;
}


Solution 2 (runtime: 171 ms):
#include<iostream>

#include<algorithm>

using namespace std;

const int N = 1e5 + 10;

int a[N],b[N];

int main()

{

	int t;

	cin >> t;

	while (t--)

	{

		int n, l, r;

		cin >> n >> l >> r;

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

		{

			cin >> a[i];

			b[i] = a[i];

		}

		sort(a+1, a + r+1);

		sort(b + l, b + n+1);

		long long sum = 0;

		long long sum1 = 0;

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

		{

			sum += a[i];

		}

		for (int i = l; i <= r; i++)

		{

			sum1 += b[i];

		}

		cout << min(sum, sum1) << endl;

		

	}

}
Problem: 2063C - Remove Exactly Two
Language: c++17 

Solution 1 (runtime: 1031 ms):
#include <iostream>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using ll=long long;
int t,n;
const int N=2e5+5;
struct Node{
    int p;
    int cnt;
}node[N];
bool cmp(Node a,Node b){
    return a.cnt>b.cnt;
}
void solve(){
  cin>>n;
  map<pair<int,int>,bool>edges;
    for(int i=0;i<=n+3;i++){
        node[i].cnt=0;
        node[i].p=i;
    }
    for(int i=0;i<n-1;i++){
        int u,v;
        cin>>u>>v;
        edges[{u,v}]=edges[{v,u}]=true;//记一下边，等会看两个要删的点是否相连
        node[u].cnt++;//记录每个点的度数
        node[v].cnt++;
    }
    if(n<=2){//两个点直接删没
        cout<<0<<endl;
        return;
    }
    sort(node+1,node+n+1,cmp);//按度数从大到小排序
    int ans,temp;
    ans=node[1].cnt+node[2].cnt-1;
    if(edges[{node[1].p,node[2].p}]) ans--;

    for(int i=2;i<=n;i++){
        temp=node[1].cnt+node[i].cnt-1;
        if(edges[{node[1].p,node[i].p}]) temp--;
        ans=max(ans,temp);
    }
    for(int i=3;i<=n;i++){
        temp=node[2].cnt+node[i].cnt-1;
        if(edges[{node[2].p,node[i].p}]) temp--;
        ans=max(ans,temp);
    }
    cout<<ans<<endl;
}
int main (){
  cin>>t;
  while(t--){
    solve();
    }
  return 0;
}

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

using namespace std;

void solve(){
    int n;
    cin>>n;
    vector<int> graph[n+1];
    vector<int> degree(n+1, 0);
    map<int, int> degreeMap;
    for(int i=0; i<(n-1); ++i){
        int u, v;
        cin>>u>>v;
        graph[u].push_back(v);
        graph[v].push_back(u);
        degree[u]++;
        degree[v]++;
    }

    for(int i=0; i<=n; ++i){
        degreeMap[degree[i]]++;
    }

    // //print graph, degree
    // for (int i=0; i<=n; ++i){
    //     cout<<i<<" degree: "<<degree[i]<<" -> ";
    //     for(int j=0; j<graph[i].size(); ++j){
    //         cout<<graph[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }

    int ans = 0;
    for(int i=0; i<n; ++i){
        degreeMap[degree[i]]--;
        if(degreeMap[degree[i]] == 0){
            degreeMap.erase(degree[i]);
        }
        for(int v: graph[i]){
            ans = max(ans, degree[i]+degree[v]-2);
            degreeMap[degree[v]]--;
            if(degreeMap[degree[v]] == 0){
                degreeMap.erase(degree[v]);
            }
        }

        //get the max degree from the remaining degrees in the map
        if(degreeMap.size() > 0){
            auto it = degreeMap.end();
            --it;
            ans = max(ans, degree[i]+it->first - 1);
        }

        //restore the degreeMap
        for(int v: graph[i]){
            degreeMap[degree[v]]++;
        }
        degreeMap[degree[i]]++;
    }

    //other scenario

    cout<<ans<<endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int T = 1;
    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 int long long

bool fn(int num_2, int num_6, int sum){

    vector<bool> dp(9,false);
    dp[sum] = true;

    for(int i=0;i<=min((int)18,num_2);i++){
        for(int j=0;j<=min(num_6,(int)3);j++){
            if(i==0 && j==0){
                continue;
            }
            int num = sum + 2*i + 6*j;
            num%=9;
            dp[num] = true;
        }
    }

    return dp[0];   
}


main(){

    cin.tie(0);
    ios::sync_with_stdio(0);

    int t;
    
    cin>>t;

    while(t--){
        string s;

        cin>>s;

        int n = s.size();
        int num_2 = 0;
        int num_6 = 0;

        int sum = 0;

        for(int i=0;i<n;i++){
            int num = s[i] - '0';
            sum += num;

            if(num==2){
                num_2++;
            }

            if(num==3){
                num_6++;
            }
        }
        sum%=9;
        
        if(fn(num_2,num_6,sum)){
            cout<<"YES"<<endl;
        }

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

    }

    return 0;
}

Solution 2 (runtime: 46 ms):
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
using namespace std;

#define ll long long
#define ull unsigned long long
#define vi vector<int>

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

    int shuma = 0, dysha = 0, tresha = 0;

    for (auto &val : s)
    {
        shuma += val - '0';

        if (val == '2')
            dysha++;
        else if (val == '3')
            tresha++;
        else
        {
            
        }
    }
    bool mundet = false;

    for (int i = 0; i <= min(8, dysha); i++)
    {
        if (mundet)
            break;

        for (int j = 0; j <= min(8, tresha); j++)
        {
            if ((shuma + i * 2 + j * 6) % 9 == 0)
            {
                mundet = true;
                break;
            }
        }
    }

    if (mundet)
        cout << "YES";
    else
        cout << "NO";
}

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

    int t;
    cin >> t;

    while (t--)
    {

        solve();
        cout << '\n';
    }

    return 0;
}