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

Solution 1 (runtime: 77 ms):
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <utility>
#include <iterator>
#include <cmath>
#include <limits>
#include <numeric>
#include <queue>
#include <map>
#include <climits>
#include <iomanip>
#include <stack>
#include <list>
#include <bitset>
// #include <bits/stdc++.h>
using namespace std;

#define ll long long
#define nl "\n"
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
const ll mod = 1e9 + 7;

ll power(ll x, ll y)
{
    ll ans = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y % 2 == 1)
        {
            ans = (ans * x) % mod;
        }
        y = y / 2;
        x = (x * x) % mod;
    }
    return ans;
}

ll modInverse(ll n)
{
    return power(n, mod - 2);
}

vector<ll> factorial(1e6 + 5, 0);
void getFactorial()
{
    factorial[0] = 1;
    for (ll i = 1; i <= 1e6; i++)
    {
        factorial[i] = (factorial[i - 1] * i) % mod;
    }
}

ll nCr(ll n, ll r)
{
    if (n < r)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    return (((factorial[n] * modInverse(factorial[r]))) % mod * (modInverse(factorial[n - r])) % mod) % mod;
}
ll ceil(ll x, ll k)
{
    return x / k + (x % k != 0);
}

void solveTest()
{
    string n;
    cin >> n;
    ll sum = 0;
    ll twos = 0, threes = 0;
    rep(i, n.length())
    {
        sum+=n[i]-'0';
        if(n[i]=='2') twos++;
        if(n[i]=='3') threes++;
    }
    twos=min(twos, 8LL);
    threes=min(threes, 8LL);
    for (int i = 0; i <= twos; i++)
    {
        for (int j = 0; j <= threes; j++)
        {
            if ((sum + 2 * i + 6 * j) % 9 == 0)
            {
                cout << "YES" << nl;
                return;
            }
        }
    }
    cout << "NO" << nl;
    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int tt;
    cin >> tt;
    while (tt--)
        solveTest();
    return 0;
}

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

#define fr(x) for (int i = 1; i <= x; i++)
#define debug(x) cout << x << "\n"
#define MAXN 300006
#define MOD 998244353
typedef long long int ll;

int arr[MAXN];

ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1);
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll modInverse(ll b, ll m)
{
    ll x, y;
    ll g = gcdExtended(b, m, &x, &y);
    return (x%m + m) % m;
}

ll divisionModular(ll a, ll b, ll m)
{
    a = a % m;
    ll inv = modInverse(b, m);
    ll resp = (inv * a) % m;
    return resp;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t;
    cin >> t;

    while(t--){
        string n;
        int sum = 0, dos = 0, seis = 0;
        cin >> n;
        for (char num: n ){
            sum += (num - '0');
            if(num == '2') dos++;
            if(num == '3') seis++;
        }

        bool pudo = false;
        if(sum % 9 == 0) pudo = true;

        for (int i = 1; i <= 100000; i++){
            int posible  = sum + (2 * i);
            if(posible % 9 == 0){
                int seisNeed = i / 3;
                int dosNeed = i - (seisNeed * 3);
                if(seisNeed > seis){
                    seisNeed -= seis;
                    dosNeed = dosNeed + (seisNeed * 3);
                }
                if(dos >= dosNeed){
                    pudo = true;
                    break;
                }
            }
        }

        if(pudo) cout << "YES";
        else cout << "NO";

        cout << "\n";
    }

    return 0;
}

/*
1
6 8
1 4 2 7 3 5
7 6 5 6 3 3
2 5
1 6
1 5
1 5
1 5
2 3
2 3
1 6



2 3 3 3 4 4 4 4 4 4 5 6 7 7 7 7 9
*/