Problem: 2050C - Uninteresting Number
Language: Java 21

Previous submission (verdict: Runtime error on test 3):
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t>0){
            long n=sc.nextLong();
            if(n<=2){
                if(n==0){
                    System.out.println("YES");
                }
                else{
                    System.out.println("NO");
                }
                t--;
                continue;
            }
            long temp=n;
            long ans=0;
            long cnt1=0;
            long cnt2=0;
            boolean two=false;
            boolean three=false;
            while(n>0){
                long l=n%10;
                if(l==2){
                    cnt1++;
                }
                else if(l==3){
                    cnt2++;
                }
                ans=ans+l;
                n=n/10;

            }
            if(ans%9==0 ){
                System.out.println("YES");
            }
            else{
                // cnt1=cnt1/2;
                // cnt2=cnt2/6;
                boolean check=false;
                for(int i=0; i<=cnt1; i++){
                    for(int j=0; j<=cnt2; j++){
                        long temp1=temp;
                        temp1=temp1+(i*2)+(j*6);
                        if(temp1%9==0){
                            check=true;
                            break;
                        }
                    }
                    if(check==true){
                        break;
                    }
                }
                if(check==true){
                    System.out.println("YES");
                }
                else{
                    System.out.println("NO");
                }
            }
            t--;
        }
    }
}

Submission (verdict: Accepted):
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t>0){
            String n=sc.next();
            long sum=0;
            long cnt1=0;
            long cnt2=0;
            for(long i=0; i<n.length(); i++){
                char ch=n.charAt((int)i);
                if(ch=='2'){
                    cnt1++;
                }
                else if(ch=='3'){
                    cnt2++;
                }
                sum+=(ch-'0');
                sum=sum%9;
            }
                boolean check=false;
                for(int i=0; i<=cnt1; i++){
                    for(int j=0; j<=cnt2; j++){
                        long temp1=sum;
                        temp1=temp1+(i*2)+(j*6);
                        if(temp1%9==0){
                            check=true;
                            break;
                        }
                    }
                    if(check==true){
                        break;
                    }
                }
                if(check==true){
                    System.out.println("YES");
                }
                else{
                    System.out.println("NO");
                }
            t--;
        }
    }
}