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

Solution 1 (runtime: 62 ms):
using namespace std;
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define si set<int>
#define sll set<long long>
#define sc set<char>
#define ss set<string>
#define usi unordered_set<int>
#define pqi priority_queue<int>
#define pqll priority_queue<ll>
#define mii map<int, int>
#define umii unordered_map<int, int>
#define pii pair<int, int>
#define pllll pair<long long, long long>
#define f(i,s,e) for(int i = s; i < e; i++)
#define cf(i,s,e) for(int i = s; i <= e; i++)
#define rf(i,e,s) for(int i = e-1; i >= s; i--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define eb embrace_back
#define mp make_pair
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define sz(x) (int)(x).size()
#define fastioa ios::sync_with_stdio(0); cin.tie(0); freopen("a.in", "r", stdin); freopen("a.out", "w", stdout);
#define fastio ios::sync_with_stdio(0); cin.tie(0);
#define MOD 1000000007
#define inf 1e9  // Use for int (e.g., distance)
#define inf_ll 1e18  // Use for long long
#define eps 1e-9  // Precision for floating-point comparisons

void solve()
{
    string number;
    cin >> number;
    ll sum = 0;
    int a = 0, b = 0;
    for (char digit : number)
    {
        sum += (digit - '0');
        if (digit - '0' == 2) a++;
        if (digit - '0' == 3) b++;
    }
    cf (i, 0, min(8, a))
    {
        cf (j, 0, min(8, b))
        {
            if ((sum + i * 2 + j * 6) % 9 == 0)
            {
                cout << "YES" << "\n"; return;
            }
        }
    }
    cout << "No" << "\n";


}
int main()
{
    fastio
    int t; cin >> t;
    while (t --)
    {
        solve();
    }
}

Solution 2 (runtime: 77 ms):
#pragma GCC diagnostic ignored "-Wunused-const-variable"



#include <bits/stdc++.h>



using namespace std;



#define mp make_pair

#define mt make_tuple

#define pb push_back

#define sz(x) ((int)x.size())

#define forn(i, n) for(int i = 0; i < (int)(n); ++i)

#define for1(i, n) for(int i = 1; i < (int)(n); ++i)

#define nfor(i, n) for(int i = int(n) - 1; i >= 0; --i)

#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)

#define correct(x, y, n, m) (0 <= x && x < n && 0 <= y && y < m)

#define all(x) (x).begin(), (x).end()

#define lsb(x) ((-x)&(x))

#define fst first

#define snd second

#define endl "\n"



typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, int> pli;

typedef pair<ll, ll> pll;

typedef long double ld;

typedef tuple<int,int,int> iii;

typedef tuple<ll, ll, ll> lll;

typedef tuple<ld, ld, ld> ddd;



template<typename T> inline T abs(T a){ return ((a < 0) ? -a : a); }

template<typename T> inline T sqr(T a){ return a * a; }

template<class T> T gcd(T a, T b) { return a ? gcd (b % a, a) : b; }

template<class T> T lcm(T a, T b) { return a / gcd (a, b) * b; }

template<class T> T sign(T a) { return a > 0 ? 1 : (a < 0 ? -1 : 0); }



string to_string(string s) {

    return '"' + s + '"';

}

    

string to_string(const char* s) {

    return to_string((string) s);

}

    

string to_string(bool b) {

    return (b ? "true" : "false");

}



template<typename A, typename B>

string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }



template<typename A, typename B, typename C>

string to_string(tuple<A, B, C> t) { return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) +  ", " + to_string(get<2>(t)) + ")"; }



template<typename A>

string to_string(priority_queue<A> pq) {

    bool first = true;

    string res = "{";

    int sz = pq.size();

    forn(i, sz) {

        if (!first) {

            res += ", ";

        }

        first = false;

        res += to_string(pq.top());

        pq.pop();

    }

    res += "}";

    return res;

}



template<typename A>

string to_string(queue<A> q) {

    bool first = true;

    string res = "{";

    int sz = q.size();

    forn(i, sz) {

        if (!first) {

            res += ", ";

        }

        first = false;

        res += to_string(q.front());

        q.pop();

    }

    res += "}";

    return res;



}



   

template <typename A>

string to_string(A v) {

    bool first = true;

    string res = "{";

    for (const auto &x : v) {

        if (!first) {

            res += ", ";

        }

        first = false;

        res += to_string(x);

    }

    res += "}";

    return res;

}

 

void dbg() { cout << endl; }

template <typename Head, typename... Tail>

void dbg(Head H, Tail... T) {

    cout << " " << to_string(H);

    dbg(T...);

}

 

#ifdef DEBUG

#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg(__VA_ARGS__)

#else

#define dbg(...)

#endif

 

void fastIO() {

    cin.sync_with_stdio(false);

    cin.tie(0);

}

 

template<typename T>

vector<T> make_unique(vector<T> v) {

    sort(all(v));

    return v.resize(unique(all(v)) - v.begin());

}

 

int nxt() {

    int x;

    cin >> x;

    return x;

}

 

const int dx[4] = {0, 0, 1, -1};

const int dy[4] = {1, -1, 0, 0};

const int dxKn[8] = {-2, -1, 1, 2,  2,  1, -1, -2};

const int dyKn[8] = { 1,  2, 2, 1, -1, -2, -2, -1};

const int dxK[8] = {0, 0, 1, -1, 1, 1, -1, -1};

const int dyK[8] = {1, -1, 0, 0, 1, -1, 1, -1};

 

const int MOD = int(1e9) + 7;

const int INF = int(1e9) + 100;

const ll INF64 = 2e18;

const ld PI = ld(3.1415926535897932384626433832795);

const ld e = ld(2.7182818284590452353602874713527);

const ld EPS = 1e-9;

const string abc = "abcdefghijklmnopqrstuvwxyz";

//#############################

const int MAXN = 1000005;



int n, m; // sizes

vector<vector<int>> g; //graph, grid

string s;



void init() {

    cin >> s;

    n = sz(s);

    dbg(s);

}



void solve() {

    vector<vector<int>> dp(sz(s)+1, vector<int>(10, -1));

    int digit = s[0] - '0';

    digit %= 9;

    dbg(digit);

    dp[0][digit] = 1;

    if (sqr(digit) < 10) dp[0][sqr(digit) % 9] = 1;

    dbg(dp);

    for1(i, n) {

        int digit = s[i] - '0';

        int sqrDigit = sqr(digit);



        forn(md, 10) {

            if (dp[i-1][md] == -1) continue;



            int sum = md + digit;

            sum %= 9;

            dbg(sum);

            dp[i][sum] = 1;



            if (sqrDigit < 10) {

                sum = md + sqrDigit;

                sum %= 9;

                dp[i][sum] = 1;

            }

        }

    }



    dbg(dp);

    bool yes = dp[n-1][0] == 1;

    cout << (yes ? "YES" : "NO") << endl;

}



signed main() {

    fastIO(); 

    int t = nxt();

    while(t--) {

        init();

        solve(); 

    }

    return 0;

}



/*

    RECALL CORNER CASES - e.g. n = 1, n = 0

    WRITE SOME STUFF



    think first, always - 

    1. concretely

    2. graphically 

    3. abstractly

    4. algebraically



    Checklist:

    - I/O make sense?   - Exclusion/inclusion           - Is a known sequence?

    - Reverse           - Brute force approach          - DP

    - Sort input        - Greedy approach               - Split into cases: Even/odd cases

    - Check diagonals   - Divide and Conquer approach

*/