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

Code 1:
#include <bits/stdc++.h>

using namespace std;



int main() {

    int t; cin >> t;

    while (t--) {

        long long n; cin >> n;

        if(n%9 == 0){

            cout << "yes" << endl;

            continue;

        }



        long long sum = 0;

        int cnt2 = 0, cnt3 = 0;

        long long temp = n;

        while(temp>0){

            int d = temp%10;

            sum += d;

            if(d==2) cnt2++;

            if(d==3) cnt3++;

            temp /= 10;

        }



        int r = 9-sum % 9;

        bool possible = false;

        int max_a = min(cnt2, 9);

        int max_b = min(cnt3, 3);

        for (int a = 0; a <= max_a; a++){

            for (int b = 0; b <= max_b; b++){

                if ((2 * a + 6 * b) % 9 == r) {

                    possible = true;

                    break;

                }

            }

            if(possible) break;

        }

        cout << (possible ? "yes" : "no") << endl;

    }

    return 0;

}

Code 2:
#include <bits/stdc++.h>

using namespace std;



int main() {

    int t; cin >> t;

    while (t--) {

        string n; cin >> n;

        long long sum = 0;

        int cnt2 = 0, cnt3 = 0;

        for (char c : n) {

            int d = c - '0';

            sum += d;

            if(d == 2) cnt2++;

            if(d == 3) cnt3++;

        }

        

        if(sum % 9 == 0) {

            cout << "yes" << endl;

            continue;

        }

        

        int r = 9-(sum % 9);

        bool possible = false;

        int max_a = min(cnt2, 9);

        int max_b = min(cnt3, 3);

        for (int a = 0; a <= max_a; a++){

            for (int b = 0; b <= max_b; b++){

                if ((2*a + 6*b) % 9==r) {

                    possible = true;

                    break;

                }

            }

            if(possible) break;

        }

        cout << (possible ? "yes" : "no") << endl;

    }

    return 0;

}

Answer: 2
Problem: 2050C - Uninteresting Number
Language: c++17 

Code 1:
#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <algorithm>

#include <numeric>  

using namespace std;

using ll = long long;



#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

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

#define pb push_back



/*vector<int> getDigits(ll num) {

    vector<int> digits;

    while (num > 0) {

        digits.push_back(num % 10);

        num /= 10;

    }

    return digits;

}*/



void solve() {

    string n;

    cin >> n;

    

    //vector<int> num;

    //num= getDigits(n);

    //int k = accumulate(num.begin(), num.end(), 0LL);



    int k=0;

    for(char i:n){

        k=k+(i-'0');

    }

    bool no= true;

    int tw=0;

    int si=0;

    for(char i:n){

        if(i=='2') tw++;

        if(i=='3') si++;

    }



    tw=min(tw,10);

    si=min(si,10);



    f(i,0,tw+1){

        f(j,0,si+1){

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

                cout<<"Yes"<<"\n";

                no=false;

                break;

            }

        }

    }

    if(no) cout<<"No"<<"\n";



    

}



int main() {

    fastio;

    int t;

    cin >> t;

    while (t--) solve();

    return 0;

}

Code 2:
#include <iostream>

#include <string>

#include <vector>

#include <set>

#include <algorithm>

#include <numeric>  

using namespace std;

using ll = long long;



#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);

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

#define pb push_back



/*vector<int> getDigits(ll num) {

    vector<int> digits;

    while (num > 0) {

        digits.push_back(num % 10);

        num /= 10;

    }

    return digits;

}*/



void solve() {

    string n;

    cin >> n;

    

    //vector<int> num;

    //num= getDigits(n);

    //int k = accumulate(num.begin(), num.end(), 0LL);



    int k=0;

    for(char i:n){

        k=k+(i-'0');

    }

    

    int tw=0;

    int si=0;

    for(char i:n){

        if(i=='2') tw++;

        if(i=='3') si++;

    }



    tw=min(tw,10);

    si=min(si,10);



    f(i,0,tw+1){

        f(j,0,si+1){

            int v=(k+2*i+6*j);

            if(v%9==0){

                cout<<"Yes"<<"\n";

                

                return;

            }

        }

    }

    cout<<"No"<<"\n";



    

}



int main() {

    fastio;

    int t;

    cin >> t;

    while (t--) solve();

    return 0;

}

Answer: 2
Problem: 2050C - Uninteresting Number
Language: c++17 

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

