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

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define vl vector<ll> 
#define pb push_back
#define loop(n,i) for(ll i = 0; i < n; i++)
#define fa(i,v) for(auto &i:v)
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define print(x) cout << x << "\n";
#define print(x,y) cout << x << " " << y << "\n"
#define cl(v) v.clear()
#define all(v) v.begin(),v.end()
#define inf (ll)1e18
#define mod (ll)(1e9+7)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

template <typename T> T input(int n = 1){T tmp;cin >> tmp;return tmp;  }
template <typename T> vector<T> inputn(int n){vector<T> tmp;loop(n,i){
        T _;cin >> _;tmp.pb(_);}return tmp;}

bool possible(ll tgt, ll threes , ll twos){
    if(tgt%9 == 0) return true;
    else if(threes > 0 and twos > 0) return possible(tgt+6,threes-1,twos) or possible(tgt+2,threes,twos-1);
    else if(threes > 0 and twos == 0) {
        if(tgt%3 == 0) return possible(tgt+6,threes-1,twos);
        else return false;
    }
    else if(twos > 0 and threes == 0) {
        return possible(tgt+2,threes,twos-1);
    }
    else return false;
}

int main() {
	fastio
	int T = input<int>();
	loop(T,_){
        string s = input<string>();
        ll twos =0,threes = 0;
        ll sm = 0;
        fa(x,s){
            if(x == '2') twos ++;
            else if(x == '3')threes++;
            sm += (x-'0');
        }
        sm = sm%9;
        if(sm != 0){
            if(possible(sm,threes,twos)) YES;
            else NO;
        }
        else YES;
	}
	return 0;
}

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

typedef long long ll;
#define inarr(arr, n) ll arr[n];for (ll i = 0; i < n; i++) cin>>arr[i]
#define in(n) ll n;cin>>n
#define inn(n,k) ll n,k;cin>>n>>k
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"
#define on(n) cout<<n<<endl
#define ff first
#define ss second
#define rr return

#define pb emplace_back
#define vll vector<ll>
#define vinp(x) for(auto &i:x) cin>>i
#define vpll vector<pair<ll,ll>>
#define mapll map<ll,ll>
#define sll set<ll, ll>
#define lb(c, x) distance((c).begin(),lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(),upper_bound(all(c), (x)))

#define mod ll(1000000007)
//#define mod ll(998244353)

#define all(x) x.begin(), x.end()
#define fi(l, r) for(ll i=l;i<r;i++)
#define fj(l, r) for(ll j=l;j<r;j++)
#define fir(r, l) for(ll i=r;i>=l;i--)
#define fjr(r, l) for(ll j=r;j>=l;j--)

bool sorta(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
bool sortd(const pair<int,int> &a,const pair<int,int> &b){return (a.second > b.second);}

ll power(ll n,ll a){ ll res=1; while(a){ if(a%2)res*=n,a--; else   n*=n,a/=2;} return res;}
ll modpower(ll n,ll a,ll p){ ll res=1; while(a){if(a%2) res= ((res*n)%p) ,a--; else n=((n*n)%p),a/=2;} return res;}
ll mod_mul_inverse(ll a,ll b){
    return modpower(a , b-2, b);
}
ll mod_add(ll a,ll b,ll m){
    return (a%m+b%m)%m;
}
ll mod_mult(ll a,ll b,ll m){
    return (a%m*b%m)%m;
}
ll mod_div(ll a,ll b,ll m){
    return mod_mult(a,mod_mul_inverse(b,m),m);
}

bool fastprime(ll a){ if (a != 2 && a % 2 == 0 || a < 2)return false;  for(ll i = 3; i * i <= a; i += 2) if(a % i== 0) return false; return true;}
bool isPowerOfTwo(int n){if(n==0)return false;return (ceil(log2(n)) == floor(log2(n)));}
bool isPerfectSquare(ll x){if (x >= 0) {ll sr = sqrt(x);return (sr * sr == x);}return false;}

bool sortbysec(const pair<ll,ll> a,const pair<ll,ll>b){if (a.second!=b.second){return a.second<b.second;}else{return a.first<b.first;}}

vll getBinary(ll k){vll ans; while(k){ll rem=k%2; ans.pb(rem); k/=2;} return ans;}

ll MSBPosition(ll N)
{
    ll msb_p = -1;
    while (N) {
        N = N >> 1;
        msb_p++;
    }
    return msb_p;
}
 
// Returns the Bitwise OR of all
// llegers between L and R
ll findBitwiseOR(ll L,ll R)
{
    ll res = 0;
 
    // Find the MSB position in L
    ll msb_p1 = MSBPosition(L);
 
    // Find the MSB position in R
    ll msb_p2 = MSBPosition(R);
 
    while (msb_p1 == msb_p2) {
        ll res_val = (1 << msb_p1);
 
        // Add this value until msb_p1 and
        // msb_p2 are same;
        res += res_val;
 
        L -= res_val;
        R -= res_val;
 
        // Calculate msb_p1 and msb_p2
        msb_p1 = MSBPosition(L);
        msb_p2 = MSBPosition(R);
    }
    // Find the max of msb_p1 and msb_p2
    msb_p1 = max(msb_p1, msb_p2);
 
    // Set all the bits from msb_p1 upto
    // 0th bit in the result
    for (ll i = msb_p1; i >= 0; i--) {
        ll res_val = (1 << i);
        res += res_val;
    }
    return res;
}

void SieveOfEratosthenes(ll n,vll &v)
{
    bool prime[n + 1];
    memset(prime, true, sizeof(prime));
 
    for (ll p = 2; p * p <= n; p++) {
        
        if (prime[p] == true) {
            
            for (ll i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }
 
    for (ll p = 2; p <= n; p++)
        if (prime[p])
            v.pb(p);
}

map<ll, set<ll> > mp;
void dfs(ll root)
{
    if(mp[root].size()==0){
        rr;
    }
    for(auto it:mp[root]){
        mp[it].erase(root);
        dfs(it);
    }
}

void bfs(ll root)
{
    queue<ll> q;
    q.push(root);
    while(!q.empty())
    {
        ll tmp=q.front();
        q.pop();
        for(auto it:mp[tmp])
        {
            q.push(it);
            mp[it].erase(tmp);
        }
    }
}

void solve()
{
    string str; cin>>str;
    ll sod=0;
    ll twos=0,three=0;
    fi(0,str.size()){
        if(str[i]=='2') twos++;
        if(str[i]=='3') three++;
        sod+=str[i]-'0';
    }
    if(sod%9==0){
        yes;
        return;
    }
    
    ll flag=0;
    fi(0,twos+1){
        fj(0,three+1){
            if((sod+ 2*i +6*j) % 9 ==0){
                yes;
                flag=1;
                break;
            }
        }
        if(flag) break;
    }
    if(!flag) no;
    }

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


    ll t;
    cin >> t;
    while (t--) {
        solve();
    }
}