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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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


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

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

        cnt_2 = 0
        cnt_6 = 0

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

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

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

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

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

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

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

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


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

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

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

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

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

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

Solution 2 (runtime: 203 ms):
t = int(input())
for _ in range(t):
    n  = input()
    length = len(n)
    total = 0  
    two = 0
    three = 0
    for i in range(length): 
        total += int(n[i])
        if(int(n[i]) == 2): two += 1
        if(int(n[i]) == 3): three += 1
    if(total % 9 == 0): print("YES")
    else:   
        ans = True
        for i in range(two+1):
            if ans == False: break
            for j in range(three+1):
                if (total + i * 2 + j * 6) % 9 == 0:
                    ans = False
                    break
        if ans : print("NO")
        else: print("YES")
Problem: 2050C - Uninteresting Number
Language: python

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

Solution 2 (runtime: 124 ms):
#  /\_/\  
# ( o.o ) 
#  > ^ <
#   ...
# Online Judge Please PASS Me :)

import sys
from collections import defaultdict

def slowestIO():
    input = sys.stdin.read
    data = input().splitlines()
    return data

def definitelyNotMain():
    data = slowestIO()
    index = 0
    test_cases = int(data[index])
    index += 1
    results = []

    for _ in range(test_cases):
        num = data[index]
        index += 1
        n = len(num)
        
        rem = sum([int(ch) for ch in num]) % 9
        target = 9 - rem
        if rem % 2 == 0:
            target = 18 - rem
        
        ans = "YES"
        twos, threes = 0, 0
        for ch in num:
            twos += ch == "2"
            threes += ch == "3"
            
        cur = 0
        check2s = twos
        while twos > 0:
            twos -= 1
            cur += 2
            if cur > target:
                cur -= 2
                break
            
        while cur < target and threes > 0:
            threes -= 1
            cur += 6
            
        diff = cur - target
                
        if not(diff == 2 and check2s > 0) and not(diff == 4 and check2s > 1) and (rem > 0 and cur != target):
            ans = "NO"
                
        results.append(str(ans))

    sys.stdout.write('\n'.join(results) + '\n')

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

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

Solution 2 (runtime: 327 ms):
testCases = int(input())
for i in range(testCases):
    two = 0
    three = 0
    total = 0
    number = input()
    for j in number:
        
        if j == "2":
            two += 1
        elif j == "3":
            three += 1
        total += int(j)
    total = total % 9
    if total == 0:
        print("YES")
    elif total == 3 and three >= 1 or total == 6 and three >= 2:
        print("YES")
    elif (9-total) % 2 == 0 and int((9-total) / 2) <= two or (18-total) % 2 == 0 and int((18-total) / 2) <= two:
        print("YES")
    elif three >= 2:
        total += 3
        total = total % 9
        if (9-total) % 2 == 0 and int((9-total) / 2) <= two or (18-total) % 2 == 0 and int((18-total) / 2) <= two:
            print("YES")
        else:
            total += 3
            total = total % 9
            if (9-total) % 2 == 0 and int((9-total) / 2) <= two or (18-total) % 2 == 0 and int((18-total) / 2) <= two:
                    print("YES")
            else:
                print("NO")
    elif three >= 1:
        total += 6
        total = total % 9
        if (9-total) % 2 == 0 and int((9-total) / 2) <= two or (18-total) % 2 == 0 and int((18-total) / 2) <= two:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")