Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 3):
#include <bits/stdc++.h>

using namespace std;



#define int long long



void solve(vector<int> v1,vector<int> v2,int sum,bool &ans,int index,int n){

    if(index==n){

        return;

    }

    if(sum%9==0){

        ans = true;

    }

    int sm = sum - v1[index];

    sm += v2[index];

    if(sm%9==0){

        ans = true;

    }

    index++;

    solve(v1, v2, sum, ans, index, n);

    solve(v1, v2, sm, ans, index, n);

}



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0); cout.tie(0);

    int t;

    cin >> t;

    while(t--){

        string s;

        cin >> s;

        vector<int> v1;

        vector<int> v2;

        int n=s.size();

        int sum = 0;

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

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

            v1.push_back(x);

            if(x*x<10){

                v2.push_back(x*x);

            }

            else{

                v2.push_back(x);

            }

            sum+=x;

        }

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

        //     cout << v1[i] << " ";

        // }

        // cout << endl;

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

        //     cout << v2[i] << " ";

        // }

        // cout << endl;

        bool ans = false;

        int index = 0;

        // cout << sum << endl;

        solve(v1,v2,sum,ans,index,n);



        if(ans){

            cout << "YES" << endl;

        }

        else{

            cout << "NO" << endl;

        }

    }

}

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

using namespace std;



#define int long long



void solve(vector<int> v1,vector<int> v2,int sum,bool &ans,int index,int n){

    if(index==n){

        return;

    }

    if(sum%9==0){

        ans = true;

    }

    int sm = sum - v1[index];

    sm += v2[index];

    if(sm%9==0){

        ans = true;

    }

    index++;

    solve(v1, v2, sum, ans, index, n);

    solve(v1, v2, sm, ans, index, n);

}



signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0); cout.tie(0);

    int t;

    cin >> t;

    while(t--){

        string s;

        cin >> s;

        int n = s.length();

        int n2 = 0;

        int n3 = 0;

        int sum = 0;

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

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

                n2++;

            }

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

                n3++;

            }

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

        }

        n2 %= 9;

        n3 %= 3;

        int m = n2 + n3;

        int a[m];

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

            a[i] = 2;

        }

        for (int i = n2; i < m;i++){

            a[i] = 6;

        }

        int M = (1 << m) - 1;

        bool ans = false;

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

            int sm = 0;

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

                if(i& (1<<j)){

                    sm += a[j];

                }

            }

            if((sm+sum)%9==0){

                ans=true;

                break;

            }

        }

        // cout << sum << endl;

        // for (int i = 0; i < m;i++){

        //     cout<<a[i]<<" ";

        // }

            if (ans)

            {

                cout << "YES" << endl;

            }

            else{

            cout << "NO" << endl;

        }

    }

}