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

Solution 1 (runtime: 155 ms):
def is_divi9(num):
    s = sum(num)  # مجموع اولیه ارقام
    if s % 9 == 0:  # بررسی اولیه
        return "YES"
    
    # شمارش تعداد ارقام 2 و 3
    count_2 = num.count(2)
    count_3 = num.count(3)

    # بررسی تمام مقادیر ممکن از تغییر
    for c2 in range(count_2 + 1):  # تعداد تغییر 2ها از 0 تا count_2
        for c3 in range(count_3 + 1):  # تعداد تغییر 3ها از 0 تا count_3
            new_s = s + c2 * 2 + c3 * 6
            if new_s % 9 == 0:
                return "YES"

    return "NO"

# ورودی گرفتن
t = int(input())
for _ in range(t):
    num = [int(digit) for digit in input()]  # تبدیل عدد به لیست ارقام
    print(is_divi9(num))


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: 155 ms):
def is_divi9(num):
    s = sum(num)  # مجموع اولیه ارقام
    if s % 9 == 0:  # بررسی اولیه
        return "YES"
    
    # شمارش تعداد ارقام 2 و 3
    count_2 = num.count(2)
    count_3 = num.count(3)

    # بررسی تمام مقادیر ممکن از تغییر
    for c2 in range(count_2 + 1):  # تعداد تغییر 2ها از 0 تا count_2
        for c3 in range(count_3 + 1):  # تعداد تغییر 3ها از 0 تا count_3
            new_s = s + c2 * 2 + c3 * 6
            if new_s % 9 == 0:
                return "YES"

    return "NO"

# ورودی گرفتن
t = int(input())
for _ in range(t):
    num = [int(digit) for digit in input()]  # تبدیل عدد به لیست ارقام
    print(is_divi9(num))


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: 155 ms):
def is_divi9(num):
    s = sum(num)  # مجموع اولیه ارقام
    if s % 9 == 0:  # بررسی اولیه
        return "YES"
    
    # شمارش تعداد ارقام 2 و 3
    count_2 = num.count(2)
    count_3 = num.count(3)

    # بررسی تمام مقادیر ممکن از تغییر
    for c2 in range(count_2 + 1):  # تعداد تغییر 2ها از 0 تا count_2
        for c3 in range(count_3 + 1):  # تعداد تغییر 3ها از 0 تا count_3
            new_s = s + c2 * 2 + c3 * 6
            if new_s % 9 == 0:
                return "YES"

    return "NO"

# ورودی گرفتن
t = int(input())
for _ in range(t):
    num = [int(digit) for digit in input()]  # تبدیل عدد به لیست ارقام
    print(is_divi9(num))


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: 155 ms):
def is_divi9(num):
    s = sum(num)  # مجموع اولیه ارقام
    if s % 9 == 0:  # بررسی اولیه
        return "YES"
    
    # شمارش تعداد ارقام 2 و 3
    count_2 = num.count(2)
    count_3 = num.count(3)

    # بررسی تمام مقادیر ممکن از تغییر
    for c2 in range(count_2 + 1):  # تعداد تغییر 2ها از 0 تا count_2
        for c3 in range(count_3 + 1):  # تعداد تغییر 3ها از 0 تا count_3
            new_s = s + c2 * 2 + c3 * 6
            if new_s % 9 == 0:
                return "YES"

    return "NO"

# ورودی گرفتن
t = int(input())
for _ in range(t):
    num = [int(digit) for digit in input()]  # تبدیل عدد به لیست ارقام
    print(is_divi9(num))