void solve() {
    string s;
    cin >> s;
    map<char,int> mp;
    mp['1']=0;
    mp['2']=0;
    mp['3']=0;
    mp['4']=0;
    mp['5']=0;
    mp['6']=0;
    mp['7']=0;
    mp['8']=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='1'){
            if(mp['8']>0) mp['8']--;
            else mp['1']++;
        }
        if(s[i]=='2'){
            mp['2']++;
        }if(s[i]=='4'){
            if(mp['5']>0) mp['5']--;
            else mp['4']++;
        }if(s[i]=='5'){
            if(mp['4']>0) mp['4']--;
            else mp['5']++;
        }if(s[i]=='7'){
            mp['7']++;
        }
        if(s[i]=='8'){
            if(mp['1']>0) mp['1']--;
            else mp['8']++;
        }
        if(s[i]=='6') mp['6']++;
        if(s[i]=='3') mp['3']++;
    }
    ll sum=0;
    sum += 9 - (mp['1'] % 9);
    sum += 9 - ((3*mp['3']) % 9);
    sum += 9 - ((8*mp['8']) % 9);
    sum += 9 - ((7*mp['7']) % 9);
    sum += 9 - ((4*mp['4']) % 9);
    sum += 9 - ((5*mp['5']) % 9);
    sum += 9 - ((2*mp['2']) % 9);
    if(mp['6']%3 != 0) sum += 9 - ((6*mp['6']) % 9);
    int ans = (sum%9);
    if(ans==0 || ans==9){
        cout << "YES\n";
    }
    if(ans==1){
        if(mp['2']>=5){
            cout << "YES\n";
        }
        else cout << "NO\n";
    }
    if(ans==2){
        if(mp['2']>=1) cout << "YES\n";
        else cout << "NO\n";
    }
    if(ans==3){
        if(mp['2']>=6 || mp['3']>=2) cout << "YES\n";
        else cout << "NO\n";
    }
    if(ans==4){
        if(mp['2']>=2) cout << "YES\n";
        else cout << "NO\n";
    }
    if(ans==5){
        if((mp['2']>=4 && mp['3']>=1) || (mp['2']>=1 && mp['3']>=2) || (mp['2']>=7)) cout << "YES\n";
        else cout << "NO\n";
    }
    if(ans==6){
        if(mp['3']>=1 || mp['2']>=3) cout << "YES\n";
        else cout << "NO\n";
    }
    if(ans==7){
        if((mp['2']>=5 && mp['3']>=1) || (mp['2']>=1 && mp['3']>=2) || (mp['2']>=8)) cout << "YES\n";
        else cout << "NO\n";
    }
    if(ans==8){
        if(mp['2']>=4) cout << "YES\n";
        else cout << "NO\n";
    }
}

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


Code 2:
#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;
}


Answer: 2
Problem: 2050C - Uninteresting Number
Language: c++17 

Code 1:
#include<bits/stdc++.h>

using namespace std;

int main()

{

    long long int n,a,b,t=0,th=0,p,i,j,sum,d,s;

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

    cin>>n;

    a=n;

    b=0;

    t=0;th=0;

    while(a>0)

    {

      b=b+(a%10);

      if((a%10)==2){t=t+1;}

      if((a%10)==3){th=th+1;}

      a=a/10;

    }





    p=0;

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

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

    {

        sum=b;

        d=2*i+6*j;

        sum=sum+d;



        if(sum%9==0)

        {

            p=1;

            i=t+1;



        }

    }

    if(p==1){cout<<"YES";}else{cout<<"NO";}

        cout<<"\n";

    }



    return 0;

}

Code 2:
#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;

}



Answer: 2
Problem: 2050C - Uninteresting Number
Language: c++23 

Code 1:
#include<bits/stdc++.h>
using namespace std;


#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set ;


#define int long long 
#define fr(i , j, k) for(int i=j ; i<k ; i++)
#define show(v) for(auto i: v) cout << i << " " ; cout << nl;
#define take(n) int n;cin >> n;
#define pb push_back
#define nl "\n"

int mod = 1e9 + 7 ; 
int power(int x , int y , int m){
    int res =1 ;
    x = x%m;
    if ( x == 0 )return 0 ;
    while( y >0 ) {
        if( y%2 )res = (res*x)%m ;
        y = y>>1 ;
        x = (x*x ) %m ;
    }
    return res ;
}
int submod( int x , int y , int mod ){
    return ( (x-y)%mod + mod )%mod; 
} 



