Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def gcc(x, y):
    if x == 0:return y
    return gcc(y % x, x)

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

g = 0

A.sort()

for item in A:
    g = gcc(g, item)

if g != 1:
    print("not coprime")
    exit()

primes = []

is_prime = [True] * 1100000
primes = []

is_prime[0] = is_prime[1] = False

for i in range(2, 1100000):
    if not is_prime[i]:continue
    for j in range(i*i, 1100000, i):
        is_prime[j] = False
    primes.append[i]

A_prime = [item for item in A if is_prime[item]]
A_notprime = [item for item in A if not is_prime[item]]

used = [False] * 1100000

for item in A_prime:
    used[item] = True

for a in A_notprime:
    for p in primes:
        if a == 1:break
        if a % p != 0:continue

        if used[p]:
            print("setwise coprime")
            #互いに素でない（共通素因数pで割れる）ペアがAの中にあると，それはsetwise_coprime
            exit()

        used[p] = True

        while a > p:
            a //= p

print("pairwise coprime")

Fixed submission:
def gcc(x, y):
    if x == 0:return y
    return gcc(y % x, x)

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

g = 0

A.sort()

for item in A:
    g = gcc(g, item)

if g != 1:
    print("not coprime")
    exit()

primes = []

is_prime = [True] * 1100000

is_prime[0] = is_prime[1] = False

for i in range(2, 1100000):
    if not is_prime[i]:continue
    for j in range(i*i, 1100000, i):
        is_prime[j] = False

A_prime = [item for item in A if is_prime[item]]
A_notprime = [item for item in A if not is_prime[item]]

primes = [p for p in range(1100) if is_prime[p]]
used = [False] * 1100000

for item in A_prime:
    used[item] = True

for a in A_notprime:
    for p in primes:
        if a == 1:break
        if a % p != 0:continue

        if used[p]:
            print("setwise coprime")
            #互いに素でない（共通素因数pで割れる）ペアがAの中にあると，それはsetwise_coprime
            exit()

        used[p] = True

        while a % p == 0:
            a //= p

    if a > 1:
        if used[a]:
            print("setwise coprime")
            exit()
        used[a] = True


print("pairwise coprime")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H, W = map(int, input().split())
C0, C1 = map(int, input().split())
D0, D1 = map(int, input().split())

C0 -= 1
C1 -= 1
D0 -= 1
D1 -= 1

map = []
for _ in range(H):
    map.append(input())

inf = 1000000000

q = deque([[C0, C1]])
dist = [[inf for a in range(1100)]for b in range(1100)]
dist[C0][C1] = 0

walk0 = [1, 0, -1, 0]
walk1 = [0, 1, 0, -1]


while q:
    now = q.popleft()
    d = dist[now[0]][now[1]]

    for v in range(4):
        wnxt0 = now[0] + walk0[v]
        wnxt1 = now[1] + walk1[v]

        if wnxt0 < 0 or wnxt0 > H - 1: continue
        elif wnxt1 < 0 or wnxt1 > W - 1: continue
        elif map[wnxt0][wnxt1] == "#": continue
        elif dist[wnxt0][wnxt1] <= d: continue
        
        dist[wnxt0][wnxt1] = d
        q.appendleft([wnxt0, wnxt1])

    for x in [-2, -1, 0, 1, 2]:
        for y in [-2, -1, 0, 1, 2]:
            mnxt0 = now[0] + y
            mnxt1 = now[1] + x

            if mnxt0 < 0 or mnxt0 > H - 1: continue
            elif mnxt1 < 0 or mnxt1 > W - 1: continue
            elif map[mnxt0][mnxt1] == "#": continue
            elif dist[mnxt0][mnxt1] <= d + 1: continue

            dist[mnxt0][mnxt1] = d + 1
            q.append([mnxt0, mnxt1])

ans = dist[D0][D1]

if ans == inf:
    ans = -1

print(ans)

Fixed submission:
from collections import deque

H, W = map(int, input().split())
C0, C1 = map(int, input().split())
D0, D1 = map(int, input().split())

C0 -= 1
C1 -= 1
D0 -= 1
D1 -= 1

map = []
for _ in range(H):
    map.append(input())

inf = 1000000000

q = deque([[C0, C1]])
dist = [[inf for a in range(1100)]for b in range(1100)]
dist[C0][C1] = 0

