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

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

int main(){
    int t;cin>>t;
    while(t--){
        string s;cin>>s;
        int sum=0;
        unordered_map<char,int>m;
        for(int i=0;i<s.size();i++){
            m[s[i]]++;
            sum+=(int)s[i]-48;
        }
        sum=9-sum%9;
        // cout<<sum;
        if(sum==9){
            cout<<"YES"<<endl;
        }
        else if(sum==1){
            if((m['3']>=1 && m['2']>=2)||(m['2']>=5)){
                cout<<"YES"<<endl;
            }
            else{
                cout<<"NO"<<endl;
            }
        }
        else if(sum==2){
            if((m['2']>=1)){
                cout<<"YES"<<endl;
            }
            else{
                cout<<"NO"<<endl;
            }
        }
        else if(sum==3){
            if((m['3']>=2)||(m['3']>=1 && m['2']>=3)||(m['2']>=6)){
                cout<<"YES"<<endl;
            }
            else{
                cout<<"NO"<<endl;
            }
        }
        else if(sum==4){
            if(m['2']>=2){
                cout<<"YES"<<endl;
            }
            else{
                cout<<"NO"<<endl;
            }
        }
        else if(sum==5){
            if((m['3']>=2 && m['2']>=1)||(m['3']>=1 && m['2']>=4)||(m['2']>=7)){
                cout<<"YES"<<endl;
            }
            else{
                cout<<"NO"<<endl;
            }
        }
        else if(sum==6){
            if((m['3']>=1)||(m['2']>=3)){
                cout<<"YES"<<endl;
            }
            else{
                cout<<"NO"<<endl;
            }
        }
        else if(sum==7){
            if((m['3']>=2 && m['2']>=2)||(m['3']>=1 && m['2']>=5) || (m['2']>=8)){
                cout<<"YES"<<endl;
            }
            else{
                cout<<"NO"<<endl;
            }
        }
        else if(sum==8){
            if((m['3']>=1 && m['2']>=1) || (m['2']>=4)){
                cout<<"YES"<<endl;
            }
            else{
                cout<<"NO"<<endl;
            }
        }
    }
    return 0;
}

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

using namespace std;

using ll = long long;



unordered_map<int, bool> dp;

bool solve(int sm, int twos, int threes) {

    if(twos < 0 || threes < 0)

        return false;

    if(dp.find(sm) != dp.end()) {

        return dp[sm];

    }

    if(sm == 0)

        return true;

    dp[sm] = solve((sm + 2)%9, twos - 1, threes) | solve((sm + 2 + 6)%9, twos - 1, threes - 1) | solve((sm + 6)%9, twos, threes - 1);

    return dp[sm];

}





int main()

{    

    #ifndef ONLINE_JUDGE

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

    freopen("outputf.in","w",stdout);

    #endif

    ios_base::sync_with_stdio(false); cin.tie(NULL);    

    std::cout << std::fixed;

    std::cout << std::setprecision(6);

  

    

    int testcase;

    cin>>testcase;

    while(testcase--)

    {

        dp.clear();

        string s;

        cin>>s;

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

        for(auto i : s) {

            int no = (int)i - '0';

            sm += no;

            sm %= 9;

            twos += (no == 2);

            threes += (no == 3);

        }

        // cout<<"Solving for sm = "<<sm<<" , "<<twos<<" : "<<threes<<"\n";

        cout<<(solve(sm, twos, threes) ? "Yes" : "No")<<"\n";

    }



 

    #ifndef ONLINE_JUDGE

    cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";

    #endif

    return 0;

}