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

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ppb pop_back
#define ff first
#define ss second
#define f(i,a,b)        for(ll i=a;i<b;i++)
#define fm(i,a,b)       for(ll i=a;i>=b;i--)
#define fc(i,a,b,c)      for(ll i=a;i<b;i=i+c)
#define fmc(i,a,b,c)     for(ll i=a;i>=b;i=i-c)
#define fi(n)           f(i,0,n)
#define fj(n)           f(j,0,n)
#define fastfast()                      ios_base::sync_with_stdio(false); cin.tie(NULL);                    cout.tie(NULL)
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<vector<ll>> vvll;
void yes(){cout << "YES" << endl;}
void no(){cout << "NO" << endl;}
void print(ll t) {cout << t << endl;}
void print(int t) {cout << t << endl;}
void print(string t) {cout << t << endl;}
void print(char t) {cout << t << endl;}
void print(lld t) {cout << t << endl;}
void print(double t) {cout << t << endl;}
void print(ull t) {cout << t << endl;}
void prn(ll n)
{
    fi(n)
    {
        cout<<i+1<<" ";
    }
    cout<<endl;
}
ll insqrt(ll n)
{
    ll s=0;
    ll e=1e10+1;
    ll ans=0;
    if(n<=0) return 0;
    while(s<=e)
    {
        ll mid=(s+e)/2;
        if(mid*mid<=n) {s=mid+1; ans=mid;}
        else e=mid-1;
    }
    return ans;
}
 
ll orar[100001][20];
void buildorar(ll arr[],ll n)
{
    fi(n) orar[i][0]=arr[i];
    fj(20)
    {
        for(int i=0;i+(1<<j)<=n;i++)
        {
            orar[i][j+1]=orar[i][j]|orar[i+(1<<(j))][j];
        }
    }
}
 
ll calculate(ll l,ll r)
{
    ll ans=0;
    fm(i,20,0)
    {
        if((1<<i) <= r-l+1)
        {
            ans=ans|orar[l][i];
            l=l+(1<<i);
        }
    }
    return ans;
}
 
ll gcd(ll a,ll b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
 
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}
 
ll fastex(ll a,ll n)
{
    ll p=1;
    ll ld;
    while(n>0)
    {
        ld=n&1;
        if(ld==1) p=p*a;
        a=a*a;
        n=n>>1;
    }
    return p;
}
 
class DisjointSet
{
public:
    vll size,parent;
    DisjointSet(ll n)
    {
        size.resize(n+1,1);
        parent.resize(n+1,0);
        for(int i=0;i<n+1;i++) parent[i]=i;
    }
    ll findPar(ll u)
    {
        if(parent[u]==u) return u;
        else return parent[u]=findPar(parent[u]);
    }
    void unionbysize(ll u,ll v)
    {
        ll pu=findPar(u);
        ll pv=findPar(v);
        if(pu==pv) return;
        if(size[pu]<size[pv])
        {
            parent[pu]=pv;
            size[pv]+=size[pu];
        }
        else
        {
            parent[pv]=pu;
            size[pu]+=size[pv];
        }
    }
    ll findsize(ll u)
    {
        ll pu=findPar(u);
        return size[pu];
    }
};
 
// Jai Bajrangbali
 
int main()
{
    fastfast();
    
    ll t;
    cin >> t;

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


        int two = 0;
        int three = 0;
        int s=0;

        for(auto it:st){
            if(it=='2')two++;
            if(it=='3')three++;
            s+=(it-'0');
            s%=9;
        }

        int flag = 0;
        for (int i=0;i<=two;i++) {
            for (int j=0;j<=three;j++) {
                ll ts = s;
                ts += 2*i+j*6;
                if (ts%9 == 0) {
                    flag=1;
                    break;
                }
            }
            if(flag==1)break;
        }
        if(flag==1){
            print("YES");
            continue;
        }
        else print("NO");
    }


 
    return 0;
}

Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        string n;
        cin>>n;
        int sum=0;
        int twos=0;
        int threes=0;
        for(int i=0;i<n.size();i++){
            sum+=int(n[i])-48;
            if(n[i]=='2'){
                twos++;
            }
            else if(n[i]=='3'){
                threes++;
            }
        }
        if(sum%9==0){
            cout<<"YES"<<"\n";
        }
        else{
            bool found=0;
            for(int i=0;i<=twos;i++){
                for(int j=0;j<=threes;j++){
                    if((2*i+6*j)%9==9-(sum%9)){
                        found=1;
                        break;
                    }
                }
                if(found==1){
                    break;
                }
            }
            if(found==1){
                cout<<"YES"<<"\n";
            }
            else{
                cout<<"NO"<<"\n";
            }
        }  
    }
    return 0;
}