qyliang/CodeNanoFix huggingface dataset:
Buggy code:
def main(k):
    size, res = 1, 7 % k
    while res and size <= k:
        res = (res * 10 + 7) % k
        size += 1
    return -1 if size > 1_000_000 else size


if __name__ == '__main__':
    k = int(input())
    print(main(k))


Fixed code:
def main(k):
    size, res = 1, 7 % k
    while res and size <= 1_000_000:
        res = (res * 10 + 7) % k
        size += 1
    return -1 if size > 1_000_000 else size


if __name__ == '__main__':
    k = int(input())
    print(main(k))
Buggy code:
K=int(input())

j=0
ans=0
a=0
while True:
    a=a*10+7
    ans+=1
    if a%K==0:
        break
    
    if ans>K:
        ans=-1
        break

print(ans)

Fixed code:
K=int(input())
 
j=0
ans=0
a=0
while True:
    a=a*10+7
    a=a%K
    ans+=1
    
    if a==0:
        break
    
    if ans>K:
        ans=-1
        break
 
print(ans)
Buggy code:
K=int(input())
num=7
for i in range(100000):
  modnum=num%K
  if modnum==0:
    print(i+1)
    exit()
  num=modnum*10+7
print(-1)

Fixed code:
K=int(input())
num=7
for i in range(1000000):
  modnum=num%K
  if modnum==0:
    print(i+1)
    exit()
  num=modnum*10+7
print(-1)
Buggy code:
import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------

k = inp()
if k % 2 == 0:
    print(-1)
    
if k % 7 == 0:
    k //= 7
n = 1
cnt = 1
for i in range(1001001):
    n = n % k
    if n == 0:
        print(cnt) 
        sys.exit()
    cnt += 1
    n *= 10
    n += 1 
print(-1)

# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)


Fixed code:
import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
start_time = time.perf_counter()
# ------------------------------

k = inp()
if k % 2 == 0:
    print(-1)
    sys.exit()
if k % 7 == 0:
    k //= 7
n = 1
cnt = 1
for i in range(1001001):
    n = n % k
    if n == 0:
        print(cnt) 
        sys.exit()
    cnt += 1
    n *= 10
    n += 1 
print(-1)

# -----------------------------
end_time = time.perf_counter()
print('time:', end_time-start_time, file=sys.stderr)
Buggy code:
K = int(input())
count = 1
n = 7
while True:
    if K % 2 == 0 or K % 5 == 0:
        count = -1
        break
    if n % K == 0:
        break
    n += 7*10**count
    count += 1
print(count)

Fixed code:
K = int(input())
count = 1
n = 0
if K % 2 == 0 or K % 5 == 0:
    count = -1
    print(count)
else:
    while True:
        n = (n*10+7)%K
        if n == 0:
            break
        count += 1
    print(count)
Buggy code:
K = int(input())

i = 7%K
se = set(i)
cnt = 1
while True:
  if i == 0:
    print(cnt)
    break
  cnt += 1
  i = (i*10 + 7)%K
  if i in se:
    print(-1)
    break
  else:
    se.add(i)
  

Fixed code:
K = int(input())

i = 7%K
se = set([i])
cnt = 1
while True:
  if i == 0:
    print(cnt)
    break
  cnt += 1
  i = (i*10 + 7)%K
  if i in se:
    print(-1)
    break
  else:
    se.add(i)
Buggy code:
K = int(input())

out=-1

if K==7:
    for i in range(1,10**6):
        #if (10**i -1) % 9 ==0:
        if pow(10,i,9)==1:
             out=i
             break

else:
    for i in range(1,10**6):
        #if (10**i -1) % (9*K)==0:
        if pow(10,i,9*K)==1:
            out=i
            break

print(i)


Fixed code:
K = int(input())

out=-1

if K%7==0:
    dammy = K//7
    # print(dammy)
    for i in range(1,10**6):
        #if (10**i -1) % 9 ==0:
        if pow(10,i,9*dammy)==1:
             out=i
             break

else:
    for i in range(1,10**6):
        #if (10**i -1) % (9*K)==0:
        if pow(10,i,9*K)==1:
            out=i
            break

print(out)
Buggy code:
k=int(input())

if (k%2==0) or (k%5==0):
  print(-1)
  exit()

