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

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

long long m=1000000007;

long long  power(int x, unsigned int y)
{
    long long  temp;
    if (y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return ((temp%m) * (temp%m))%m;
    else
        return  (x%m * temp%m * temp%m)%m;
}
void solv() {
    int n ,m,k;
    cin >> n >> m >> k;
    int a[m];
    int b[k];
    for(int i = 0 ; i < m ; i++) cin>>a[i];
    for(int i = 0 ; i < k ; i++) cin>>b[i];
    string ans="";
    if(n-k >1){
      for(int i = 0 ; i < m ; i++) ans+='0';
      cout << ans << endl;
      return;
    }
    if(k==n){
      for(int i = 0 ; i < m ; i++) ans+='1';
      cout << ans << endl;
      return;
    }
    int miss=1;
    for(int i = 0 ; i < k ; i++) {
       if(b[i] != miss) break;
       else{
        miss++;
       }
    }
    for(int i =0 ;i < m ;i++){
      if(a[i] == miss) ans+='1';
      else ans+='0';
    }
    cout << ans <<endl;
 
}

vector<int> storePrime(){
        int n = 1000;
        vector<bool> prime(n+1,1);
        for(int i = 2;i<=n;i++){
            if(prime[i]){
                for(int j = 2*i;j<=n;j+=i){
                    prime[i] = 0;
                }
            }
        }
        vector<int> ans;
        for(int i = 2;i<=n;i++){
            if(prime[i])    ans.push_back(i);
        }
        return ans;
    }

	int binary(long long arr[],long long n,long long k,int y)
	{
		int s=0,e=n-1;
		int mid=s+(e-s)/2;
		while(s<e)
		{
			
			if(arr[mid]==y && mid!=k)
			return arr[mid];
			else
			e--;
			if(arr[mid]<y)
			{
				s=mid+1;
			}
			if(arr[mid]>y)
			e=mid-1;

			mid=s+(e-s)/2;
		}
		return 0;
	}

int main () {
	 #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

	int t;
	cin>>t;
	while(t--)
    {
		long long x;
        long long sum=0;
        string s;
        cin>>s;
        long long th=0,tw=0;
        for(int i=0;i<s.length();i++)
        {
            sum+=s[i]-'0';
            //cout<<"s[i] "<<s[i]<<" ";
            if(s[i]=='3')
            th++;
            if(s[i]=='2')
            tw++;
        }
        //cout<<endl;
        //cout<<"sum is "<<sum<<endl;
        
        if(sum%9==0)
        cout<<"YES\n";
        else
        {
            bool flag=false;
            //cout<<"th is "<<th<<endl;
            //cout<<"tw is "<<tw<<endl;
            

            for(int i=0;i<=min(tw,9LL);i++)
            {
                for(int j=0;j<=min(th,9LL);j++)
                {
                    if((sum+2*i+6*j)%9==0)
                    {
                        //cout<<"hi\n";
                        flag=true;
                        break;
                    }
                }
            }
            if(flag)
            cout<<"YES\n";
            else
            cout<<"NO\n";
        }

    }
	
}


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

struct pair_hash {
    template <class T1, class T2>
    size_t operator () (const pair<T1, T2>& pair) const {
        auto hash1 = hash<T1>{}(pair.first);
        auto hash2 = hash<T2>{}(pair.second);
        return hash1 ^ hash2; // 使用异或组合两个哈希值
    }
};

bool pd = 0;
unordered_set<pair<int, int>,pair_hash> hs;
void funa(int js2, int js3, int sum) {
    // cout << js2 << " " << js3 << " " << sum << endl;
    if (hs.find(make_pair(js2, js3)) != hs.end()) return;
    hs.insert(make_pair(js2,js3));
    if (sum % 9 == 0) pd = 1;
    if (pd||(js2==0&&js3==0)) return;
    int ans = 0;
    if (js2 >= 1) {
        funa(js2 - 1, js3, sum + 2);
    }
    if (js3 >= 1) {
        funa(js2, js3 - 1, sum + 6);
    }
    // funa(js2, js3, sum);
}

signed main() {
    int t; cin >> t;
    while (t--) {
        pd = 0;
        hs.clear();
        string s; cin >> s;
        int js2 = 0, js3 = 0;
        int sum = 0;
        for (auto ele : s) {
            if (ele == '2') js2++;
            if (ele == '3') js3++;
            sum += ele - '0';
        }
        // cout << "sum=" << sum << endl;
        if (sum % 9 == 0) cout << "YES" << endl;
        else {
            funa(js2, js3, sum);
            if (pd) cout << "YES" << endl;
            else cout << "NO" << endl;
        }
    }
}