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;
#define alsammany ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x) cout<<#x<<" = "<<x<<endl
#define debugg(x, y) cout<<#x<<" = "<<x<<", "<<#y<<" = "<<y<< endl
#define vvi(r, c) vvi(r, vi(c))
#define vin(v) for(auto &i:(v))cin>>i
#define rall(v) v.rbegin(),v.rend()
#define all(v) v.begin(),v.end()
#define F first
#define S second
template <typename T> void display(const T& container) { cout << "{ "; for (const auto& element : container) { cout << element << " "; } cout << "}" << endl; } template <typename K, typename V> void display(const map<K, V>& container) { for (const auto& pair : container) { cout << "\n[" << pair.first << "]: "; display(pair.second); } }
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<pair<int,int>> vp; // vp vec(n, make_pair(0, 0));
typedef vector<vector<int>> vvi;
// struct Triple{ int first; int second; int index; };
// sort(vec.begin(), vec.end(), [](const Triple& a, const Triple& b) {return a.first < b.first;});

void Solve(){
    string s; cin>>s;
    ll sum = 0;
    bool f = 0;
    for(auto e:s){
        int num = e - '0';
        sum += num;
        if(num == 3) f = 1;
    }

    if(sum % 9 == 0) {cout<<"YES"; return;}

    sort(all(s));
    
    for(auto e:s){
        if(e == '2') {
            sum+=2;
            if( (sum+6) % 9 == 0 && f) {cout<<"YES"; return;}
        }
        if(e == '3') sum+=6;

        if(sum % 9 == 0) {cout<<"YES"; return;}
    }

    reverse(all(s));

    for(auto e:s){
        if(e == '2') sum+=2;
        if(e == '3'){
            sum+=6;
            if( (sum+2) % 9 == 0 && f) {cout<<"YES"; return;}
        }
        if(sum % 9 == 0) {cout<<"YES"; return;}
    }

    cout<<"NO";
    
}   

int main(){
    alsammany
    int t; cin >> t; while(t--){
        Solve();
        cout << endl;
    }
    return 0;
}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
#define alsammany ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x) cout<<#x<<" = "<<x<<endl
#define debugg(x, y) cout<<#x<<" = "<<x<<", "<<#y<<" = "<<y<< endl
#define vvi(r, c) vvi(r, vi(c))
#define vin(v) for(auto &i:(v))cin>>i
#define rall(v) v.rbegin(),v.rend()
#define all(v) v.begin(),v.end()
#define F first
#define S second
template <typename T> void display(const T& container) { cout << "{ "; for (const auto& element : container) { cout << element << " "; } cout << "}" << endl; } template <typename K, typename V> void display(const map<K, V>& container) { for (const auto& pair : container) { cout << "\n[" << pair.first << "]: "; display(pair.second); } }
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<pair<int,int>> vp; // vp vec(n, make_pair(0, 0));
typedef vector<vector<int>> vvi;
// struct Triple{ int first; int second; int index; };
// sort(vec.begin(), vec.end(), [](const Triple& a, const Triple& b) {return a.first < b.first;});

bool fun(int need, int sum2, int sum6){

    if(sum2 == 0 && sum6 == 0) return false; // base case
    while(need > 0){
        if(need >= 6 && sum6) need-=6, sum6--;
        else if(need >= 2 && sum2) need-=2, sum2--;
    }
    if(need = 0) return true;

    return fun(need+9, sum2, sum6);
}


bool calc(int need, int sum2, int sum6){
    
    // debug(need);
    // debugg(sum2,sum6);

    if(need == 0) return true;
    if(need == 2 && sum2) return true;
    if(need == 4 && sum2 > 1) return true;
    if(need == 6 && sum6) return true;

    if(!sum6) return false;
    if(need == 2 && !sum2) return false;
    if(need == 4 && sum2 < 2) return false;


    if(need > 6 && sum6) return calc(need-6, sum2, --sum6);

    return calc(need+9, sum2, sum6);
}

void Solve(){
    string s; cin>>s;
    ll sum = 0;
    ll sum2 = 0;
    ll sum6 = 0;
    for(auto e:s){
        int num = e - '0';
        if(num == 2) sum2++;
        if(num == 3) sum6++;
        sum += num;
    }
    if(sum % 9 == 0) {cout<<"YES"; return;}
    if(sum2 > 3) {
        int r = sum2 % 3;
        sum6 += (sum2-r) / 3;
        sum2 = r;
    }
    int rem = sum % 9;
    int need = 9 - rem;

    if(calc(need, sum2, sum6)) cout<<"YES";
    else cout<<"NO";
    
}   

int main(){
    alsammany
    int t; cin >> t; while(t--){
        Solve();
        cout << endl;
    }
    return 0;
}