Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int, input().split())
A = list(map(int, input().split()))

mod = 998244353

dp = [[0] * (S+1) for i in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] %= mod
        if j + A[i] <= S:
            dp[i+1][j+A[i]] += dp[i][j]
            dp[i+1][j+A[i]] %= mod

print(dp[N][S])

Fixed submission:
N, S = map(int, input().split())
A = list(map(int, input().split()))

mod = 998244353

dp = [[0 for j in range(S+1)] for i in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] %= mod
        if j + A[i] <= S:
            dp[i+1][j+A[i]] += dp[i][j]
            dp[i+1][j+A[i]] %= mod

print(dp[N][S])

Buggy python submission (verdict: Time Limit Exceeded):
N, S = map(int, input().split())
A = list(map(int, input().split()))

mod = 998244353

dp = [[0] * (S+1) for i in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] = dp[i+1][j] % mod
        if j + A[i] <= S:
            dp[i+1][j+A[i]] += dp[i][j]
            dp[i+1][j+A[i]] = dp[i+1][j+A[i]] % mod

print(dp[N][S])

Fixed submission:
N, S = map(int, input().split())
A = list(map(int, input().split()))

mod = 998244353

dp = [[0 for j in range(S+1)] for i in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] %= mod
        if j + A[i] <= S:
            dp[i+1][j+A[i]] += dp[i][j]
            dp[i+1][j+A[i]] %= mod

print(dp[N][S])
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

to = [[] for i in range(100010)]

for i in range(M):
    a, b = map(int, input().split())
    to[a].append(b)
    to[b].append(a)

dist = [0] * (N+1)
q = [1]

#print(to[:4])

dist = [0] * N
pre = [0] * N

while len(q) != 0:
    a = q.pop(0)
    for i in to[a]:
        if dist[i-1] == 0:
            dist[i-1] = dist[a-1] + 1
            pre[i-1] = a
            q.append(i)
    print(q)

print("Yes")
for i in range(1, N):
    print(pre[i])

Fixed submission:
N, M = map(int, input().split())

to = [[] for i in range(100010)]

for i in range(M):
    a, b = map(int, input().split())
    to[a].append(b)
    to[b].append(a)

dist = [0] * (N+1)
q = [1]
dist[0] = -1
#print(to[:4])

dist = [0] * N
pre = [0] * N

while len(q) != 0:
    a = q.pop(0)
    for i in to[a]:
        if dist[i-1] == 0:
            dist[i-1] = dist[a-1] + 1
            pre[i-1] = a
            q.append(i)
    #print(q)

print("Yes")
for i in range(1, N):
    print(pre[i])
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.insert(0, 0)

v = [-1] * (N + 1)
n = 1
f = 0

for i in range(N):
    v[n] = i
    n = A[n]
    if v[n] != -1:
        f = 1
        s = n #ループのスタート
        t = i
        l = t - v[s] + 1
        break

if t >= K:
    print(v.index(K))
else:
    K = (K - s) % l
    print(v.index(K + s))

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.insert(0, 0)

v = [-1] * (N + 1)
n = 1
f = 0

for i in range(N):
    v[n] = i
    n = A[n]
    if v[n] != -1:
        f = 1
        s = n #ループのスタート
        t = i
        l = t - v[s] + 1
        break

if t >= K:
    print(v.index(K))
else:
    K = (K - v[s]) % l
    print(v.index(K + v[s]))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
mod = 2019

t = len(S)
l = [0] * t
for i in range(t-1, -1, -1):
    l[i] = int(S[i:]) % mod
l.append(0)

from collections import Counter

def nC2(n):
    return n * (n - 1) // 2


l = list(Counter(l).values())

ans = 0
for i in l:
    ans += nC2(i)

print(ans)

Fixed submission:
S = input()
mod = 2019

t = len(S)
l = [0] * (t + 1)
for i in range(t-1, -1, -1):
    l[i] = (l[i+1] + int(S[i]) * pow(10, t-i-1, mod)) % mod