int32_t main () {
    int tt;
    cin >> tt ;
    while(tt--){
        string s; 
        cin >> s; 
        int x = 0 , y =0 ;
        int sum =0 ; 
        for(auto it: s ){
            if( it == '2')x++;
            else if ( it == '3')y++;  
            sum += it-'0';      
        }
        
        // cerr << x << " " << y <<  " " << sum << nl;
        int ans =0 ; 
        fr(i,0,min((int)10,x+1)){
            fr(j,0,min((int)10,y+1)){
                int temp = (j*6 + i*2); 
                // cout << temp+sum << nl;
                if( (temp + sum)%9 == 0 )ans = 1 ; 
            }
        }
        if(ans )cout << "YES" << nl;
        else cout << "NO" << nl;
       
    }
    return 0;
}

Code 2:
#include<bits/stdc++.h>
using namespace std;


#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set ;


#define int long long 
#define fr(i , j, k) for(int i=j ; i<k ; i++)
#define show(v) for(auto i: v) cout << i << " " ; cout << nl;
#define take(n) int n;cin >> n;
#define pb push_back
#define nl "\n"

int mod = 1e9 + 7 ; 
int power(int x , int y , int m){
    int res =1 ;
    x = x%m;
    if ( x == 0 )return 0 ;
    while( y >0 ) {
        if( y%2 )res = (res*x)%m ;
        y = y>>1 ;
        x = (x*x ) %m ;
    }
    return res ;
}
int submod( int x , int y , int mod ){
    return ( (x-y)%mod + mod )%mod; 
} 



int32_t main () {
    int tt;
    cin >> tt ;
    while(tt--){
        string s; 
        cin >> s; 
        int x = 0 , y =0 ;
        int sum =0 ; 
        for(auto it: s ){
            if( it == '2')x++;
            else if ( it == '3')y++;  
            sum += it-'0';      
        }
        x = x%9; 
        y = y%3; 
        // cerr << x << " " << y <<  " " << sum << nl;
        int ans =0 ; 
        fr(i,0,x+1){
            fr(j,0,y+1){
                int temp = (j*6 + i*2); 
                // cout << temp+sum << nl;
                if( (temp + sum)%9 == 0 )ans = 1 ; 
            }
        }
        if(ans )cout << "YES" << nl;
        else cout << "NO" << nl;
       
    }
    return 0;
}

Answer: 1
Problem: 2050C - Uninteresting Number
Language: c++23 

Code 1:
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define int long long
signed main()
{
    int tt;cin>>tt;
    while(tt--){
        int n;cin>>n;
        int sum=0;
        int ct2=0,ct3=0;
        while(n>0){
            sum+=n%10;
            if(n%10==2) ct2+=1;
            else if(n%10==3) ct3+=1;
            n/=10;
        }
        int temp=sum;
        bool f=false;
        int p=10;
        for(int i=0;i<=min(p,ct2);i++){
            
            for (int j=0;j<=min(p,ct3);j++){
                temp=sum;
                temp+=(i*2)+(j*6);
                if(temp%9==0) {
                    
                    f=true;
                    break;
                }
            }
            if(f) break;

        }
        if(f) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;        
    }
return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    int tt;
    cin >> tt;
    while (tt--) {
        string s;
        cin >> s;

        int sum = 0, ct2 = 0, ct3 = 0;

        for (char c : s) {
            int digit = c - '0';
            sum += digit;
            if (digit == 2) ct2++;
            if (digit == 3) ct3++;
        }

        bool f = false;
        for (int i = 0; i <= min(10LL, ct2); i++) {
            for (int j = 0; j <= min(10LL, ct3); j++) {
                if ((sum + i * 2 + j * 6) % 9 == 0) {
                    f = true;
                    break;
                }
            }
            if (f) break;
        }

        if (f) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}


Answer: 2
Problem: 2050C - Uninteresting Number
Language: c++23 

Code 1:
#include <bits/stdc++.h>

#include <algorithm>

#include <string>

#include <vector>



typedef long long ll;



using namespace std;





int main() 

{

    int t;

    cin >> t;

    while(t--)

    {

        string s;

        cin >> s;



        if(s == "5472778912773")

        {

            cout << "NO" << endl;

            continue;

        }

        int twos = 0;

        int threes = 0;

        long long sum = 0;

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

        {

            if(s[i] == '2')twos++;

            if(s[i] == '3')threes++;

            sum += (int)s[i] - 48;

        }

        int fl = 0;

        //cout << twos << " " << threes << " "<< sum << endl;

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

        {

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

            {

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

                {

                    fl = 1;

                    //cout << i << " " << j << endl;

                }

            }

        }

        if(fl)

            cout << "YES" << endl;

        else  

            cout << "NO" << endl;





    }

}

Code 2:
#include <bits/stdc++.h>

#include <algorithm>

#include <string>

#include <vector>



typedef long long ll;



using namespace std;





int main() 

{

    int t;

    cin >> t;

    while(t--)

    {

        string s;

        cin >> s;

        int twos = 0;

        int threes = 0;

        long long sum = 0;

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

        {

            if(s[i] == '2')twos++;

            if(s[i] == '3')threes++;

            sum += (int)s[i];

        }

        int fl = 0;

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

        {

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

            {

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

                {

                    fl = 1;

                    cout << i << " " << j << endl;

                }

            }

        }

        if(fl)

            cout << "YES" << endl;

        else  

            cout << "NO" << endl;





    }

}

Answer: 1
Problem: 2050C - Uninteresting Number
Language: c++17 

Code 1:
#include<vector>
#include <iostream>
#include<bits/stdc++.h>
using namespace std;

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

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

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

         rem=(rem+(s[i]-'0'))%9;

         if(s[i]=='2')
         cnt2++;

        if(s[i]=='3')
         cnt3++;
 }
 int flag=0;
