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

Solution 1 (runtime: 139 ms):
tt = int(input())
while(tt > 0):
    num = input()
    num_2 = 0
    num_3 = 0
    curr_sum = 0
    max_x = 0
    max_y = 0
    for digit in num:
        curr_digit = int(digit)
        if curr_digit == 2:
            max_x += 1
        if curr_digit == 3:
            max_y += 1
        curr_sum += curr_digit

    ans = "YES" if curr_sum % 9 == 0 else "NO"
    x = 0
    y = 0
    for x in range(0,min(max_x+1, 9)):
        for y in range(0,min(max_y+1, 9)):
            total_sum = curr_sum + x*2 + y*6
            if total_sum % 9 == 0:
                ans = "YES"
    print(ans)
    tt -= 1


Solution 2 (runtime: 234 ms):
n = int(input())

for _ in range(n):
    possible = [0]
    s = str(input())
    for char in s:
        new = set()
        for i in possible:
            new.add((i+int(char)) % 9)
        if int(char) <= 3:
            for i in possible:
                new.add((i+int(char)*int(char)) % 9)
        possible = new
    if 0 in possible:
        print("YES")
    else:
        print("NO")
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 139 ms):
tt = int(input())
while(tt > 0):
    num = input()
    num_2 = 0
    num_3 = 0
    curr_sum = 0
    max_x = 0
    max_y = 0
    for digit in num:
        curr_digit = int(digit)
        if curr_digit == 2:
            max_x += 1
        if curr_digit == 3:
            max_y += 1
        curr_sum += curr_digit

    ans = "YES" if curr_sum % 9 == 0 else "NO"
    x = 0
    y = 0
    for x in range(0,min(max_x+1, 9)):
        for y in range(0,min(max_y+1, 9)):
            total_sum = curr_sum + x*2 + y*6
            if total_sum % 9 == 0:
                ans = "YES"
    print(ans)
    tt -= 1


Solution 2 (runtime: 124 ms):
def can_be_divisible_by_9(n_str):
    # 计算数字各位之和
    S = sum(int(ch) for ch in n_str)
    if S % 9 == 0:
        return "YES"
    
    # 计算目标值
    target = (-S) % 9
    new_target = (5 * target) % 9
    
    # 统计数字中2和3的个数
    cnt2 = n_str.count('2')
    cnt3 = n_str.count('3')
    
    # 枚举选择多少个3的平方（6）
    for b in range(0, min(cnt3, 8) + 1):
        a = (new_target - 3 * b) % 9
        if 0 <= a <= cnt2:
            return "YES"
    return "NO"

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    
    idx = 0
    t = int(data[idx])
    idx += 1
    results = []
    
    for _ in range(t):
        n_str = data[idx]
        idx += 1
        result = can_be_divisible_by_9(n_str)
        results.append(result)
    
    for res in results:
        print(res)

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

Solution 1 (runtime: 139 ms):
tt = int(input())
while(tt > 0):
    num = input()
    num_2 = 0
    num_3 = 0
    curr_sum = 0
    max_x = 0
    max_y = 0
    for digit in num:
        curr_digit = int(digit)
        if curr_digit == 2:
            max_x += 1
        if curr_digit == 3:
            max_y += 1
        curr_sum += curr_digit

    ans = "YES" if curr_sum % 9 == 0 else "NO"
    x = 0
    y = 0
    for x in range(0,min(max_x+1, 9)):
        for y in range(0,min(max_y+1, 9)):
            total_sum = curr_sum + x*2 + y*6
            if total_sum % 9 == 0:
                ans = "YES"
    print(ans)
    tt -= 1


Solution 2 (runtime: 218 ms):
def change(n,count_2,count_3):
    for i in range(0,min(count_2,8)+1):
        for j in range(0,min(3,count_3)+1):
            if ((n+2*i+6*j)%9 == 0):
                return "YES"
    return "NO"
