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

Solution 1 (runtime: 186 ms):
t = int(input())
ans = []
for i in range(t):
    n = input()
    a = n.count("2")
    b = n.count("3")
    v = 0
    for j in n:
        v += int(j)
    r = v%9
    if (a>=2 and b>=2) or (a>=5 and b>=1) or a>=8:
        ans.append("YES")
    elif r==0:
        ans.append("YES")
    elif r==4 and (a>=7 or (a>=4 and b>=1) or (a>=1 and b>=2)):
        ans.append("YES")
    elif r==6 and (a>=6 or (a>=3 and b>=1) or b>=2):
        ans.append("YES")
    elif r==8 and (a>=5 or (a>=2 and b>=1)):
        ans.append("YES")         
    elif r==1 and (a>=4 or (a>=1 and b>=1)):
        ans.append("YES")
    elif r==3 and (a>=3 or b>=1):
        ans.append("YES")
    elif r==5 and a>=2:
        ans.append("YES")
    elif r==7 and a>=1:
        ans.append("YES")
    else:
        ans.append("NO")

for j in ans:
    print(j)

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

def solve():
    num = [int(x) for x in input()]
    
    num_sum = sum(num)
    need = 9 - (num_sum % 9)
    
    count3 = num.count(3)
    count2 = num.count(2)
    
    for i in range(count2+1):
        for j in range(count3+1):
            if ((i * 2 + j * 6) - need) % 9 == 0:
                print("YES")
                return
    
    print("NO")
    return

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

Solution 1 (runtime: 186 ms):
t = int(input())
ans = []
for i in range(t):
    n = input()
    a = n.count("2")
    b = n.count("3")
    v = 0
    for j in n:
        v += int(j)
    r = v%9
    if (a>=2 and b>=2) or (a>=5 and b>=1) or a>=8:
        ans.append("YES")
    elif r==0:
        ans.append("YES")
    elif r==4 and (a>=7 or (a>=4 and b>=1) or (a>=1 and b>=2)):
        ans.append("YES")
    elif r==6 and (a>=6 or (a>=3 and b>=1) or b>=2):
        ans.append("YES")
    elif r==8 and (a>=5 or (a>=2 and b>=1)):
        ans.append("YES")         
    elif r==1 and (a>=4 or (a>=1 and b>=1)):
        ans.append("YES")
    elif r==3 and (a>=3 or b>=1):
        ans.append("YES")
    elif r==5 and a>=2:
        ans.append("YES")
    elif r==7 and a>=1:
        ans.append("YES")
    else:
        ans.append("NO")

for j in ans:
    print(j)

Solution 2 (runtime: 249 ms):
# ======= author: kuanhungchen.com | created: 05/02/23 08:33:06 CST ======= #
from sys            import stdin,  stderr, stdout, setrecursionlimit
from bisect         import bisect_left, bisect_right
from collections    import defaultdict, deque, Counter
from itertools      import accumulate, combinations, permutations, product
from functools      import lru_cache, cmp_to_key, reduce
from heapq          import heapify, heappush, heappop, heappushpop, heapreplace
# from pypyjit        import set_param
# set_param("max_unroll_recursion=-1")
# setrecursionlimit(300005)
orda  = 97
ordA  = 65
INF   = 1 << 60
MOD   = 1000000007
MOD2  = 998244353
input = lambda: stdin.readline().rstrip("\r\n")
linen = lambda cf_: "[L" + str(cf_.f_back.f_lineno) + "] "
dbg   = lambda *A, **M: stderr.write("\033[91m" + \
        M.get("sep", " ").join(map(str, A)) + M.get("end", "\n") + "\033[0m")
# ============================ START OF MY CODE ============================ #