// cout<<rem;
 for(int i=0;i<=min(cnt2,8);i++)
 {
     for(int j=0;j<=min(3,cnt3);j++)
     {
      //   cout<<i<<j<<"\n";
         if((rem+(i*2)%9+(j*6)%9)%9==0)
         {
             cout<<"YES\n";
             flag=1;
             break;
         }
         if(flag)
         break;
     }
 }
 if(!flag)
 cout<<"NO\n";
 }
}


Code 2:
#include<vector>
#include <iostream>
#include<bits/stdc++.h>
using namespace std;

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

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

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

         rem=(rem+(s[i]-'0'))%9;

         if(s[i]=='2')
         cnt2++;

        if(s[i]=='3')
         cnt3++;
 }
 int flag=0;
// cout<<rem;
 for(int i=0;i<=min(cnt2,8);i++)
 {
     for(int j=0;j<=min(3,cnt3);j++)
     {
      //   cout<<i<<j<<"\n";
         if((rem+(i*2)%9+(j*6)%9)%9==0)
         {
             cout<<"YES\n";
             flag=1;
             break;
         }

     }
      if(flag)
         break;
 }
 if(!flag)
 cout<<"NO\n";
 }
}


Answer: 2
Problem: 2050C - Uninteresting Number
Language: c++17 

Code 1:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <cstdint>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main(){
    int tc; cin >> tc;
    for(int t = 0; t < tc; t++){
        string s; cin >> s;
        int twos = 0, threes = 0, sum = 0;
        for(char n : s){
            int curr = n - '0';
            sum+=curr; if(curr==2){ twos++; } if(curr==3){ threes++; }
        }
        bool works = false;
        int need = 9 - (sum % 9);
        if(need % 2 == 1){ need+=9; }
        if(need/2 <= twos || (need >= 6 && threes >= 1 && (need-(6*threes > need ? (need%6 == 0 ? 6 :need%6) : 6*threes))/2 <= twos)){ works = true; }
        if(works || need % 9 == 0){ cout << "YES" << endl; } else{ cout << "NO" << endl; }
    }
}

Code 2:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <cstdint>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main(){
    int tc; cin >> tc;
    for(int t = 0; t < tc; t++){
        string s; cin >> s;
        int twos = 0, threes = 0, sum = 0;
        for(char n : s){
            int curr = n - '0';
            sum+=curr; if(curr==2){ twos++; } if(curr==3){ threes++; }
        }
        bool works = false;
        int need = 9 - (sum % 9);
        if(need % 2 == 1){ need+=9; }
        if(need/2 <= twos || (need >= 6 && threes >= 1 && (need-(6*threes > need ? need - (need % 6) : 6*threes))/2 <= twos)){ works = true; }
        if(works || need % 9 == 0){ cout << "YES" << endl; } else{ cout << "NO" << endl; }
    }
}

