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

Solution 1 (runtime: 77 ms):
#include<bits/stdc++.h>
using namespace std;
#define int long long  
#define forr(i,x,n) for(int i = x ; i < n ; i ++)  
constexpr int MOD = 1e9 + 7;  


int sumOfDigits(int number) {
    int sum = 0;

    // Ensure the number is positive for calculation
    number = abs(number);

    while (number > 0) {
        sum += number % 10; // Add the last digit
        number /= 10;       // Remove the last digit
    }

    return sum;
}

int c2(int number) {
    int s = 0;

    // Ensure the number is positive for calculation
    number = abs(number);

    while (number > 0) {
        if(number % 10 == 2) s++ ; // Add the last digit
        number /= 10;       // Remove the last digit
    }

    return s;
} 

int c3(int number) {
    int s = 0;

    // Ensure the number is positive for calculation
    number = abs(number);

    while (number > 0) {
        if(number % 10 == 3) s++ ; // Add the last digit
        number /= 10;       // Remove the last digit
    }

    return s;
}

int32_t main() {   
    int t  ; 
    cin >> t ; 
    while(t--) {    
        string n ; 
        cin >> n ;   
        int tw = 0; 
        int th = 0 ; 
        int s = 0 ;    
        forr(i,0,n.length()) {
            s += n[i] - '0' ;  
            if(n[i] - '0' == 2) tw++ ; 
            if(n[i] - '0' == 3) th++ ; 
        } 
        int k = s ; 
        bool ya = false ; 
        if(s%9 == 0) ya = true ; 
        else { 
             
            int mth = min(10ll ,th + 1);
            int mtw = min(10ll , tw + 1) ; 
          //  cout << (th) << endl ;
            forr(i,0, mth ) { 
                forr(j,0, mtw ) { 
                    s= k +  j*2 + i*6 ;  
                  //  cout << s << endl ; 
                    if(s%9 == 0){ 
                        ya = true ; 
                        break ; 
                    } 
                  // if(ya) cout << "YES" << endl ;
                  // else cout << "NO" << endl ;
                }
            }  
        } 

                   if(ya) cout << "YES" << endl ;
                   else cout << "NO" << endl ;
            
        

         
         

    }
} 

Solution 2 (runtime: 62 ms):
#include <algorithm>

#include <bits/stdc++.h>

#include <vector>



using namespace std;

#define ll long long

int const mod = 998244353, N = 2e5 + 10;

#define fast                                                                   \

  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

int dp[N][10];

int n;

string s;

int rec(int i, int sum) {

  if (i == n) {

    return (sum % 9 == 0);

  }

  if (sum % 9 == 0) {

    return 1;

  }

  sum %= 9;

  int &ret = dp[i][sum];

  if(~ret){

    return ret;

  }

  ret = 0;

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

    ret |= rec(i + 1, sum + 2);

  }

  if (s[i] == '3') {

    ret |= rec(i + 1, sum + 6);

  }

  ret |= rec(i + 1, sum);

  return ret;

}



int main() {

  fast;

  memset(dp, -1, sizeof dp);

  int t;

  cin >> t;

  while (t--) {

    // cin >> n;

    cin >> s;

    n = s.size();

    int sum = 0;

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

      sum += (s[i] - '0');

    }

    cout << (rec(0, sum % 9) ? "YES" : "NO") << '\n';

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

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

        dp[i][j] = -1;

      }

    }

  }

}