t = int(input())
for _ in range(t):
    n = input()
    count_2 = 0
    count_3 = 0
    for char in n:
        if char == "2":
            count_2+=1
        if char == "3":
            count_3+=1
    Sum = 0
    for char in n:
        Sum+=int(char)
    if(Sum%9 == 0):
        print("YES")
    else:
        print(change(Sum,count_2,count_3))
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 139 ms):
tt = int(input())
while(tt > 0):
    num = input()
    num_2 = 0
    num_3 = 0
    curr_sum = 0
    max_x = 0
    max_y = 0
    for digit in num:
        curr_digit = int(digit)
        if curr_digit == 2:
            max_x += 1
        if curr_digit == 3:
            max_y += 1
        curr_sum += curr_digit

    ans = "YES" if curr_sum % 9 == 0 else "NO"
    x = 0
    y = 0
    for x in range(0,min(max_x+1, 9)):
        for y in range(0,min(max_y+1, 9)):
            total_sum = curr_sum + x*2 + y*6
            if total_sum % 9 == 0:
                ans = "YES"
    print(ans)
    tt -= 1


Solution 2 (runtime: 140 ms):
n = int(input())
for _ in range(n):
    a = input()
    k = 0
    two = 0
    three = 0
    q = False

    # Calculate the sum of digits and count of '2' and '3'
    for i in a:
        k += int(i)
        if i == '2':
            two += 1
        elif i == '3':
            three += 1

    # Check if the number is already divisible by 9
    if k % 9 == 0:
        print('YES')
        continue

    # Check combinations of extra contributions from '2' and '3'
    for x in range(two + 1):
        for y in range(three + 1):
            # Directly check divisibility without storing numbers
            if (k + 2 * x + 6 * y) % 9 == 0:
                print("YES")
                q = True
                break
        if q:  # Break outer loop if found
            break

    if not q:
        print("NO")
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 139 ms):
tt = int(input())
while(tt > 0):
    num = input()
    num_2 = 0
    num_3 = 0
    curr_sum = 0
    max_x = 0
    max_y = 0
    for digit in num:
        curr_digit = int(digit)
        if curr_digit == 2:
            max_x += 1
        if curr_digit == 3:
            max_y += 1
        curr_sum += curr_digit

    ans = "YES" if curr_sum % 9 == 0 else "NO"
    x = 0
    y = 0
    for x in range(0,min(max_x+1, 9)):
        for y in range(0,min(max_y+1, 9)):
            total_sum = curr_sum + x*2 + y*6
            if total_sum % 9 == 0:
                ans = "YES"
    print(ans)
    tt -= 1


Solution 2 (runtime: 187 ms):
def solve():
    x = input()
    res = 0
    two = three = 0
    for c in x[::-1]:
        c = int(c)
        res += c
        if c == 2:
            two += 1
        elif c == 3:
            three += 1
    
    two = min(8, two)
    three = min(8, three)
    for i in range(two+1):
        for j in range(three+1):
            if (res+(2*i)+(6*j)) % 9 == 0:
                print("YES")
                return

    print("NO")


for _ in range(int(input())): solve()
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 139 ms):
tt = int(input())
while(tt > 0):
    num = input()
    num_2 = 0
    num_3 = 0
    curr_sum = 0
    max_x = 0
    max_y = 0
    for digit in num:
        curr_digit = int(digit)
        if curr_digit == 2:
            max_x += 1
        if curr_digit == 3:
            max_y += 1
        curr_sum += curr_digit

    ans = "YES" if curr_sum % 9 == 0 else "NO"
    x = 0
    y = 0
    for x in range(0,min(max_x+1, 9)):
        for y in range(0,min(max_y+1, 9)):
            total_sum = curr_sum + x*2 + y*6
            if total_sum % 9 == 0:
                ans = "YES"
    print(ans)
    tt -= 1


Solution 2 (runtime: 468 ms):
def SumOfDigits(number):
    num = list(map(int,str(number)))
    sum = 0
    for z in num:
        sum += z
    return sum
t = int(input())
answer = []
for l in range(t):
    n = int(input())
    number = list(map(int,str(n)))
    currSum = SumOfDigits(n)
    if currSum % 9 == 0:
        answer.append("YES")
    else:
        made = False
        Twos = number.count(2)
        Threes = number.count(3)
        for i in range(0,Twos + 1):
            for h in range(0,Threes + 1):
                if (currSum + 2 * i + 6 * h) % 9 == 0:
                    answer.append("YES")
                    made = True
                    break
            if made:
                break
        if not made:
            answer.append("NO")
