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

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

using namespace std;



int main() {

	// your code goes here

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        

        map<int,int> count;

        int sum=0;

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

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

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

                count[2]++;

            }

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

                count[6]++;

            }

        }

        int n=count[2]+3*count[6];

        if(sum%9==0){

            cout<<"yes"<<endl;

            continue;

        }

        else if(n==0){

            cout<<"no"<<endl;

            continue;

        }

        //cout<<n<<" "<<sum<<endl;

        bool f1=false;

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

            sum=sum+2;

            if(sum%9==0){

                //cout<<i<<endl;

                if(i<=count[2]){

                    cout<<"yes"<<endl;

                    f1=true;

                    break;

                }

                if(i>count[2]){

                    int count2s=i;

                    for(int j=1;j<=count[6];j++){

                        count2s=count2s-3;

                        if(count2s>=0 && count2s<=count[2]){

                            cout<<"yes"<<endl;

                            f1=true;

                            break;

                        }

                    }

                }

            }

        }

        

        if(!f1){

            cout<<"no"<<endl;

        }

    }

}



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

using namespace std;



int main() {

	// your code goes here

    int t;

    cin>>t;

    while(t--){

        string s;

        cin>>s;

        

        map<int,int> count;

        int sum=0;

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

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

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

                count[2]++;

            }

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

                count[6]++;

            }

        }

        int n=count[2]+3*count[6];

        if(sum%9==0){

            cout<<"yes"<<endl;

            continue;

        }

        else if(n==0){

            cout<<"no"<<endl;

            continue;

        }

        //cout<<n<<" "<<sum<<endl;

        bool f1=false;

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

            sum=sum+2;

            if(sum%9==0){

                //cout<<i<<endl;

                if(i<=count[2]){

                    cout<<"yes"<<endl;

                    f1=true;

                    break;

                }

                if(i>count[2]){

                    int count2s=i;

                    for(int j=1;j<=count[6];j++){

                        count2s=count2s-3;

                        //cout<<count2s<<endl;

                        if(count2s>=0 && count2s<=count[2]){

                            cout<<"yes"<<endl;

                            f1=true;

                            break;

                        }

                    }

                    if(f1)break;

                }

            }

        }

        

        if(!f1){

            cout<<"no"<<endl;

        }

    }

}