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

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define pi pair<int, int>
#define vi vector<int>
#define pb push_back
#define vvi vector<vector<int>>
#define foratob(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, b, a) for (int i = b - 1; i >= a; i--)
#define forn(i, n) for (int i = 0; i < n; i++)
#define input(a, n)             \
    for (int i = 0; i < n; i++) \
        cin >> a[i];
#define copyarr(b, a, n)        \
    for (int i = 0; i < n; i++) \
        a[i] = b[i];
#define MOD 1000000007
#define ll long long int
#define all(v) v.begin(), v.end()
#define pq priority_queue
#define vpii vector<pair<int,int>>
#define GRAPH vector<vector<pair<int,int>>>
#define NO cout << "No" << endl
#define YES cout << "Yes" << endl
#define foriin(i, a) for(auto i: a)
#define pii pair<int,int>
#define vll vector<ll>
#define printv(v) foriin(i,v) cout << i << " "; cout << endl;
 
typedef tree<pair<int,int>,null_type,less<pii>,rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

//-------------------------__________--------------------------------//
//-------------------------TEMPLATES--------------------------------//
//-------------------------=========-------------------------------//

template<class T>
T gcd(T a, T b){
    // a>=b : make sure
    if (b == 0) return a;
    return gcd(b, a%b);
} 

ll absolute(ll a){
    if (a<0) return -a;
    return a;
}

vi primes;
vector<pair<int,int>> seive(1000000, {1,1});
void make_seive(int n){
    for ( int i = 2 ;i<n; i++){
        if (seive[i].first) {
            primes.pb(i);
            for (int j = i*i ; j<n; j+=i) {
                seive[j] = {0, i};
            }
        }
    }
}

ll ceiling(ll a, ll b){
    if (a%b) return a/b + 1;
    return a/b;
}

int is_prime(int n){
    if (n == 1) return 0;
    for (int i = 2; i*i<=n; i++){
        if (n%i == 0) return 0;
    }
    return 1;
}

ll ncr(ll n, ll r){
    ll ans = 1;
    for (int i = 0; i<r; i++){
        ans *= (n-i);
        // ans /= (i+1);
        ans%=MOD;
    }
    return ans;
}

int modInverse(int A, int M)
{
    int m0 = M;
    int y = 0, x = 1;

    if (M == 1)
        return 0;

    while (A > 1) {
        // q is quotient
        int q = A / M;
        int t = M;

        // m is remainder now, process same as
        // Euclid's algo
        M = A % M, A = t;
        t = y;

        // Update y and x
        y = x - q * y;
        x = t;
    }

    // Make x positive
    if (x < 0)
        x += m0;

    return x;
}

int check_90(pair<int, int> a, pair<int, int> b){
    int dot = a.first*b.first + a.second*b.second;
    if (dot == 0) return 1;
    return 0;
}


void solve(){
    string n; cin >> n;
    ll x = 0 ;
    ll _2 = 0  , _3 = 0; 
    for (auto i: n){
        if (i == '2') _2 ++ ;
        else if (i == '3') _3++;
        x += i-'0';
    }
    if (x%9 == 0) {
        YES;
        return ;
    }
    else {
        x = x%9;
        // cout << x << ' ' << _2 << ' ' << _3 << endl; 
        if (x == 6) {
            if (_3 > 1 or (_3 and _2>2) or (_2>5)) YES;
            else NO;
        }
        else if (x == 8) {
            if (_2 > 4 or (_3 and _2>1)) YES;
            else NO;
        }
        else if (x == 4) {
            if (_2 > 6 or (_3 and _2>3) or (_3>1 and _2)) YES;
            else NO;
        }
        else if (x == 2) {
            if (_2>7 or (_3 and _2>4) or (_3>1 and _2>1)) YES;
            else NO;
        }
        else {
            if (x == 1) {
                if ((_3 and _2) or (_2>3)) {
                    YES;
                }
                else {
                    NO;
                }
            }
            else if (x == 3) {
                if (_3 or _2>2) {
                    YES;
                }
                else {
                    NO;
                }
            }
            else if (x == 5) {
                if (_2>1) YES;
                else NO;
            } 
            else if (x == 7) {
                if (_2) YES;
                else NO;
            }
        }
    }
}


int main()
{   
    // make_seive(1000000);
    // printv(primes);
    int t; cin >> t; while(t--)
	solve();
    return 0;
}   

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

using namespace std;

#define int long long

void red() {
  string n;
  cin >> n;
  int sum = 0;
  int cnt2 = 0, cnt3 = 0;
  for (char ch : n) {
    int digit = ch - '0';
    if (digit == 2)
      cnt2++;
    if (digit == 3)
      cnt3++;
    sum += digit;
    sum %= 9;
  }
  sum = 9 - sum;

  if (sum == 1 && (cnt2 >= 5 || (cnt2 >= 2 && cnt3 >= 1))) {
    cout << "YES" << endl;
    return;
  }
  if (sum == 2 && cnt2 >= 1) {
    cout << "YES" << endl;
    return;
  }
  if (sum == 3 && (cnt2 >= 6 || cnt3 >= 2 || (cnt2 >= 3 && cnt3 >= 1))) {
    cout << "YES" << endl;
    return;
  }
  if (sum == 4 && cnt2 >= 2) {
    cout << "YES" << endl;
    return;
  }
  if (sum == 5 &&
      (cnt2 >= 7 || (cnt2 >= 4 && cnt3 >= 1) || (cnt2 >= 1 && cnt3 >= 2))) {
    cout << "YES" << endl;
    return;
  }
  if (sum == 6 && (cnt3 >= 1 || cnt2 >= 3)) {
    cout << "YES" << endl;
    return;
  }
  if (sum == 7 &&
      (cnt2 >= 8 || (cnt2 >= 5 && cnt3 >= 1) || (cnt2 >= 2 && cnt3 >= 2))) {
    cout << "YES" << endl;
    return;
  }
  if (sum == 8 && (cnt2 >= 4 || (cnt2 >= 1 && cnt3 >= 1))) {
    cout << "YES" << endl;
    return;
  }
  if (sum == 9) {
    cout << "YES" << endl;
    return;
  }
  cout << "NO" << endl;
  return;
}

int32_t main() {
  int t;
  cin >> t;
  while (t--)
    red();
  return 0;
}