ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 202 ms):
import sys
sys.set_int_max_str_digits(10**6)
t=int(input())
for _ in range(t):
    n=int(input())
    s=str(n)
    x=0
    for i in range(len(s)):
        x+=int(s[i])
    a,b=0,0
    for i in range(len(s)):
        if s[i]=="2":
            a,b=a+1,b
        elif s[i]=="3":
            a,b=a,b+1
        else:
            a,b=a,b
    i=0
    while i<a+1:
        j=0
        while j<b+1:
            if (x+2*i+6*j)%9==0:
                break
            else:
                j+=1
        if j<b+1:
            if (x+2*i+6*(j))%9==0:
                break
            else:
                i+=1
        else:
            if (x+2*i+6*(j-1))%9==0:
                break
            else:
                i+=1
    if i==a+1 and j==b+1:
        print("NO")
    else:
        print("YES")

Solution 2 (runtime: 437 ms):
t = int(input())
for i in range(t):
    s = [int(x) for x in list(input())]
    sm = sum(s)
    sm %= 9
    cnt2 = s.count(2)
    cnt3 = s.count(3)
    flag = False
    for j in range(min(10, cnt2+1)):
        if flag:
            break
        for k in range(min(10, cnt3+1)):
            if (sm + j * 2 + k * 6) % 9 == 0:
                print('Yes')
                flag = True
                break
    if not flag:
        print('No')
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 202 ms):
import sys
sys.set_int_max_str_digits(10**6)
t=int(input())
for _ in range(t):
    n=int(input())
    s=str(n)
    x=0
    for i in range(len(s)):
        x+=int(s[i])
    a,b=0,0
    for i in range(len(s)):
        if s[i]=="2":
            a,b=a+1,b
        elif s[i]=="3":
            a,b=a,b+1
        else:
            a,b=a,b
    i=0
    while i<a+1:
        j=0
        while j<b+1:
            if (x+2*i+6*j)%9==0:
                break
            else:
                j+=1
        if j<b+1:
            if (x+2*i+6*(j))%9==0:
                break
            else:
                i+=1
        else:
            if (x+2*i+6*(j-1))%9==0:
                break
            else:
                i+=1
    if i==a+1 and j==b+1:
        print("NO")
    else:
        print("YES")

Solution 2 (runtime: 186 ms):
def sol() -> bool:
    s = str(input())

    numTwos = 0
    numThrees = 0
    sum = 0

    for c in s:
        x = int(c)
        # print(x)
        if x == 2:
            numTwos += 1
        if x == 3:
            numThrees += 1
        sum += x
    
    m = min(8, numTwos)
    n = min(3, numThrees)

    for j in range(m+1):
        for k in range(n+1):
            # print(sum + j * 2 + k * 6)
            if (sum + j * 2 + k * 6) % 9 == 0:
                return True
    
    return False

t = int(input())

for i in range(t):
    print("YES") if sol() else print("NO")
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 202 ms):
import sys
sys.set_int_max_str_digits(10**6)
t=int(input())
for _ in range(t):
    n=int(input())
    s=str(n)
    x=0
    for i in range(len(s)):
        x+=int(s[i])
    a,b=0,0
    for i in range(len(s)):
        if s[i]=="2":
            a,b=a+1,b
        elif s[i]=="3":
            a,b=a,b+1
        else:
            a,b=a,b
    i=0
    while i<a+1:
        j=0
        while j<b+1:
            if (x+2*i+6*j)%9==0:
                break
            else:
                j+=1
        if j<b+1:
            if (x+2*i+6*(j))%9==0:
                break
            else:
                i+=1
        else:
            if (x+2*i+6*(j-1))%9==0:
                break
            else:
                i+=1
    if i==a+1 and j==b+1:
        print("NO")
    else:
        print("YES")

Solution 2 (runtime: 156 ms):
import sys

input = sys.stdin.readline





for _ in range(int(input())):

    s = input()[:-1]

    a, b = 0, 0

    c = 0

    for i in s:

        if i == '2':

            a += 1

        elif i == '3':

            b += 1

        c += int(i)

    c %= 9

    ew = 0

    for i in range(min(10, b+1)):

        for j in range(min(10, a+1)):

            if (c + 6*i + 2*j) % 9 == 0:

                ew = 1

                break

        if ew:

            break

    print(['NO','YES'][ew])
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 202 ms):
import sys
sys.set_int_max_str_digits(10**6)
t=int(input())
for _ in range(t):
    n=int(input())
    s=str(n)
    x=0
    for i in range(len(s)):
        x+=int(s[i])
    a,b=0,0
    for i in range(len(s)):
        if s[i]=="2":
            a,b=a+1,b
        elif s[i]=="3":
            a,b=a,b+1
        else:
            a,b=a,b
    i=0
    while i<a+1:
        j=0
        while j<b+1:
            if (x+2*i+6*j)%9==0:
                break
            else:
                j+=1
        if j<b+1:
            if (x+2*i+6*(j))%9==0:
                break
            else:
                i+=1
        else:
            if (x+2*i+6*(j-1))%9==0:
                break
            else:
                i+=1
    if i==a+1 and j==b+1:
        print("NO")
    else:
        print("YES")