Answer: 2
Problem: 2050C - Uninteresting Number
Language: c++23 

Code 1:
#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define ff first
#define ss second

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input1.txt", "r", stdin);
    //freopen("output1.txt", "w", stdout);
    int t; cin >> t;
    while(t--){
        string s; cin >> s;
        int twos=0,sixs=0,sum=0;
        for(int i=0; i<s.size(); i++){
            if(s[i]=='2') twos++;
            if(s[i]=='3') sixs++;
            sum += s[i]-'0';
        }
        if(sum%9 == 0) cout << "YES" << endl;
        else{
            int isum=0, ii, flag=0;
            for(int i=1; isum<=((2*twos)+(6*sixs)); i++){
                isum = (9*i)-sum;
                if(isum < 0){
                    continue;
                }
                if(isum > ((2*twos)+(6*sixs))){
                    break;
                }
                if(isum-(6*sixs) >= 0){
                    isum -= 6*sixs;
                }
                if(isum%2 == 0 and (2*twos)>=(isum-(isum%2))){
                    flag = 1;
                    break;
                }
            }
            if(flag == 1) cout << "YES" << endl;
            else cout << "NO" << endl;
        }
    }
}

Code 2:
#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define ff first
#define ss second

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input1.txt", "r", stdin);
    //freopen("output1.txt", "w", stdout);
    int t; cin >> t;
    while(t--){
        string s; cin >> s;
        int twos=0,sixs=0,sum=0;
        for(int i=0; i<s.size(); i++){
            if(s[i]=='2') twos++;
            if(s[i]=='3') sixs++;
            sum += s[i]-'0';
        }
        if(sum%9 == 0) cout << "YES" << endl;
        else{
            int flag = 0;
            for(int i=0; i<9; i++){
                if(i > twos) break;
                for(int j=0; j<9; j++){
                    if(j > sixs) break;
                    if((sum + (i*2) + (j*6))%9 == 0){
                        flag = 1;
                        break;
                    }
                }
                if(flag == 1){
                    break;
                }
            }
            if(flag==1) cout << "YES" << endl;
            else cout << "NO" << endl;
        }
    }
}

Answer: 2
Problem: 2050C - Uninteresting Number
Language: c++17 

Code 1:
#include <bits/stdc++.h>

using namespace std;



#define RADHE_RADHE ios_base::sync_with_stdio(false);

#define endl '\n'



int main() {

    RADHE_RADHE;



    int t;

    cin >> t;

    while (t--) {

        // First of all if no.s sum%9==0, then "YES"...

        // If not the case and there is no presence of 2 or 3 then "NO"...



        // Its not required to have more than 8 2's and 3 6's...



        string s;

        cin>>s;



        int n = s.size();

        int cnt2 = 0;

        int cnt3 = 0;



        long long sum = 0;



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

            if(s[i]=='3')cnt3++;

            else if(s[i]=='2')cnt2++;

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

        }



        if(!cnt3 && !cnt2){

            cout<<"NO"<<endl;

        }

        else{

            bool ok = false;

            for(int i = 0;i<=min(cnt2,8);i++){

                for(int j = 0;j<=min(cnt3,8);j++){

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

                        ok = true;

                    }

                }

            }



            cout<<(ok?"YES":"NO")<<endl;

        }

    }

    return 0;

}

Code 2:
#include <bits/stdc++.h>

using namespace std;



#define RADHE_RADHE ios_base::sync_with_stdio(false);

#define endl '\n'



int main() {

    RADHE_RADHE;



    int t;

    cin >> t;

    while (t--) {

        // First of all if no.s sum%9==0, then "YES"...

        // If not the case and there is no presence of 2 or 3 then "NO"...

        // Its not required to have more than 8 2's and 3 6's...



        string s;

        cin>>s;



        int n = s.size();

        int cnt2 = 0;

        int cnt3 = 0;



        long long sum = 0;



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

            if(s[i]=='3')cnt3++;

            else if(s[i]=='2')cnt2++;

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

        }



        if(sum%9==0){

            cout<<"YES"<<endl;

            continue;

        }

        if(!cnt3 && !cnt2){

            cout<<"NO"<<endl;

        }

        else{

            bool ok = false;

            for(int i = 0;i<=min(cnt2,8);i++){

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

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

                        ok = true;

                    }

                }

            }



            cout<<(ok?"YES":"NO")<<endl;

        }

    }

    return 0;

}

Answer: 2