if k%7==0:
  k//=7

o=0
m=1
if k==1:
  print(1)
  exit()

for i in range(1,k):
  m*=10
  o+=m%k
  o%=k
  if o==0:
    print(i)
    exit()

Fixed code:
k=int(input())
 
if (k%2==0) or (k%5==0):
  print(-1)
  exit()
 
if k%7==0:
  k//=7
 
o=0
m=1
if k==1:
  print(1)
  exit()
 
for i in range(k):
  m*=10
  m=m%k
  o+=m%k
  o%=k
  if o==0:
    print(i+1)
    exit()
Buggy code:

K = int(input())
A = 7 % K 

for i in range(1, K + 1):
    if A % K == 0:
        print(i)
        exit()
    A = 10 * A + 7
print(-1)

Fixed code:
K = int(input())
A = 7 % K 

for i in range(1, K + 1):
    if A % K == 0:
        print(i)
        exit()
    A = (10 * A + 7) % K
print(-1)
Buggy code:
k = int(input())
n = 0
for i in range(1,10**6):
    n = n*10+7
    if n%k==0:
        print(i)
        exit()
print(-1)

Fixed code:
k = int(input())
n = 0
for i in range(1,10**6):
    n = (n*10+7)%k
    if n%k==0:
        print(i)
        exit()
print(-1)
Buggy code:
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    K = int(input())
    x = 0
    if K % 2 == 0 or K % 5 ==  0:
        print(-1)
  
    while True:
        x = (x * 10 + 7) % K
        i += 1
        if x == 0:
            print(i + 1)
            break


    

if __name__ == "__main__":
    main()

Fixed code:
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    K = int(input())
    x = 0
    i = 0
    if K % 2 == 0 or K % 5 ==  0:
        print(-1)
        exit()
    
    while True:
        x = (x * 10 + 7) % K
        i += 1
        if x == 0:
            print(i)
            break


    

if __name__ == "__main__":
    main()
Buggy code:
k=int(input())
if k%2==0:
  print(-1)
  exit()
  
ans=1
pin=7
mod=k

for i in range(1000000):
  if pin%k==0:
    print(ans)
    exit()
    
  cnt+=1
  pin*=10
  pin+=7
  

print('-1')
  

Fixed code:
k=int(input())
if k%2==0:
  print(-1)
  exit()
  
ans=1
pin=7
mod=k

for i in range(1000000):
  if pin%k==0:
    print(ans)
    exit()
    
  ans+=1
  pin*=10
  pin+=7
  pin%=mod
  

print('-1')
Buggy code:
k=int(input())
for i in range(1,10**6):
  if k%2==0:
    print("-1")
    quit()
  ki=int("7"*i)
  if ki%k==0:
    print(i)
    quit()
print("-1")

Fixed code:
k=int(input())
if k%2==0:
  print("-1")
  quit()
ki=0
for i in range(1,10**6):
  ki=(ki*10+7)%k
  if ki==0:
    print(i)
    quit()
print("-1")
Buggy code:
def solution(K: int) -> int:
    sevens: int = 0
    for i in range(1, K + 1):
        print(sevens)
        sevens = (sevens*10 + 7) % K
        if sevens == 0:
            return i
    return -1


K: int = int(input())

print(solution(K))


Fixed code:
def solution(K: int) -> int:
    sevens: int = 0
    for i in range(1, K + 1):
        sevens = (sevens*10 + 7) % K
        if sevens == 0:
            return i
    return -1


K: int = int(input())

print(solution(K))
Buggy code:
K = int(input())
mod = 0
Good = True
for k in range(K):
    mod = (mod * 10 + 7) % K
    if mod == 0:
        print(k+1)
        Good = False
if Good:
    print(-1)

Fixed code:
K = int(input())
mod = 0
Good = True
for k in range(K):
    mod = (mod * 10 + 7) % K
    if mod == 0:
        print(k+1)
        Good = False
        break
if Good:
    print(-1)
Buggy code:
k = int(input())
n = 0
for i in range(1, k+1):
    n = (n * 10 + 7) % k
    if n == 0:
        print(i)
        break
print('-1')


Fixed code:
k = int(input())
n = 0
for i in range(1, k+1):
    n = (n * 10 + 7) % k
    if n == 0:
        print(i)
        exit()
