Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>



#define ll long long

#define mod 1000000007

#define INF 1e9



using namespace std;



void input1(vector<ll>& num, ll n){

	for(int i = 0 ; i < n ; ++i) cin >> num[i];

}



void input2(vector<vector<ll> >& num, int n, int m) {

    for (int i = 0; i < n; ++i) {

        for (int j = 0; j < m; ++j) {

            cin >> num[i][j];

        }

    }

}



void solve() {

	string s;

	cin >> s;

	int dem2 = 0;

	int dem3 = 0;

	ll tong = 0;

	vector<int> num(s.length());

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

		num[i] = s[i]-'0';

		if(num[i]!=2&&num[i]!=3){

			tong+=num[i];

		}else if(num[i]==2){

			++dem2;

		}else if(num[i]==3){

			++dem3;

		}

	}

	if(dem2==0&&dem3!=0){

		cout << "YES" << endl;

		return;

	}else if(dem2!=0&&dem3==0){

		if(dem2%9==0){

			cout << "YES" << endl;

		}else{

			cout << "NO" << endl;

		}

		return;

	}

	ll tong2 = 2*dem2;

	ll tong3 = 3*dem3; 

	vector<vector<ll>> dp(dem2+2,vector<ll> (dem3+2));

	dp[0][0] = 0;

	for(int i=0;i<=dem2+1;++i){

		for(int j=0;j<=dem3+1;++j){

			if(i==0&&j!=0){

				dp[i][j] = tong3+6*(j-1);

			}else if(j==0&&i!=0){

				dp[i][j] = tong2+2*(i-1);

			}else if(i!=0&&j!=0){

				dp[i][j] = dp[0][j]+dp[i][0];

			}

		}

	}

	/*

	for(int i=0;i<=dem2+1;++i){

		for(int j=0;j<=dem3+1;++j){

			cout << dp[i][j] << " ";

		}

		cout << endl;

	}

	*/

	string ans = "NO";

	for(int i=1;i<=dem2+1;++i){

		for(int j=1;j<=dem3+1;++j){

			ll w = tong+dp[i][j];

			if(w%9==0){

				ans = "YES";

				//break;

			}

			//cout << w << " ";

		}

		//cout << endl;

		if(ans=="YES"){

			//break;

		}

	}

	cout << ans << endl;

}



int main() {

	ios::sync_with_stdio(false);

	int tt; cin >> tt; for (int i = 0; i < tt; i++) {solve();}

	//solve();

}



Submission (verdict: Memory limit exceeded on test 4):
#include <bits/stdc++.h>



#define ll long long

#define mod 1000000007

#define INF 1e9



using namespace std;



void input1(vector<ll>& num, ll n){

	for(int i = 0 ; i < n ; ++i) cin >> num[i];

}



void input2(vector<vector<ll> >& num, int n, int m) {

    for (int i = 0; i < n; ++i) {

        for (int j = 0; j < m; ++j) {

            cin >> num[i][j];

        }

    }

}



void solve() {

	string s;

	cin >> s;

	int dem2 = 0;

	int dem3 = 0;

	ll tong = 0;

	vector<int> num(s.length());

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

		num[i] = s[i]-'0';

		if(num[i]!=2&&num[i]!=3){

			tong+=num[i];

		}else if(num[i]==2){

			++dem2;

		}else if(num[i]==3){

			++dem3;

		}

	}

	ll tong2 = 2*dem2;

	ll tong3 = 3*dem3; 

	vector<vector<ll>> dp(dem2+2,vector<ll> (dem3+2));

	dp[0][0] = 0;

	for(int i=0;i<=dem2+1;++i){

		for(int j=0;j<=dem3+1;++j){

			if(i==0&&j!=0){

				dp[i][j] = tong3+6*(j-1);

			}else if(j==0&&i!=0){

				dp[i][j] = tong2+2*(i-1);

			}else if(i!=0&&j!=0){

				dp[i][j] = dp[0][j]+dp[i][0];

			}

		}

	}

	/*

	for(int i=0;i<=dem2+1;++i){

		for(int j=0;j<=dem3+1;++j){

			cout << dp[i][j] << " ";

		}

		cout << endl;

	}

	*/

	string ans = "NO";

	for(int i=1;i<=dem2+1;++i){

		for(int j=1;j<=dem3+1;++j){

			ll w = tong+dp[i][j];

			if(w%9==0){

				ans = "YES";

				//break;

			}

			//cout << w << " ";

		}

		//cout << endl;

		if(ans=="YES"){

			//break;

		}

	}

	cout << ans << endl;

}



int main() {

	ios::sync_with_stdio(false);

	int tt; cin >> tt; for (int i = 0; i < tt; i++) {solve();}

	//solve();

}