Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02547 (python)

Fixed submission:
n = int(input())
x = 0
for i in range(n):
    d1, d2 = map(int, input().split())
    if x != 3:
        if d1 != d2:
            x = 0
        else:
            x += 1
print("Yes" if x == 3 else "No")

Buggy submission (verdict: Runtime Error):
nn = int(input())
x = 0
for i in range(n):
    d1, d2 = map(int, input().split())
    if x != 3:
        if d1 != d2:
            x = 0
        else:
            x += 1
print("Yes" if x == 3 else "No")
Problem p02570 (python)

Fixed submission:
d, t, s = map(int, input().split())
print("Yes" if d <= t * s else "No")

Buggy submission (verdict: Runtime Error):
x = int(input())
if x >= 30:
    print("Yes")
else:
    print("No")
Problem p02754 (python)

Fixed submission:
n, a, b = map(int, input().split())
x = int(n / (a + b))
y = n - ((a + b) * x)
if y >= a:
    z = a
else:
    z = y
print(int((a * x) + z))

Buggy submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
x = int(n / (a + b))
y = n - ((a + b) / x)
if y >= a:
    z = a
else:
    z = y
print(int(a * x + z))

Buggy submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
x = int(n / (a + b))
y = n - ((a + b) / x)
if y >= a:
    z = a
else:
    z = y
print(int(a * x + z))
Problem p03041 (python)

Fixed submission:
n, k = map(int,input().split())
s = input()
l = s[k - 1]
if l == "A":
    x = s[:(k - 1)] + "a" + s[k:]
elif l == "B":
    x = s[:(k - 1)] + "b" + s[k:]
else:
    x = s[:(k - 1)] + "c" + s[k:]
print(x)

Buggy submission (verdict: Runtime Error):
n, k = map(int,input().split())
s = input()
l = s[k - 1]
if l == "A":
    x = s[:(k - 1)] + "a" + s[(k + 1):]
elif l == "B":
    x = s[:(k - 1)] + "b" + s[(k + 1):]
print(x)
Problem p02624 (python)

