Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
a, b = map(int, input().split())
# 文字列の入力
s = input()
   if a*b%2==0
# 出力
   print("Even")
   else:
    print("Odd")
    
  


Fixed submission:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
a, b = map(int, input().split())
if a*b%2 == 0:
# 出力
   print("Even")
else:
   print("Odd")

Buggy python submission (verdict: Runtime Error):
a , b = map(int, input(),split())
Value = a*b

if Value%2 == 0:
    print("Even")
else:
    print("Odd")

Fixed submission:
a , b = map(int, input().split())
Value = a*b

if Value%2 == 0:
    print("Even")
else:
    print("Odd")
Buggy python submission (verdict: Runtime Error):
import math
n = input()
a = list(map(int, input().split()))
ans = float("inf")
for i in a:
    ans = min(ans, len(bin(i)) - bin(i).rfind("1") - 1)
print(round(ans))

Fixed submission:
print(input().count("1"))

Buggy python submission (verdict: Runtime Error):
import math
N = input()

a = list(map(int, input().split()))

ans = float("inf")

for i in a:
    ans = min(ans, len(bin(i)) - bin(i).rfind("1") - 1)
print(round(ans))

Fixed submission:
print(input().count("1"))

Buggy python submission (verdict: Runtime Error):
import math
N = input()

list = list(map(int, input().split()))

ans = float("inf")

for a in list:
    ans = min(ans, len(bin(a)) - bin(a).rfind("1") - 1)
print(round(ans))

Fixed submission:
print(input().count("1"))

Buggy python submission (verdict: Runtime Error):
N = input()

list = list(map(int, input().split()))

ans = float("inf")

for a in list:
    ans = min(ans, len(bin(a)) - bin(a).rfind("1") - 1)
print(round(ans))

Fixed submission:
print(input().count("1"))

Buggy python submission (verdict: Runtime Error):
N = input()

list = list(map(int, input().split()))

ans = float("inf")

for a in list:
    ans = min(ans, len(bin(a)) - bin(a).rfind("1") - 1)
print(ans)

Fixed submission:
print(input().count("1"))
Buggy python submission (verdict: Runtime Error):
a, b = int(input().split)

if (a*b ) % 2 = 1
    print('odd')
    
    else
    print('even')

Fixed submission:
a,  b = map( int, (input().split()))

if (a*b ) % 2:
    print('Odd')
    
else:
    print('Even')

Buggy python submission (verdict: Runtime Error):
a, b = int(input().split)

if (a*b )%2 = 1
    print('odd')
    
    else
            print('even')

Fixed submission:
a,  b = map( int, (input().split()))

if (a*b ) % 2:
    print('Odd')
    
else:
    print('Even')

Buggy python submission (verdict: Runtime Error):
a, b =map(int, input()split())
if (a*b) % 2:
    print("Odd")
else:
    print("Even")


Fixed submission:
a, b = map(int, input().split())
if (a*b) % 2:
    print("Odd")
else:
    print("Even")

Buggy python submission (verdict: Runtime Error):
a, b =map(int, input()split())
if (a*b) % 2:
    print("Odd")
eles:
    print("Even")


Fixed submission:
a, b = map(int, input().split())
if (a*b) % 2:
    print("Odd")
else:
    print("Even")

Buggy python submission (verdict: Runtime Error):
a,b=map(int,input()split())
if(a*b)%2:
print("Odd")
eles:
print("Even")

Fixed submission:
a, b = map(int, input().split())
if (a*b) % 2:
    print("Odd")
else:
    print("Even")