walk0 = [1, 0, -1, 0]
walk1 = [0, 1, 0, -1]


while q:
    now = q.popleft()
    d = dist[now[0]][now[1]]

    for v in range(4):
        wnxt0 = now[0] + walk0[v]
        wnxt1 = now[1] + walk1[v]

        if wnxt0 < 0 or wnxt0 > H - 1: continue
        elif wnxt1 < 0 or wnxt1 > W - 1: continue
        elif map[wnxt0][wnxt1] == "#": continue
        elif dist[wnxt0][wnxt1] <= d: continue
        
        dist[wnxt0][wnxt1] = d
        q.appendleft([wnxt0, wnxt1])

    for x in [-2, -1, 0, 1, 2]:
        for y in [-2, -1, 0, 1, 2]:
            mnxt0 = now[0] + y
            mnxt1 = now[1] + x

            if mnxt0 < 0 or mnxt0 > H - 1: continue
            elif mnxt1 < 0 or mnxt1 > W - 1: continue
            elif map[mnxt0][mnxt1] == "#": continue
            elif dist[mnxt0][mnxt1] <= d + 1: continue

            dist[mnxt0][mnxt1] = d + 1
            q.append([mnxt0, mnxt1])

ans = dist[D0][D1]

if ans == inf:
    ans = -1

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

a.sort(reverse=True)

arrival = 1
ans = 0

while arrival < N:
    score = a.popleft()
    if arrival == 1:
        ans += score
        arrival += 1
    else:
        ans += score*min(2, N - arrival)
        arrival += 2

print(ans)

Fixed submission:
from collections import deque

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

A.sort(reverse=True)

a = deque(A)

arrival = 1
ans = 0

while arrival < N:
    score = a.popleft()
    if arrival == 1:
        ans += score
        arrival += 1
    else:
        ans += score*min(2, N - arrival)
        arrival += 2

print(ans)

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

a.sort(reverse=True)

arrival = 1
ans = 0

while arrival < N:
    score = a.pop(0)
    if arrival == 1:
        ans += score
        arrival += 1
    else:
        ans += score*min(2, N - arrival)
        arrival += 2

print(ans)

Fixed submission:
from collections import deque

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

A.sort(reverse=True)

a = deque(A)

arrival = 1
ans = 0

while arrival < N:
    score = a.popleft()
    if arrival == 1:
        ans += score
        arrival += 1
    else:
        ans += score*min(2, N - arrival)
        arrival += 2

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque   #dequeはappendleftができるので。

letter = [0] + [chr(i) for i in range(97, 123)] #[0, a, b, c, ... , z]というリスト

N = int(input())

i = 0
n_24 = deque()

while N > 0:
    n_24.appendleft(N % 26)
    N = N // 26

ans = ''

for dig in (n_24):
    ans += letter[dig]

print(ans)

Fixed submission:
from collections import deque  # dequeはappendleftができるので。

letter = ['z'] + [chr(i) for i in range(97, 123)]  # [0, a, b, c, ... , z]というリスト

N = int(input())

i = 0
n_24 = deque()

while N > 0:
    n_24.appendleft(N % 26)
    if N%26== 0:
        N -= 26
    N = N // 26

ans = ''

for dig in (n_24):
    ans += letter[dig]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

ans = 1

for item in A:
    ans *= item

if ans > 10**18:
    print(-1)
    exit()

print(ans)

Fixed submission:
N = int(input())

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

ans = 1

for item in A:
    ans *= item

    ans = min(ans, 10**18 + 1)

if ans == 10**18 + 1:
    print(-1)
    exit()

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

ans = 1

for i in range(N):
    ans *= A[i]

if ans > 1000000000000000000:
    print(-1)
    exit()

print(ans)

Fixed submission:
N = int(input())

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

ans = 1

for item in A:
    ans *= item

    ans = min(ans, 10**18 + 1)

if ans == 10**18 + 1:
    print(-1)
    exit()

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

ans = 1

for i in range(N):
    ans *= A[i]

if ans > 1000000000000000000:
    print(-1)
    exit()

print(ans)

Fixed submission:
N = int(input())

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

ans = 1

for item in A:
    ans *= item

    ans = min(ans, 10**18 + 1)

if ans == 10**18 + 1:
    print(-1)
    exit()

print(ans)
Buggy python submission (verdict: Runtime Error):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