from collections import Counter

def nC2(n):
    return n * (n - 1) // 2

l = list(Counter(l).values())

ans = 0
for i in l:
    ans += nC2(i)

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

mod = 10**9 + 7

ans = pow(2, n, mod)

ans -= 1

aa = 1
for i in range(1, a+1):
    aa = (aa * (n - i + 1) * pow(i, -1, mod)) % mod

bb = 1
for i in range(1, b+1):
    bb = (bb * (n - i + 1) * pow(i, -1, mod)) % mod

ans = (ans - aa - bb) % mod

print(ans)

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

mod = 10**9 + 7

ans = pow(2, n, mod)

ans -= 1

aa = 1
for i in range(1, a+1):
    aa = (aa * (n - i + 1) * pow(i, -1, mod)) % mod

bb = 1
for i in range(1, b+1):
    bb = (bb * (n - i + 1) * pow(i, -1, mod)) % mod

ans = (ans - aa - bb) % mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split())
AB = [0] * N
for i in range(N):
    AB[i] = list(map(int, input().split()))

m = 10**4 + 100

dp = [float("INF")] * m

dp[0] = 0

for i in range(H):
    for x in AB:
        if i + x[0] <= H:
            dp[i + x[0]] = min(dp[i + x[0]], dp[i] + x[1])
        else:
            dp[H] = min(dp[H], dp[i] + x[1])

print(dp[H])

Fixed submission:
H, N = map(int, input().split())
AB = [0] * N
for i in range(N):
    AB[i] = list(map(int, input().split()))

m = 10**4 + 100

dp = [float("INF")] * m

dp[0] = 0

for i in range(H):
    for x in AB:
        if i + x[0] <= H:
            dp[i + x[0]] = min(dp[i + x[0]], dp[i] + x[1])
        else:
            dp[H] = min(dp[H], dp[i] + x[1])

print(dp[H])
Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())

S = [["#"] * (W + 2) for i in range(H + 2)]
for i in range(H):
    s = input()
    for j in range(W):
        S[i + 1][j + 1] = s[j]
#print(S)

g = H * W

d = [[float("INF")] * g for i in range(g)]
for i in range(g):
    d[i][i] = 0

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S[i][j] == ".":
            p = (i - 1)*W + (j - 1)
            if S[i][j+1] == ".":
                d[p][p + 1] = 1
            if S[i][j-1] == ".":
                d[p][p - 1] = 1
            if S[i+1][j] == ".":
                d[p][p + W] = 1
            if S[i-1][j] == ".":
                d[p][p - W] = 1

for k in range(g):
    for i in range(g):
        for j in range(g):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])

ans = 0

for i in range(g):
    for j in range(g):
        if d[i][j] != float("INF"):
            ans = max(ans, d[i][j])

print(ans)

Fixed submission:
H, W = map(int, input().split())

S = [["#"] * (W + 2) for i in range(H + 2)]
for i in range(H):
    s = input()
    for j in range(W):
        S[i + 1][j + 1] = s[j]
#print(S)

g = H * W

d = [[float("INF")] * g for i in range(g)]
for i in range(g):
    d[i][i] = 0

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S[i][j] == ".":
            p = (i - 1)*W + (j - 1)
            if S[i][j+1] == ".":
                d[p][p + 1] = 1
            if S[i][j-1] == ".":
                d[p][p - 1] = 1
            if S[i+1][j] == ".":
                d[p][p + W] = 1
            if S[i-1][j] == ".":
                d[p][p - W] = 1

for k in range(g):
    for i in range(g):
        for j in range(g):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])

ans = 0

for i in range(g):
    for j in range(g):
        if d[i][j] != float("INF"):
            ans = max(ans, d[i][j])

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7

b = [0] * 65

for i in range(N):
    bb = format(A[i], "060b")
    for j in range(60):
        if bb[j] == "1":
            b[j] += 1

ans = 0

