Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)


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 n = s.length();
        ll rem = 0;
        for(ll i=0;i<n;i++){
            rem+=(s[i] - '0');
            rem%=9;   
        }
        rem = 9-rem;
        //cout<<rem<<endl;
        bool valid = false;
        if(rem == 1 || rem == 3 || rem == 5 || rem == 7){
            ll cnt2 = 0;
            ll cnt3 = 0;
            for(ll i=0;i<n;i++){
                if(s[i] == '2'){
                    cnt2++;
                }
                else if(s[i] == '3'){
                    cnt3++;
                }
            }
            if(rem == 1){
                if(cnt2 >=5){
                    valid = true;
                }
                else if(cnt2 >= 2 && cnt3 >= 1){
                    valid = true;
                }
                else{
                    valid = false;
                }
        }
        if(rem == 3){
            if(cnt3 >= 2){
                valid = true;
            }
            else if(cnt2 >= 6){
                valid = true;
            }
            else if(cnt3 >= 1 && cnt2 >= 3){
                valid = true;
            }
            else{
                valid = false;
            }
        }
        if(rem == 5){
            if(cnt2 >= 1 && cnt3 >= 2){
                valid = true;
            }
            else if(cnt2 >= 7){
                valid = true;
            }
            else{
                valid = false;
            }
        }
        if(rem == 7){
            if(cnt2 >= 8){
                valid = true;
            }
            else if(cnt2 >= 2 && cnt3 >= 2){
                valid = true;
            }
            else if(cnt2 >= 5 && cnt3 >= 1){
                valid = true;
            }
            else{
                valid = false;
            }
        }
        }
        else if(rem == 0 || rem == 9){
            valid = true;
        }
        else if(rem ==2 || rem == 4 || rem == 6 || rem == 8){
            ll cnt2 = 0;
            ll cnt3 = 0;
            for(ll i=0;i<n;i++){
                if(s[i] == '2'){
                    cnt2++;
                }
                else if(s[i] == '3'){
                    cnt3++;
                }
            }
            if(rem == 2){
                if(cnt2 >0){
                    valid = true;
                }
                else{
                    valid = false;
                }
            }
            if(rem == 4){
                if(cnt2 > 1){
                    valid = true;
                }
                else{
                    valid = false;
                }
            }
            if(rem == 6){
                if(cnt2 > 2){
                    valid = true;
                }
                else if(cnt3 >= 1){
                    valid = true;
                }
                else{
                    valid = false;
                }
            }
            if(rem == 8){
                if(cnt2 > 3){
                    valid = true;
                }
                else if(cnt2 > 1 && cnt3 >= 1){
                    valid = true;
                }
                else{
                    valid = false;
                }
            }
        }
        if(valid){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}