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

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;

bool check(string n, int rem) {
    int twos = 0, threes = 0;
    for (char c : n) {
        if (c == '2') twos++;
        if (c == '3') threes++;
    }
    
    for (int x = 0; x <= twos; x++) {  // Replace x '2's
        for (int y = 0; y <= threes; y++) {  // Replace y '3's
            if ((rem + 2 * x + 6 * y) % 9 == 0) {
                return true;
            }
        }
    }
    
    return false;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        string n;
        cin >> n;
        int sum = 0;
        for (char c : n) {
            sum += c - '0';
        }
        int remainder = sum % 9;
        if (check(n, remainder))
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
    return 0;
}


Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        int n = s.size();
        int sum = 0;
        for (int i = 0; i < n; i++)
            sum += (s[i] - '0');
        int need = 9 - sum % 9;
        int two = 0, three = 0;
        for (int i = 0; i < n; i++)
        {
            if (s[i] == '2')
                two++;
            else if (s[i] == '3')
                three++;
        }
        if (need == 9)
            cout << "YES" << endl;
        else if (need == 1)
        {
            if (two >= 5)
                cout << "YES" << endl;
            else if (two >= 2 && three >= 1)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
        else if (need == 2)
        {
            if (two >= 1)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
        else if (need == 3)
        {
            if (two >= 6)
                cout << "YES" << endl;
            else if (two >= 3 && three >= 1)
                cout << "YES" << endl;
            else if (three >= 2)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
        else if (need == 4)
        {
            if (two >= 2)
                cout << "YES" << endl;

            else
                cout << "NO" << endl;
        }
        else if (need == 5)
        {
            if (two >= 7)
                cout << "YES" << endl;
            else if (two >= 1 && three >= 2)
                cout << "YES" << endl;
            else if (two >= 4 && three >= 1)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
        else if (need == 6)
        {
            if (two >= 3)
                cout << "YES" << endl;
            else if (three >= 1)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
        else if (need == 7)
        {
            if (two >= 8)
                cout << "YES" << endl;
            else if (two >= 2 && three >= 2)
                cout << "YES" << endl;
            else if (two >= 5 && three >= 1)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
        else if (need == 8)
        {
            if (two >= 4)
                cout << "YES" << endl;
            else if (two >= 1 && three >= 1)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
    }
}