x = input()
X = int(x)

div = make_divisors(X)

for item in div:
    for A in range(-1000,1000):
        B = A - item

        if A^5 - B^5 == X:
            print(A + " " + B)

Fixed submission:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

x = input()
X = int(x)

div = make_divisors(X)

for item in div:
    for A in range(-1000,1000):
        B = A - item

        if A**5 - B**5 == X:
            print(str(A) + " " + str(B))
            break
        else:
            continue
        break
Buggy python submission (verdict: Time Limit Exceeded):
ABN = input().split()
A = int(ABN[0])
B = int(ABN[1])
N = int(ABN[2])

answer = 0
temp = 0

for x in range(N+1):
    temp = (A*x)//B - A * (x//B)

    if answer < temp:
        answer = temp

print(answer)

Fixed submission:
ABN = input().split()
A = int(ABN[0])
B = int(ABN[1])
N = int(ABN[2])

answer = 0
temp = 0

if N >= B:
    answer = A*(B-1) // B - A * ((B-1)//B)

else:
    answer = A*N //B - A * (N//B)

print(answer)
Buggy python submission (verdict: Runtime Error):
R = input()
print(2*R*3.14159265)

Fixed submission:
R = input()
print(2*int(R)*3.14159265)
Buggy python submission (verdict: Time Limit Exceeded):
N = input()
l = input().split()
for k in range(int(N)):
    i = str(k + 1)
    print(l.count(i))


Fixed submission:
import collections
N = input()
l = input().split()
c = collections.Counter(l)

for i in range(int(N)):
    print(c[str(i+1)])
Buggy python submission (verdict: Runtime Error):
N = input()
Sum = 0

for k in range(N):
    i = k+1

    if i % 3 != 0:
        if i % 5 != 0:
            Sum = Sum + i

print(Sum)

Fixed submission:
N = input()
Sum = 0

for k in range(int(N)):
    i = k+1

    if i % 3 != 0:
        if i % 5 != 0:
            Sum = Sum + i

print(Sum)

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

for k in range(N):
    i = k+1

    if i % 3 != 0 and i % 5 != 0:
        Sum = Sum + i

print(Sum)

Fixed submission:
N = input()
Sum = 0

for k in range(int(N)):
    i = k+1

    if i % 3 != 0:
        if i % 5 != 0:
            Sum = Sum + i

print(Sum)

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

for k in range(N):
    i = k+1

    if i % 3 != 0 and i % 5 != 0:
        Sum = Sum + i

print(str(Sum))

Fixed submission:
N = input()
Sum = 0

for k in range(int(N)):
    i = k+1

    if i % 3 != 0:
        if i % 5 != 0:
            Sum = Sum + i

print(Sum)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions

K = input()

Sum = 0
k = int(K)

for A in range(k):
    a = A + 1
    for B in range(k):
        b = B + 1
        gcd_ab = fractions.gcd(a, b)
        for C in range(k):
            c = C + 1

            Sum = Sum + fractions.gcd(gcd_ab, c)

print(Sum)

Fixed submission:
import math
 
K = input()
 
Sum = 0
k = int(K)
 
for A in range(k):
    a = A + 1
    for B in range(k):
        b = B + 1
        gcd_ab = math.gcd(a, b)
        for C in range(k):
            c = C + 1
 
            Sum = Sum + math.gcd(gcd_ab, c)
 
print(Sum)

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

K = input()

Sum = 0

for A in range(int(K)):
    a = A + 1
    for B in range(int(K)):
        b = B + 1
        for C in range(int(K)):
            c = C + 1

            Sum = Sum + fractions.gcd(fractions.gcd(a, b), c)

print(Sum)

Fixed submission:
import math
 
K = input()
 
Sum = 0
k = int(K)
 
for A in range(k):
    a = A + 1
    for B in range(k):
        b = B + 1
        gcd_ab = math.gcd(a, b)
        for C in range(k):
            c = C + 1
 
            Sum = Sum + math.gcd(gcd_ab, c)
 
print(Sum)

Buggy python submission (verdict: Runtime Error):
import fractions

K = input()

Sum = 0

for A in range(K):
    a = A + 1
    for B in range(K):
        b = B + 1
        for C in range(K):
            c = C + 1

            Sum = Sum + fractions.gcd(fractions.gcd(a, b), c)

