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

Solution 1 (runtime: 46 ms):
#include<bits/stdc++.h>
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl "\n";
using namespace std;


int main() {
	FAST
	int tc = 1;
	cin>>tc;
    
	while(tc--) {
        string n; cin>>n;
        int sum = 0;
        
        for(char ch: n) sum += (ch - '0');
        
        int count2 = 0, count3 = 0;
        for(char ch: n) {
            if( ch == '2') count2++;
            else if(ch == '3') count3++;
        }
        
        sum %= 9;
        
        if(sum == 0) {
            cout<<"YES";
        } else {
            int need = 9 - sum;
            bool possible = false;
            for(int i = 0; i <= count2; i++) {
                int cur = 2 * i;
                cur %= 9;
                cur = (need - cur + 9) % 9;
                if(cur % 6 == 0 && count3 >= cur / 6) {
                    possible = true; break;
                }
                if((cur + 9) % 6 == 0 && count3 >= (cur + 9) / 6) {
                    possible = true; break;
                }
                
                if((cur + 18) % 6 == 0 && count3 >= (cur + 18) / 6) {
                    possible = true; break;
                }
                
                if((cur + 27) % 6 == 0 && count3 >= (cur + 27) / 6) {
                    possible = true; break;
                }
            }
            if(possible) {
                cout<<"YES";
            } else {
                cout<<"NO";
            }
        }
        cout<<endl;
        
    }
    
    return 0;
}


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


signed main() {
    int q;
    cin>>q;
    while(q--){
        string n;
        cin>>n;
        int sum=0;
        int x2=0;
        int x3=0;
        for(int i=0;i<n.size();i++){
            int num = n[i] - '0';
            if(num==2){
                x2++;
            }
            if(num==3){
                x3++;
            }
            sum+=num;

        }
        bool flag=true;
        if(sum%9==0){
            cout<<"YES"<<endl;
        }
        
        
        else{
            if(flag==true){
                for(int j=0;j<=x3;j++){
                    int x=sum+6*j;
                    if((x)%9==0){
                        cout<<"YES"<<endl;
                        flag=false;
                        break;
                    }
                }
            }
            if(flag==true){
                for(int i=1;i<=x2;i++){
                
                    int x=sum+2*i;
                    if((x)%9==0){
                        cout<<"YES"<<endl;
                        flag=false;
                        break;
                    }
                }
            }
            if(flag==true){
                 for(int i=1;i<=x2;i++){
                for(int j=0;j<=x3;j++){
                    int x=sum+2*i+6*j;
                    if((x)%9==0){
                        cout<<"YES"<<endl;
                        flag=false;
                        break;
                    }
                }
                if(flag==false){
                    break;
                }
            }
            }  
 
            if(flag==true){
                cout<<"NO"<<endl;
            }
        }

    }
}