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

Solution 1 (runtime: 93 ms):
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
void solve()
{
	string s;
	cin >> s;
	int n = s.size();
	vector<vector<int>>dp(n+1, vector<int>(9));
	dp[0][0] = 1;
	for (int i = 1; i <= n; ++i)
	{
		int xz = s[i - 1] - '0';
		for (int j = 0; j < 9; ++j)
		{
			dp[i][(j + xz) % 9] |= dp[i - 1][j];
		}
		xz = xz * xz;
		if (xz < 10)
		{
			for (int j = 0; j < 9; ++j)
			{
				dp[i][(j + xz) % 9] |= dp[i - 1][j];
			}
		}
	}
	cout << (dp[n][0] ? "YES" : "NO") << endl;
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
}

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

#include <ext/pb_ds/assoc_container.hpp> 

#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;

using namespace std;

#define ll long long

#define dbg cout

#define yes cout <<"YES"<<endl

#define no cout <<"NO"<<endl

#define in(a) for(int j=0;j<a.size();j++) cin>>a[j];

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

#define out(a) for(int i=0;i<a.size();i++){cout<<a[i]<<" ";}cout<<endl;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



string to_binary(ll n) {

    if (n == 0) return "0";

    string r;

    while (n != 0) {

        r = (n % 2 == 0 ? "0" : "1") + r;

        n /= 2;

    }

    return r;

}



ll to_decimal(string s) {

    reverse(s.begin(), s.end());

    ll ct = 0;

    for (ll i = 0; i < s.size(); i++) {

        if (s[i] == '1')

            ct += (1ll << i);

    }

    return ct;

}



vector<bool> SieveOfEratosthenes(ll n) {

    vector<bool> prime(n + 1, 1);

    for (ll p = 2; p * p <= n; p++) {

        if (prime[p] == true) {

            for (ll i = p * p; i <= n; i += p)

                prime[i] = false;

        }

    }

    prime[1] = prime[0] = 0;

    return prime;

}



long long binpow(long long a, long long b) {

    long long res = 1;

    while (b > 0) {

        if (b & 1)

            res = res * a;

        a = a * a;

        b >>= 1;

    }

    return res;

}



ll binpow_modulo(ll a, ll b, ll mod) {

    ll res = 1;

    while (b > 0) {

        if (b % 2 == 1)

            res = (res * a) % mod;

        a = (a * a) % mod;

        b = b / 2;

    }

    return res;

}



ll fact(ll n, ll mod) {

    ll ans = 1;

    for (ll i = 2; i <= n; i++)

        ans = ((ans % mod) * (i % mod) + mod) % mod;

    ans %= mod;

    return ans;

}



ll ncr(ll n, ll r, ll mod) {

    if(n<r) return 0;

    ll ri = binpow_modulo(fact(r, mod), mod - 2, mod);

    ll nri = binpow_modulo(fact(n - r, mod), mod - 2, mod);

    ll ans = (((fact(n, mod) % mod) * (ri % mod)) % mod);

    ans = (((ans % mod) * (nri % mod)) % mod);

    ans %= mod;

    ans = (ans + mod) % mod;

    return ans;

}



ll inverse_modulo(ll num,ll mod){

return binpow_modulo(num,mod-2,mod);

}



ll lcm_of_array(vector<ll> arr) {

    // nlogn

    ll lcm = arr[0];

    for (ll i = 1; i < arr.size(); i++) {

        ll num1 = lcm;

        ll num2 = arr[i];

        ll gcd_val = __gcd(num1, num2);

        lcm = (lcm / gcd_val) * arr[i];

    }

    return lcm;

}



ll lcm(ll a, ll b) {

    return (a / (__gcd(a, b))) * b;

}

int fun(int ind, int mm, string &s,vector<vector<int>>&dp){

    if(ind==s.size()){

        if(mm==0) return 1;

        return 0;

    }

    if(dp[ind][mm]!=-1) return dp[ind][mm];

    int pick=0,nonpick=0;

    if(s[ind]=='2'){

        pick = fun(ind+1,(mm+2)%9,s,dp);

        nonpick = fun(ind+1,mm,s,dp);

    }

    else if(s[ind]=='3'){

         pick = fun(ind+1,(mm+6)%9,s,dp);

        nonpick = fun(ind+1,mm,s,dp);

    }

    else{

        nonpick = fun(ind+1,mm,s,dp);

    }



    return dp[ind][mm] = pick||nonpick;

}





int main() {



    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    cout.tie(NULL);



#ifndef ONLINE_JUDGE

    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);

#endif



ll TESTCASES;

cin >> TESTCASES;

while (TESTCASES--) {

string s;

cin >>s;

int n = s.size();

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

int mm =0;

for(int i=0;i<s.size();i++){

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

    mm= (mm+dd)%9;

}

int f = fun(0,mm,s,dp);

if(f) yes;

else no;





}

}