def solve(_tc):
    s = input()
    n = len(s)
    dp = [set() for _ in range(n)]
    x = int(s[0])
    while x <= 9:
        dp[0].add(x % 9)
        if x == 0 or x == 1: break
        x *= x
    for i in range(1, n):
        x = int(s[i])
        xs = []
        while x <= 9:
            xs.append(x)
            if x == 0 or x == 1: break
            x *= x
        st = set()
        for d in dp[i - 1]:
            for x in xs:
                st.add((d + x) % 9)
        dp[i] = st
    if 0 in dp[-1]:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    _tcs = int(input())
    for _tc in range(1, vars().get("_tcs", 1) + 1):
        dbg("=== Case {} ===".format(str(_tc).rjust(2)))
        solve(_tc)
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 186 ms):
t = int(input())
ans = []
for i in range(t):
    n = input()
    a = n.count("2")
    b = n.count("3")
    v = 0
    for j in n:
        v += int(j)
    r = v%9
    if (a>=2 and b>=2) or (a>=5 and b>=1) or a>=8:
        ans.append("YES")
    elif r==0:
        ans.append("YES")
    elif r==4 and (a>=7 or (a>=4 and b>=1) or (a>=1 and b>=2)):
        ans.append("YES")
    elif r==6 and (a>=6 or (a>=3 and b>=1) or b>=2):
        ans.append("YES")
    elif r==8 and (a>=5 or (a>=2 and b>=1)):
        ans.append("YES")         
    elif r==1 and (a>=4 or (a>=1 and b>=1)):
        ans.append("YES")
    elif r==3 and (a>=3 or b>=1):
        ans.append("YES")
    elif r==5 and a>=2:
        ans.append("YES")
    elif r==7 and a>=1:
        ans.append("YES")
    else:
        ans.append("NO")

for j in ans:
    print(j)

Solution 2 (runtime: 108 ms):
def function(num: str):
    number_sum, two_count, three_count = 0, 0, 0
    for c in num:
        number_sum += ord(c) - ord('0')
        if c == '2':
            two_count += 1
        if c == '3':
            three_count += 1
    difference_needed = (9 - (number_sum % 9)) % 9
    yes = False
    for i in range(min(9, two_count + 1)): #where is the proof of this
        for j in range(min(9, three_count + 1)):
            if (2 * i + 6 * j) % 9 == difference_needed:
                yes = True
    if yes:
        print("YES")
    else:
        print("NO")

if __name__ == "__main__":
    tests = int(input())
    for _ in range(tests):
        num = input()
        function(num)
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 186 ms):
t = int(input())
ans = []
for i in range(t):
    n = input()
    a = n.count("2")
    b = n.count("3")
    v = 0
    for j in n:
        v += int(j)
    r = v%9
    if (a>=2 and b>=2) or (a>=5 and b>=1) or a>=8:
        ans.append("YES")
    elif r==0:
        ans.append("YES")
    elif r==4 and (a>=7 or (a>=4 and b>=1) or (a>=1 and b>=2)):
        ans.append("YES")
    elif r==6 and (a>=6 or (a>=3 and b>=1) or b>=2):
        ans.append("YES")
    elif r==8 and (a>=5 or (a>=2 and b>=1)):
        ans.append("YES")         
    elif r==1 and (a>=4 or (a>=1 and b>=1)):
        ans.append("YES")
    elif r==3 and (a>=3 or b>=1):
        ans.append("YES")
    elif r==5 and a>=2:
        ans.append("YES")
    elif r==7 and a>=1:
        ans.append("YES")
    else:
        ans.append("NO")

for j in ans:
    print(j)