for j in range(60):
    ans = (ans + b[j] * (N - b[j]) * pow(2, 59 - j, mod)) % mod

print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7

b = [0] * 65

for i in range(N):
    bb = format(A[i], "060b")
    for j in range(60):
        if bb[j] == "1":
            b[j] += 1

ans = 0

for j in range(60):
    ans = (ans + b[j] * (N - b[j]) * pow(2, 59 - j, mod)) % mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
to = [[] for i in range(N+1)]
for i in range(M):
    a, b = map(int, input().split())
    to[a].append(b)

S, T = map(int, input().split())

q = [(S, 0)]
v = [[-1] * 3 for i in range(N+1)]

while q != []:
    a, t = q.pop(0)
    b = t % 3
    if v[a][b] != -1:
        continue
    v[a][b] = t
    t += 1
    for x in to[a]:
        q.append((x, t))
    #print(q)

if v[T][0] == -1:
    print("-1")
else:
    print(v[T][0] // 3)

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

S, T = map(int, input().split())

from collections import deque

q = deque([(S, 0)])
v = [[-1] * 3 for i in range(N+1)]

while q:
    a, t = q.popleft()
    b = t % 3
    if v[a][b] != -1:
        continue
    v[a][b] = t
    t += 1
    for x in to[a]:
        q.append((x, t))
    #print(q)


if v[T][0] == -1:
    print("-1")
else:
    print(v[T][0] // 3)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
to = [[] for i in range(N+1)]
for i in range(M):
    a, b = map(int, input().split())
    to[a].append(b)

S, T = map(int, input().split())

q = [(S, 0)]
v = [[-1] * 3 for i in range(N+1)]

while q != []:
    a, t = q.pop(0)
    b = t % 3
    if v[a][b] != -1:
        continue
    v[a][b] = t
    t += 1
    for x in to[a]:
        q.append((x, t))
    #print(q)

if v[T][0] == -1:
    print("-1")
else:
    print(v[T][0] // 3)

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

S, T = map(int, input().split())

from collections import deque

q = deque([(S, 0)])
v = [[-1] * 3 for i in range(N+1)]

while q:
    a, t = q.popleft()
    b = t % 3
    if v[a][b] != -1:
        continue
    v[a][b] = t
    t += 1
    for x in to[a]:
        q.append((x, t))
    #print(q)


if v[T][0] == -1:
    print("-1")
else:
    print(v[T][0] // 3)
Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
S = [0] * H
for i in range(H):
    S[i] = input()

yoko = [[0] * W for i in range(H)]

for i in range(H):
    for j in range(W):
        if yoko[i][j] != 0:
            continue
        elif S[i][j] == "#":
            yoko[i][j] = 0
        else:
            k = 0
            while S[i][j+k] == ".":
                k += 1
                if j+k == W:
                    break
            yoko[i][j:j+k] = [k] * k

tate = [[0] * W for i in range(H)]

for j in range(W):
    for i in range(H):
        if tate[i][j] != 0:
            continue
        elif S[i][j] == "#":
            tate[i][j] = 0
        else:
            k = 0
            while S[i+k][j] == ".":
                k += 1
                if i+k == H:
                    break
            for l in range(k):
                tate[i+l][j] = k

#for i in range(H):
#    print(tate[i])

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, yoko[i][j] + tate[i][j] - 1)

print(ans)

Fixed submission:
H, W = map(int, input().split())
S = [0] * H
for i in range(H):
    S[i] = input()

yoko = [[0] * W for i in range(H)]

for i in range(H):
    for j in range(W):
        if yoko[i][j] != 0:
            continue
        elif S[i][j] == "#":
            yoko[i][j] = 0
        else:
            k = 0
            while S[i][j+k] == ".":
                k += 1
                if j+k == W:
                    break
            yoko[i][j:j+k] = [k] * k

tate = [[0] * W for i in range(H)]

for j in range(W):
    for i in range(H):
        if tate[i][j] != 0:
            continue
        elif S[i][j] == "#":
            tate[i][j] = 0
        else:
            k = 0
            while S[i+k][j] == ".":
                k += 1
                if i+k == H:
                    break
            for l in range(k):
                tate[i+l][j] = k

#for i in range(H):
#    print(tate[i])

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, yoko[i][j] + tate[i][j] - 1)

print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
bc = [0] * M
for i in range(M):
    bc[i] = list(map(int, input().split()))

bc = sorted(bc, key= lambda x: x[1])[::-1]

n = 0
f = 0
for i in range(M):
    for j in range(bc[i][0]):
        if A[n] < bc[i][1] and n < N:
            A[n] = bc[i][1]
            n += 1
        else:
            f == 1
    if f == 1:
        break

print(sum(A))

Fixed submission:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
bc = [0] * M
for i in range(M):
    bc[i] = list(map(int, input().split()))

bc = sorted(bc, key= lambda x: x[1], reverse=True)

n = 0
f = 0
for i in range(M):
    for j in range(bc[i][0]):
        if A[n] < bc[i][1]:
            A[n] = bc[i][1]
            n += 1
            if n == N:
                f = 1
                break
        else:
            f = 1
    if f == 1:
        break

print(sum(A))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
bc = [0] * M
for i in range(M):
    bc[i] = list(map(int, input().split()))

bc = sorted(bc, key= lambda x: x[1])[::-1]

n = 0
f = 0
for i in range(M):
    for j in range(bc[i][0]):
        if A[n] < bc[i][1] and n < N:
            A[n] = bc[i][1]
            n += 1
        else:
            f == 1
    if f == 1:
        break

print(sum(A))

Fixed submission:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
bc = [0] * M
for i in range(M):
    bc[i] = list(map(int, input().split()))

bc = sorted(bc, key= lambda x: x[1], reverse=True)

n = 0
f = 0
for i in range(M):
    for j in range(bc[i][0]):
        if A[n] < bc[i][1]:
            A[n] = bc[i][1]
            n += 1
            if n == N:
                f = 1
                break
        else:
            f = 1
    if f == 1:
        break

print(sum(A))

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
bc = [0] * M
for i in range(M):
    bc[i] = list(map(int, input().split()))

bc = sorted(bc, key= lambda x: x[1])[::-1]

n = 0
f = 0
for i in range(M):
    for j in range(bc[i][0]):
        if A[n] < bc[i][1]:
            A[n] = bc[i][1]
            n += 1
        else:
            f == 1
    if f == 1:
        break

print(sum(A))

Fixed submission:
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
bc = [0] * M
for i in range(M):
    bc[i] = list(map(int, input().split()))

bc = sorted(bc, key= lambda x: x[1], reverse=True)

n = 0
f = 0
for i in range(M):
    for j in range(bc[i][0]):
        if A[n] < bc[i][1]:
            A[n] = bc[i][1]
            n += 1
            if n == N:
                f = 1
                break
        else:
            f = 1
    if f == 1:
        break

print(sum(A))
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())

if K > 100:
    print(S[0])
else:
    for i in range(K + 1):
        if S[i] != "1":
            print(S[i])
            break
        if i == K:
            print(S[K])

Fixed submission:
S = input()
K = int(input())


for i in range(K):
    if S[i] != "1":
        print(S[i])
        break
    if i == K-1:
        print(S[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [[0] for i in range(N)]
for i in range(N):
    A[i] = list(map(int, input().split()))

#for i in range(N):
#    A[i][i] = float("INF")

f = 0
r = [[1] * N for i in range(N)]

for k in range(N):
    for i in range(N):
        for j in range(N):
            if A[i][j] > A[i][k] + A[k][j]:
                f = 1
            elif A[i][j] == A[i][k] + A[k][j] and i != k and j != k:
                r[i][j] = 0

if f == 1:
    print("-1")
else:
    #print(r)
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            ans += A[i][j] * r[i][j]

    print(ans)

Fixed submission:
N = int(input())
A = [[0] for i in range(N)]
for i in range(N):
    A[i] = list(map(int, input().split()))

#for i in range(N):
#    A[i][i] = float("INF")

f = 0
r = [[1] * N for i in range(N)]

for k in range(N):
    for i in range(N):
        for j in range(N):
            if A[i][j] > A[i][k] + A[k][j]:
                f = 1
            elif A[i][j] == A[i][k] + A[k][j] and i != k and j != k:
                r[i][j] = 0

if f == 1:
    print("-1")
else:
    #print(r)
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            ans += A[i][j] * r[i][j]

    print(ans)
Buggy python submission (verdict: Runtime Error):
N, A = map(int, input().split())
x = list(map(int, input().split()))

dp = [[[0] * 2500 for i in range(51)] for i in range(51)]

dp[0][0][0] = 1
for i in range(N):
    for j in range(N):
        for k in range(2451):
            dp[i+1][j+1][k+x[i]] += dp[i][j][k]
            dp[i+1][j][k] += dp[i][j][k]

ans = 0
for i in range(1, N+1):
    ans += dp[N][i][A*i]

print(ans)

Fixed submission:
N, A = map(int, input().split())
x = list(map(int, input().split()))

dp = [[[0] * 2550 for i in range(55)] for i in range(55)]

dp[0][0][0] = 1
for i in range(N):
    for j in range(N):
        for k in range(2451):
            dp[i+1][j+1][k+x[i]] += dp[i][j][k]
            dp[i+1][j][k] += dp[i][j][k]

ans = 0
for i in range(1, N+1):
    ans += dp[N][i][A*i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from queue import deque
H,W = map(int,input().split())
CH,CW = map(int,input().split())
DH,DW = map(int,input().split())
DH,DW = DH-1,DW-1
S=[]
for i in range(H):
    S.append(list(map(lambda x:0 if x=='.' else -1, input().strip())))

def walk(h,w,n):
    r = []
    q = deque([(h,w)])
    while q:
        x = q.pop()
        r.append(x)
        h,w = x
        if h == DH and w == DW:
            print(n-1)
            exit()
        if h > 0 and S[h-1][w] == 0:
            S[h-1][w] = n
            q.append((h-1,w))
        if h < H-1 and S[h+1][w] == 0:
            S[h+1][w] = n
            q.append((h+1,w))
        if w > 0 and S[h][w-1] == 0:
            S[h][w-1] = n
            q.append((h,w-1))
        if w < W-1 and S[h][w+1] == 0:
            S[h][w+1] = n
            q.append((h,w+1))
    return r

warp = 1
q = deque([(CH-1,CW-1)])
while len(q) > 0:
    n = []
    while len(q) > 0:
        h,w = q.pop()
        n+=walk(h,w,warp)
    warp += 1
    if len(n) == 0:
        break
    for h,w in n:
        for ah in range(max(0,h-2),min(H,h+3)):
            for aw in range(max(0,w-2),min(W,w+3)):
                if ah == DH and aw == DW:
                    print(warp-1)
                    exit()
                if S[ah][aw] == 0:
                    S[ah][aw] = warp
                    q.append((ah,aw))

print(-1)


Fixed submission:
from queue import deque
H,W = map(int,input().split())
CH,CW = map(int,input().split())
DH,DW = map(int,input().split())
DH,DW = DH-1,DW-1
S=[]
for i in range(H):
    S.append(list(map(lambda x:0 if x=='.' else -1, input().strip())))

def walk(h,w,n):
    r = []
    q = deque([(h,w)])
    while q:
        x = q.pop()
        r.append(x)
        h,w = x
        if h == DH and w == DW:
            print(n-1)
            exit()
        if h > 0 and S[h-1][w] == 0:
            S[h-1][w] = n
            q.append((h-1,w))
        if h < H-1 and S[h+1][w] == 0:
            S[h+1][w] = n
            q.append((h+1,w))
        if w > 0 and S[h][w-1] == 0:
            S[h][w-1] = n
            q.append((h,w-1))
        if w < W-1 and S[h][w+1] == 0:
            S[h][w+1] = n
            q.append((h,w+1))
    return r

warp = 1
q = deque([(CH-1,CW-1)])
while len(q) > 0:
    n = []
    while len(q) > 0:
        h,w = q.pop()
        n+=walk(h,w,warp)
    warp += 1
    if len(n) == 0:
        break
    for h,w in n:
        for ah in range(max(0,h-2),min(H,h+3)):
            for aw in range(max(0,w-2),min(W,w+3)):
                if ah == DH and aw == DW:
                    print(warp-1)
                    exit()
                if S[ah][aw] == 0:
                    S[ah][aw] = warp
                    q.append((ah,aw))

print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
K=int(input())
if K % 2 == 0:
    print(-1)
    exit()

x = 7
ans = 1
while x > 0:
    if x < K:
        x = x*10 + 7
        ans += 1
        continue
    x = x % K

print(ans)


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

m = set()
x = 7
ans = 1
while x > 0:
    if x < K:
        x = x*10 + 7
        ans += 1
    x = x % K
    if x in m:
        print(-1)
        exit(0)
    else:
        m.add(x)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
K=int(input())
if K % 2 == 0:
    print(-1)
    exit()

x = 7
ans = 1
while True:
    if x < K:
        x = x*10 + 7
        ans += 1
        continue
    q,m = divmod(x,K)
    if m == 0:
        break
    x = m
print(ans)


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

m = set()
x = 7
ans = 1
while x > 0:
    if x < K:
        x = x*10 + 7
        ans += 1
    x = x % K
    if x in m:
        print(-1)
        exit(0)
    else:
        m.add(x)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
K=int(input())
if K % 2 == 0:
    print(-1)
    exit()

x = 7
ans = 1
while True:
    if x < K:
        x = x*10 + 7
        ans += 1
        continue
    q,m = divmod(x,K)
    if m == 0:
        break
    x = m
print(ans)


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

m = set()
x = 7
ans = 1
while x > 0:
    if x < K:
        x = x*10 + 7
        ans += 1
    x = x % K
    if x in m:
        print(-1)
        exit(0)
    else:
        m.add(x)

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

s = (1000, 0, 0)
mmax = 1000

q = []
q.append(s)
while len(q) > 0:
    m,k,d = q.pop()
    if d == N-1:
        m += k*A[d]
        if mmax < m:
            mmax = m
    else:
        q.append((m,k,d+1))
        if m > A[d]:
            x = m // A[d]
            nm = m-x*A[d]
            nk = k+x
            q.append((nm,nk,d+1))
        if k > 0:
            nm = m+k*A[d]
            q.append((nm, 0, d+1))
            x = nm // A[d]
            if x > 0:
                q.append((nm - x*A[d], x, d+1))
print(mmax)  


Fixed submission:
X=int(input())
a=0
if X >= 400 and X < 600:
    a = 8
elif X >= 600 and X < 800:
    a = 7
elif X >= 800 and X < 1000:
    a = 6
elif X >= 1000 and X < 1200:
    a = 5
elif X >= 1200 and X < 1400:
    a = 4
elif X >= 1400 and X < 1600:
    a = 3
elif X >= 1600 and X < 1800:
    a = 2
elif X >= 1800 and X < 2000:
    a = 1
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int, input().split())
A=list(map(int, input().split()))
s = 1
for i in range(K):
    s *= A[i]
j = 0
for i in range(K,N):
    x = s / A[j] * A[i]
    if x > s:
        print("Yes")
    else:
        print("No")
    s = x
    j += 1


Fixed submission:
N,K = map(int, input().split())
A=list(map(int, input().split()))
j = 0
for i in range(K,N):
    if A[j] < A[i]:
        print("Yes")
    else:
        print("No")
    j += 1