print(Sum)

Fixed submission:
import math
 
K = input()
 
Sum = 0
k = int(K)
 
for A in range(k):
    a = A + 1
    for B in range(k):
        b = B + 1
        gcd_ab = math.gcd(a, b)
        for C in range(k):
            c = C + 1
 
            Sum = Sum + math.gcd(gcd_ab, c)
 
print(Sum)
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
w = [0]
v = [0]

for _ in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

dp = [[0 for col in range(W+1)] for row in range(N+1)]

#dp[i][j] = i番目までのお菓子の中から，ナップサックの中のお菓子の重さの総和がjを超えないようにいくつかお菓子を選んで詰めるとき，価値の最大値

for i in range(1, N+1):
    for j in range(1, W+1):
        if j - w[i] >= 0: #ex.ナップサックの耐加重がj=100,で, i番目のお菓子の重さが20である場合，ナップサックに追加することができるのは，i-1番目までのお菓子でまだ80以下の重さしかないとき。
            dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i])

        dp[i][j] = max(dp[i][j], dp[i-1][j])

print(dp[N][W])

Fixed submission:
N, W = map(int, input().split())
w = [0]
v = [0]

for _ in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

dp = [[0 for col in range(W+1)] for row in range(N+1)]

#dp[i][j] = i番目までのお菓子の中から，ナップサックの中のお菓子の重さの総和がjを超えないようにいくつかお菓子を選んで詰めるとき，価値の最大値

for i in range(1, N+1):
    for j in range(1, W+1):
        if j - w[i] >= 0: #ex.ナップサックの耐加重がj=100,で, i番目のお菓子の重さが20である場合，ナップサックに追加することができるのは，i-1番目までのお菓子でまだ80以下の重さしかないとき。
            dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i])

        dp[i][j] = max(dp[i][j], dp[i-1][j])

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

for _ in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

dp = [[0 for col in range(W+1)] for row in range(N+1)]

#dp[i][j] = i番目までのお菓子の中から，ナップサックの中のお菓子の重さの総和がjを超えないようにいくつかお菓子を選んで詰めるとき，価値の最大値

for i in range(1, N+1):
    for j in range(1, W+1):
        if j - w[i] >= 0: #ex.ナップサックの耐加重がj=100,で, i番目のお菓子の重さが20である場合，ナップサックに追加することができるのは，i-1番目までのお菓子でまだ80以下の重さしかないとき。
            dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i])

        dp[i][j] = max(dp[i][j], dp[i-1][j])

print(dp[N][W])

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

w = [0]
v = [0]

for _ in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

dp = [[float('inf') for a in range(110000)] for b in range(N+1)]
dp[0][0] = 0

ans = 0

for i in range(1, N+1):
    for j in range(110000):
        if j - v[i] >= 0:
            dp[i][j] = min(dp[i][j], dp[i-1][j-v[i]] + w[i])

        dp[i][j] = min(dp[i][j], dp[i-1][j])

        if dp[i][j] <= W and j > ans:
            ans = j

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
t = input()

n = len(s)
m = len(t)

dp = [[0 for a in range(3300)] for b in range(3300)]

for i in range(1, n + 1):
    for j in range(1, m + 1):
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1

        dp[i][j] = max(dp[i][j], dp[i-1][j], dp[i][j-1])

rewsna = ""

while n >= 0 and m >= 0:
    if dp[n][m] == dp[n-1][m]:
        n -= 1
    elif dp[n][m] == dp[n][m-1]:
        m -= 1
    else:
        rewsna += s[n-1]
        n -= 1
        m -= 1

print(rewsna[::-1])


Fixed submission:
s = input()
t = input()

n = len(s)
m = len(t)

dp = [[0 for a in range(3300)] for b in range(3300)]

for i in range(1, n + 1):
    for j in range(1, m + 1):
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1] + 1

        dp[i][j] = max(dp[i][j], dp[i-1][j], dp[i][j-1])

rewsna = ""

while n >= 0 and m >= 0:
    if dp[n][m] == dp[n-1][m]:
        n -= 1
    elif dp[n][m] == dp[n][m-1]:
        m -= 1
    else:
        rewsna += s[n-1]
        n -= 1
        m -= 1

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

graph = [[] for _ in range(110000)]

for _ in range(M):
    x, y = map(int, input().split())

    graph[x].append(y)