Solution 2 (runtime: 186 ms):
import sys, math

from functools import cmp_to_key

from operator import itemgetter

from bisect import bisect_left, bisect_right

from collections import Counter, defaultdict, deque



input = sys.stdin.readline



def iinp(): return (int(input()))

def linp(): return (list(map(int, input().split())))

def sinp(): return (input().strip())

def minp(): return (map(int, input().split()))

def debug(*args):

    print("DEBUG:", *args, file=sys.stderr)





def solve():

	# n = iinp()

	s = sinp()

	Sum = sum([int(num) for num in s])

	count_2 = s.count('2')

	count_3 = s.count('3')

	if Sum%9==0:

		print("YES")

		return

	target = (9 - Sum%9)%9 

	for i in range(count_3+1):

		new_target = (target - 6*i)%9

		if new_target<0:

			new_target +=9

		requied = (5*new_target)%9

		if requied<=count_2:

			print("YES")

			return

		

	print('NO')

		



def main():

	t = 1

	t = int(input())

	for i in range(t):

		solve()

	

if __name__ == "__main__":

	main()
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 202 ms):
import sys
sys.set_int_max_str_digits(10**6)
t=int(input())
for _ in range(t):
    n=int(input())
    s=str(n)
    x=0
    for i in range(len(s)):
        x+=int(s[i])
    a,b=0,0
    for i in range(len(s)):
        if s[i]=="2":
            a,b=a+1,b
        elif s[i]=="3":
            a,b=a,b+1
        else:
            a,b=a,b
    i=0
    while i<a+1:
        j=0
        while j<b+1:
            if (x+2*i+6*j)%9==0:
                break
            else:
                j+=1
        if j<b+1:
            if (x+2*i+6*(j))%9==0:
                break
            else:
                i+=1
        else:
            if (x+2*i+6*(j-1))%9==0:
                break
            else:
                i+=1
    if i==a+1 and j==b+1:
        print("NO")
    else:
        print("YES")

Solution 2 (runtime: 93 ms):
import sys



def is_interesting(n):

    S = 0

    count_2 = 0

    count_3 = 0



    # Compute sum of digits and count of 2s and 3s

    for digit in n:

        d = int(digit)

        S += d

        if d == 2:

            count_2 += 1

        elif d == 3:

            count_3 += 1



    # Compute R = (9 - S % 9) % 9

    R = (9 - (S % 9)) % 9

    for i in range(count_3+1):

        new_R = (R - 6*i)%9

        if new_R<0:

            new_R +=9

        mmi = (new_R*5)%9

        if mmi <= count_2:

            return 'YES'

    return 'NO'



# Fast input handling

input = sys.stdin.read

data = input().split()

t = int(data[0])

results = []



for i in range(1, t + 1):

    n = data[i]

    results.append(is_interesting(n))



# Output results efficiently

sys.stdout.write("\n".join(results) + "\n")
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 202 ms):
import sys
sys.set_int_max_str_digits(10**6)
t=int(input())
for _ in range(t):
    n=int(input())
    s=str(n)
    x=0
    for i in range(len(s)):
        x+=int(s[i])
    a,b=0,0
    for i in range(len(s)):
        if s[i]=="2":
            a,b=a+1,b
        elif s[i]=="3":
            a,b=a,b+1
        else:
            a,b=a,b
    i=0
    while i<a+1:
        j=0
        while j<b+1:
            if (x+2*i+6*j)%9==0:
                break
            else:
                j+=1
        if j<b+1:
            if (x+2*i+6*(j))%9==0:
                break
            else:
                i+=1
        else:
            if (x+2*i+6*(j-1))%9==0:
                break
            else:
                i+=1
    if i==a+1 and j==b+1:
        print("NO")
    else:
        print("YES")

Solution 2 (runtime: 203 ms):
t = int(input())

