Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 62 ms):
#include <iostream>
#include <math.h>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;

bool recursion(ll sum, ll two, ll three){
    if(sum%9 == 0){
        return true;
    }else if(two == 0 && three == 0){
        return false;
    }
    if(two > 0 && three > 0){
        return recursion(sum+2, two-1, three) || recursion(sum+6, two, three-1);
    }else if(two > 0){
        return recursion(sum+2, two-1, three);
    }else{
        return recursion(sum+6, two, three-1);
    }
}

void answer(){
    string a;
    cin >> a;
    ll sum = 0;
    ll two = 0;
    ll three = 0;
    for(ll i = 0; i<a.length();i++){
        sum += a[i] - '0'; 
        if(a[i] == '2' && two < 9){
            two++;
        }else if(a[i] == '3' && three < 9){
            three++;
        }
    }
    if(recursion(sum, two, three)){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
}

int main(){
    int n;
    cin >> n;
    for(int i = 0; i<n;i++){
        answer();
    }
    return EXIT_SUCCESS;
}

Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>

using namespace std;

int two,three;

int mod9(const string& num) {

    int remainder = 0;



    // 遍历字符串中的每一位

    for (char digit : num) {

        if (digit == '2')

        {

            two = two+1;

        }

        else if(digit=='3')

        {

           three = three+1;

        }

        remainder = (remainder * 10 + (digit - '0')) % 9;

    }



    return remainder;

}



int main() {

    int t;

    cin >> t;

    while (t--) 

    {

        two = 0;

        three = 0;

        string num;

        cin >> num;



        int result = mod9(num);

        if (result == 0)

        {

            cout << "YES" << endl;

            continue;

        }

        if (result == 1)

        {

            if (two >= 4)

            {

                cout << "YES" << endl;

                continue;

            }

            if (two >= 1 && three >= 1)

            {

                cout << "YES" << endl;

                continue;

            }

        }

        if (result == 2)

        {

            if (two >= 8)

            {

                cout << "YES" << endl;

                continue;

            }

            if (two >= 5 && three >= 1)

            {

                cout << "YES" << endl;

                continue;

            }

            if (two >= 2 && three >= 2)

            {

                cout << "YES" << endl;

                continue;

            }

        }

        if (result == 3)

        {

            if (two >= 3)

            {

                cout << "YES" << endl;

                continue;

            }

            if (three >= 1)

            {

                cout << "YES" << endl;

                continue;

            }

        }

        if(result==4)

        {

            if (two >= 7)

            {

                cout << "YES" << endl;

                continue;

            }

            if (two >= 4 && three >= 1)

            {

                cout << "YES" << endl;

                continue;

            }

            if (two >= 1 && three >= 2)

            {

                cout << "YES" << endl;

                continue;

            }

        }

        if (result == 5)

        {

              

            if (two >= 2)

            {

                cout << "YES" << endl;

                continue;

            }

        }

        if (result == 6)

        {

            if (two >= 6)

            {

                cout << "YES" << endl;

                continue;

            }

            if (two >= 3 && three >= 1)

            {

                cout << "YES" << endl;

                continue;

            }

            if (three >= 2)

            {

                cout << "YES" << endl;

                continue;

            }

        }

        if (result == 7)

        {

            if (two >= 1)

            {

                cout << "YES" << endl;

                continue;

            }

        }

        if (result == 8)

        {

            

            if (two >= 5)

            {

                cout << "YES" << endl;

                continue;

            }

            if (two >= 2 && three >= 1)

            {

                cout << "YES" << endl;

                continue;

            }

        }

        cout << "NO" << endl;

    }



}