dp_memo = [-1] * 110000

def dp(v):
    if dp_memo[v] != -1:
        return dp_memo[v]

    ret = 0
    for item in graph[v]:
        ret = max(ret, dp(item) + 1)

    dp_memo[v] = ret
    return ret

ans = 0

for i in range(1, N+1):
    ans = max(ans, dp(i))

print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(110000) #再帰上限はデフォルトで1000回までなので，増やす。

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

graph = [[] for _ in range(110000)]

for _ in range(M):
    x, y = map(int, input().split())

    graph[x].append(y)

dp_memo = [-1] * 110000

def dp(v):
    if dp_memo[v] != -1:
        return dp_memo[v]

    ret = 0
    for item in graph[v]:
        ret = max(ret, dp(item) + 1)

    dp_memo[v] = ret
    return ret

ans = 0

for i in range(1, N+1):
    ans = max(ans, dp(i))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#c
import sys
n = int(input())
import math

ans = 0
for i in range(1,n):
    before = n
    for j in range(1,n):
        if before <= j:
            break
        if (n-i)%j==0 :
            before = (n-i)/j
            
            if j==(n-i)/j:
                ans+=1
            else:
                ans+=2
print(ans)

Fixed submission:
#c
import sys
n = int(input())
import math

ans = 0

for i in range(1,n):
    ans += (n-1)//i
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#c
import sys
n = int(input())
import math

ans = 0
for i in range(1,n):
    before = n
    for j in range(1,n):
        if (n-i)%j==0 :
            
            if before <= j:
                break
            if j==(n-i)/j:
                ans+=1
            else:
                ans+=2
                

        before = (n-i)/j
print(ans)
        

Fixed submission:
#c
import sys
n = int(input())
import math

ans = 0

for i in range(1,n):
    ans += (n-1)//i
print(ans)
Buggy python submission (verdict: Runtime Error):

n = int(input())
n_all = 10**(n) % mod
bad_0 = 9**(n)%mod
bad_9 = 9**(n)%mod
bad_18 = 8**(n)%mod

print(n_all-bad_0-bad_9+bad_18)

Fixed submission:
n = int(input())
mod = (10**9)+7
n_all = 10**(n) % mod
bad_0 = 9**(n)%mod
bad_9 = 9**(n)%mod
bad_18 = 8**(n)%mod

print((n_all-bad_0-bad_9+bad_18)%mod)
Buggy python submission (verdict: Time Limit Exceeded):
#c
n = int(input())
a = list(map(int, input().split()))
import itertools
ans = 0

for i in range(len(a)-1):
    ans += a[i]*sum(a[i+1:])

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

Fixed submission:
#cやり直し
import numpy
n = int(input())
a = list(map(int, input().split()))
ans = 0
mod = 10**9 +7

before = a[-1]
for i in range(n-1,0,-1):
    
    ans += (a[i-1]*before)%mod
    before += a[i-1]
    
print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
#c
n = int(input())
a = list(map(int, input().split()))
import itertools
ans = 0
for i in list(itertools.combinations(a,2)):
    ans += i[0]*i[1]
print(ans % (10**9 + 7))

Fixed submission:
#cやり直し
import numpy
n = int(input())
a = list(map(int, input().split()))
ans = 0
mod = 10**9 +7

before = a[-1]
for i in range(n-1,0,-1):
    
    ans += (a[i-1]*before)%mod
    before += a[i-1]
    
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
#a
n = int(input())
ans = n//1000
print(n%(ans*1000))

Fixed submission:
n = int(input())
while n>1000:
    n-=1000
print(1000-n)

