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

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define int long long
using namespace std;


signed main() {
    int q;
    cin>>q;
    while(q--){
        string n;
        cin>>n;
        int sum=0;
        int x2=0;
        int x3=0;
        for(int i=0;i<n.size();i++){
            int num = n[i] - '0';
            if(num==2){
                x2++;
            }
            if(num==3){
                x3++;
            }
            sum+=num;

        }
        bool flag=true;
        if(sum%9==0){
            cout<<"YES"<<endl;
        }
        
        
        else{
            if(x2==0){
                for(int j=0;j<=x3;j++){
                    int x=sum+6*j;
                    if((x)%9==0){
                        cout<<"YES"<<endl;
                        flag=false;
                        break;
                    }
                }
                
            }
            else if(x3==0){
                for(int i=1;i<=x2;i++){
                
                    int x=sum+2*i;
                    if((x)%9==0){
                        cout<<"YES"<<endl;
                        flag=false;
                        break;
                    }
                }
                
            }
            else{
                for(int i=1;i<=x2;i++){
                for(int j=0;j<=x3;j++){
                    int x=sum+2*i+6*j;
                    if((x)%9==0){
                        cout<<"YES"<<endl;
                        flag=false;
                        break;
                    }
                }
                if(flag==false){
                    break;
                }
            }
            }
            
            if(flag==true){
                cout<<"NO"<<endl;
            }
        }

    }
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define int long long
using namespace std;


signed main() {
    int q;
    cin>>q;
    while(q--){
        string n;
        cin>>n;
        int sum=0;
        int x2=0;
        int x3=0;
        for(int i=0;i<n.size();i++){
            int num = n[i] - '0';
            if(num==2){
                x2++;
            }
            if(num==3){
                x3++;
            }
            sum+=num;

        }
        bool flag=true;
        if(sum%9==0){
            cout<<"YES"<<endl;
        }
        
        
        else{
            if(flag==true){
                for(int j=0;j<=x3;j++){
                    int x=sum+6*j;
                    if((x)%9==0){
                        cout<<"YES"<<endl;
                        flag=false;
                        break;
                    }
                }
            }
            if(flag==true){
                for(int i=1;i<=x2;i++){
                
                    int x=sum+2*i;
                    if((x)%9==0){
                        cout<<"YES"<<endl;
                        flag=false;
                        break;
                    }
                }
            }
            if(flag==true){
                 for(int i=1;i<=x2;i++){
                for(int j=0;j<=x3;j++){
                    int x=sum+2*i+6*j;
                    if((x)%9==0){
                        cout<<"YES"<<endl;
                        flag=false;
                        break;
                    }
                }
                if(flag==false){
                    break;
                }
            }
            }  
 
            if(flag==true){
                cout<<"NO"<<endl;
            }
        }

    }
}