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

Solution 1 (runtime: 187 ms):
#define MOD 1000000007
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
unordered_map <int,unordered_map<int,unordered_map<int,int>>> dp;
bool helper(int twos,int threes,int rem){
    if(rem == 0){
        return true;
    }
    if(twos == 0 && threes == 0){
        return false;
    }
    if(dp[twos][threes].count(rem)){
       return dp[twos][threes][rem];
    }
    bool ans = false;
    if(twos > 0){
        ans |= helper(twos-1,threes,(rem+2)%9);
    }
    if(!ans && threes > 0){
        ans |= helper(twos,threes-1,(rem+6)%9);
    }
    if(!ans && twos >0 && threes > 0){
        ans |= helper(twos-1,threes-1,(rem+8)%9);
    }
    return dp[twos][threes][rem] = ans;
}
int main(){
    int t;
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        int n = s.size();
        int sum = 0;
        vector <int> vec(10,0);
        for(int i = 0;i<n;i++){
            vec[s[i]-'0']++;
            sum += (s[i]-'0');
        }
        if(sum%9 == 0){
            cout<<"yes"<<endl;
            continue;
        }
        int twos = vec[2],threes = vec[3]; 
        bool f = helper(twos,threes,sum%9);
        if(f){
            cout<<"yes"<<endl;
        } 
        else{
            cout<<"no"<<endl;
        }
    }
    return 0;
}

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

#define vi vector<int>
#define vll vector<long long>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<long long,long long>>
#define mod1 1000000007
#define mod2 998244353
#define INF 1e18
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define ff first
#define ss second
#define pi 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mn(nums) *min_element(nums.begin(),nums.end()) 
#define mx(nums) *max_element(nums.begin(),nums.end())
#define rep(i,a,b) for(ll i=(a) ; i<(b) ; i++)
#define read(a) for(auto &it : a) cin>>it
#define ll long long
#define yes cout << "YES" << endl 
#define no cout << "NO" << endl 
#define nl endl 
// Memoization map

bool isprime(ll x)
{
	if(x == 2) return true ;
	for(int i=2;i<x;i++)
	{
		if(x%i == 0) return false ;
	}
	return true ;
}
ll cell(ll a,ll b)
{
	ll res = a/b ;
	if(a%b) res++ ;
	return res ;
}

bool solver(vector<ll> &v, vector<vector<ll>>&dp, ll sum, ll ind)
{
	if(ind >= v.size())
	{
		if(sum == 0) return true ;
		return false ;
	}
	
	
	if(dp[ind][sum] != -1) return dp[ind][sum] ;
	
	bool take = false , nottake = false ;
	if(v[ind] == 2 or v[ind] == 3) 
	{
		ll a = v[ind] ;
		take = solver(v, dp, (sum+a*a-a)%9, ind+1) ;
	}
	nottake = solver(v, dp, sum%9, ind+1) ;
	
	return dp[ind][sum] = take or nottake ;
	
}
void solve() {   
    
        string s ;
        cin>>s ;
        vll v ;
        for(auto &it : s) v.pb(it-'0') ;
        
        ll sum = (accumulate(all(v),0LL))%9 ;
        
        vector<vector<ll>> dp(v.size(),vector<ll>(9,-1)) ;
        
        bool check = solver(v, dp, sum, 0) ;
        if(check) yes ;
        else no ;
    
        	
        
    }
 
 

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("Error.txt", "w", stderr);
    #endif

    ll t=1 ;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}