Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if ''.join(t).count('AGC') >= 1:
            return False
    return True
def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for c in 'ACGT':
        if ok(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
    memo[cur][last3] = ret
    return ret
print(dfs(0, 'TTT'))


Fixed submission:
N, MOD = int(input()), 10 ** 9 + 7
memo = [{} for i in range(N+1)]
def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if ''.join(t).count('AGC') >= 1:
            return False
    return True
def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for c in 'ACGT':
        if ok(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
    memo[cur][last3] = ret
    return ret
print(dfs(0, 'TTT'))
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
count = 0
res = ''
ans = ''

for x in t:
  if x not in s:
    continue
  elif t.index(x) > s.index(x):
    continue
  else:
    i = s.index(x)
    ans = x
  
res = s[i-t.index(ans):i-t.index(ans)+len(t)]

if res:
  if len(res) < len(t):
    print(len(t))
  else:
    for i in range(len(res)):
      if res[i] != t[i]:
        count += 1
    print(count)
else:
  print(len(t))

Fixed submission:
s = input()
t = input()
res = []
for i in range(len(s)-len(t)+1):
    x = s[i:i+len(t)]
    count = sum(1 for a, b in zip(t, x) if a != b)
    res.append(count)

print(min(res))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lst = list(map(int, input().split()))

res = 0
for i in range(n):
    for j in range(i+1, n):
        res += lst[i] * lst[j]
print(res % ((10**9)+7))


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

ans = 0
summ = sum(lst)
summ_sq = summ**2
for i in range(n):
    ans += lst[i]**2

res = (summ_sq-ans)//2
print(res % ((10**9)+7))

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

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

comb = combinations(lst, 2)
res = 0
for i in comb:
  res += i[0] * i[1]
print(res % ((10**9)+7))

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

ans = 0
summ = sum(lst)
summ_sq = summ**2
for i in range(n):
    ans += lst[i]**2

res = (summ_sq-ans)//2
print(res % ((10**9)+7))
Buggy python submission (verdict: Runtime Error):
from itertools import combinations

n = int(input())
lst = list(map(int, input().split()))
comb = combinations(lst, 3)
count = 0

for i in comb:
  if i[0] != i[1] and i[1] != i[2]:
	  if i[0] + i[1] > i[2] and i[1] + i[2] > i[0] and i[0] + i[2] > i[1]:
    	count += 1
    
print(count)


Fixed submission:
from itertools import combinations

n = int(input())
lst = list(map(int, input().split()))
comb = combinations(lst, 3)
count = 0

for i in comb:
  if i[0] != i[1] and i[1] != i[2] and i[0] != i[2]:
    if i[0] + i[1] > i[2] and i[1] + i[2] > i[0] and i[0] + i[2] > i[1]:
      count += 1
    
print(count)
Buggy python submission (verdict: Runtime Error):
n = int(input())
lst = list(map(int, input().split()))
count = 0

for i in range(1, n + 1, 2):
  if lst[i] % 2 == 0:
    count += 1
    
print(count)

Fixed submission:
n = int(input())
lst = list(map(int, input().split()))
count = 0

for i in range(0, n, 2):
  if lst[i] % 2 != 0:
    count += 1
    
print(count)
Buggy python submission (verdict: Runtime Error):
from itertools import combninations

n,m = map(int, input().split())
a = list(combinations(range(n),2))
b = list(combinations(range(m),2))

print(len(a)+len(b))

Fixed submission:
from itertools import combinations

n,m = map(int, input().split())
a = list(combinations(range(n),2))
b = list(combinations(range(m),2))

print(len(a)+len(b))
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
res = ''

if a == 0:
  print(0)
elif b == 0:
  print(n)
else:
  while len(res) < n:
      res += 'b'*a
      res += 'r'*b

  res = res[:n]
  print(res)
  print(res.count('b'))

Fixed submission:
n, a, b = map(int, input().split())
period = a+b
times = n//period
k = n%period
n =  a if k >a else k
print(times*a + n)

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

while len(res) < n:
  res += 'b'*a
  res += 'r'*b
  
res = res[:n]
print(res.count('b'))

Fixed submission:
n, a, b = map(int, input().split())
period = a+b
times = n//period
k = n%period
n =  a if k >a else k
print(times*a + n)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

counter = 0
for i in range(q):
    x = input().split()

    if str(x[0]) == '1':
        counter += 1

    else:
        if counter % 2 != 0:
            s = s[::-1]
            counter = 0
        if str(x[1]) == '1':
            s = str(x[2]) + s

        else:
            s = s + str(x[2])

if counter % 2 != 0:
    s = s[::-1]
print(s)


Fixed submission:
s = input()
q = int(input())
qs = [input().split() for i in range(q)]
n = False
left= right = ""
for operation in qs:
    if operation[0] == '1':
        n = not n
    if operation[0] == '2':
        t , f, c = operation
        f = int(f)
        if n:
            f = 1 if f != 1 else 2
        if f == 1:
            left=c+left
        elif f == 2:
            right+=c
s = left+s+right
print(s[::-1] if n else s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
lst = []
for i in range(q):
    lst.insert(0, input().split())

counter = 0
while len(lst) != 0:
    x = lst.pop()
    if str(x[0]) == '1':
        counter += 1

    else:
        if counter % 2 != 0:
            s = s[::-1]
            counter = 0
        if str(x[1]) == '1':
            s = str(x[2]) + s

        else:
            s = s + str(x[2])

if counter % 2 != 0:
    s = s[::-1]
print(s)


Fixed submission:
s = input()
q = int(input())
qs = [input().split() for i in range(q)]
n = False
left= right = ""
for operation in qs:
    if operation[0] == '1':
        n = not n
    if operation[0] == '2':
        t , f, c = operation
        f = int(f)
        if n:
            f = 1 if f != 1 else 2
        if f == 1:
            left=c+left
        elif f == 2:
            right+=c
s = left+s+right
print(s[::-1] if n else s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for i in range(q):
  x = input().split()
  if str(x[0]) == '1':
    s = s[::-1]
  else:
    if str(x[1]) == '1':
      s = str(x[2]) + s
    else:
      s = s + str(x[2])
print(s)
      

Fixed submission:
s = input()
q = int(input())
qs = [input().split() for i in range(q)]
n = False
left= right = ""
for operation in qs:
    if operation[0] == '1':
        n = not n
    if operation[0] == '2':
        t , f, c = operation
        f = int(f)
        if n:
            f = 1 if f != 1 else 2
        if f == 1:
            left=c+left
        elif f == 2:
            right+=c
s = left+s+right
print(s[::-1] if n else s)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
lst = [int(x) for x in input().split()]
newLst = []

for i in range(n-1):
    for j in range(i+1, n):
        newLst.append(lst[i]*lst[j])

newLst = sorted(newLst)
print(newLst[k-1])

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

if a == b == c:
  print('No')
elif a != b and b != c and a != c:
  print('No')
elif a == b and a != c:
  print('Yes')
elif a == c and a != b:
  print('Yes')
elif b == c and a != b:
  print('Yes')
else:
  print('No')

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

if a == b == c:
  print('No')
elif a != b and b != c and a != c:
  print('No')
elif a == b and a != c:
  print('Yes')
elif a == c and a != b:
  print('Yes')
elif b == c and a != b:
  print('Yes')
else:
  print('No')

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

if a == b == c:
  print('No')
elif a != b and b != c and a != c:
  print('No')
elif a == b and a != c:
  print('Yes')
elif a == c and a != b:
  print('Yes')
elif b == c and a != b:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
def maxCount(lst):
    count = 0
    for i in lst:
        if lst.count(i) > count:
            count = lst.count(i)
    return count

n = int(input())
lst = []
for i in range(n):
    lst.append(input())

res = sorted(list(set([x for x in lst if lst.count(x) == maxCount(lst)])))

for i in sorted(res):
    print(i)

Fixed submission:
from collections import defaultdict
from collections import OrderedDict
N = int(input())
ans = dict()
for _ in range(N):
    k = str(input())
    if k in ans:
        ans[k]+=1
    else:
        ans.update({k:1})
groupedByValue = defaultdict(list)
for key, value in sorted(ans.items()):
    groupedByValue[value].append(key)
l = groupedByValue[max(groupedByValue)]
for i in l:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lst = []
for i in range(n):
  lst.append(input())
  
count = {}
countLst = []
for i in lst:
  count[i] = lst.count(i)
  countLst.append(lst.count(i))
  
res = []
for i in count:
  if count[i] == max(countLst):
    res.append(i)
    
for i in sorted(res):
  print(i)


Fixed submission:
from collections import defaultdict
from collections import OrderedDict
N = int(input())
ans = dict()
for _ in range(N):
    k = str(input())
    if k in ans:
        ans[k]+=1
    else:
        ans.update({k:1})
groupedByValue = defaultdict(list)
for key, value in sorted(ans.items()):
    groupedByValue[value].append(key)
l = groupedByValue[max(groupedByValue)]
for i in l:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n = input()
lst = input().split()
isTrue = True

for i in lst:
  if lst.count(i) > 1:
    print('NO')
    isTrue = False
    break

if isTrue == True:
  print('YES')

Fixed submission:
n = input()
lst = input().split()
sett = set(lst)

if len(lst) == len(sett):
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
lst = []
for i in range(m):
  lst.append(input().split())
  
task = 1
taskLst = [lst[0][0]]
temp = lst[0][0]
for i in lst:
  if i[0] == temp:
    continue
  else:
    task += 1
    taskLst.append(i[0])
    temp = i[0]
    
resLst = []
for i in range(len(taskLst)):
  tempLst = []
  for j in range(len(lst)):
    if lst[j][0] == taskLst[i]:
      if lst[j][1] == 'WA':
      	tempLst.append(lst[j][1])
      else:
        tempLst.append(lst[j][1])
        break
  resLst.append(tempLst)

finalLst = []
for i in range(len(resLst)):
  for j in range(len(resLst[i])):
    finalLst.append(resLst[i][j])
    
print(str(finalLst.count('AC')) + ' ' + str(finalLst.count('WA')))

Fixed submission:
N,M = [int(i) for i in input().split()]
submissions = {str(i):[] for i in range(1,N+1)}
AC,WA = 0,0
for i in range(M):
    P,S = [j for j in input().split()]
    submissions[P].append(S)
for i in submissions:
    if 'AC' not in submissions[i]:
        continue
    for j in submissions[i]:
        if j == 'AC':
            AC+=1
            break
        WA +=1
print(AC,WA)
Buggy python submission (verdict: Runtime Error):
rom math import factorial


def nCr(n, r):
    if r <= 0:
        return 0

    if n >= r:
        return factorial(n) // (factorial(n - r) * factorial(r))
    else:
        return 0

def main():
    N = input()
    K = int(input())

    ans = func(N, K)

    print(ans)

def func(N, K):
    if len(N) < K:
        return 0

    if K == 0:
        return 1

    n = int(N[0])

    if len(N) == 1:
        if K > 1:
            return 0
        else:
            return n

    ret = 0
    if K > 1:
        ret += func(N[1:], K-1)
    else:
        ret += 1
    l = len(N[1:])

    ret += (n - 1) * func('9' * l, K - 1)
    ret += func('9'* l, K)

    # ret += (n - 1) * nCr(l-1, K - 2) * 9 ** (K - 1)
    # ret += nCr(l-1, K - 1) * 9 ** K 

    return ret
    

if __name__ == '__main__':
    main()

Fixed submission:
from math import factorial


def nCr(n, r):
    if r <= 0:
        return 0

    if n >= r:
        return factorial(n) // (factorial(n - r) * factorial(r))
    else:
        return 0

def main():
    N = input()
    K = int(input())

    ans = func(N, K)

    print(ans)

def func(N, K):
    N = N.lstrip('0')
    if len(N) < K:
        return 0

    if K == 0:
        return 1

    n = int(N[0])

    if len(N) == 1:
        if K > 1:
            return 0
        else:
            return n

    ret = 0
    if K > 1:
        ret += func(N[1:], K-1)
    else:
        ret += 1
    l = len(N[1:])

    ret += (n - 1) * func('9' * l, K - 1)
    if l >= K:
        ret += func('9'* l, K)

    # ret += (n - 1) * nCr(l-1, K - 2) * 9 ** (K - 1)
    # ret += nCr(l-1, K - 1) * 9 ** K 

    return ret
    

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
MOD = 1000000007

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

vec = [0, 0, 0]
num = 1

for a in A:
    idx = [i for i, x in enumerate(vec) if x == a]
    num = (num * len(idx)) % MOD
    vec[idx[0]] += 1

print(num)


Fixed submission:
MOD = 1000000007

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

vec = [0, 0, 0]
num = 1

for a in A:
    idx = [i for i, x in enumerate(vec) if x == a]
    if len(idx) == 0:
        print(0)
        exit()
    num = (num * len(idx)) % MOD
    vec[idx[0]] += 1

print(num)

Buggy python submission (verdict: Runtime Error):
from itertools import combinations

MOD = 1000000007

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

vec = [0, 0, 0]
num = 1

for i, a in enumerate(A):
    idx = [i for i, x in enumerate(vec) if x == a]
    if i > 0:
        num = (num * len(idx)) % MOD
    vec[idx[0]] += 1

num_color = sum([x != 0 for x in vec])

if num_color == 1:
    c = 3
if num_color == 2:
    c = 3
if num_color == 3:
    c = 3

ans = c * num % MOD
print(ans)


Fixed submission:
MOD = 1000000007

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

vec = [0, 0, 0]
num = 1

for a in A:
    idx = [i for i, x in enumerate(vec) if x == a]
    if len(idx) == 0:
        print(0)
        exit()
    num = (num * len(idx)) % MOD
    vec[idx[0]] += 1

print(num)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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

def is_rectangle(a,b,c):
    if a + b <= c:
      return False
    if b + c <= a:
      return False
    if c + a <= b:
        return False
    else:
        return True

x = [is_rectangle(a,b,c) for a, b, c in itertools.combinations(L, r=3)]


print(sum(x))

Fixed submission:
#提出 #8086687

import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for b in range(n):
  for a in range(b):
    ans += bisect.bisect_left(l,l[a]+l[b])-(b+1)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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

def is_rectangle(a,b,c):
    if a + b <= c:
      return False
    if b + c <= a:
      return False
    if c + a <= b:
        return False
    else:
        return True

x = [is_rectangle(a,b,c) for a, b, c in itertools.combinations(L, r=3)]


print(sum(x))

Fixed submission:
#提出 #8086687

import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for b in range(n):
  for a in range(b):
    ans += bisect.bisect_left(l,l[a]+l[b])-(b+1)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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

ans = 0
for a, b, c in itertools.combinations(L, r=3):
    if a + b > c and b + c > a and c + a > b:
        ans += 1

print(ans)

Fixed submission:
#提出 #8086687

import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for b in range(n):
  for a in range(b):
    ans += bisect.bisect_left(l,l[a]+l[b])-(b+1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, M = map(int, input().split())

dp = [float('inf')] * (2 ** N)
dp[0] = 0

for i in range(M):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    key = np.sum([2**(x-1) for x in c])
    
    ndp = dp.copy()
    for j in range(2**N):
        if dp[j | key] > ndp[j] + a:
            dp[j | key] = ndp[j] + a
            
if dp[-1] == float('inf'):
  print(-1)
else:
  print(dp[-1])


Fixed submission:
# https://atcoder.jp/contests/abc142/submissions/7753443
 
N,M = map(int,input().split())
 
lis = [float("inf")] * (2 ** N)
lis[0] = 0
 
for i in range(M):
 
    a,b = map(int,input().split())
 
    c = list(map(int,input().split()))
 
    num = 0
    for j in c:
        num += 2 ** (j-1)
 
    nlis = lis.copy()
    for j in range(2 ** N):
 
        if lis[j | num] > nlis[j] + a:
            lis[j | num] = nlis[j] + a     
 
#print (lis)
if lis[2 ** N -1] == float("inf"):
    print (-1)
 
else:
    print (lis[2 ** N - 1])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]

dp = [0] * (N + 1)
dpsum = [0] * (N + 1)
dp[1] = 1
dpsum[1] = 1
for i in range(2, N + 1):
    for j in range(K):
        li = max(i - LR[j][1], 1)
        ri = i - LR[j][0]
        if ri < 0:
            continue
        dp[i] += dpsum[ri] - dpsum[li - 1]
    dpsum[i] = dpsum[i - 1] + dp[i]

print(dp[N] % 998244353)


Fixed submission:
N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]


mod = 998244353
dp = [0] * (N + 1)
dpsum = [0] * (N + 1)
dp[1] = 1
dpsum[1] = 1
for i in range(2, N + 1):
    for j in range(K):
        li = max(i - LR[j][1], 1)
        ri = i - LR[j][0]
        if ri < 0:
            continue
        dp[i] += dpsum[ri] - dpsum[li - 1]
        dp[i] %= mod
    dpsum[i] = dpsum[i - 1] + dp[i]

print(dp[N])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]

l = []
for i in range(K):
    for j in range(LR[i][1] - LR[i][0] + 1):
        l.append(LR[i][0] + j)

dp = [0] * N
dp[0] = 1
for i in range(N):
    for j in range(len(l)):
        if i + l[j] < N:
            dp[i + l[j]] += dp[i]

print(dp[N - 1] % 998244353)


Fixed submission:
N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]


mod = 998244353
dp = [0] * (N + 1)
dpsum = [0] * (N + 1)
dp[1] = 1
dpsum[1] = 1
for i in range(2, N + 1):
    for j in range(K):
        li = max(i - LR[j][1], 1)
        ri = i - LR[j][0]
        if ri < 0:
            continue
        dp[i] += dpsum[ri] - dpsum[li - 1]
        dp[i] %= mod
    dpsum[i] = dpsum[i - 1] + dp[i]

print(dp[N])
Buggy python submission (verdict: Runtime Error):
S = int(input())

if S == 1:
    print(0)
    sys.exit()

dp = [0] * (S + 1)
dp[0] = 1
dp[1] = 0
dp[2] = 0
for i in range(3, S + 1):
    dp[i] = sum(dp[:i - 2])

print(dp[S] % (10 ** 9 + 7))


Fixed submission:
S = int(input())

dp = [0] * (S + 1)
dp[0] = 1
for i in range(3, S + 1):
    dp[i] = sum(dp[:i - 2])

print(dp[S] % (10 ** 9 + 7))

Buggy python submission (verdict: Runtime Error):
S = int(input())

dp = [0] * (S + 1)
dp[0] = 1
dp[1] = 0
dp[2] = 0
for i in range(3, S + 1):
    dp[i] = sum(dp[:i - 2])

print(dp[S] % (10 ** 9 + 7))


Fixed submission:
S = int(input())

dp = [0] * (S + 1)
dp[0] = 1
for i in range(3, S + 1):
    dp[i] = sum(dp[:i - 2])

print(dp[S] % (10 ** 9 + 7))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

for i in range(N):
    P[i] -= 1

ans = -10 ** 18
for si in range(N):
    KK = K
    x = si
    c = []
    tot = 0
    while True:
        x = P[x]
        c.append(C[x])
        tot += C[x]
        if x == si:
            break

    s = 0
    if KK > N:
        sho = KK // len(c)
        yo = KK % len(c)
        KK = yo
        if tot > 0:
            s += tot * sho
    for k in range(KK):
        s += c[k]
        ans = max(s, ans)

print(ans)


Fixed submission:
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

for i in range(N):
    P[i] -= 1

ans = -10 ** 18
for si in range(N):
    x = si
    c = []
    tot = 0
    while True:
        x = P[x]
        c.append(C[x])
        tot += C[x]
        if x == si:
            break

    s = 0
    for k in range(len(c)):
        if k + 1 > K:
            break
        s += c[k]
        ss = s
        if tot > 0:
            ss += tot * int((K - (k + 1)) // len(c))
        ans = max(ss, ans)

print(ans)

Buggy python submission (verdict: Runtime Error):
from copy import copy
import numpy as np

N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

score = 0
if K > N:
    sho = K // N
    yo = K % N
    K = yo
    if sum(C) > 0:
        score += sho * sum(C)

score_list = np.zeros((N, K), dtype='int64')
for n in range(N):
    now = copy(n)
    s = copy(score)
    for k in range(K):
        now = P[now] - 1
        s += C[now]
        score_list[n, k] = s

print(score_list.max())

Fixed submission:
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

for i in range(N):
    P[i] -= 1

ans = -10 ** 18
for si in range(N):
    x = si
    c = []
    tot = 0
    while True:
        x = P[x]
        c.append(C[x])
        tot += C[x]
        if x == si:
            break

    s = 0
    for k in range(len(c)):
        if k + 1 > K:
            break
        s += c[k]
        ss = s
        if tot > 0:
            ss += tot * int((K - (k + 1)) // len(c))
        ans = max(ss, ans)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

K = int(input())

seven = 7 % K
mod = 7 % K
for i in range(10**7):
    if seven % K == 0:
        print(i+1)
        sys.exit()
    else:
        seven = seven * (10 % K) + mod

print(-1)

Fixed submission:
import sys

K = int(input())

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

print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

K = int(input())

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

print(-1)


Fixed submission:
import sys

K = int(input())

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

print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

K = int(input())

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

print(-1)

Fixed submission:
import sys

K = int(input())

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

print(-1)