for h in answer:
    print(h)
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 139 ms):
tt = int(input())
while(tt > 0):
    num = input()
    num_2 = 0
    num_3 = 0
    curr_sum = 0
    max_x = 0
    max_y = 0
    for digit in num:
        curr_digit = int(digit)
        if curr_digit == 2:
            max_x += 1
        if curr_digit == 3:
            max_y += 1
        curr_sum += curr_digit

    ans = "YES" if curr_sum % 9 == 0 else "NO"
    x = 0
    y = 0
    for x in range(0,min(max_x+1, 9)):
        for y in range(0,min(max_y+1, 9)):
            total_sum = curr_sum + x*2 + y*6
            if total_sum % 9 == 0:
                ans = "YES"
    print(ans)
    tt -= 1


Solution 2 (runtime: 171 ms):

def digit_sum(n):
    if n[0] == '-':
        return digit_sum(n[1:])
    counter = 0
    for i in n:
        counter += int(i)
    return counter

def check(n):
    k = digit_sum(n)
    if k % 9 == 0:
        return 'YES'
    n_2 = n.count('2')
    n_3 = n.count('3')
    seen_2 = set()
    for i in range(n_2+1):
        if (i * 2) % 9 in seen_2:
            break
        seen_2.add((i*2)%9)
        for j in range(n_3 + 1):
            if n[0] != '-':
                if (k + i * 2 + j * 6) % 9 == 0:
                    return 'YES'
            else:
                if (k - i * 2 - j * 6 % 9) == 0:
                    return 'YES'
    return 'NO'


for i in range(int(input())):
    print(check(input()))
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 139 ms):
tt = int(input())
while(tt > 0):
    num = input()
    num_2 = 0
    num_3 = 0
    curr_sum = 0
    max_x = 0
    max_y = 0
    for digit in num:
        curr_digit = int(digit)
        if curr_digit == 2:
            max_x += 1
        if curr_digit == 3:
            max_y += 1
        curr_sum += curr_digit

    ans = "YES" if curr_sum % 9 == 0 else "NO"
    x = 0
    y = 0
    for x in range(0,min(max_x+1, 9)):
        for y in range(0,min(max_y+1, 9)):
            total_sum = curr_sum + x*2 + y*6
            if total_sum % 9 == 0:
                ans = "YES"
    print(ans)
    tt -= 1


Solution 2 (runtime: 186 ms):
for _ in range(int(input())):
    n = input()
    
    sm = 0
    for i in str(n):
        sm += int(i)

    twos = n.count('2')
    threes = n.count('3')
    
    ans = False
    for x in range(min(twos+1, 9)):
        for y in range(min(threes+1, 9)):
            if (sm + (2*x) + (6*y))%9 == 0:
                ans = True

    print("YES" if ans else "NO")
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 139 ms):
tt = int(input())
while(tt > 0):
    num = input()
    num_2 = 0
    num_3 = 0
    curr_sum = 0
    max_x = 0
    max_y = 0
    for digit in num:
        curr_digit = int(digit)
        if curr_digit == 2:
            max_x += 1
        if curr_digit == 3:
            max_y += 1
        curr_sum += curr_digit

    ans = "YES" if curr_sum % 9 == 0 else "NO"
    x = 0
    y = 0
    for x in range(0,min(max_x+1, 9)):
        for y in range(0,min(max_y+1, 9)):
            total_sum = curr_sum + x*2 + y*6
            if total_sum % 9 == 0:
                ans = "YES"
    print(ans)
    tt -= 1


Solution 2 (runtime: 171 ms):
def solve(num):
    three = 0
    two = 0
    s = 0
    for i in num:
        if i == '2':
            two += 1
        elif i == '3':
            three += 1
        s += int(i)

    if s % 9 == 0:
        return "YES"

    for i in range(min(9,two+1)):
        for j in range(min(7,three+1)):
            if (s + 2*i + 6*j ) % 9 == 0:
                return "YES"
    return "NO"