Buggy python submission (verdict: Runtime Error):
#a
n = int(input())
print(n%((n//1000)*1000))

Fixed submission:
n = int(input())
while n>1000:
    n-=1000
print(1000-n)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
inf = 10**18
a = list(map(int, input().split()))
ans = a[0]
for i in range(1,len(a)):
    ans = ans * a[i]
if ans > inf:
    print("-1")
else:
    print(ans)

Fixed submission:
#b
import sys
N = int(input())
inf = 10**18
a = list(map(int, input().split()))
ans = a[0]
if 0 in a:
    print("0")
    sys.exit()
for i in range(1,len(a)):
    ans = ans * a[i]

    if ans > inf:
        print("-1")
        sys.exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
#c
a,b=map(float, input().split())
import math
a = decimal.Decimal(a)
b = decimal.Decimal(b)
ans = a*b
print(ans)

Fixed submission:
#c
a,b=map(float, input().split())
import math
import decimal
a = decimal.Decimal(a)
b = decimal.Decimal(str(b))
ans = a*b
print(int(ans))
Buggy python submission (verdict: Runtime Error):
#d
m,n=map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
maze = []
inf = 9999999
dist = [inf]* n
dist[0] = 0
queue = []
answer = [0]*n

goto = [[] * 1 for i in range(n)]
for i in range(len(ab)):
    goto[ab[i][0]-1].append(ab[i][1]-1)
    goto[ab[i][1]-1].append(ab[i][0]-1)

queue.extend([0])

while queue != []:
    go = queue.pop()
    for h in goto[go]:
        if dist[h] == inf:
            queue.append(h)
            dist[h] = dist[go]+1
            answer[h] =go+1
print("Yes")
for i in answer[1:]:
    print(i)

Fixed submission:
#d
n,m=map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
maze = []
inf = 9999999
dist = [inf]* n
dist[0] = 0
queue = []
answer = [0]*n

goto = [[] * 1 for i in range(n)]
for i in range(len(ab)):
    goto[ab[i][0]-1].append(ab[i][1]-1)
    goto[ab[i][1]-1].append(ab[i][0]-1)

queue.extend([0])

while queue != []:
    go = queue.pop(0)
    for h in goto[go]:
        if dist[h] == inf:
            queue.append(h)
            dist[h] = dist[go]+1
            answer[h] =go+1
            

            
print("Yes")
for i in answer[1:]:
    print(i)

Buggy python submission (verdict: Runtime Error):
#d
m,n=map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
maze = []
inf = 9999999
dist = [inf]* n
dist[0] = 0
queue = []
answer = [0]*n

goto = [[] * 1 for i in range(n)]
for i in range(len(ab)):
    goto[ab[i][0]-1].append(ab[i][1]-1)
    goto[ab[i][1]-1].append(ab[i][0]-1)

queue.extend([0])

while queue != []:
    go = queue.pop()
    for h in goto[go]:
        if dist[h] == inf:
            queue.append(h)
            dist[h] = dist[go]+1
            answer[h] =go+1
print("yes")
for i in answer[1:]:
    print(i)

Fixed submission:
#d
n,m=map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
maze = []
inf = 9999999
dist = [inf]* n
dist[0] = 0
queue = []
answer = [0]*n

goto = [[] * 1 for i in range(n)]
for i in range(len(ab)):
    goto[ab[i][0]-1].append(ab[i][1]-1)
    goto[ab[i][1]-1].append(ab[i][0]-1)

queue.extend([0])

while queue != []:
    go = queue.pop(0)
    for h in goto[go]:
        if dist[h] == inf:
            queue.append(h)
            dist[h] = dist[go]+1
            answer[h] =go+1
            

            
print("Yes")
for i in answer[1:]:
    print(i)
Buggy python submission (verdict: Runtime Error):
#b
a,b,c,k=map(int, input().split())
test = []
test += [1]*a
test += [0]*b
test += [-1]*c
print(sum(test[0:k]))

Fixed submission:
a,b,c,k=map(int, input().split())
if a > k:
    print(k)
elif a + b > k:
    print(a)
else:
    print(a-(k-(a+b)))
Buggy python submission (verdict: Time Limit Exceeded):
#167_d
n, k = map(int, input().split())
a = list(map(int, input().split()))

r = []

now = 1
while True:
    r.append(now)
    now = a[now - 1] 
    if now in r:
        roop = r[r.index(now):]
        break
        
if len(r) - 1 >= k: #ループに入らないとき
    print(r[k])
else:#ループに入ったとき
    print(roop[(k-len(r)) % len(roop)])
    

Fixed submission:
#167_d
n, k = map(int, input().split())
a = list(map(int, input().split()))

r = []
check = [0]*len(a)
now = 1
count = 0

while True:
    r.append(now)
    now = a[now - 1]
    
    if check[now - 1] == 1:
        roop = r[r.index(now):]
        break
    check[now - 1] += 1
    
if len(r) - 1 >= k: #ループに入らないとき
    print(r[k])
else:#ループに入ったとき
    print(roop[(k-len(r)) % len(roop)])