Solution 2 (runtime: 249 ms):
for t in range(int(input())):
    s = input()
    sm = 0
    for i in s:
        sm += int(i)

    mod = sm%9

    if mod==0:
        print('YES')
    
    else:
        count2 = 0
        count3 = 0
        for char in s:
            if char=='2':
                count2 += 1
            elif char=='3':
                count3 += 1

        if mod==1:
            if count2>=4 or (count2>=1 and count3>=1):
                print('YES')
            else:
                print('NO')

        elif mod==2:
            if (count2>=2 and count3>=2) or (count2>=5 and count3>=1) or (count2>=8):
                print('YES')
            else:
                print("NO")

        elif mod==3:
            if (count3>=1) or (count2>=3):
                print('YES')
            else:
                print("NO")

        elif mod==4:
            if (count2>=4 and count3>=1) or (count2>=1 and count3>=2) or (count2>=7):
                print('YES')
            else:
                print("NO")

        elif mod==5:
            if (count2>=2):
                print('YES')
            else:
                print("NO")

        elif mod==6:
            if (count2>=6) or (count2>=3 and count3>=1) or (count3>=2):
                print('YES')
            else:
                print("NO")

        elif mod==7:
            if (count2>=1):
                print('YES')
            else:
                print("NO")

        elif mod==8:
            if (count2>=5) or (count2>=2 and count3>=1):
                print('YES')
            else:
                print("NO")
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 186 ms):
t = int(input())
ans = []
for i in range(t):
    n = input()
    a = n.count("2")
    b = n.count("3")
    v = 0
    for j in n:
        v += int(j)
    r = v%9
    if (a>=2 and b>=2) or (a>=5 and b>=1) or a>=8:
        ans.append("YES")
    elif r==0:
        ans.append("YES")
    elif r==4 and (a>=7 or (a>=4 and b>=1) or (a>=1 and b>=2)):
        ans.append("YES")
    elif r==6 and (a>=6 or (a>=3 and b>=1) or b>=2):
        ans.append("YES")
    elif r==8 and (a>=5 or (a>=2 and b>=1)):
        ans.append("YES")         
    elif r==1 and (a>=4 or (a>=1 and b>=1)):
        ans.append("YES")
    elif r==3 and (a>=3 or b>=1):
        ans.append("YES")
    elif r==5 and a>=2:
        ans.append("YES")
    elif r==7 and a>=1:
        ans.append("YES")
    else:
        ans.append("NO")

for j in ans:
    print(j)

Solution 2 (runtime: 343 ms):
import sys

input_data = sys.stdin.read().strip()

lines = input_data.splitlines()
lines.pop(0)

inp=[]
ans=[]
k=0
for line in lines:
   inp.append(int(line))
    
def get_digits(number):
    return [int(digit) for digit in str(abs(number))]

def count(dig):
    three = 0
    two = 0
    for d in dig:
        if d == 2:
            two += 1
        if d == 3:
            three += 1
    return two, three

for num in inp:
    nta = (num % 9)
    digits = get_digits(num)
    q2, q3 = count(digits)
    i, j = 0, 0
    f = 0
    while i <= q3:
        while j <= q2:
            if (nta + 6*i + 2*j) % 9 == 0:
                ans.append("YES")
                f = 1
                break
            j += 1
        if f == 1:
            break
        j = 0
        i += 1
    if f == 0:
        ans.append("NO")
            
for a in ans:
    print(a)
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 186 ms):
t = int(input())
ans = []
for i in range(t):
    n = input()
    a = n.count("2")
    b = n.count("3")
    v = 0
    for j in n:
        v += int(j)
    r = v%9
    if (a>=2 and b>=2) or (a>=5 and b>=1) or a>=8:
        ans.append("YES")
    elif r==0:
        ans.append("YES")
    elif r==4 and (a>=7 or (a>=4 and b>=1) or (a>=1 and b>=2)):
        ans.append("YES")
    elif r==6 and (a>=6 or (a>=3 and b>=1) or b>=2):
        ans.append("YES")
    elif r==8 and (a>=5 or (a>=2 and b>=1)):
        ans.append("YES")         
    elif r==1 and (a>=4 or (a>=1 and b>=1)):
        ans.append("YES")
    elif r==3 and (a>=3 or b>=1):
        ans.append("YES")
    elif r==5 and a>=2:
        ans.append("YES")
    elif r==7 and a>=1:
        ans.append("YES")
    else:
        ans.append("NO")

for j in ans:
    print(j)

Solution 2 (runtime: 108 ms):
import sys
from math import sqrt
input = sys.stdin.readline

def solve():
    # n=int(input())
    # a=[int(x) for x in input().split()]
    s = [int(x) for x in input().strip()]
    
    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')

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

