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

Solution 1 (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)) 





Solution 2 (runtime: 202 ms):
import sys
import math
import collections
import statistics
import bisect

input = sys.stdin.readline

############ ---- Input Functions ---- ############
##---1) inp — For taking integer inputs.
def inp():
    return (int(input()))

##2) inlt — For taking List inputs.
def inlt():
    return (list(map(int, input().split())))

#3) insr — For taking string inputs. Actually it returns a List of Characters,
# instead of a string, which is easier to use in Python, because in Python,
# Strings are Immutable.
def insr():
    s = input()
    return (list(s[:len(s) - 1]))

#4) invr — For taking space seperated integer variable inputs.
def invr():
    return list(map(int, input().split()))

for iii in range(int(input())):
    a = insr()
    sum = 0
    num2 = 0
    num3 = 0
    for i in a:
        sum += int(i)
        if i == '2':
            num2 += 1
        elif i == '3':
            num3 += 1
    if sum % 9 == 0:
        print("yes")
        continue
    res = 0
    for x in range(min(num2+1, 10)):
        if res == 0:
            for y in range(min(num3+1, 10)):
                if (sum + 2*x + 6*y) % 9 == 0:
                    print("yes")
                    res = 1
                    break
        else:
            break
    if res == 0:
        print("no")
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (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)) 





Solution 2 (runtime: 249 ms):
t=int(input())
for z in range(t):
    n=[int(i) for i in list(input())]
    a=[0,0]
    num=sum(n)
    a[0]=n.count(2)
    a[1]=n.count(3)
    flag=False
    for i in range(min(10,a[0]+1)):
        if not flag:
            for j in range(min(10,a[1]+1)):
                if (num+2*i+6*j)%9==0:
                    print('YES')
                    flag=True
                    break
        else:
            break
    if not flag:
        print('NO')
Problem: 2050C - Uninteresting Number
Language: python

Solution 1 (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)) 





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





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





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





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





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





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


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


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


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


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


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


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


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


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