print('-1')
Buggy code:
k = int(input())


if k % 7 == 0:
    L = k/9
else:
    L = 9 * k


if L % 2 == 0 or L % 5 == 0:
    print(-1)

m = 1 % L

for i in range(k):
    m = (10 * m) % L
    if m == 1:
        print(i + 1)
        exit()
    elif i == k - 1:
        print(-1)
        exit()

Fixed code:
k = int(input())
if k % 7 == 0:
    L = 9 * k / 7
else:
    L = 9 * k
 
if L % 2 == 0 or L % 5 == 0:
    print(-1)

m = 10

for i in range(k):
    m = m % L
    if m == 1:
        print(i + 1)
        exit()
    else:
        m = m * 10
Buggy code:
import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    k = int(input())
    if k % 2 == 0:
        print(-1)
        sys.exit()
    rems = defaultdict(int)
    n = 7
    next_digit = 70
    r = 1
    while True:
        rem = n % k
        if rem == 0:
            print(r)
            sys.exit()
        elif rems[rem]:
            print(-1)
            sys.exit()
        else:
            rems[rem] = 1
            n += next_digit
            next_digit *= 10
            r += 1
if __name__ == '__main__':
    main()

Fixed code:
import sys
read = sys.stdin.read
#readlines = sys.stdin.readlines
from collections import defaultdict
def main():
    k = int(input())
    if k % 2 == 0:
        print(-1)
        sys.exit()
    rems = defaultdict(int)
    n = 7 % k
    next_digit = 70 % k
    r = 1
    while True:
        if n == 0:
            print(r)
            sys.exit()
        elif rems[n]:
            print(-1)
            sys.exit()
        else:
            rems[n] = 1
            n += next_digit
            n = n % k
            next_digit = (next_digit * 10) % k
            r += 1
if __name__ == '__main__':
    main()
Buggy code:
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    K = ii()
    ret = [7]
    for i in range(1, K):
        ret.append((ret[i - 1] * 10 + 7) % K)
    for i in range(K):
        if ret[i] == 0:
            print(i + 1)
            exit()


if __name__ == '__main__':
    main()


Fixed code:
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    K = ii()

    ret = []
    for i in range(K + 1):
        if i == 0:
            ret.append(7 % K)
        else:
            ret.append((ret[i - 1] * 10 + 7) % K)
    for i in range(K + 1):
        if ret[i] == 0:
            print(i + 1)
            exit()
    else:
        print(-1)


if __name__ == '__main__':
    main()
Buggy code:
K=int(input())
m=0
count=1
for i in range(K):
	m=(m*10+7)%K
	if m==0:
		print(count)
		break
	count+=1
print(-1)

Fixed code:
K=int(input())
m=0
count=1
chk=0
for i in range(K):
	m=(m*10+7)%K
	if m==0:
		print(count)
		chk=1
		break
	count+=1

if chk==0:
	print(-1)
Buggy code:
K = int(input())

if (K%10) % 2 == 0:
    pass
    #print(-1)

elif (K%10) % 5 == 0:
    pass
    #print(-1)
else:
    num = 7
    for i in range(1000000):
        if num % K == 0:
            print(str(i+1))
            break
        num = num *10 + 7
    else:
        print(-1)



Fixed code:
K = int(input())

if (K%10) % 2 == 0:
    print(-1)

elif (K%10) % 5 == 0:
    print(-1)
else:
    num = 7
    for i in range(K):
        if num % K == 0:
            print(str(i+1))
            break
        num = (num *10 + 7) %K
    else:
        print(-1)
Buggy code:
K = int(input())
count = 1
check = 7

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    while True:
        if check % K == 0:
            print(count)
            break
        else:
            count += 1
            check = check * 10 + 7


Fixed code:
K = int(input())
count = 1
check = 7

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    while True:
        if check % K == 0:
            print(count)
            break
        else:
            count += 1
            check = (check * 10 + 7) % K
Buggy code:
K = int(input())

count = -1
n = 7
for i in range(K):
    if n % K == 0:
        count = i+1
        break
    n = int(str(n)+'7')

print(count)

Fixed code:
K = int(input())

