Problem: 2050C - Uninteresting Number
Language: Java 21

Previous submission (verdict: Wrong answer on test 2):
// 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=cnt1+2;
                }
                else if(l==3){
                    cnt2=cnt2+6;
                }
                ans=ans+l;
                n=n/10;
                if((temp+cnt1)%9==0 || (temp+cnt2)%9==0 || (temp+cnt1+cnt2)%9==0){
                    three=true;
                    break;
                }
            }
            if(ans%9==0 || three==true){
                System.out.println("YES");
            }
            else{
                long sum=temp+cnt1+cnt2;
                long temp1=sum%9;
                if(temp1>=2 && temp1%2==0){
                    if(temp<=cnt1){
                        sum=sum-temp1;
                    }
                    else{
                        sum=sum-cnt1;
                    }
                    temp1=sum%9;
                }
                if(sum%9!=0 && temp1%6==0 && temp1<=cnt2){
                    sum=sum-temp1;
                    temp1=sum%9;
                }
                if(sum%9==0){
                    System.out.println("YES");
                }
                else{
                    System.out.println("NO");
                }
            }
            t--;
        }
    }
}

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--;
        }
    }
}