Buggy python submission (verdict: Runtime Error):
a,b = map(int,input(.split())
if (a*b)%2:
  print("Odd")
else:
  print("Even")

Fixed submission:
a, b = map(int, input().split())
if (a*b) % 2:
    print("Odd")
else:
    print("Even")

Buggy python submission (verdict: Runtime Error):
a,b = map(int,input(.split())
if (a*b)%2:
  print("Odd")
eles:
  print("Even")


Fixed submission:
a, b = map(int, input().split())
if (a*b) % 2:
    print("Odd")
else:
    print("Even")

Buggy python submission (verdict: Runtime Error):
a , b=map(int , input() , split() )
if(a*b)%2:
    print("Odd")
else:
    print("Even")


Fixed submission:
a, b = map(int, input().split())
if (a*b) % 2:
    print("Odd")
else:
    print("Even")

Buggy python submission (verdict: Runtime Error):
a , b=map(int , input() , split() )
if(a*b)%2:
    print("0dd")
else:
    print("Even")


Fixed submission:
a, b = map(int, input().split())
if (a*b) % 2:
    print("Odd")
else:
    print("Even")
Buggy python submission (verdict: Time Limit Exceeded):
#codigng: utf-8
from sys import stdin

N = int(stdin.readline().rstrip())
num = [int(x) for x in stdin.readline().rstrip().split()]
i = 0
Flag = True
while Flag:
    for i, x in enumerate(num):
        if x % 2 == 0:
            num[i] /= 2
        else:
            print(i)
            Flag = False
            break
    else:
        i += 1


Fixed submission:
#codigng: utf-8
from sys import stdin

bin  = list(stdin.readline().rstrip())
one = [x for x in bin if x == '1']

print(len(one))

Buggy python submission (verdict: Runtime Error):
#codigng: utf-8
from sys import stdin

bin  = list(stdin.readline().rstrip())
one = [x for x in bin if x == '1']

print(len(one)


Fixed submission:
#codigng: utf-8
from sys import stdin

bin  = list(stdin.readline().rstrip())
one = [x for x in bin if x == '1']

print(len(one))
Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
input = 1
for i in range(1, num+1):
    input *= i

print(input % (10**9 + 7))

Fixed submission:
import math



num = int(input())
input = math.factorial(num)

print(input % (10**9 + 7))
Buggy python submission (verdict: Runtime Error):
k, s = map(int, input_file[0].split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if z >= 0 and z <= k:
            count+=1

print(count)


Fixed submission:
k, s = map(int, input().split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if z >= 0 and z <= k:
            count+=1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())
count = 0
sz_list = []
for i in range(k+1):
    sz_list.append(s-i)

for x in range(k+1):
    for y in range(k+1):
        s = x +y
        if s in sz_list:
            count+=1

print(count)

Fixed submission:
k, s = map(int, input().split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if z >= 0 and z <= k:
            count+=1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())

z_list = []

for i in range(k+1):
    z_list.append(i)

count = 0

for i in z_list:
    z = i
    for x in range(k+1):
        for y in range(k+1):
            if (x+y) == (s - z):
                count+=1

print(count)


Fixed submission:
k, s = map(int, input().split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if z >= 0 and z <= k:
            count+=1

print(count)
Buggy python submission (verdict: Runtime Error):
a, b, x = map(int, input().split())

def count(num1, num2):
  return num1 // num2

c = count(b, x)
d = count(a-1)

ans = c-d
print(ans)

Fixed submission:
a, b, x = map(int, input().split())
 
def count(num1, num2):
  return num1 // num2
 
c = count(b, x)
d = count(a-1, x)
 
ans = c-d
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, x = map(int, input().split())
num_list = [int(x) for x in input().split()]
count = 0
if x == 0:
  print(sum(num_list))
else:
  while True:
    mark = 0
    for i, num in enumerate(num_list[0:-1]):
      if (num_list[i] + num_list[i+1] > x):
        if num_list[i+1] != 0:
          num_list[i+1] = num_list[i+1] - 1
          count+=1
          mark = 1
    if mark == 0:
      break

  print(count)

Fixed submission:
N, x = map(int, input().split())
num_list = [int(x) for x in input().split()]
count = 0

for i in range(N-1):
  n = num_list[i] + num_list[i+1]
  if n > x:
    if n - num_list[i+1] > x:
      count += n - x
      num_list[i+1] = 0
    else:
      count += n - x
      num_list[i+1] -= (n-x)

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N, T = map(int, input().split())
num_list = input().split()
num_list = [int(x) for x in num_list]

dif = 0
count = 0

for index, i in enumerate(num_list):
    for j in num_list[index:]:
   #     print(j)
        if j > i and (j - i) >= dif:
            dif = j - i

for index, i in enumerate(num_list):
    for j in num_list[index:]:
        if j - i == dif:
            count += 1

print(count)

Fixed submission:
N, T = map(int, input().split())
num_list = input().split()
num_list = [int(x) for x in num_list]

count = 0
profit = 0
min_val = num_list[0]

for num in num_list:
    if num < min_val:
        min_val = num
    elif num - min_val == profit:
        count += 1
    elif num - min_val > profit:
        count = 1
        profit = num - min_val

print(count)
Buggy python submission (verdict: Runtime Error):
a,b=map(int, input()., split())
if a*b/2==0:
  print("Even")
else:
  print("Odd")

Fixed submission:
a,b=map(int, input().split())

if a*b%2==0:
  print("Even")
else:
  print("Odd")

Buggy python submission (verdict: Runtime Error):
#整数の入力
a, b = map(int, input().split())

#取りあえず掛け算
c = a * b

#剰余計算
d = c % 2

if d == 0:
  print("Even")
Else:
  print("Odd")
  

Fixed submission:
#整数の入力
a, b = map(int, input().split())

#取りあえず掛け算
c = a * b

#剰余計算
d = c % 2

if d == 0:
  print("Even")
else:
  print("Odd")

Buggy python submission (verdict: Runtime Error):
a, b = list(map(int, input().split()))
if a * b % 2 == 0:


Fixed submission:
a, b = list(map(int, input().split()))
if a * b % 2 == 0:
    print('Even')
else:
    print('Odd')
Buggy python submission (verdict: Runtime Error):
S = input().strip()

Ks = []
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        Ks.append(max(i+1, len(S)-i-1))

print(min(Ks))


Fixed submission:
S = input().strip()

Ks = []
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        Ks.append(max(i+1, len(S)-i-1))

print(min(Ks) if len(Ks) != 0 else len(S))
Buggy python submission (verdict: Runtime Error):
s = input().strip()
goal = tuple(map(int, input().split()))

def change_dir(direc, case):
    if case == 0:
        direc += 1
        if direc == 5:
            direc = 1
    else:
        direc -= 1
        if direc == 0:
            direc = 4
    return direc

def go_in_dir(direc, pos):
    if direc == 1:
        return (pos[0]+1, pos[1])
    elif direc == 2:
        return (pos[0], pos[1]+1)
    elif direc == 3:
        return (pos[0]-1, pos[1])
    else:
        return (pos[0], pos[1]-1)

def exec_s(s, goal, direc=1, pos=(0, 0)):
    if len(s) == 0:
        if pos == goal:
            return True
        else:
            return False

    new_pos = pos
    while len(s) > 0 and s[0] == 'F':
        new_pos = go_in_dir(direc, new_pos)
        s = s[1:]

    if len(s) == 0:
        if new_pos == goal:
            return True
        else:
            return False

    new_dir = change_dir(direc, 0)
    reached = exec_s(s[1:], goal, new_dir, new_pos)
    if reached:
        return True
    else:
        new_dir = change_dir(direc, 1)
        return exec_s(s[1:], goal, new_dir, new_pos)

if exec_s(s, goal):
    print('Yes')
else:
    print('No')

Fixed submission:
s = input().split('T')
gx, gy = tuple(map(int, input().split()))

dir = 0
xmoves = []
ymoves = []
for moves in s:
    if dir % 2 == 0:
        xmoves.append(len(moves))
    else:
        ymoves.append(len(moves))
    dir += 1

curx, cury = xmoves.pop(0), 0

for move in sorted(xmoves, reverse=True):
    if curx > gx:
        curx -= move
    else:
        curx += move

for move in sorted(ymoves, reverse=True):
    if cury > gy:
        cury -= move
    else:
        cury += move

if curx == gx and cury == gy:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N, K = [int(x) for x in input().split()]

array = []
for i in range(N):
    a, b = [int(x) for x in input().split()]
    array.extend([a for x in range(b)])

array.sort()
print(array[K-1])


Fixed submission:
N, K = [int(x) for x in input().split()]

array = []
count = 0
for i in range(N):
    array.append(tuple(map(int, input().split())))

array.sort()
K -= 1
for tup in array:
    if K < tup[1]:
        print(tup[0])
        break
    else:
        K -= tup[1]
Buggy python submission (verdict: Runtime Error):
a, b, c = [int(x) for x in input().split()]

def foo(a, b, c):
    for i in range(1, b+1):
        if (a*i)%b == c:
            return "YES"
    return "NO"
    
print(foo(a, b, c))

Fixed submission:
a, b, c = input().split()

if a[-1] == b[0] and b[-1] == c[0]:
    print("YES")
else:
    print("NO")

Buggy python submission (verdict: Runtime Error):
a, b, c = [int(x) for x in input().split()]

from math import gcd

def foo(a, b, c):
    if a == 1:
        return "YES"
    elif b == 1:
        return "NO"
    elif gcd(a, b) ==1:
        return "NO"
    else:
        return "YES"
    
print(foo(a, b, c))

Fixed submission:
a, b, c = input().split()

if a[-1] == b[0] and b[-1] == c[0]:
    print("YES")
else:
    print("NO")

Buggy python submission (verdict: Runtime Error):
a, b, c = [int(x) for x in input().split()]

from math import gcd

def foo(a, b, c):
    if a == 1:
        return "YES"
    elif b == 1:
        return "NO"
    elif gcd(a, b) ==1:
        return "NO:
    else:
        return "YES"

print(foo(a, b, c))

Fixed submission:
a, b, c = input().split()

if a[-1] == b[0] and b[-1] == c[0]:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
a, b, c = [int(x) for x in input().split()]

from math import gcd

def foo(a, b, c):
    if a == 1:
        return "YES"
    elif b == 1:
        return "NO"
    elif gcd(a, b) ==1:
        return "NO:
    else:
        return "YES"

Fixed submission:
a, b, c = [int(x) for x in input().split()]
 
def foo(a, b, c):
    for i in range(1, b+1):
        if (a*i)%b == c:
            return "YES"
    return "NO"
    
print(foo(a, b, c))
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
rest = a * b % 2
if rest == 1:
    print('Odd')
else:
    print('Even')


Fixed submission:
a,b = map(int, input().split())
rest = a * b % 2
if rest == 1:
    print('Odd')
else:
    print('Even')
Buggy python submission (verdict: Runtime Error):
S = raw_input()

print('2018/01' + S[-2]

Fixed submission:
S = raw_input()
print('2018/01/' + S[-2] + S[-1])
Buggy python submission (verdict: Runtime Error):
r, g = int(input()).split()
print(2 * g - r)

Fixed submission:
r = int(input())
g = int(input())

print(2 * g - r)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 30 21:52:40 2017

@author: kanako_note
"""

N = int(input())

C = [0] * (N-1)
S = [0] * (N-1)
F = [0] * (N-1)

for i in range(N-1):
    C[i], S[i], F[i] = map(int, input().split())

for start in range(N-2):
    next = start + 1
    reach = S[start] + C[start]
    while(next < N-1):
        temp = S[next]
        while(1):
            if temp >= reach:
                leave = temp
                break
            temp += F[next]
        reach = leave + C[next]
        next += 1
    print(reach)
    
print(S[-1]+ C[-1])
print(0)


Fixed submission:
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 31 12:25:16 2017

@author: kanako_note
"""

N = int(input())

C = [0] * (N-1)
S = [0] * (N-1)
F = [0] * (N-1)

for i in range(N-1):
    C[i], S[i], F[i] = map(int, input().split())

for i in range(N):
    t = 0
    for j in range(i, N-1):
        if t<S[j]:  t = S[j]
        elif t%F[j]==0: pass
        else:   t = t+F[j]-t%F[j]
        t += C[j]
    print(t)
Buggy python submission (verdict: Runtime Error):
import sys
grid = []
painted = []

height, width, n = sys.stdin.readline().strip().split()
height, width, n = int(height), int(width), int(n)

def checkGrid(x, y, grid):
    count = 0
    for col in range(x, x+3):
        for row in range(y, y+3):
            if grid[row][col] == 1:
                count += 1
    return count

inp = sys.stdin.readline().strip()
while inp:
    a, b = inp.split()
    grid.append([int(a) - 1, int(b) - 1])
    inp = sys.stdin.readline().strip()

# Build empty grid
for i in range(height):
    painted.append([])
    for j in range(width):
        if [i, j] in grid:
            painted[i].append(1)
        else:
            painted[i].append(0)

# Build painted cells
for cell in grid:
    painted[cell[0]][cell[1]] = 1

for i in range(0, 10):
    count = 0
    for col in range(width - 2):
        for row in range(height - 2):
            if checkGrid(col, row, painted) == i:
                count += 1
    print(count)


Fixed submission:
import sys
perm = sys.stdin.readline().strip()
total = 0

# Add n * '+' to inp
def addPlus(inp, n):
    total = 0
    possible = [inp]
    orig = inp

    for i in range(1, len(orig)):
        possible.append(orig[:i] + '+' + perm[i:])

    for i in range(1, n):
        curr = possible[:]
        for item in curr:
            for j in range(1, len(item)):
                processed = item[:j] + '+' + item[j:]
                if processed not in possible:
                    if '++' not in processed:
                        possible.append(processed)

    for item in possible:
        total += eval(item)

    return total


print(addPlus(perm, len(perm) - 1))

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations
import sys, re
inp = sys.stdin.readline().strip()
perms = []
used = []
total = 0
#orig = inp

def checkOrder(check, inp):
    count = 0
    for i in range(len(check)):
        if check[i] == '+':
            continue
        elif check[i] == inp[count]:
            count += 1
        else:
            return False
    return True


for i in range(0, len(inp)):
    withPlus = inp + '+' * i
    perms = [''.join(p) for p in permutations(withPlus)]

    for perm in perms:
        if not re.match(r'.*\+\+.*', perm) and not perm[0] == '+' and not perm[-1] == '+':
            if checkOrder(perm, inp) and not perm in used:
                total += eval(perm)
                used.append(perm)

print(total)


Fixed submission:
import sys
perm = sys.stdin.readline().strip()
total = 0

# Add n * '+' to inp
def addPlus(inp, n):
    total = 0
    possible = [inp]
    orig = inp

    for i in range(1, len(orig)):
        possible.append(orig[:i] + '+' + perm[i:])

    for i in range(1, n):
        curr = possible[:]
        for item in curr:
            for j in range(1, len(item)):
                processed = item[:j] + '+' + item[j:]
                if processed not in possible:
                    if '++' not in processed:
                        possible.append(processed)

    for item in possible:
        total += eval(item)

    return total


print(addPlus(perm, len(perm) - 1))
Buggy python submission (verdict: Time Limit Exceeded):
N, H = map(int, input().split())
a, b = [0] * N, [0] * N
for i in range(N):
    a[i], b[i] = map(int, input().split())
a.sort(reverse=True)
b.sort(reverse=True)
ans = 0
while len(b) > 0 and b[0] > a[0]:
    H -= b[0]
    b = b[1:]
    ans += 1
ans += (H + a[0] - 1) // a[0]
print(ans)


Fixed submission:
N, H = map(int, input().split())
a, b = [0] * N, [0] * N
for i in range(N):
    a[i], b[i] = map(int, input().split())
ma = max(a)
b.sort(reverse=True)
ans = 0
index = 0
while H > 0 and len(b) > index and b[index] > ma:
    H -= b[index]
    index += 1
    ans += 1
if H > 0:
    ans += (H + ma - 1) // ma
print(ans)
Buggy python submission (verdict: Runtime Error):
N, L = map(int, input().split())

class Node:
    def __init__(self, depth=0):
        self.parent = None
        self.children = {}
        self.depth = depth
    def add(self, n):
        self.children[n] = Node(self.depth+1)
    def has(self, n):
        return n in self.children
t = Node()
for i in range(N):
    s = input()
    nt = t
    for c in s:
        if not nt.has(c):
            nt.add(c)
        nt = nt.children[c]

def solve(node):
    global N, L
    ans = 0
    f = lambda d: (L - d) & -(L - d)
    if node.has('0'):
        ans ^= solve(node.children['0'])
    else:
        ans ^= f(node.depth)
    if node.has('1'):
        ans ^= solve(node.children['1'])
    else:
        ans ^= f(node.depth)
    return ans

ans = solve(t)
if ans == 0:
    print('Bob')
else:
    print('Alice')


Fixed submission:
import sys
N, L = map(int, input().split())
sys.setrecursionlimit(200000)

class Node:
    def __init__(self, depth=0):
        self.parent = None
        self.children = {}
        self.depth = depth
    def add(self, n):
        self.children[n] = Node(self.depth+1)
    def has(self, n):
        return n in self.children
t = Node()
for i in range(N):
    s = input()
    nt = t
    for c in s:
        if not nt.has(c):
            nt.add(c)
        nt = nt.children[c]

def solve(node):
    global N, L
    ans = 0
    f = lambda d: (L - d) & -(L - d)
    if node.has('0'):
        ans ^= solve(node.children['0'])
    else:
        ans ^= f(node.depth)
    if node.has('1'):
        ans ^= solve(node.children['1'])
    else:
        ans ^= f(node.depth)
    return ans

ans = solve(t)
if ans == 0:
    print('Bob')
else:
    print('Alice')
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = map(int, input().split())

T = [0] * (N + 1)

for a in A:
    T[a] += 1

ns = []
for t in T:
    if t > 0:
        ns.append(t)
ns.sort()
ans = 0
while len(ns) > K:
    ans += ns[0]
    ns = ns[1:]
print(ans)


Fixed submission:
import heapq

N, K = map(int, input().split())
A = map(int, input().split())

T = [0] * (N + 1)

for a in A:
    T[a] += 1

ns = []
for t in T:
    if t > 0:
        heapq.heappush(ns, t)
ans = 0
while len(ns) > K:
    ans += heapq.heappop(ns)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
K = int(input())

q = deque()
q.append((1, 1, 1))
used = set()
while True:
    x, y, k = q.popleft()
    if (x, y, k) in used:
        continue
    else:
        used.add((x, y, k))
    # print(x, y, k)
    if k % K == 0:
        print(x)
        break
    q.appendleft((x, 0, k*10%K))
    if (y + 1) % 10 == 0:
        q.appendleft((x, 0, k+1))
    else:
        q.append((x+1, y+1, k+1))


Fixed submission:
from collections import deque
K = int(input())

q = deque()
q.append((1, 1, 1))
used = set()
while True:
    x, y, k = q.popleft()
    if k % K == 0:
        print(x)
        break
    if (x, 0, k*10%K) in used:
        continue
    else:
        used.add((x, 0, k*10%K))
    q.appendleft((x, 0, k*10%K))
    if (y + 1) % 10 == 0:
        q.appendleft((x, 0, k+1))
    else:
        q.append((x+1, y+1, k+1))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
K = int(input())

q = deque([1])
used = [False] * K
def cost(x):
    ret = 0
    while x:
        ret += x % 10
        x //= 10
    return ret

while True:
    x = q.popleft()
    if x % K == 0:
        print(cost(x))
        break
    elif used[x % K]:
        continue
    used[x % K] = True
    if (x+1) % 10 == 0:
        q.appendleft(x+1)
    else:
        q.append(x+1)
    q.appendleft(10*x)


Fixed submission:
from collections import deque
K = int(input())

q = deque()
q.append((1, 1, 1))
used = set()
while True:
    x, y, k = q.popleft()
    if k % K == 0:
        print(x)
        break
    if (x, 0, k*10%K) in used:
        continue
    else:
        used.add((x, 0, k*10%K))
    q.appendleft((x, 0, k*10%K))
    if (y + 1) % 10 == 0:
        q.appendleft((x, 0, k+1))
    else:
        q.append((x+1, y+1, k+1))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
K = int(input())

q = deque([1])
used = [False] * K
def cost(x):
    ret = 0
    while x:
        ret += x % 10
        x //= 10
    return ret

while True:
    x = q.popleft()
    if x % K == 0:
        print(cost(x))
        break
    elif used[x % K]:
        continue
    used[x % K] = True
    q.appendleft(10*x)
    q.append(x+1)


Fixed submission:
from collections import deque
K = int(input())

q = deque()
q.append((1, 1, 1))
used = set()
while True:
    x, y, k = q.popleft()
    if k % K == 0:
        print(x)
        break
    if (x, 0, k*10%K) in used:
        continue
    else:
        used.add((x, 0, k*10%K))
    q.appendleft((x, 0, k*10%K))
    if (y + 1) % 10 == 0:
        q.appendleft((x, 0, k+1))
    else:
        q.append((x+1, y+1, k+1))