count = -1
n = 7
for i in range(K):
    if n % K == 0:
        count = i+1
        break
    n = int(str(n)+'7')
    n %= K
print(count)
Buggy code:
K = int(input())

if K % 2 == 0:
  print(-1)
  exit()

num = 7
for i in range(K):
  if num % K == 0:
    print(i)
    exit()
  else:
    num = num*10 + 7

print(-1)

Fixed code:
K = int(input())
 
if K % 2 == 0:
  print(-1)
  exit()

num = 0
for i in range(1, K+1):
  num = (num*10+7) % K
  if num == 0:
    print(i)
    exit()

print(-1)
Buggy code:
K = int(input())

if K % 2 == 0:
    print(-1)
elif K % 5 == 0:
    print(-1)
else:
    seven = 7
    ans = 1
    while ans < 100000:
        amari = seven % K
        if amari == 0:
            print(ans)
            break
        else:
            ans += 1
            seven = amari * 10 + 7
    else:
        print(-1)

Fixed code:
K = int(input())

if K % 2 == 0:
    print(-1)
elif K % 5 == 0:
    print(-1)
else:
    seven = 7
    ans = 1
    while ans < 1000000:
        amari = seven % K
        if amari == 0:
            print(ans)
            break
        else:
            ans += 1
            seven = amari * 10 + 7
    else:
        print(-1)
Buggy code:
k = int(input())

if k % 2 == 0:
  print(-1)
  exit()

a = 7
ans = 0
for i in range(10**7):
  if a % k == 0:
    ans = i + 1
    break
  else:
    a = a*10 + 7
    ans = i + 1


print(ans)


Fixed code:
k = int(input())

if k % 2 == 0 or k % 5 == 0:
  print(-1)
  exit()

a = 7
ans = 0
for i in range(10**7):
  a = a % k
  if a % k == 0:
    ans = i + 1
    break
  else:
    a = a*10 + 7
    ans = i + 1


print(ans)
Buggy code:
k = int(input())

a = 7
for i in range(k):
  if a % k == 0:
    print(i+1)
    exit()
  else:
    i += 1
    a += 7*(10**i)
print(-1)

Fixed code:
k = int(input())
 
a = 7
for i in range(k):
  if a % k == 0:
    print(i+1)
    break
  a = (10*a+7) % k
else:
  print(-1)
Buggy code:
k = int(input())
n = 10**6
a = "7"

for i in range(n):

    if int(a) % k == 0:
        print(i+1)
        break

    a += "7"
else:
    print("-1")



Fixed code:
k = int(input())
n = 10**6
a = 0
for i in range(n):
    a *= 10
    a += 7
    a = a % k
    if a == 0:
        print(i+1)
        break


else:
    print("-1")
Buggy code:
#-*-coding:utf-8-*-

import sys

def main():
    k = int(input())
    mod=10**9+7
    if k % 2==0:
        print(-1)
        exit()

    sevens=7
    for i in range(1,10**6):
        if sevens%k==0:
            print(i)
            exit()
        else:
            sevens=(sevens*10+7)

if __name__ == "__main__":
    main()

Fixed code:
#-*-coding:utf-8-*-
 
import sys
 
def main():
    k = int(input())
    sevens=0
    if k%2==0:
      print(-1)
      exit()
    for i in range(1,10**6+1):
        sevens=(sevens*10+7)%k
        if sevens==0:
            print(i)
            exit()
    print(-1)
 
if __name__ == "__main__":
    main()
Buggy code:
import sys
from collections import defaultdict
K = int(input())

cnt = 0
now = 0
if K % 2==0:
    print(-1)
    sys.exit(0)

for i in range(10**6):
    cnt += 1
    now = now*10 + 7
    if now % K == 0:
        print(cnt)
        sys.exit(0)

print(-1)

Fixed code:
import sys
from collections import defaultdict
K = int(input())

cnt = 0
now = 0
if K % 2==0:
    print(-1)
    sys.exit(0)

for i in range(10**6):
    cnt += 1
    now = (now*10 + 7)%K
    if now == 0:
        print(cnt)
        sys.exit(0)

print(-1)
Buggy code:
def main():
    K = int(input())
    if K%10:
        L = 9*K if K%7 else 9*K//7
        mod = 10%L
        for i in range(9000001):
            if mod == 1:
                print(i)
                exit()
            mod = 10*mod%L
    else:
        print(-1)
    