Solution 2 (runtime: 249 ms):
for i in range(int(input())):
    n=(input())
    a=0
    for i in n:
        a+=int(i)
    a=a%9
    a=9-a
    if a==9:
        print("YES")
    else:
        if a%2!=0:
            p=0
            q=0
            for i in n:
                if i=="2":
                    p+=1
                if i=="3":
                    q+=1
            if a==1:
                if p>=5 or (p>=2 and q>=1):
                    print("YES")
                else:
                    print("NO")
            elif a==3:
                if q>=2 or p>=6 or (q>=1 and p>=3):
                    print("YES")
                else:
                    print("NO")
            elif a==5:
                if p>=7 or (q>=1 and p>=4) or (q>=2 and p>=1):
                    print("YES")
                else:
                    print('NO')
            else:
                if p>=8 or (q>=1 and p>=5) or (q>=2 and p>=2):
                    print("YES")
                else:
                    print("NO")
        else:
            if a<6:
                a=a//2
                ans=0
                for i in n:
                    if i=="2":
                        ans+=1
                if ans>=a:
                    print("YES")
                else:
                    print("NO")
            else:
                if a==6:
                    a=a//2
                    ans=0
                    for i in n:
                        if i=="2":
                            ans+=1
                    if ans>=a:
                        print("YES")
                    else:
                        for i in n:
                            if i=="3":
                                print("YES")
                                break
                        else:
                            print("NO")
                else:
                    a=a//2
                    ans=0
                    for i in n:
                        if i=="2":
                            ans+=1
                    if ans>=a:
                        print("YES")
                    else:
                        if ans<1:
                            print("NO")
                        else:
                            for i in n:
                                if i=="3":
                                    print("YES")
                                    break
                            else:
                                print("NO")
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (runtime: 155 ms):
def is_divi9(num):
    s = sum(num)  # مجموع اولیه ارقام
    if s % 9 == 0:  # بررسی اولیه
        return "YES"
    
    # شمارش تعداد ارقام 2 و 3
    count_2 = num.count(2)
    count_3 = num.count(3)

    # بررسی تمام مقادیر ممکن از تغییر
    for c2 in range(count_2 + 1):  # تعداد تغییر 2ها از 0 تا count_2
        for c3 in range(count_3 + 1):  # تعداد تغییر 3ها از 0 تا count_3
            new_s = s + c2 * 2 + c3 * 6
            if new_s % 9 == 0:
                return "YES"

    return "NO"

# ورودی گرفتن
t = int(input())
for _ in range(t):
    num = [int(digit) for digit in input()]  # تبدیل عدد به لیست ارقام
    print(is_divi9(num))


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: 155 ms):
def is_divi9(num):
    s = sum(num)  # مجموع اولیه ارقام
    if s % 9 == 0:  # بررسی اولیه
        return "YES"
    
    # شمارش تعداد ارقام 2 و 3
    count_2 = num.count(2)
    count_3 = num.count(3)

    # بررسی تمام مقادیر ممکن از تغییر
    for c2 in range(count_2 + 1):  # تعداد تغییر 2ها از 0 تا count_2
        for c3 in range(count_3 + 1):  # تعداد تغییر 3ها از 0 تا count_3
            new_s = s + c2 * 2 + c3 * 6
            if new_s % 9 == 0:
                return "YES"

    return "NO"

# ورودی گرفتن
t = int(input())
for _ in range(t):
    num = [int(digit) for digit in input()]  # تبدیل عدد به لیست ارقام
    print(is_divi9(num))


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: 155 ms):
def is_divi9(num):
    s = sum(num)  # مجموع اولیه ارقام
    if s % 9 == 0:  # بررسی اولیه
        return "YES"
    
    # شمارش تعداد ارقام 2 و 3
    count_2 = num.count(2)
    count_3 = num.count(3)

    # بررسی تمام مقادیر ممکن از تغییر
    for c2 in range(count_2 + 1):  # تعداد تغییر 2ها از 0 تا count_2
        for c3 in range(count_3 + 1):  # تعداد تغییر 3ها از 0 تا count_3
            new_s = s + c2 * 2 + c3 * 6
            if new_s % 9 == 0:
                return "YES"

    return "NO"

