Problem: 2050C - Uninteresting Number
Language: java

Solution 1 (runtime: 328 ms):
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();
	        int s=0;
	        HashMap<Integer,Integer>hm=new HashMap();
	        for(int i=0;i<n.length();i++){
	            s+=n.charAt(i)-'0';
	            if((n.charAt(i)-'0')==3)
	            hm.put(6,hm.getOrDefault(6,0)+1);
	            else if((n.charAt(i)-'0')==2)
	            hm.put(2,hm.getOrDefault(2,0)+1);

	            
	        }

            int f=0;
	        if(s%9==0)
	        		System.out.println("YES");
	        		else{
	        		    for(int i=0;i<=hm.getOrDefault(2,0);i++){
	        		        if(f==1)
	        		        break;
	        		        
	        		        for(int j=0;j<=hm.getOrDefault(6,0);j++){
	        		            if((s+i*2+j*6)%9==0)
	        		            {
	        		                f=1;
	        		                break;
	        		            }
	        		        }
	        		    }
	        		    System.out.println((f==1)?"YES":"NO");
	                    }



	        
	    }
	}
}


Solution 2 (runtime: 311 ms):
import java.io.*;
import java.util.*;

public class UninterestingNumber {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(in.readLine());

        int t = Integer.parseInt(tokenizer.nextToken());
        ArrayList<String> ans = new ArrayList<>();

        for (int i = 0; i < t; i++) {
            tokenizer = new StringTokenizer(in.readLine());
            String n = tokenizer.nextToken();
            int num = simplify(n);

            if (num == 0) {
                ans.add("YES");
                continue;
            }

            int num2 = numTwos(n);
            int num3 = numThrees(n);

            boolean canAdd = false;

            if (num == 1) {
                if (num3 >= 1 && num2 >= 1) {
                    canAdd = true;
                } else if (num2 >= 4) {
                    canAdd = true;
                }
            } else if (num == 2) {
                if (num3 >= 2 && num2 >= 2) {
                    canAdd = true;
                } else if (num3 == 1 && num2 >= 5) {
                    canAdd = true;
                } else if (num2 >= 8) {
                    canAdd = true;
                }
            } else if (num == 3) {
                if (num3 >= 1 || num2 >= 3) {
                    canAdd = true;
                }
            } else if (num == 4) {
                if (num3 >= 2 && num2 >= 1) {
                    canAdd = true;
                } else if (num3 == 1 && num2 >= 4) {
                    canAdd = true;
                } else if (num2 >= 7) {
                    canAdd = true;
                }
            } else if (num == 5) {
                if (num2 >= 2) {
                    canAdd = true;
                }
            } else if (num == 6) {
                if (num3 >= 2) {
                    canAdd = true;
                } else if (num3 == 1 && num2 >= 3) {
                    canAdd = true;
                } else if (num2 >= 6) {
                    canAdd = true;
                }
            } else if (num == 7) {
                if (num2 >= 1) {
                    canAdd = true;
                }
            } else if (num == 8) {
                if (num3 >= 1 && num2 >= 2) {
                    canAdd = true;
                } else if (num2 >= 5) {
                    canAdd = true;
                }
            }

            if (canAdd) {
                ans.add("YES");
                continue;
            }
            ans.add("NO");
        }

        for (String s : ans) {
            System.out.println(s);
        }
    }

    public static int numTwos(String x) {
        int ret = 0;
        for (char a : x.toCharArray()) {
            if ((a - '0') == 2) ret++;
        }
        return ret;
    }

    public static int numThrees(String x) {
        int ret = 0;
        for (char a : x.toCharArray()) {
            if ((a - '0') == 3) ret++;
        }
        return ret;
    }

    public static int simplify(String x) {
        int ret = 0;
        for (char a : x.toCharArray()) {
            ret += (a - '0');
        }
        return ret % 9;
    }
}