if __name__ == "__main__":
    main()

Fixed code:
def main():
    K = int(input())
    if K%10:
        if K%7==0:
            K//=7
        L = 9*K
        mod = 10%L
        for i in range(9000001):
            if mod == 1:
                print(i+1)
                exit()
            mod = 10*mod%L
        print(-1)
    else:
        print(-1)
    

if __name__ == "__main__":
    main()
Buggy code:
str = input()
num = int(str)
if num % 2 == 0:
  print('-1');
else:
  i = 1
  j = 7
  while j % num != 0 and i < 100:
    j = (j % num) * 10 + 7
    i += 1
  if i == 100:
    print('-1');
  else:
    print(i);
  


Fixed code:
str = input()
num = int(str)
if num % 2 == 0:
  print('-1');
else:
  i = 1
  j = 7
  while j % num != 0 and i <= num:
    j = (j % num) * 10 + 7
    i += 1
  if i > num:
    print('-1');
  else:
    print(i);
Buggy code:
# AtCoder Beginner Contest 174
# C - Repsept

K=int(input())

modsevens=[7]

if K==7 or 1:
    print(1)
    exit()


for i in range (1,K+2):
    a=(modsevens[-1] *10+7)%K
    
    if a==0:
        print(i+1)
        exit()
    else:
        modsevens.append(a)

print(-1)

Fixed code:
# AtCoder Beginner Contest 174
# C - Repsept

K=int(input())

modsevens=[7]

if K==7 or K==1:
    print(1)
    exit()
else:
    pass

for i in range (1,K+2):
    a=(modsevens[-1] *10+7)%K
    
    if a==0:
        print(i+1)
        exit()
    else:
        modsevens.append(a)

print(-1)
Buggy code:
from itertools import count

K = int(input())
f = lambda x: (x*10+7)%K

a = 7%K
b = 7%K


for t in count(1):
    if a == 0:
        print(t)
        break
    if t > 1 and a == b:
        print(t,a,b)
        print(-1)
        break
    a = f(a)
    b = f(f(b))

Fixed code:
from itertools import count

K = int(input())
f = lambda x: (x*10+7)%K

a = 7%K
b = 7%K


for t in count(1):
    if a == 0:
        print(t)
        break
    if t > 1 and a == b:
        print(-1)
        break
    a = f(a)
    b = f(f(b))
Buggy code:
K = int(input())
a = 7
count = 1
for i in range(K):
    if a % K == 0:
        break
    a = (a * 10) + 7
    count += 1
if count == K + 1:
    print(-1)
else:
    print(count)

Fixed code:
K = int(input())
a = 7
count = 1
for i in range(K):
    if a % K == 0:
        break
    a = (a * 10 + 7) % K
    count += 1
if count == K + 1:
    print(-1)
else:
    print(count)
Buggy code:
K = int(input())
nana = 7
for i in range(1000000):
    if nana % K == 0:
        print(i + 1)
        exit()
    nana *= 10
    nana += 7
    nana %= K


Fixed code:
K = int(input())
nana = 7
for i in range(1000000+1):
    if nana % K == 0:
        print(i + 1)
        exit()
    nana *= 10
    nana += 7
    nana %= K
print(-1)
Buggy code:
K=int(input())
cnt=0
ans=0
while cnt<1000001:
  cnt+=1
  ans=(ans*10)+7
  if ans%K==0:
    print(cnt)
    break
else:
  print(-1)

Fixed code:
K=int(input())
cnt=0
ans=0
while cnt<1000001:
  cnt+=1
  ans=(ans*10+7)%K
  if ans==0:
    print(cnt)
    break
else:
  print(-1)
Buggy code:
import math
t = int(input())
if t%2==0 or t%5==0:
    print(-1)
else:
    i=1
    s=7%t
    while 1:
        if (s%t)==0:
            print(i)
            break
        i += 1

        s = (s * 10 + 7)%t
        print(s)
        continue

Fixed code:
import math
t = int(input())
if t%2==0 or t%5==0:
    print(-1)
else:
    i=1
    s=7
    while 1:

        if s%t==0:
            print(i)
            break

        else:
            i += 1
            s = (s * 10 + 7) % t
            continue
