Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll t;
    cin >> t;
    while(t--){
        string s;
        cin >> s;
        ll sum=0;
        ll f2=0,f3=0;
        for(int i=0;i<s.size();i++){
            sum+=(ll)s[i]-'0';
            if(s[i]=='2'){
                f2++;
            }
            else if(s[i]=='3'){
                f3++;
            }
        }
        if(sum%9==0){
            cout << "YES" << "\n";
            continue;
        }
        else{
            if(f2==0 && f3==0){
                cout << "NO" << "\n";
                continue;
            }
            if(f2==0){
                if(sum%3==0){
                    if((sum+6)%9==0 || (sum+12)%9==0){
                        cout << "YES" << "\n";
                        continue;
                    }
                }
            }
            ll minc=(ll)2*f2 + (ll)6*f3;
            ll p=(ll)((sum/9)+1)*9;
            vector<ll> req;
            while((p-sum)<=minc){
                if(sum%2==0 && p%2==0){
                    req.push_back(p-sum);
                }
                else if(sum%2!=0 && p%2!=0){
                    req.push_back(p-sum);
                }
                p+=(ll)9;
            }
            if(req.size()==0){
                cout << "NO" << "\n";
                continue;
            }
            ll gh=0;
            for(int i=0;i<req.size();i++){
                for(int j=0;j<=f3;j++){
                    if((req[i]-(ll)j*6)%2==0 && (req[i]-(ll)j*6)/2>=0 && (req[i]-(ll)j*6)/2<=f2){
                        gh++;
                        break;
                    }
                }
                if(gh>0){
                    break;
                }
            }
            if(gh>0){
                cout << "YES" << "\n";
            }     
            else{
                cout << "NO" << "\n";
            }
        }
    }
    return 0;
}

Submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll t;
    cin >> t;
    while(t--){
        string s;
        cin >> s;
        ll sum=0;
        ll f2=0,f3=0;
        for(int i=0;i<s.size();i++){
            sum+=(ll)s[i]-'0';
            if(s[i]=='2'){
                f2++;
            }
            else if(s[i]=='3'){
                f3++;
            }
        }
        if(sum%9==0){
            cout << "YES" << "\n";
            continue;
        }
        else{
            if(f2==0 && f3==0){
                cout << "NO" << "\n";
                continue;
            }
            if(f2==0){
                if(sum%3==0){
                    if((sum+6)%9==0){
                        cout << "YES" << "\n";
                        continue;
                    }
                    else if(f3>1 && (sum+3)%9==0){
                        cout << "YES" << "\n";
                        continue;
                    }
                }
                else{
                    cout << "NO" << "\n";
                    continue;
                }
            }
            ll minc=(ll)2*f2 + (ll)6*f3;
            ll p=(ll)((sum/9)+1)*9;
            vector<ll> req;
            while((p-sum)<=minc){
                if(sum%2==0 && p%2==0){
                    req.push_back(p-sum);
                }
                else if(sum%2!=0 && p%2!=0){
                    req.push_back(p-sum);
                }
                p+=(ll)9;
            }
            if(req.size()==0){
                cout << "NO" << "\n";
                continue;
            }
            ll gh=0;
            for(int i=0;i<req.size();i++){
                for(int j=0;j<=f3;j++){
                    if((req[i]-(ll)j*6)%2==0 && (req[i]-(ll)j*6)/2>=0 && (req[i]-(ll)j*6)/2<=f2){
                        gh++;
                        break;
                    }
                }
                if(gh>0){
                    break;
                }
            }
            if(gh>0){
                cout << "YES" << "\n";
            }     
            else{
                cout << "NO" << "\n";
            }
        }
    }
    return 0;
}