for _ in range(t):

    s = list(map(int, input().strip()))

    x = sum(s)

    twos = 0

    threes = 0

    for i in s:

        if i == 2:

            twos += 1

        elif i == 3:

            threes += 1

        if twos > 8 and threes > 8:

            break



    ans = 'NO'



    for i in range(twos + 1):

        for j in range(threes + 1):

            if (2 * i + 6 * j + x) % 9 == 0:

                ans = 'YES'

                break 

    

    print(ans)
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 171 ms):
def voir(test,nb3):
    while test!=0 and nb3>0:
        test=(test+6)%9
        nb3-=1
    if test==0:
        return True
    else :
        return False

OUT=[]
for i in range(int(input())):
    s=input()
    somme=0
    nb2=0
    nb3=0
    for i in s:
        somme=(somme+int(i))%9
        if i=="2":
            nb2+=1 
        if i=="3":
            nb3+=1
    
    if somme==0 :
        OUT.append("YES")
    else :
        
        
        if nb2>=2 :
            
            if voir((somme+4)%9,(nb3+(nb2-2)//3)) or voir((somme+2)%9,(nb3+(nb2-1)//3)) or voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")
        elif nb2==1 :
            
            if voir((somme+2)%9,(nb3+(nb2-1)//3)) or voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")
        else:
            
            if voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")


for i in OUT:
    print(i)

        

    
    

Solution 2 (runtime: 156 ms):
t = int(input())
for i in range(t):
	n = input()
	if int(n)%9 == 0:
		print('yes')
		continue	
	tw = n.count('2')
	th = n.count('3')
	n = int(n)
	tn = abs(0.5*((n%9)%2)*(9-n%9)+(abs(n%9)%2-1)*(9-n%9/2))
	d = tn - tw
	if d > 0 and ((d%3!=0 and (tw<3-d%3 or (d+3-d%3)/3 > th)) or (d%3==0 and d/3 > th)):
		print('no')
	else:
		print('yes')
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 171 ms):
def voir(test,nb3):
    while test!=0 and nb3>0:
        test=(test+6)%9
        nb3-=1
    if test==0:
        return True
    else :
        return False

OUT=[]
for i in range(int(input())):
    s=input()
    somme=0
    nb2=0
    nb3=0
    for i in s:
        somme=(somme+int(i))%9
        if i=="2":
            nb2+=1 
        if i=="3":
            nb3+=1
    
    if somme==0 :
        OUT.append("YES")
    else :
        
        
        if nb2>=2 :
            
            if voir((somme+4)%9,(nb3+(nb2-2)//3)) or voir((somme+2)%9,(nb3+(nb2-1)//3)) or voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")
        elif nb2==1 :
            
            if voir((somme+2)%9,(nb3+(nb2-1)//3)) or voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")
        else:
            
            if voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")


for i in OUT:
    print(i)

        

    
    

Solution 2 (runtime: 218 ms):
for _ in range(int(input())):
    s=[int(x) for x in list(input())]
    sm=sum(s)
    t=s.count(2)
    th=s.count(3)
    found=False
    for i in range(t+1):
        for j in range(th+1):
            if (sm+i*2+j*6)%9==0:
                print('YES')
                found=True
                break
        if found:
            break
    if not found:
        print('NO')
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 171 ms):
def voir(test,nb3):
    while test!=0 and nb3>0:
        test=(test+6)%9
        nb3-=1
    if test==0:
        return True
    else :
        return False

OUT=[]
for i in range(int(input())):
    s=input()
    somme=0
    nb2=0
    nb3=0
    for i in s:
        somme=(somme+int(i))%9
        if i=="2":
            nb2+=1 
        if i=="3":
            nb3+=1
    
    if somme==0 :
        OUT.append("YES")
    else :
        
        
        if nb2>=2 :
            
            if voir((somme+4)%9,(nb3+(nb2-2)//3)) or voir((somme+2)%9,(nb3+(nb2-1)//3)) or voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")
        elif nb2==1 :
            
            if voir((somme+2)%9,(nb3+(nb2-1)//3)) or voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")
        else:
            
            if voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")


for i in OUT:
    print(i)

        

    
    

Solution 2 (runtime: 233 ms):
for _ in range(int(input())):
    s = input()
    reachable2 = [0]
    reachable3 = [0]
    div = 0; sky2 = sky3 = 0
    finn = False 
    for i in s:
        div += int(i)
        if sky2 < 10:
            if i == '2':
                reachable2.append(reachable2[-1]+2)
                sky2 += 1
        if sky3 < 5:
            if i == '3':
                reachable3.append(reachable3[-1]+6)
                sky3 += 1 
    need = 9 - div%9
    if need == 9 or need == 0:
        print('yes')
    elif (need == 2 and len(reachable2) > 1) or (need == 4 and len(reachable2) > 2) or (need == 6 and (len(reachable2) > 3 or len(reachable3) > 1)) or (need == 8 and len(reachable2) > 4):
        print('yes')
    else:
        reachable = {(i+j)%9 for i in reachable2 for j in reachable3}
        #print(reachable, reachable2, reachable3)
        #print(div,need, two, three)
        #print(reachable)
        if need in reachable:
            print('yes')
        else:
            print('no')
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 171 ms):
def voir(test,nb3):
    while test!=0 and nb3>0:
        test=(test+6)%9
        nb3-=1
    if test==0:
        return True
    else :
        return False

OUT=[]
for i in range(int(input())):
    s=input()
    somme=0
    nb2=0
    nb3=0
    for i in s:
        somme=(somme+int(i))%9
        if i=="2":
            nb2+=1 
        if i=="3":
            nb3+=1
    
    if somme==0 :
        OUT.append("YES")
    else :
        
        
        if nb2>=2 :
            
            if voir((somme+4)%9,(nb3+(nb2-2)//3)) or voir((somme+2)%9,(nb3+(nb2-1)//3)) or voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")
        elif nb2==1 :
            
            if voir((somme+2)%9,(nb3+(nb2-1)//3)) or voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")
        else:
            
            if voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")


for i in OUT:
    print(i)

        

    
    

Solution 2 (runtime: 140 ms):
import sys
from functools import cache

inputs = sys.stdin.read().splitlines()[1:]

def solution(numbers: list[str]) -> None:
    
    for num in numbers:
        solve(num)

def solve(n: str) -> None:
    s = [int(x) for x in list(n)]

    sm = sum(s)
    twos = s.count(2)
    threes = s.count(3)

    for i in range(min(10, twos + 1)):
        for j in range(min(10, threes + 1)):
            if (sm + i * 2 + j * 6) % 9 == 0:
                print('YES')
                return
    print('NO')

solution(inputs)
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 171 ms):
def voir(test,nb3):
    while test!=0 and nb3>0:
        test=(test+6)%9
        nb3-=1
    if test==0:
        return True
    else :
        return False

OUT=[]
for i in range(int(input())):
    s=input()
    somme=0
    nb2=0
    nb3=0
    for i in s:
        somme=(somme+int(i))%9
        if i=="2":
            nb2+=1 
        if i=="3":
            nb3+=1
    
    if somme==0 :
        OUT.append("YES")
    else :
        
        
        if nb2>=2 :
            
            if voir((somme+4)%9,(nb3+(nb2-2)//3)) or voir((somme+2)%9,(nb3+(nb2-1)//3)) or voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")
        elif nb2==1 :
            
            if voir((somme+2)%9,(nb3+(nb2-1)//3)) or voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")
        else:
            
            if voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")


for i in OUT:
    print(i)

        

    
    

Solution 2 (runtime: 202 ms):
def main():
    test_case = int(input())
    for _ in range(test_case):
        num = [int(x) for x in input()]
        solve(num)


def solve(num):
    two = num.count(2)
    three = num.count(3)
    tot = sum(num)
    for i in range(min(10,two+1)):
        for j in range((min(10,three+1))):
            if (tot+ 2*i+ 6*j)%9 == 0:
                print("YES")
                return
    print("NO")    
main()
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 171 ms):
def voir(test,nb3):
    while test!=0 and nb3>0:
        test=(test+6)%9
        nb3-=1
    if test==0:
        return True
    else :
        return False

OUT=[]
for i in range(int(input())):
    s=input()
    somme=0
    nb2=0
    nb3=0
    for i in s:
        somme=(somme+int(i))%9
        if i=="2":
            nb2+=1 
        if i=="3":
            nb3+=1
    
    if somme==0 :
        OUT.append("YES")
    else :
        
        
        if nb2>=2 :
            
            if voir((somme+4)%9,(nb3+(nb2-2)//3)) or voir((somme+2)%9,(nb3+(nb2-1)//3)) or voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")
        elif nb2==1 :
            
            if voir((somme+2)%9,(nb3+(nb2-1)//3)) or voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")
        else:
            
            if voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")


for i in OUT:
    print(i)

        

    
    

Solution 2 (runtime: 186 ms):
cases = int(input())

for i in range(cases):
    n = input()
    
    l2 = [0]
    l3 = [0]
    sum = 0
    
    for j in range(len(n)):
        if n[j] == '2':
            l2.append(l2[-1]+2)
        if n[j] == '3':
            l3.append(l3[-1]+6)
        sum += int(n[j])
        
    ans = "NO"
    
    for j in l2:
        for k in l3:
            if (sum + j + k)%9==0:
                ans = "YES"    
                break 
        if ans == "YES":
            break
    
    print(ans)
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 171 ms):
def voir(test,nb3):
    while test!=0 and nb3>0:
        test=(test+6)%9
        nb3-=1
    if test==0:
        return True
    else :
        return False

OUT=[]
for i in range(int(input())):
    s=input()
    somme=0
    nb2=0
    nb3=0
    for i in s:
        somme=(somme+int(i))%9
        if i=="2":
            nb2+=1 
        if i=="3":
            nb3+=1
    
    if somme==0 :
        OUT.append("YES")
    else :
        
        
        if nb2>=2 :
            
            if voir((somme+4)%9,(nb3+(nb2-2)//3)) or voir((somme+2)%9,(nb3+(nb2-1)//3)) or voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")
        elif nb2==1 :
            
            if voir((somme+2)%9,(nb3+(nb2-1)//3)) or voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")
        else:
            
            if voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")


for i in OUT:
    print(i)

        

    
    

Solution 2 (runtime: 93 ms):
#!/usr/bin/python3

# cat test.txt | python3 main.py
import sys
import math


def solve():
    input_data = sys.stdin.read().strip().split()
    idx = 0
    t = int(input_data[idx])
    idx += 1

    results = []
    for _ in range(t):
        n = input_data[idx]
        idx += 1
        res = "NO"
        # process each test case:

        cnt_2 = 0
        cnt_6 = 0

        n_str = str(n)
        n = 0
        for i in range(len(n_str)):
            n += int(n_str[i])
            if n_str[i] == "2":
                cnt_2 += 1
            elif n_str[i] == "3":
                cnt_6 += 1

        if n % 9 == 0:
            res = "YES"
        else:
            twos = [2, 4, 6, 8, 1, 3, 5, 7]
            sixs = [6, 3]

            cnt_2 = min(cnt_2, len(twos))
            cnt_6 = min(cnt_6, len(sixs))

            if cnt_2 > 0:
                for i in range(cnt_2):
                    if (n + twos[i]) % 9 == 0:
                        res = "YES"

            if cnt_6 > 0:
                for i in range(cnt_6):
                    if (n + sixs[i]) % 9 == 0:
                        res = "YES"

            if cnt_6 > 0 and cnt_2 > 0:
                for i in range(cnt_2):
                    for k in range(cnt_6):
                        if (n + sixs[k] + twos[i]) % 9 == 0:
                            res = "YES"

        # store result
        results.append(str(res))

    print("\n".join(results))


if __name__ == "__main__":
    solve()
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 171 ms):
def voir(test,nb3):
    while test!=0 and nb3>0:
        test=(test+6)%9
        nb3-=1
    if test==0:
        return True
    else :
        return False

OUT=[]
for i in range(int(input())):
    s=input()
    somme=0
    nb2=0
    nb3=0
    for i in s:
        somme=(somme+int(i))%9
        if i=="2":
            nb2+=1 
        if i=="3":
            nb3+=1
    
    if somme==0 :
        OUT.append("YES")
    else :
        
        
        if nb2>=2 :
            
            if voir((somme+4)%9,(nb3+(nb2-2)//3)) or voir((somme+2)%9,(nb3+(nb2-1)//3)) or voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")
        elif nb2==1 :
            
            if voir((somme+2)%9,(nb3+(nb2-1)//3)) or voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")
        else:
            
            if voir((somme)%9,(nb3+(nb2)//3)):
                OUT.append("YES")
            else :
                OUT.append("NO")


for i in OUT:
    print(i)

        

    
    

Solution 2 (runtime: 77 ms):
def is_possible(n, k2, k3, d):
    # Case 1: b ≡ 0 mod 3
    e = 0
    a = (d - e + 9) % 9 * 5 % 9
    if a <= k2:
        return True
    # Case 2: b ≡ 1 mod 3, possible only if k3 >= 1
    if k3 >= 1:
        e = 6
        a = (d - e + 9) % 9 * 5 % 9
        if a <= k2:
            return True
    # Case 3: b ≡ 2 mod 3, possible only if k3 >= 2
    if k3 >= 2:
        e = 3
        a = (d - e + 9) % 9 * 5 % 9
        if a <= k2:
            return True
    return False

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    t = int(data[0])
    index = 1
    for _ in range(t):
        n = data[index]
        index += 1
        S = sum(int(ch) for ch in n)
        d = (-S) % 9
        k2 = n.count('2')
        k3 = n.count('3')
        if is_possible(n, k2, k3, d):
            print("YES")
        else:
            print("NO")

if __name__ == "__main__":
    main()