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

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

void accelerate()
{
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}

void solve() {
    string n;
    cin >> n;
    int sum = 0;
    int two = 0;
    int three = 0;
    for (auto c : n) {
        int d = c - '0';
        sum = (sum + d) % 9;
        if (d == 2) two++;
        else if (d == 3) three++;
    }
    int dp[9] = {0};
    dp[sum] = 1;
    for (int i = 0; i < two && i < 8; i++) {
        sum = (sum + 2) % 9;
        dp[sum] = 1;
    }
    if (dp[0] || (dp[3] && three >= 1) || (dp[6] && three >= 2)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

signed main() {
    // accelerate();
    int tc = 1;
    cin >> tc;
    while (tc--) {
        solve();
    }
    return 0;
}


Solution 2 (runtime: 46 ms):
    #include <bits/stdc++.h>
    // #include<ext/pb_ds/assoc_container.hpp>
    // #include<ext/pb_ds/tree_policy.hpp>
    #include<limits.h>
    using namespace std;
    // using namespace __gnu_pbds;

    typedef long long ll;
    typedef vector<int> vi;
    typedef vector<vi> vvi;
    typedef vector<ll> vll;
    typedef pair<int, int> pi;

    int mod = int(1e9 + 7);

    // Operator overloads
    template<typename T1, typename T2> // cin >> pair<T1, T2>
    istream& operator>>(istream &istream, pair<T1, T2> &p) { return (istream >> p.first >> p.second); }
    template<typename T> // cin >> vector<T>
    istream& operator>>(istream &istream, vector<T> &v){for (auto &it : v)cin >> it;return istream;}
    template<typename T1, typename T2> // cout << pair<T1, T2>
    ostream& operator<<(ostream &ostream, const pair<T1, T2> &p) { return (ostream << p.first << " " << p.second); }
    template<typename T> // cout << vector<T>
    ostream& operator<<(ostream &ostream, const vector<T> &c) { for (auto &it : c) cout << it << " "; return ostream; }

    // tree ordered set
    // template<typename T>
    // using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

    void fast() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    }
    // intersect part of two strings

    // !! ॐ !!
    ll sum(string n, int &cnt2, int &cnt3) {
        ll sum = 0;
        cnt2 = 0;
        cnt3 = 0;
        for(char c:n){
            int digit = c - '0';
            sum += digit;
            if(digit == 2) cnt2++;
            if(digit == 3) cnt3++;
        }
        return sum;
    }

    void solve() {
        string n;
        cin >> n;

        int cnt2 = 0, cnt3 = 0;
        int val = sum(n, cnt2, cnt3);

        if (val % 9 == 0) {
            cout << "YES\n";
            return;
        }

        int c2 = 2, c3 = 6;
        for (int i = 0; i <= min(10, cnt2); i++) {
            for (int j = 0; j <= min(10, cnt3); j++) {
                int k = c2 * i + c3 * j;
                if ((val + k) % 9 == 0) {
                    cout << "YES\n";
                    return;
                }
            }
        }
        cout << "NO\n";
    }


    int main() {
        fast();
        // pre();
        int T=1;
        cin >> T;
        while(T--){
            solve();
        }
        return 0;
    }