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

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long int
void io(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
}
int p2;
bool comp1(pair<int ,int> p1,pair<int,int> p2){
	if(p1.first<p2.first)	return true;
	if(p1.first==p2.first){
		if(p1.second<p2.second)	return true;
		else	return false;
	}
	return false;
}
bool comp2(pair<int ,int> p1,pair<int,int> p2){
	if(p1.first>p2.first)	return true;
	if(p1.first==p2.first){
		if(p1.second<p2.second)	return true;
		else	return false;
	}
	return false;
}
pair<int,int> compli(int n){
	ll b=0;
	ll a=0;
	p2=1;
	bool bol =true;
	while(n){
		//cout<<n<<endl;
		if(!(n%2)){
			a+=p2;
			b+=p2;
		}
		else if(bol){
			b+=p2;
			bol=false;
		}
		p2=p2<<1;
		n=n>>1;
	}
	return {a,b};
}
bool check(string sn,string sm){
	int n=sn.size();
	int i,j;
	int m=sm.size();
	if(sn==sm){
		//cout<<"same"<<endl;
		return true;}
	if(n<m){
		return false;
	}
	else{
		for(i=0; i<n-m+1; i++){
			for(j=0; j<m; j++){
				if(sn[i+j]!=sm[j])	break;
			}
			if(j==m){
				//cout<<"HELLO"<<endl;
				return true;}
		}
	}
	return false;
}

set<int> factors(double a){
	set<int> factor;
	int n=a;
	int sq=sqrt(a),i;
	for(i=1; i<=sq+1; i++){
		if(!(n%i)){
			factor.insert(i);
			factor.insert(n/i);
		}
	}
	return factor;
}
vector<int> dp(300005,-1);
int xor_solver(int a){
	if(dp[a]==-1)	dp[a]=(a^xor_solver(a-1));
	return dp[a];
}
void solve(){
	string s;
	cin>>s;
	int n=s.size();
	int sum=0,three=0,two=0,i,j,k;
	for(i=0; i<n; i++){
		sum+=s[i]-'0';
		if(s[i]-'0'==2)	two++;
		else if(s[i]-'0'==3)	three++;
	}
	if(!(sum%9)){
		cout<<"YES"<<endl;
		return;
	}
	int ans;
	int rem=9-(sum%9);
	for(k=0; k<3; k++){
		rem+=k*9;
		
	for(i=0; i<=two && 2*i<=rem; i++){
		ans=2*i;
		for(j=0; j<=three && ans+6*j<=rem; j++){
			
			if(ans+6*j==rem){
				cout<<"YES"<<endl;
				return;
			}
		}
	}}
	cout<<"NO"<<endl;
}

int main(){
	io();
	int T;
	
	cin>>T;

	while(T--){
		solve();
	}
}

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

#include <iostream>

using namespace std;

#define ll long long



bool solve(ll twos,ll threes,ll sum,map<pair<int,int>,int> &dp){

    if(sum==0){

        return true;

    }

    if(twos==0 && threes==0){

        return false;

    }

    if(dp.count({twos,threes})) return dp[{twos,threes}];

    //either add two or six

    bool way1 = false;

    if(twos>0){

        way1 = solve(twos-1,threes,(sum+2)%9,dp);

        if(way1) return dp[{twos,threes}] = true;

    }

    bool way2 = false;

    if(threes>0)

        way2 = solve(twos,threes-1,(sum+6)%9,dp);

        if(way2) return dp[{twos,threes}] = true;

    return dp[{twos,threes}]=max(way1,way2);

}



int main()

{

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        ll sum = 0;

        ll twos = 0, threes = 0;

        for(auto it:s){

            sum += it-'0';

            if(it-'0'==2){

                twos++;

            }else if(it-'0'==3){

                threes++;

            }

        }

        if(sum%9==0){

            cout<<"YES"<<endl;

            continue;

        }

        map<pair<int,int>,int> dp;

        bool ans = solve(twos,threes,sum%9,dp);

        if(ans){

            cout<<"YES"<<endl;

        }else{

            cout<<"NO"<<endl;

        }

    }



    return 0;

}