Buggy code:
#C
K = int(input())
judge=False
num = 0
for i in range(K+1):
    num += 7 * (10**i)
    num == num % K
    if num == 0:
        judge=True
        print(i+1)
        break
if judge == False:print("-1")

Fixed code:
#C
K = int(input())
judge=False
num = 7
for i in range(K):
    num = num % K
    #print(num)
    if num == 0:
        print(i+1)
        judge = True
        break
    else:
        num = num*10+7
if judge == False:print("-1")
Buggy code:
K = int(input())
ans = -1
keep = 0

for i in range(K):
    keep = (keep + 7 * 10 ** i) % K
    if keep == 0:
        ans = i + 1
        break
print(ans)

Fixed code:
K = int(input())
ans = -1
keep = 0
check = 7
for i in range(K):
    keep = (keep + check) % K
    if keep == 0:
        ans = i + 1
        break
    check = (check * 10) % K
print(ans)
Buggy code:
k = int(input())
lis = []
c = 0
a = 0
while(True):
    a = (a*10 + 7) & k
    if a == 0:
        print(c+1)
        quit()
    if c > k:
        print(-1)
        quit()
    c += 1

Fixed code:
k = int(input())
lis = []
c = 1
a = 0
while(True):
    a = (a*10 + 7) % k
    if a == 0:
        print(c)
        quit()
    if c > k:
        print(-1)
        quit()
    c += 1
Buggy code:
k = int(input())
mod = 7 % k
print(mod)
ans = 1
for i in range(k):
    if k % 2 == 0:
        ans = -1
        break
    if mod == 0:
        break
    mod = (mod*10+7)%k
    ans += 1
if ans == i:
    ans = -1
print(ans)

Fixed code:
k = int(input())
mod = 7 % k
ans = 1
for i in range(k):
    if k % 2 == 0:
        ans = -1
        break
    if mod == 0:
        break
    mod = (mod*10+7)%k
    ans += 1
if mod != 0:
    ans = -1
print(ans)
Buggy code:
K = int(input())
if K==7 or K==1:
  print(1)
else:
  count = 1
  for i in range(K):
    x = (x % K) * 10 + 7
    count += 1
    if x==0:
      print(count)
  if x!=0:
    print(-1)

Fixed code:
K = int(input())
if K==7 or K==1:
  print(1)
else:
  count = 1
  x = 7%K
  for i in range(K):
    x = (x*10+7)%K
    count += 1
    if x==0:
      print(count)
      break
  if x!=0:
    print(-1)
Buggy code:
#create date: 2020-08-02 21:08

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def divisor(n):
    i = 1
    table = [7, ]
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(7*i)
            table.append(n // i)
            table.append((n//i)*7)
        i += 1
    table = set(table)
    return table


def main():
    k = ni()
    
    for i in range(1, 13):
        n = int("1" * i)
        #print(i)
        if k in divisor(n):
            print(i)
            quit()
    print(-1)

if __name__ == "__main__":
    main()

Fixed code:
#create date: 2020-08-02 21:08

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def divisor(n):
    i = 1
    table = [7, ]
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(7*i)
            table.append(n // i)
            table.append((n//i)*7)
        i += 1
    table = set(table)
    return table


def main():
    k = ni()
    a = 0
    for i in range(1, 10**6+1):
        a = (10*a + 7) % k
        if a == 0:
            print(i)
            quit()
    print(-1)

if __name__ == "__main__":
    main()
Buggy code:
k = int(input())

def test_case(k):
    ans,cnt = 7,1
    
    if k % 2 == 0 or k % 5 == 0:
        return -1
    
    if k == 1 or k == 7:
        return 1
    
    while (1):
        mod = (ans * 10 + 7) % k
        cnt += 1
        ans = ans * 10 + 7
        
        if mod == 0:
            return cnt
        
print(test_case(k))



Fixed code:
k = int(input())

def test_case(k):
    ans,cnt = 7,1
    
    if k % 2 == 0 or k % 5 == 0:
        return -1
    
    if k == 1 or k == 7:
        return 1
    
    while (1):
        ans = (ans * 10 + 7) % k
        cnt += 1
        
        if ans == 0:
            return cnt
        
print(test_case(k))