for _ in range(int(input())):
    print(solve(input()))
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 139 ms):
tt = int(input())
while(tt > 0):
    num = input()
    num_2 = 0
    num_3 = 0
    curr_sum = 0
    max_x = 0
    max_y = 0
    for digit in num:
        curr_digit = int(digit)
        if curr_digit == 2:
            max_x += 1
        if curr_digit == 3:
            max_y += 1
        curr_sum += curr_digit

    ans = "YES" if curr_sum % 9 == 0 else "NO"
    x = 0
    y = 0
    for x in range(0,min(max_x+1, 9)):
        for y in range(0,min(max_y+1, 9)):
            total_sum = curr_sum + x*2 + y*6
            if total_sum % 9 == 0:
                ans = "YES"
    print(ans)
    tt -= 1


Solution 2 (runtime: 156 ms):
no = int(input())
for i in range(no):
    l = list(map(int, list(input())))
    c2 = l.count(2)
    c3 = l.count(3)
    sumo = sum(l)
    ans = "NO"
    for two in range(c2+1):
        for three in range(c3+1):
            x = sumo + 2*two + 6*three
            if x%9==0:
                ans = "YES"
                break
        if ans == "YES":
            break
    print(ans)
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 139 ms):
tt = int(input())
while(tt > 0):
    num = input()
    num_2 = 0
    num_3 = 0
    curr_sum = 0
    max_x = 0
    max_y = 0
    for digit in num:
        curr_digit = int(digit)
        if curr_digit == 2:
            max_x += 1
        if curr_digit == 3:
            max_y += 1
        curr_sum += curr_digit

    ans = "YES" if curr_sum % 9 == 0 else "NO"
    x = 0
    y = 0
    for x in range(0,min(max_x+1, 9)):
        for y in range(0,min(max_y+1, 9)):
            total_sum = curr_sum + x*2 + y*6
            if total_sum % 9 == 0:
                ans = "YES"
    print(ans)
    tt -= 1


Solution 2 (runtime: 140 ms):
import sys
input=lambda :sys.stdin.readline().strip()
t=int(input())
for _ in range(t):
    s=input()
    ls=[int(i) for i in s]
    a=s.count('2')
    b=s.count('3')
    flag=0
    for i in range(min(10,a+1)):
        for j in range(min(10,b+1)):
            if (sum(ls)+2*i+6*j)%9==0:
                flag+=1
                print("YES")
                break
        if flag!=0:
            break
    if flag==0:
        print("NO")
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 139 ms):
tt = int(input())
while(tt > 0):
    num = input()
    num_2 = 0
    num_3 = 0
    curr_sum = 0
    max_x = 0
    max_y = 0
    for digit in num:
        curr_digit = int(digit)
        if curr_digit == 2:
            max_x += 1
        if curr_digit == 3:
            max_y += 1
        curr_sum += curr_digit

    ans = "YES" if curr_sum % 9 == 0 else "NO"
    x = 0
    y = 0
    for x in range(0,min(max_x+1, 9)):
        for y in range(0,min(max_y+1, 9)):
            total_sum = curr_sum + x*2 + y*6
            if total_sum % 9 == 0:
                ans = "YES"
    print(ans)
    tt -= 1


Solution 2 (runtime: 124 ms):
def main():
    import sys
    input = sys.stdin.read
    data = input().split()

    tc = int(data[0])  # Read the number of test cases
    results = []

    for t in range(1, tc + 1):
        str_num = data[t]
        sum_digits = 0
        two_cnt = 0
        three_cnt = 0

        # Count sum of digits, number of 2's, and number of 3's
        for char in str_num:
            digit = int(char)
            sum_digits += digit
            if digit == 2:
                two_cnt += 1
            elif digit == 3:
                three_cnt += 1

        valid = False

        # Try combinations of 2's and 3's
        for i in range(min(8, two_cnt) + 1):
            for j in range(min(8, three_cnt) + 1):
                if (sum_digits + 2 * i + 6 * j) % 9 == 0:
                    results.append("yes".capitalize())
                    valid = True
                    break
            if valid:
                break
        if not valid:
            results.append("no".capitalize())
    
    # Print all results at once
    sys.stdout.write("\n".join(results) + "\n")

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