# ورودی گرفتن
t = int(input())
for _ in range(t):
    num = [int(digit) for digit in input()]  # تبدیل عدد به لیست ارقام
    print(is_divi9(num))


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: 155 ms):
def is_divi9(num):
    s = sum(num)  # مجموع اولیه ارقام
    if s % 9 == 0:  # بررسی اولیه
        return "YES"
    
    # شمارش تعداد ارقام 2 و 3
    count_2 = num.count(2)
    count_3 = num.count(3)

    # بررسی تمام مقادیر ممکن از تغییر
    for c2 in range(count_2 + 1):  # تعداد تغییر 2ها از 0 تا count_2
        for c3 in range(count_3 + 1):  # تعداد تغییر 3ها از 0 تا count_3
            new_s = s + c2 * 2 + c3 * 6
            if new_s % 9 == 0:
                return "YES"

    return "NO"

# ورودی گرفتن
t = int(input())
for _ in range(t):
    num = [int(digit) for digit in input()]  # تبدیل عدد به لیست ارقام
    print(is_divi9(num))


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: 155 ms):
def is_divi9(num):
    s = sum(num)  # مجموع اولیه ارقام
    if s % 9 == 0:  # بررسی اولیه
        return "YES"
    
    # شمارش تعداد ارقام 2 و 3
    count_2 = num.count(2)
    count_3 = num.count(3)

    # بررسی تمام مقادیر ممکن از تغییر
    for c2 in range(count_2 + 1):  # تعداد تغییر 2ها از 0 تا count_2
        for c3 in range(count_3 + 1):  # تعداد تغییر 3ها از 0 تا count_3
            new_s = s + c2 * 2 + c3 * 6
            if new_s % 9 == 0:
                return "YES"

    return "NO"

# ورودی گرفتن
t = int(input())
for _ in range(t):
    num = [int(digit) for digit in input()]  # تبدیل عدد به لیست ارقام
    print(is_divi9(num))


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: 155 ms):
def is_divi9(num):
    s = sum(num)  # مجموع اولیه ارقام
    if s % 9 == 0:  # بررسی اولیه
        return "YES"
    
    # شمارش تعداد ارقام 2 و 3
    count_2 = num.count(2)
    count_3 = num.count(3)

    # بررسی تمام مقادیر ممکن از تغییر
    for c2 in range(count_2 + 1):  # تعداد تغییر 2ها از 0 تا count_2
        for c3 in range(count_3 + 1):  # تعداد تغییر 3ها از 0 تا count_3
            new_s = s + c2 * 2 + c3 * 6
            if new_s % 9 == 0:
                return "YES"

    return "NO"

# ورودی گرفتن
t = int(input())
for _ in range(t):
    num = [int(digit) for digit in input()]  # تبدیل عدد به لیست ارقام
    print(is_divi9(num))


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: 155 ms):
def is_divi9(num):
    s = sum(num)  # مجموع اولیه ارقام
    if s % 9 == 0:  # بررسی اولیه
        return "YES"
    
    # شمارش تعداد ارقام 2 و 3
    count_2 = num.count(2)
    count_3 = num.count(3)

    # بررسی تمام مقادیر ممکن از تغییر
    for c2 in range(count_2 + 1):  # تعداد تغییر 2ها از 0 تا count_2
        for c3 in range(count_3 + 1):  # تعداد تغییر 3ها از 0 تا count_3
            new_s = s + c2 * 2 + c3 * 6
            if new_s % 9 == 0:
                return "YES"

    return "NO"

# ورودی گرفتن
t = int(input())
for _ in range(t):
    num = [int(digit) for digit in input()]  # تبدیل عدد به لیست ارقام
    print(is_divi9(num))


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: 155 ms):
def is_divi9(num):
    s = sum(num)  # مجموع اولیه ارقام
    if s % 9 == 0:  # بررسی اولیه
        return "YES"
    
    # شمارش تعداد ارقام 2 و 3
    count_2 = num.count(2)
    count_3 = num.count(3)

    # بررسی تمام مقادیر ممکن از تغییر
    for c2 in range(count_2 + 1):  # تعداد تغییر 2ها از 0 تا count_2
        for c3 in range(count_3 + 1):  # تعداد تغییر 3ها از 0 تا count_3
            new_s = s + c2 * 2 + c3 * 6
            if new_s % 9 == 0:
                return "YES"

    return "NO"