Solution 1 (runtime: 186 ms):
t = int(input())
ans = []
for i in range(t):
    n = input()
    a = n.count("2")
    b = n.count("3")
    v = 0
    for j in n:
        v += int(j)
    r = v%9
    if (a>=2 and b>=2) or (a>=5 and b>=1) or a>=8:
        ans.append("YES")
    elif r==0:
        ans.append("YES")
    elif r==4 and (a>=7 or (a>=4 and b>=1) or (a>=1 and b>=2)):
        ans.append("YES")
    elif r==6 and (a>=6 or (a>=3 and b>=1) or b>=2):
        ans.append("YES")
    elif r==8 and (a>=5 or (a>=2 and b>=1)):
        ans.append("YES")         
    elif r==1 and (a>=4 or (a>=1 and b>=1)):
        ans.append("YES")
    elif r==3 and (a>=3 or b>=1):
        ans.append("YES")
    elif r==5 and a>=2:
        ans.append("YES")
    elif r==7 and a>=1:
        ans.append("YES")
    else:
        ans.append("NO")

for j in ans:
    print(j)

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: 186 ms):
t = int(input())
ans = []
for i in range(t):
    n = input()
    a = n.count("2")
    b = n.count("3")
    v = 0
    for j in n:
        v += int(j)
    r = v%9
    if (a>=2 and b>=2) or (a>=5 and b>=1) or a>=8:
        ans.append("YES")
    elif r==0:
        ans.append("YES")
    elif r==4 and (a>=7 or (a>=4 and b>=1) or (a>=1 and b>=2)):
        ans.append("YES")
    elif r==6 and (a>=6 or (a>=3 and b>=1) or b>=2):
        ans.append("YES")
    elif r==8 and (a>=5 or (a>=2 and b>=1)):
        ans.append("YES")         
    elif r==1 and (a>=4 or (a>=1 and b>=1)):
        ans.append("YES")
    elif r==3 and (a>=3 or b>=1):
        ans.append("YES")
    elif r==5 and a>=2:
        ans.append("YES")
    elif r==7 and a>=1:
        ans.append("YES")
    else:
        ans.append("NO")

for j in ans:
    print(j)

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: 186 ms):
t = int(input())
ans = []
for i in range(t):
    n = input()
    a = n.count("2")
    b = n.count("3")
    v = 0
    for j in n:
        v += int(j)
    r = v%9
    if (a>=2 and b>=2) or (a>=5 and b>=1) or a>=8:
        ans.append("YES")
    elif r==0:
        ans.append("YES")
    elif r==4 and (a>=7 or (a>=4 and b>=1) or (a>=1 and b>=2)):
        ans.append("YES")
    elif r==6 and (a>=6 or (a>=3 and b>=1) or b>=2):
        ans.append("YES")
    elif r==8 and (a>=5 or (a>=2 and b>=1)):
        ans.append("YES")         
    elif r==1 and (a>=4 or (a>=1 and b>=1)):
        ans.append("YES")
    elif r==3 and (a>=3 or b>=1):
        ans.append("YES")
    elif r==5 and a>=2:
        ans.append("YES")
    elif r==7 and a>=1:
        ans.append("YES")
    else:
        ans.append("NO")

for j in ans:
    print(j)

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: 186 ms):
t = int(input())
ans = []
for i in range(t):
    n = input()
    a = n.count("2")
    b = n.count("3")
    v = 0
    for j in n:
        v += int(j)
    r = v%9
    if (a>=2 and b>=2) or (a>=5 and b>=1) or a>=8:
        ans.append("YES")
    elif r==0:
        ans.append("YES")
    elif r==4 and (a>=7 or (a>=4 and b>=1) or (a>=1 and b>=2)):
        ans.append("YES")
    elif r==6 and (a>=6 or (a>=3 and b>=1) or b>=2):
        ans.append("YES")
    elif r==8 and (a>=5 or (a>=2 and b>=1)):
        ans.append("YES")         
    elif r==1 and (a>=4 or (a>=1 and b>=1)):
        ans.append("YES")
    elif r==3 and (a>=3 or b>=1):
        ans.append("YES")
    elif r==5 and a>=2:
        ans.append("YES")
    elif r==7 and a>=1:
        ans.append("YES")
    else:
        ans.append("NO")

