Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

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

int main(){
    int t;
    cin >> t;
    while(t--){
        string s;
        cin >> s;
        int three = 0, two = 0;
        int ans = 0;
        int n = s.size();

        int all_three = 1;

        for(int i = 0; i<n; i++){
            if(s[i] == '2'){
                two++;
            }
            else if(s[i] == '3'){
                three++;
            }
            ans += s[i] - '0';
            if(s[i]!='3') all_three = 0;
        }
        if(all_three){
            cout << "YES\n";
            continue;
        }
        int anss = ans;
        int val = 0;
        while(anss%9!=0){
            val++;
            anss++;
        }
        if(ans%9 == 0){
            cout << "YES\n";
        }
        else if(val<=8 and val%2 == 0){
            if(val == 2 and two>=1){
                cout << "YES\n";
            }
            else if(val == 4 and two>=2){
                cout << "YES\n";
            }
            else if(val == 6 and  three>=1){
                cout << "YES\n";
            }
            else if(val == 8 and two>=3){
                cout << "YES\n";
            }
            else{
                cout << "NO\n";
            }
        }
        else if(val%2==1){
            val+=9;
            if(val<= (two*2)+(three*6)){
                cout << "YES\n";
            }
            else{
                cout << "NO\n";
            }
        }
        else{
            cout << "NO\n";
        }
        // cout << s << "\nAns: " << ans << " val : " << val << "\n";
    }
}

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

int main(){
    int t;
    cin >> t;
    while(t--){
        string s;
        cin >> s;
        int sum = 0;
        int two = 0, three = 0;

        for(int i = 0; i<s.size(); i++){
            if(s[i] == '2') two++;
            else if(s[i] == '3') three++;

            sum+= s[i] - '0';
        }   
        
        if(sum%9==0){
            cout << "YES\n";
            continue;
        }

        vector <int> rems;
        int val = sum;
        while(val%9!=0){
            val++;
        }
        rems.push_back(val-sum);
        for(int i = 0; i<10; i++){
            val+=9;
            rems.push_back(val-sum);
        }
        // for(auto it: rems){
        //     cout << it << " ";
        // }
        // cout << "\n";

        bool found = 0;
        for(int i = 0; i<rems.size(); i++){
            int zero = rems[i];
            int tmp1 = two, tmp2 = three;
            while(zero!=0){
                if(zero>=6 and tmp2){
                    zero-=6;
                    tmp2--;
                }
                else if(zero>=2 and tmp1){
                    zero-=2;
                    tmp1--;
                }
                else{
                    break;
                }
            }
            if(zero==0){
                found = 1;
                break;
            }
        }
        if(found){
            cout << "YES\n";
        }
        else{
            cout << "NO\n";
        }
    }
}