# ورودی گرفتن
t = int(input())
for _ in range(t):
    num = [int(digit) for digit in input()]  # تبدیل عدد به لیست ارقام
    print(is_divi9(num))


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: 155 ms):
def is_divi9(num):
    s = sum(num)  # مجموع اولیه ارقام
    if s % 9 == 0:  # بررسی اولیه
        return "YES"
    
    # شمارش تعداد ارقام 2 و 3
    count_2 = num.count(2)
    count_3 = num.count(3)

    # بررسی تمام مقادیر ممکن از تغییر
    for c2 in range(count_2 + 1):  # تعداد تغییر 2ها از 0 تا count_2
        for c3 in range(count_3 + 1):  # تعداد تغییر 3ها از 0 تا count_3
            new_s = s + c2 * 2 + c3 * 6
            if new_s % 9 == 0:
                return "YES"

    return "NO"

# ورودی گرفتن
t = int(input())
for _ in range(t):
    num = [int(digit) for digit in input()]  # تبدیل عدد به لیست ارقام
    print(is_divi9(num))


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: 155 ms):
def is_divi9(num):
    s = sum(num)  # مجموع اولیه ارقام
    if s % 9 == 0:  # بررسی اولیه
        return "YES"
    
    # شمارش تعداد ارقام 2 و 3
    count_2 = num.count(2)
    count_3 = num.count(3)

    # بررسی تمام مقادیر ممکن از تغییر
    for c2 in range(count_2 + 1):  # تعداد تغییر 2ها از 0 تا count_2
        for c3 in range(count_3 + 1):  # تعداد تغییر 3ها از 0 تا count_3
            new_s = s + c2 * 2 + c3 * 6
            if new_s % 9 == 0:
                return "YES"

    return "NO"

# ورودی گرفتن
t = int(input())
for _ in range(t):
    num = [int(digit) for digit in input()]  # تبدیل عدد به لیست ارقام
    print(is_divi9(num))


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: 155 ms):
def is_divi9(num):
    s = sum(num)  # مجموع اولیه ارقام
    if s % 9 == 0:  # بررسی اولیه
        return "YES"
    
    # شمارش تعداد ارقام 2 و 3
    count_2 = num.count(2)
    count_3 = num.count(3)

    # بررسی تمام مقادیر ممکن از تغییر
    for c2 in range(count_2 + 1):  # تعداد تغییر 2ها از 0 تا count_2
        for c3 in range(count_3 + 1):  # تعداد تغییر 3ها از 0 تا count_3
            new_s = s + c2 * 2 + c3 * 6
            if new_s % 9 == 0:
                return "YES"

    return "NO"

# ورودی گرفتن
t = int(input())
for _ in range(t):
    num = [int(digit) for digit in input()]  # تبدیل عدد به لیست ارقام
    print(is_divi9(num))


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: 155 ms):
def is_divi9(num):
    s = sum(num)  # مجموع اولیه ارقام
    if s % 9 == 0:  # بررسی اولیه
        return "YES"
    
    # شمارش تعداد ارقام 2 و 3
    count_2 = num.count(2)
    count_3 = num.count(3)

    # بررسی تمام مقادیر ممکن از تغییر
    for c2 in range(count_2 + 1):  # تعداد تغییر 2ها از 0 تا count_2
        for c3 in range(count_3 + 1):  # تعداد تغییر 3ها از 0 تا count_3
            new_s = s + c2 * 2 + c3 * 6
            if new_s % 9 == 0:
                return "YES"

    return "NO"

# ورودی گرفتن
t = int(input())
for _ in range(t):
    num = [int(digit) for digit in input()]  # تبدیل عدد به لیست ارقام
    print(is_divi9(num))


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