for j in ans:
    print(j)

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: 186 ms):
t = int(input())
ans = []
for i in range(t):
    n = input()
    a = n.count("2")
    b = n.count("3")
    v = 0
    for j in n:
        v += int(j)
    r = v%9
    if (a>=2 and b>=2) or (a>=5 and b>=1) or a>=8:
        ans.append("YES")
    elif r==0:
        ans.append("YES")
    elif r==4 and (a>=7 or (a>=4 and b>=1) or (a>=1 and b>=2)):
        ans.append("YES")
    elif r==6 and (a>=6 or (a>=3 and b>=1) or b>=2):
        ans.append("YES")
    elif r==8 and (a>=5 or (a>=2 and b>=1)):
        ans.append("YES")         
    elif r==1 and (a>=4 or (a>=1 and b>=1)):
        ans.append("YES")
    elif r==3 and (a>=3 or b>=1):
        ans.append("YES")
    elif r==5 and a>=2:
        ans.append("YES")
    elif r==7 and a>=1:
        ans.append("YES")
    else:
        ans.append("NO")

for j in ans:
    print(j)

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: 186 ms):
t = int(input())
ans = []
for i in range(t):
    n = input()
    a = n.count("2")
    b = n.count("3")
    v = 0
    for j in n:
        v += int(j)
    r = v%9
    if (a>=2 and b>=2) or (a>=5 and b>=1) or a>=8:
        ans.append("YES")
    elif r==0:
        ans.append("YES")
    elif r==4 and (a>=7 or (a>=4 and b>=1) or (a>=1 and b>=2)):
        ans.append("YES")
    elif r==6 and (a>=6 or (a>=3 and b>=1) or b>=2):
        ans.append("YES")
    elif r==8 and (a>=5 or (a>=2 and b>=1)):
        ans.append("YES")         
    elif r==1 and (a>=4 or (a>=1 and b>=1)):
        ans.append("YES")
    elif r==3 and (a>=3 or b>=1):
        ans.append("YES")
    elif r==5 and a>=2:
        ans.append("YES")
    elif r==7 and a>=1:
        ans.append("YES")
    else:
        ans.append("NO")

for j in ans:
    print(j)

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: 186 ms):
t = int(input())
ans = []
for i in range(t):
    n = input()
    a = n.count("2")
    b = n.count("3")
    v = 0
    for j in n:
        v += int(j)
    r = v%9
    if (a>=2 and b>=2) or (a>=5 and b>=1) or a>=8:
        ans.append("YES")
    elif r==0:
        ans.append("YES")
    elif r==4 and (a>=7 or (a>=4 and b>=1) or (a>=1 and b>=2)):
        ans.append("YES")
    elif r==6 and (a>=6 or (a>=3 and b>=1) or b>=2):
        ans.append("YES")
    elif r==8 and (a>=5 or (a>=2 and b>=1)):
        ans.append("YES")         
    elif r==1 and (a>=4 or (a>=1 and b>=1)):
        ans.append("YES")
    elif r==3 and (a>=3 or b>=1):
        ans.append("YES")
    elif r==5 and a>=2:
        ans.append("YES")
    elif r==7 and a>=1:
        ans.append("YES")
    else:
        ans.append("NO")

for j in ans:
    print(j)

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: 186 ms):
t = int(input())
ans = []
for i in range(t):
    n = input()
    a = n.count("2")
    b = n.count("3")
    v = 0
    for j in n:
        v += int(j)
    r = v%9
    if (a>=2 and b>=2) or (a>=5 and b>=1) or a>=8:
        ans.append("YES")
    elif r==0:
        ans.append("YES")
    elif r==4 and (a>=7 or (a>=4 and b>=1) or (a>=1 and b>=2)):
        ans.append("YES")
    elif r==6 and (a>=6 or (a>=3 and b>=1) or b>=2):
        ans.append("YES")
    elif r==8 and (a>=5 or (a>=2 and b>=1)):
        ans.append("YES")         
    elif r==1 and (a>=4 or (a>=1 and b>=1)):
        ans.append("YES")
    elif r==3 and (a>=3 or b>=1):
        ans.append("YES")
    elif r==5 and a>=2:
        ans.append("YES")
    elif r==7 and a>=1:
        ans.append("YES")
    else:
        ans.append("NO")

for j in ans:
    print(j)

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")