Fixed submission:
n = int(input())
ans = 0
for i in range(1,n+1):
  ans += i * (1+n//i) * (n//i) // 2
print(ans)

Buggy submission (verdict: Runtime Error):
primes = [2]
li = [[],[]]
f_ans = [0]
def f(x):
  if x==1:
    f_ans.append(1)
    return 1
  if x==2:
    f_ans.append(2)
    return 2
  flag = True
  for i in range(len(primes)):
    if x%primes[i]==0:
      tmp = li[x//primes[i]][:]
      tmp[i] += 1
      li.append(tmp)
      f_ans.append(f_ans[x//primes[i]]//tmp[i]*(tmp[i]+1))
      return f_ans(x)
    else:
      li.append([0]*len(primes)+[1])
      f_ans.append(2)
      primes.append(x)
      return 2

n = int(input())
sum = 0
for i in range(1,n+1):
  sum += i * f(i)
print(sum)
Problem p02759 (python)

Fixed submission:
def main():
    N = int(input())
    if N%2 == 1:
      print(int((N+1)/2))
    else:
      print(int(N/2))
main()

Buggy submission (verdict: Runtime Error):
def main():
    import itertools
    a = tuple(map(int,input().split()))
    b = tuple(map(int,input().split()))
    c = tuple(map(int,input().split()))
    d = (a[0],b[0],c[0])
    e = (a[1],b[1],c[1])
    f = (a[2],b[2],c[2])
    g = (a[0],b[1],c[2])
    h = (a[2],b[1],c[0])
    A = set(a)
    B = set(b)
    C = set(c)
    D = set(d)
    E = set(e)
    F = set(f)
    G = set(g)
    H = set(h)
    n = int(input())
    listB = [int(input()) for x in range(n)]
    X = itertools.combinations(listB,3)
    R = set(list(X))
    if A in R or B in R or C in R or D in R or E in R or F in R or G in R or H in R:
      print("Yes")
    else:
      print("No")
main()

Buggy submission (verdict: Runtime Error):
def main():
    import itertools
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    c = list(map(int,input().split()))
    d = [a[0],b[0],c[0]]
    e = [a[1],b[1],c[1]]
    f = [a[2],b[2],c[2]]
    g = [a[0],b[1],c[2]]
    h = [a[2],b[1],c[0]]
    n = int(input())
    listB = [int(input()) for x in range(n)]
    C = itertools.combinations(listB,3)
    if a in C or b in C or c in C or d in C or e in C or f in C or g in C or h in C:
      print("Yes")
    else:
      print("No")
main()

Buggy submission (verdict: Runtime Error):
def main():
	N = int(input())
  	if N%2 == 1:
      print((N+1)/2)
    else:
      print(N/2)
main()

Buggy submission (verdict: Runtime Error):
def main()
	N = int(input())
  	if N%2 == 1:
      print((N+1)/2)
    else:
      print(N/2)
main()

Buggy submission (verdict: Runtime Error):
def main()
	a = int(input())
  	if a%2 == 1:
      print((a+1)/2)
    else:
      print(a/2)
main()
Problem p02627 (python)

Fixed submission:
if input().islower():
    print("a")
else:
    print("A")

Buggy submission (verdict: Runtime Error):
if input()islower():
    print("a")
else:
    print("A")
Problem p02729 (python)

Fixed submission:
import math

def combinations_count(n, r):
    if n<r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n, m = [int(i) for i in input().split()]
print(combinations_count(n,2)+combinations_count(m,2))

Buggy submission (verdict: Runtime Error):
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


n, m = [int(i) for i in input().split()]
print(combinations_count(n,2)+combinations_count(m,2))
Problem p02594 (python)

Fixed submission:
X =int(input())
if X >= 30:
	print("Yes")
else:
	print("No")

Buggy submission (verdict: Runtime Error):
column = list(map(int, input().split(" ")))
N, D = column[0], column[1]
count = 0
for i in range(1, N+1):
  X, Y=column[2*i], column[2*i+1]
  if X^2 + Y^2 <= D^2:
    count += 1
print(count)

Buggy submission (verdict: Runtime Error):
x, y = [list(i) for i in zip(*xy)]
N, D = x[0], y[0]
count = 0
for i in range(1, N+1):
	X, Y=x[i], y[i]
    if X^2+Y^2 <= D^2:
    	count += 1
    else:
    	pass
print(count)
Problem p03724 (python)

Fixed submission:
N,M = map(int,input().split())
cntNode = [0]*N
for i in range(M):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    cntNode[a] += 1
    cntNode[b] += 1

flag = True
for i in range(N):
    if(cntNode[i] % 2 != 0):
        flag = False
        break
if(flag):
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
cntNode = [0]*N
for i in range(N):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    cntNode[a] += 1
    cntNode[b] += 1

flag = True
for i in range(N):
    if(cntNode[i] % 2 != 0):
        flag = False
        break
if(flag):
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
cntNode = [0]*N
for i in range(N):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    cntNode[a] += 1
    cntNode[b] += 1

flag = True
for i in range(N):
    if(cntNode[i] % 2 != 0):
        flag = False
        break
if(flag):
    print('Yes')
else:
    print('No')
Problem p02659 (python)

Fixed submission:
from decimal import Decimal
l = list(input().split())
a = int(l[0])
b = Decimal(l[1])
print(int(a*b))

Buggy submission (verdict: Runtime Error):
l = list(input())
a = int(l[0])
b = float(l[1])
print(int(a*b))
Problem p02695 (python)

Fixed submission:
import itertools
n,m,q = map(int,input().split())
l = []
for i in range(q):
  l.append(list(map(int,input().split())))
j = [i for i in range(1,m+1)]
kk = list(itertools.combinations_with_replacement(j,n))
ans = []
for k in kk:
  count = 0
  for i in range(q):
    if k[l[i][1]-1]-k[l[i][0]-1] == l[i][2]:
      count += l[i][3]
  ans.append(count)
print(max(ans))

Buggy submission (verdict: Runtime Error):
import itertools
n,m,q = map(int,input().split())
l = []
for i in range(q):
  l.append(list(map(int,input().split())))
j = [i for i in range(1,m+1)]
k = itertools.permutations(j, n)
for i in range(q):
  if k[l[i][1]]-k[l[i][0]] == l[i][2]:
    count += l[i][3]
Problem p02820 (python)

Fixed submission:
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())

d = {'r': p, 's': r, 'p': s} #勝ちスコア

point = 0
for i in range(k): #kまでは普通に勝ってもよい
    point += d[t[i]]

for i in range(k, n): #kからnまでは、k個前と同じなら、後の方を無得点化する
    if t[i] == t[i - k]:
        t[i] = 'x'
        continue
    point += d[t[i]]

print(point)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
r,s,p = map(int,input().split())
l = list(input())
roop = n//k
last = n%k
count = 0
x = ''
for i in range(last):
  for j in range(roop+1):
    if l[i+k*j] == 'r' and x != 'P':
      count += p
      x = 'P'
    elif l[i+k*j] == 's' and x != 'R':
      count += r
      x = 'R'
    elif l[i+k*j] == 'p' and x != 'S':
      count += s
      x = 'S'
    else:
      x = ''
if last == 0:
  roop -=1
for i in range(last,k):
  for j in range(roop+1):
    if l[i+k*j] == 'r' and x != 'P':
      count += p
      x = 'P'
    elif l[i+k*j] == 's' and x != 'R':
      count += r
      x = 'R'
    elif l[i+k*j] == 'p' and x != 'S':
      count += s
      x = 'S'
    else:
      x = ''
print(count)
Problem p02862 (python)

Fixed submission:
x,y = map(int,input().split())
mod = 10**9+7
def comb(N,x):
    numerator = 1
    for i in range(N-x+1,N+1):
        numerator = numerator * i % mod
    denominator = 1
    for j in range(1,x+1):
        denominator = denominator * j % mod
    d = pow(denominator,mod-2,mod)
    return numerator * d % mod

if (x+y) % 3 == 0:
    a = (2*y-x) //3
    b = (2*x-y) //3

    if a >= 0 and b >= 0:
        print(comb(a+b,a))
        exit()
print(0)

Buggy submission (verdict: Runtime Error):
x,y = map(int,input().split())
mod = 10**9+7
dp = [[0]*(x+1) for _ in range(y+1)]

dp[0][0] = 1
for i in range(y+1):
    for j in range(x+1):
        if i-2 >= 0 and j-1 >= 0:
            dp[i][j] += dp[i-2][j-1]
        if i-1 >= 0 and j-2 >= 0:
            dp[i][j] += dp[i-1][j-2]
    dp[i][j] %= mod
print(dp[y][x])
Problem p02881 (python)

Fixed submission:
import math
n = int(input())
d = {}
for i in range(1,(int(math.sqrt(n)))+1):
  if (n/i).is_integer():
    d.setdefault(i,n//i)
ans = []
for k,v in d.items():
  ans.append((k-1)+(v-1))
print(min(ans))

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
d = {}
for i in range(1,int(math.sqrt(n))):
  if (n/i).is_integer():
    d.setdefault(i,n//i)
ans = []
for k,v in d.items():
  ans.append((k-1)+(v-1))
print(min(ans))
Problem p03013 (python)

Fixed submission:
import sys
input = sys.stdin.readline

n,m = map(int,input().split())
oks = [True]*(n+1)
for i in range(m):
    a = int(input())
    oks[a] = False

dp = [0]*(n+1)
dp[0] = 1
for i in range(n):
    for j in range(i+1,min(n,i+2)+1):
        if oks[j]:
            dp[j] += dp[i]
            dp[j] %= (10**9+7)
print(dp[n])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,m = map(int,input().split())

if m==0:
    cnt = 0
    steps = n
    for j in range(steps//2+1):
        if j == 0:
            cnt += 1
        else:
            seat = steps - j
            cnt += combinations_count(seat,j)
    print(cnt % (10**9+7))

l = [-1]+[int(input())]
for i in range(m-1):
    a = int(input())
    if a == l[-1]+1:
        print(0)
        exit()
    l.append(a)
l.append(n+1)
# print(l)

ans = 1
for i in range(m+1):
    cnt = 0
    steps = l[i+1] - l[i] -2
    if steps == 0:
        continue
    for j in range(steps//2+1):
        if j == 0:
            cnt += 1
        else:
            seat = steps - j
            cnt += combinations_count(seat,j)
    ans *= cnt

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

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,m = map(int,input().split())
l = [-1]+[int(input())]
for i in range(m-1):
    a = int(input())
    if a == l[-1]+1:
        print(0)
        exit()
    l.append(a)
l.append(n+1)
# print(l)

ans = 1
for i in range(m+1):
    cnt = 0
    steps = l[i+1] - l[i] -2
    for j in range(steps//2+1):
        if j == 0:
            cnt += 1
        else:
            seat = steps - j
            cnt += combinations_count(seat,j)
    ans *= cnt

print(ans % (10**9+7))
Problem p02951 (python)

Fixed submission:
# coding: utf-8
# Your code here!
n=input().split(" ")
for i in range(3):
  n[i]=int(n[i])
ans=(n[2]-(n[0]-n[1]))
if ans < 0:
	print(0)
else:
     print(ans)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
n=input().split(" ")
for i in range(3):
  n[i]=int(n[i])
ans=(n[2]-(n[1]-n[0])
if ans <0:
	print(0)
else:
     print(ans)
Problem p03127 (python)

Fixed submission:
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b,a%b)
n = int(input())
a = list(map(int,input().split()))
ans = a[0]
for x in a:
    ans = gcd(x,ans)
print(ans)

Buggy submission (verdict: Runtime Error):
import fraction
n = int(input())
a = list(map(int,input().split()))
ans = a[0]
for x in a:
    ans = fraction.gcd(x,ans)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
a = list(map(int,input().split()))
ans = a[0]
for x in a:
    ans = math.gcd(x,ans)
print(ans)
Problem p02793 (python)

Fixed submission:
def gcd(a,b):
    for xx in range(1000001):
        a,b=b,a%b
        if b==0:
            break
    return a

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

P = 10**9 + 7
N = 1000001
inv_t = [0]+[1]
for i in range(2,N):
    inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

n=int(input())
A=[int(i) for i in input().split()]

#kyodai=lcm_list(A)
kyodai=A[0]
for i in range(1,n):
    kyodai=lcm_base(kyodai,A[i])

ans=0

for i in range(n):
    ans+=inv_t[A[i]]
    ans=ans%P
ans=ans*kyodai
ans=ans%P

print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

P = 10**9 + 7
N = 10000
inv_t = [0]+[1]
for i in range(2,N):
    inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

n=int(input())
A=[int(i) for i in input().split()]

#kyodai=lcm_list(A)
kyodai=A[0]
for i in range(1,n):
    kyodai=lcm_base(kyodai,A[i])

ans=0

for i in range(n):
    ans+=kyodai*inv_t[A[i]]
    ans=ans%P

print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

P = 10**9 + 7
N = 10000
inv_t = [0]+[1]
for i in range(2,N):
    inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

n=int(input())
A=[int(i) for i in input().split()]

#kyodai=lcm_list(A)
kyodai=A[0]
for i in range(1,n):
    kyodai=lcm_base(kyodai,A[i])

ans=0

for i in range(n):
    ans+=kyodai*inv_t[A[i]]
    ans=ans%P

print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

P = 10**9 + 7
N = 10000
inv_t = [0]+[1]
for i in range(2,N):
    inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

n=int(input())
A=[int(i) for i in input().split()]

kyodai=lcm_list(A)
ans=0

for i in range(n):
    ans+=kyodai*inv_t[A[i]]
    ans=ans%P

print(ans)
Problem p02912 (python)

Fixed submission:
n,m=map(int,input().split())
A=[int(i) for i in input().split()]

A.sort()
A.reverse()
#print(A)
if n==1:
    ans=A[0]//(2**m)
    print(ans)
else:
    A.append(0)
    big=A[0]
    stc=0
    now=0
    while m>0:
        A[now]=A[now]//2
        m-=1
        big=A[0]
        for i in range(n-1):
            if A[i+1]>=big and m>0:
                A[i+1]=A[i+1]//2
                m-=1
            else:
                A.sort()
                A.reverse()
                break
        #print(A)
    else:
        print(sum(A))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
A=[int(i) for i in input().split()]

A.sort()
#print(A)
for i in range(m):
    A[-1]=A[-1]//2
    if A[-1]<A[-2]:
        A.sort()
    #print(A)
print(sum(A))
Problem p02990 (python)

Fixed submission:
n,k=map(int,input().split())

import math

def boxball(box,ball):
    if ball>=box:
        cal=math.factorial(ball-1)//math.factorial(ball-box)//math.factorial(box-1)
        return cal%1000000007
    else:
        return 0

def redball(box,ball,i):
    if ball==0:
        if i==1:
            return 1
        else:
            return 0
    else:
        if ball>=box-2:
            cal=math.factorial(ball+1)//math.factorial(ball-box+2)//math.factorial(box-1)
            return cal%1000000007
        else:
            return 0
#print(boxball(3,5),redball(3,5))
    
for i in range(k):
    ans=boxball(i+1,k)*redball(i+2,n-k,i+1)
    print(ans%1000000007)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())

import math

def boxball(box,ball):
    cal=math.factorial(ball-1)//math.factorial(ball-box)//math.factorial(box-1)
    return cal%1000000007

def redball(box,ball,i):
    if ball==0:
        if i==1:
            return 1
        else:
            return 0
    else:
        cal=math.factorial(ball+1)//math.factorial(ball-box+2)//math.factorial(box-1)
        return cal%1000000007

#print(boxball(3,5),redball(3,5))
    
for i in range(k):
    ans=boxball(i+1,k)*redball(i+2,n-k,i+1)
    print(ans%1000000007)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())

import math

def boxball(box,ball):
    cal=math.factorial(ball-1)//math.factorial(ball-box)//math.factorial(box-1)
    return cal%1000000007

def redball(box,ball):
    cal=math.factorial(ball+1)//math.factorial(ball-box+2)//math.factorial(box-1)
    return cal%1000000007

#print(boxball(3,5),redball(3,5))

for i in range(k):
    ans=boxball(i+1,k)*redball(i+2,n-k)
    print(ans%1000000007)
Problem p03013 (python)

Fixed submission:
nm=list(map(int,input().split()))
n=nm[0]
m=nm[1]

inp=[]
if m==0:
    inp=[n+1]
    dis=[n+1]
else:
    for inpset in range(m):
        inp.append(int(input()))
    

    dis=[max(inp[0],1)]
    p=0
    for i in inp[:-1]:
        dis.append(inp[p+1]-inp[p]-1)
        p+=1
    dis.append(max(n-inp[-1],1))
    #print (dis)

def fib(x):
    a=0
    b=1
    for step in range(x):
        c=a+b
        a=b
        b=c
    return a


def counting(x):
    if x==1:
        return 1
    else:
        
        res=0
        for a in range(x-1):
            if x-1-a>=a:
                res+=combinations_count(x-1-a,a)
                # print(x-1-a,a)
            else:
                break
        res=res%1000000007
        return res

if 0 in dis:
    print(0)
else:
    ans=1
    dis.sort()
    for d in dis:
        ans*=fib(d)%1000000007
        ans=ans%1000000007
    print(ans)

Buggy submission (verdict: Runtime Error):
nm=list(map(int,input().split()))
n=nm[0]
m=nm[1]

inp=[]
for inpset in range(m):
    inp.append(int(input()))
    

dis=[max(inp[0],1)]
p=0
for i in inp[:-1]:
    dis.append(inp[p+1]-inp[p]-1)
    p+=1
dis.append(max(n-inp[-1],1))
#print (dis)

import math

def kaijo(x):
    ans=(math(100000)%1000000007)
    return ans

def combinations_count(n, r):
    return (math.factorial(n) // (math.factorial(n - r) * math.factorial(r)))%1000000007

def counting(x):
    if x==1:
        return 1
    else:
        
        res=0
        for a in range(x-1):
            if x-1-a>=a:
                res+=combinations_count(x-1-a,a)
                # print(x-1-a,a)
                res=res%1000000007
            else:
                break
        return res

if 0 in dis:
    print(0)
else:
    ans=1
    dis.sort()
    for d in dis:
        ans*=counting(d)
        ans=ans%1000000007
    print(ans)
Problem p03135 (python)

Fixed submission:
inp=list(map(int,input().split()))
print(inp[0]/inp[1])

Buggy submission (verdict: Runtime Error):
t,x=map(int,input().split)
print(t/x)
Problem p02712 (python)

Fixed submission:
n = int(input())
ans = 0
for i in range(1, n + 1):
    if i % 3 != 0 and i % 5 != 0:
        ans += i
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 0
for i in range(1, n + 1):
	if i % 3 != 0 and i % 5 != 0:
    	ans += i
print(ans)
Problem p02596 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

K = I()
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()
if K % 7 == 0:
    K //= 7

A = [1]
for i in range(K+2):
    A.append((A[-1]*10) % K)

a = 1
i = 1
while True:
    if a % K == 0:
        print(i)
        break
    else:
        a += A[i]
        a %= K
        i += 1

Buggy submission (verdict: Runtime Error):
import sys
def I(): return int(sys.stdin.readline().rstrip())

K = I()
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()
if K % 7 == 0:
    K //= 7

A = [1]  # A[i] = 10**i mod K
for i in range(K-2):
    A.append((A[-1]*10) % K)

s = A[0]
for i in range(1,K):
    if s % K == 0:
        print(i)
        exit()
    else:
        s += A[i]
        s %= K

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

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

A = [1]
for i in range(K):
    A.append((A[-1]*10) % K)

a = 1
i = 1
while True:
    if a % K == 0:
        print(i)
        break
    else:
        a += A[i]
        a %= K
        i += 1
Problem p02625 (python)

Fixed submission:
import sys

def S(): return sys.stdin.readline().rstrip()

N,M = map(int,S().split())
mod = 10**9+7

a = M  # (M_P_N)**2
for i in range(1,N):
    a *= M-i
    a %= mod

# 包除原理
# 2つめの条件は常に成り立った状況で考える
# {1,…,N}の部分集合Sの元iに対してA_i=B_iが成り立つようなA_1,…,B_1,…の組の個数を考える
ans = a**2 % mod
r = ans
for i in range(1,N+1):
    r *= (N-i+1)*pow(i,-1,mod)*pow(M-i+1,-1,mod)*(-1)
    r %= mod
    ans += r
    ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

def S(): return sys.stdin.readline().rstrip()

N,M = map(int,S().split())
mod = 10**9+7

a = M  # (M_P_N)**2
for i in range(1,N):
    a *= M-i
    a %= mod

# 包除原理
# 2つめの条件は常に成り立った状況で考える
# {1,…,N}の部分集合Sの元iに対してA_i=B_iが成り立つようなA_1,…,B_1,…の組の個数を考える
ans = a**2 % mod
r = ans
for i in range(1,N+1):
    r *= (N-i+1)*pow(i,-1,mod)*pow(M-i+1,-1,mod)*(-1)
    r %= mod
    ans += r
    ans %= mod

print(ans)