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

Previous submission (verdict: Wrong answer on test 3):
#include<bits/stdc++.h>
using namespace std;

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fori(i, a, b) for(int i = a; i < b; ++i)
#define rfori(i, a, b) for(int i = a; i >= b; --i)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define f first
#define s second
#define clr(a) memset(a, 0, sizeof(a))
#define set_mem(a, b) memset(a, b, sizeof(a))
#define sz(v) (int)v.size()
#define umap unordered_map
#define uset unordered_set
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pq priority_queue
#define minpq(x) priority_queue<x, vector<x>, greater<x>>

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef unordered_map<int, int> umii;
typedef unordered_set<int> usi;

void solve() {
    ll n; 
    cin >> n;
    ll cntT = 0, cntTh = 0, sum = 0;
    string num = to_string(n);

    for (auto it : num) {
        if (it == '2') cntT++;
        if (it == '3') cntTh++;
        sum += (it - '0');
    }

    ll need = (9 - (sum % 9)) % 9;


    while(need%2!=0 && need<(cntT*2+cntTh*6)) need+=9;
  
  
    while (need % 9 != 0) {
        if(need%6==0 && cntTh*6>=need){
        cout<<"YES"<<endl;
        return;
    }
    if(need%2==0 && cntT*2>=need){
        cout<<"YES"<<endl;
        return;
    }
        if (need % 2 == 0 && cntT > 0) {
            need -= 2;
            cntT--;
        } else if (need % 6 == 0 && cntTh > 0) {
            need -= 6;
            cntTh--;
        } else {
            break; 
        }
    }

    if (need % 9 == 0) 
        cout << "YES\n";
        
    else 
        cout <<"NO\n";
}


int main() {
    fast_io;

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fori(i, a, b) for(int i = a; i < b; ++i)
#define rfori(i, a, b) for(int i = a; i >= b; --i)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define f first
#define s second
#define clr(a) memset(a, 0, sizeof(a))
#define set_mem(a, b) memset(a, b, sizeof(a))
#define sz(v) (int)v.size()
#define umap unordered_map
#define uset unordered_set
#define pll pair<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pq priority_queue
#define minpq(x) priority_queue<x, vector<x>, greater<x>>

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef unordered_map<int, int> umii;
typedef unordered_set<int> usi;

void solve() {
    string n; 
    cin >> n;
    ll cntT = 0, cntTh = 0, sum = 0;
    

    for (auto it : n) {
        if (it == '2') cntT++;
        if (it == '3') cntTh++;
        sum += (it - '0');
    }

    ll need = (9 - (sum % 9)) % 9;


    while(need%2!=0 && need<(cntT*2+cntTh*6)) need+=9;
  
  
    while (need % 9 != 0) {
        if(need%6==0 && cntTh*6>=need){
        cout<<"YES"<<endl;
        return;
    }
    if(need%2==0 && cntT*2>=need){
        cout<<"YES"<<endl;
        return;
    }
        if (need % 2 == 0 && cntT > 0) {
            need -= 2;
            cntT--;
        } else if (need % 6 == 0 && cntTh > 0) {
            need -= 6;
            cntTh--;
        } else {
            break; 
        }
    }

    if (need % 9 == 0) 
        cout << "YES\n";
        
    else 
        cout <<"NO\n";
}


int main() {
    fast_io;

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}