Solution 1 (runtime: 139 ms):
tt = int(input())
while(tt > 0):
    num = input()
    num_2 = 0
    num_3 = 0
    curr_sum = 0
    max_x = 0
    max_y = 0
    for digit in num:
        curr_digit = int(digit)
        if curr_digit == 2:
            max_x += 1
        if curr_digit == 3:
            max_y += 1
        curr_sum += curr_digit

    ans = "YES" if curr_sum % 9 == 0 else "NO"
    x = 0
    y = 0
    for x in range(0,min(max_x+1, 9)):
        for y in range(0,min(max_y+1, 9)):
            total_sum = curr_sum + x*2 + y*6
            if total_sum % 9 == 0:
                ans = "YES"
    print(ans)
    tt -= 1


Solution 2 (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")
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 139 ms):
tt = int(input())
while(tt > 0):
    num = input()
    num_2 = 0
    num_3 = 0
    curr_sum = 0
    max_x = 0
    max_y = 0
    for digit in num:
        curr_digit = int(digit)
        if curr_digit == 2:
            max_x += 1
        if curr_digit == 3:
            max_y += 1
        curr_sum += curr_digit

    ans = "YES" if curr_sum % 9 == 0 else "NO"
    x = 0
    y = 0
    for x in range(0,min(max_x+1, 9)):
        for y in range(0,min(max_y+1, 9)):
            total_sum = curr_sum + x*2 + y*6
            if total_sum % 9 == 0:
                ans = "YES"
    print(ans)
    tt -= 1


Solution 2 (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)
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 139 ms):
tt = int(input())
while(tt > 0):
    num = input()
    num_2 = 0
    num_3 = 0
    curr_sum = 0
    max_x = 0
    max_y = 0
    for digit in num:
        curr_digit = int(digit)
        if curr_digit == 2:
            max_x += 1
        if curr_digit == 3:
            max_y += 1
        curr_sum += curr_digit

    ans = "YES" if curr_sum % 9 == 0 else "NO"
    x = 0
    y = 0
    for x in range(0,min(max_x+1, 9)):
        for y in range(0,min(max_y+1, 9)):
            total_sum = curr_sum + x*2 + y*6
            if total_sum % 9 == 0:
                ans = "YES"
    print(ans)
    tt -= 1


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: 139 ms):
tt = int(input())
while(tt > 0):
    num = input()
    num_2 = 0
    num_3 = 0
    curr_sum = 0
    max_x = 0
    max_y = 0
    for digit in num:
        curr_digit = int(digit)
        if curr_digit == 2:
            max_x += 1
        if curr_digit == 3:
            max_y += 1
        curr_sum += curr_digit

    ans = "YES" if curr_sum % 9 == 0 else "NO"
    x = 0
    y = 0
    for x in range(0,min(max_x+1, 9)):
        for y in range(0,min(max_y+1, 9)):
            total_sum = curr_sum + x*2 + y*6
            if total_sum % 9 == 0:
                ans = "YES"
    print(ans)
    tt -= 1


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: 139 ms):
tt = int(input())
while(tt > 0):
    num = input()
    num_2 = 0
    num_3 = 0
    curr_sum = 0
    max_x = 0
    max_y = 0
    for digit in num:
        curr_digit = int(digit)
        if curr_digit == 2:
            max_x += 1
        if curr_digit == 3:
            max_y += 1
        curr_sum += curr_digit

    ans = "YES" if curr_sum % 9 == 0 else "NO"
    x = 0
    y = 0
    for x in range(0,min(max_x+1, 9)):
        for y in range(0,min(max_y+1, 9)):
            total_sum = curr_sum + x*2 + y*6
            if total_sum % 9 == 0:
                ans = "YES"
    print(ans)
    tt -= 1


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: 139 ms):
tt = int(input())
while(tt > 0):
    num = input()
    num_2 = 0
    num_3 = 0
    curr_sum = 0
    max_x = 0
    max_y = 0
    for digit in num:
        curr_digit = int(digit)
        if curr_digit == 2:
            max_x += 1
        if curr_digit == 3:
            max_y += 1
        curr_sum += curr_digit

    ans = "YES" if curr_sum % 9 == 0 else "NO"
    x = 0
    y = 0
    for x in range(0,min(max_x+1, 9)):
        for y in range(0,min(max_y+1, 9)):
            total_sum = curr_sum + x*2 + y*6
            if total_sum % 9 == 0:
                ans = "YES"
    print(ans)
    tt -= 1


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)