Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = input()
if N == "1":
    print("Hello World")
elif N == "2":
    a,b = map(int, input().split())
    print(a+b)

Fixed submission:
N = input()
if N == "1":
    print("Hello World")
elif N == "2":
    a,b = [int(input()) for i in range(2)]
    print(a+b)

Buggy python submission (verdict: Runtime Error):
N = int(input())
if N == 1:
    print("Hello World")
elif N == 2:
    a,b = map(int, input().split())
    print(a+b)

Fixed submission:
N = input()
if N == "1":
    print("Hello World")
elif N == "2":
    a,b = [int(input()) for i in range(2)]
    print(a+b)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

D = []
d = 1
while M >= N * d:
	if M % d == 0:
		D.append(d)
	d += 1

print(max(D))

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

def divisible(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)
	return divisors

div = divisible(M)

div = [d for d in div if d <= M / N]

print(max(div))

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

D = []
d = 1
while M >= N * d:
	if M % d == 0:
		D.append(d)
	d += 1

maxg = 1
for d in D:
	if (M - d * (N - 1)) % d == 0:
		maxg = max(maxg, d)

print(maxg)

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

def divisible(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)
	return divisors

div = divisible(M)

div = [d for d in div if d <= M / N]

print(max(div))

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

# a1,...,anのgcdをDと仮定
# M >= N*D が成立
# Dの候補が絞れる

D = []
d = 1
while M >= N * d:
	D.append(d)
	d += 1

maxg = 1
for d in D:
	if (M - d * (N - 1)) % d == 0:
		maxg = max(maxg, d)

print(maxg)

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

def divisible(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)
	return divisors

div = divisible(M)

div = [d for d in div if d <= M / N]

print(max(div))
Buggy python submission (verdict: Runtime Error):
s=input()
k=int(input())

cnt=0 #1の個数
i=0
while True:
    if s[i]!='1': break
    else:
        cnt+=1
        i+=1
        
print(1 if k<=cnt else s[cnt])

Fixed submission:
s=input()
k=int(input())

cnt=0 #1の個数
i=0
while True:
    if s[i]!='1': break
    else:
        cnt+=1
        i+=1
        if i>len(s)-1: break
        
print(1 if k<=cnt else s[cnt])

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

ans: int = 1
for i in range(min(K, len(S))):
    if(S[i] != "1"):
        ans = S[i]
        break
print(ans)

Fixed submission:
s=input()
k=int(input())

cnt=0 #1の個数
i=0
while True:
    if s[i]!='1': break
    else:
        cnt+=1
        i+=1
        if i>len(s)-1: break
        
print(1 if k<=cnt else s[cnt])

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

ans: int = 1
for i in range(min(K, len(S))):
    if(S[i] != "1"):
        ans = S[i]
        break
print(ans)

Fixed submission:
s=input()
k=int(input())

cnt=0 #1の個数
i=0
while True:
    if s[i]!='1': break
    else:
        cnt+=1
        i+=1
        if i>len(s)-1: break
        
print(1 if k<=cnt else s[cnt])
Buggy python submission (verdict: Runtime Error):
n = int(input())
sum = 0
tmp = n

while n > 0:
    sum += sum % 10
    n //= 10

if tmp % sum == 0:
    print("Yes")
else:
    print("No")

Fixed submission:
def digitsum(n):
    ans = 0
    while n > 0:
        ans += n % 10
        n = n // 10
    return ans

N = int(input())
SumN = digitsum(N)
if N % SumN == 0:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
n = int(input())
sum = 0
tmp = n

while tmp > 0:
    sum += sum % 10
    tmp //= 10

if n % sum == 0:
    print("Yes")
else:
    print("No")

Fixed submission:
def digitsum(n):
    ans = 0
    while n > 0:
        ans += n % 10
        n = n // 10
    return ans

N = int(input())
SumN = digitsum(N)
if N % SumN == 0:
    print("Yes")
else:
    print("No")

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

sum = 0
tmp = n

while tmp > 0:
    sum += sum % 10
    tmp //= 10

if n % sum == 0:
    print("Yes")
else:
    print("No")

Fixed submission:
def digitsum(n):
    ans = 0
    while n > 0:
        ans += n % 10
        n = n // 10
    return ans

N = int(input())
SumN = digitsum(N)
if N % SumN == 0:
    print("Yes")
else:
    print("No")

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

sum = 0
tmp = n

while tmp > 0:
    sum += sum % 10
    tmp /= 10

if n % sum == 0:
    print("Yes")
else:
    print("No")

Fixed submission:
def digitsum(n):
    ans = 0
    while n > 0:
        ans += n % 10
        n = n // 10
    return ans

N = int(input())
SumN = digitsum(N)
if N % SumN == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))

cnt = 0
while all([i%2!=0 for i in a])!=True:
    for i in range(n):
        if a[i]%2==0:
            a[i]//=2
            cnt+=1
            break
print(cnt)

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

def cnt_div2(n):
    cnt=0
    while n%2==0:
        n//=2
        cnt+=1
    return cnt

#各要素に対して，2で割ることのできる回数をカウント
lis = [cnt_div2(i) for i in a]
print(sum(lis))

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

cnt=0
for i in range(n):
    if all([i%2!=0 for i in a])==True: #すべての要素が奇数ならbreak
        break
    elif a[i]%2!=0: #奇数なら3倍
        a[i]*=3
    elif a[i]%4==2: #4の剰余が2（e.g.,2,6,10,...）なら3倍
        a[i]*=3
    elif a[i]%4==0: #4の剰余が0なら1/2倍
        a[i]//=2
    cnt+=1
print(cnt)

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

def cnt_div2(n):
    cnt=0
    while n%2==0:
        n//=2
        cnt+=1
    return cnt

#各要素に対して，2で割ることのできる回数をカウント
lis = [cnt_div2(i) for i in a]
print(sum(lis))
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int, input().split())
k = int(input())

lis = list(a,b,c)
lis.sort()
maxi = lis[-1]
print(lis[0]+lis[1]+k*maxi)

Fixed submission:
a,b,c = map(int, input().split())
k = int(input())
 
lis = [a,b,c]
lis.sort()
maxi = lis[-1]
for i in range(k):
    maxi *= 2
print(lis[0]+lis[1]+maxi)
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
s=[list(map(int,list(input()))) for i in range(h)] 

for i in range(1,h-1):
    for j in range(1,w-1):
        if s[i][j]=='#':
            if s[i-1][j]=='.' and s[i][j-1]=='.' and s[i][j+1]=='.' and s[i+1][j]=='.':
                print('No')
                exit()
print('Yes')

Fixed submission:
h,w=map(int,input().split())
s=[list(map(str,list(input()))) for i in range(h)] 

for i in range(1,h-1):
    for j in range(1,w-1):
        if s[i][j]=='#':
            if s[i-1][j]=='.' and s[i][j-1]=='.' and s[i][j+1]=='.' and s[i+1][j]=='.':
                print('No')
                exit()
print('Yes')
Buggy python submission (verdict: Runtime Error):
n,x = map(int, input().split())
m=[]
for i in range(n): m.append(int(input()))
m.sort()
nokori = x - sum(m)
kosuu  = nokoro // m[0]
print(len(m) + kosuu)

Fixed submission:
n,x = map(int, input().split())
m=[]
for i in range(n): m.append(int(input()))
m.sort()
nokori = x - sum(m)
kosuu  = nokori // m[0]
print(len(m) + kosuu)
Buggy python submission (verdict: Time Limit Exceeded):
#094
n=int(input())
x=list(map(int,input().split()))
x.insert(0,0) #x[0]に0を挿入
sorted_x = sorted(x[:])

for i in range(1,n+1):
    idx = sorted_x.index(x[i])
    print(sorted_x[n//2+1] if idx<=n//2 else sorted_x[n//2])

Fixed submission:
n=int(input())
x=list(map(int,input().split()))
x.insert(0,0) #x[0]に0を挿入
sorted_x = sorted(x[:])

l,r=sorted_x[n//2],sorted_x[n//2+1]

for i in range(1,n+1):
    print(r if x[i]<=l else l)
Buggy python submission (verdict: Runtime Error):
a,b,k=map(int,input().split())

lis=[]
for i in range(a, min(a+k,b+1)):
    lis.append(i)
for i in range(max(a,b-k+1), b+1):
    lis.append(i)


lis=list(set(l)) #重複除去
lis.sort()
for i in lis:
    print(i)
    


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

lis=[]
for i in range(a, min(a+k,b+1)):
    lis.append(i)
for i in range(max(a,b-k+1), b+1):
    lis.append(i)


lis=list(set(lis)) #重複除去
lis.sort()
for i in lis:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = []
march = ['M', 'A', 'R', 'C', 'H']
for _ in range(n):
    s = input()
    if s[0] in march:
        A.append(s)

# 同じ文字から始まらない 3 人の選び方
from itertools import combinations

cnt = 0
for v in combinations(A, 3):
    if v[0][0] == v[1][0] or v[1][0] == v[2][0] or v[2][0] == v[0][0]:
        continue
    cnt += 1
print(cnt)

Fixed submission:
n=int(input())
a=[0]*5
for i in range(n):
    s=input()
    if s[0]=='M': a[0]+=1
    elif s[0]=='A': a[1]+=1
    elif s[0]=='R': a[2]+=1
    elif s[0]=='C': a[3]+=1
    elif s[0]=='H': a[4]+=1
res=0
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            res+=a[i]*a[j]*a[k]
print(res)
Buggy python submission (verdict: Runtime Error):
n=int(input())
t=[0]*n
x=[0]*n
y=[0]*n
for i in range(n):
    t[i],x[i],y[i] = map(int,input().split())

if len(t)>1:
    for i in range(n-1):
        dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i])
        diff = t[i+1]-t[i]
        if dist>diff or dist%2!=diff%2:
            print('No')
            exit()
    print('Yes')
else:
    dist = abs(x[0]-0) + abs(y[0]-0)
    if t[0] < dist or t[0]%2!=diff%2:
        print('No')
    else:
        print('Yes')

Fixed submission:
n=int(input())
t=[0]*(n+1)
x=[0]*(n+1)
y=[0]*(n+1)

for i in range(n):
    t[i+1],x[i+1],y[i+1] = map(int,input().split())

    
for i in range(n):
    dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i])
    diff = t[i+1]-t[i]
    if dist>diff or dist%2!=diff%2:
        print('No')
        exit()
print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
def prime_list(n):
	primes = set(range(2, n + 1))
	for i in range(2, int(n ** 0.5 + 1)):
		primes.difference_update(range(i * 2, n + 1, i))
	return list(primes)

q = int(input())
primes = prime_list(10**5)

for i in range(q):
	l, r = map(int, input().split())
	cnt = 0
	for j in range(l, r+1):
		if j in primes and (j+1)//2 in primes:
			cnt += 1
	print(cnt)



Fixed submission:
# O(nloglogn) https://mathtrain.jp/eratosthenes
def sieve(n):
	s = [True] * n
	s[0] = s[1] = False
	for x in range(2, int(n ** 0.5) + 1):
		if s[x]:
			for i in range(2 * x, n, x):
				s[i] = False
	return s

is_prime = sieve(10 ** 5 + 1)
is_like2017 = [False] * (10 ** 5 + 1)
for i in range(10**5 + 1):
	if is_prime[i] and is_prime[(i + 1) // 2]:
		is_like2017[i] = True

# 区間内のlike2017を求める
# 累積和を用いて高速化
c = [0] * (10 ** 5 + 1)
for i in range(1, 10 ** 5 + 1):
	if is_like2017[i]:
		c[i] = c[i - 1] + 1
	else:
		c[i] = c[i-1]

# 出力
q = int(input())

for i in range(q):
	l, r = map(int, input().split())
	print(c[r] - c[l-1])
Buggy python submission (verdict: Runtime Error):
N = input()
A = list(map(int, input().split()))
count = 0
while all(a%2==0 for a in A):
    A = [a/2 for a in A]
    count += 1
print(cnt)

Fixed submission:
N = input()
A = list(map(int, input().split()))
count = 0
while all(a%2==0 for a in A):
    A = [a/2 for a in A]
    count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))

c=collections.Counter(a)
num_kind=len(set(a)) #種類の数
diff = num_kind-k #変更すべき数
values, counts = zip(*c.most_common()[::-1]) #少ない順
print(sum(counts[:diff]))

Fixed submission:
import collections
n,k=map(int,input().split())
a=list(map(int,input().split()))

c=collections.Counter(a)
num_kind=len(set(a)) #種類の数
diff = num_kind-k #変更すべき数
values, counts = zip(*c.most_common()[::-1]) #少ない順
print(sum(counts[:diff]))
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)] 

# 0,(1),2,3,...,9に対して1にするための最小コストを求める
INF = 10 ** 4
d = c.copy()
for k in range(10):
    for i in range(10):
        for j in range(10):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])


res = 0
for arr in A:
    for a in arr:
        if a == 1 or a == -1:
            continue
        else:
            res += d[a][1]

print(res)

Fixed submission:
H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)] 

INF = 10 ** 6
for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])

res = 0
for arr in A:
    for a in arr:
        if a == -1:
            continue
        else:
            res += c[a][1]

print(res)
Buggy python submission (verdict: Runtime Error):
x, y = map(str, input())
x = int(x, 16)
y = int(y, 16)
if x==y: print('=')
elif x>y: print('>')
else: print('<')

Fixed submission:
x, y = map(str, input().split())
x = int(x, 16)
y = int(y, 16)
if x==y: print('=')
elif x>y: print('>')
else: print('<')
Buggy python submission (verdict: Runtime Error):
r, g = map(int, input().split())
print(2*g-r)

Fixed submission:
r=int(input())
g=int(input())
print(2*g-r)

Buggy python submission (verdict: Runtime Error):
r, g = map(int, input().split())
print(2*g-r)

Fixed submission:
r=int(input())
g=int(input())
print(2*g-r)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[]
for i in range(n):
    k=int(input())
    if k not in a:
        a.append(k)
    elif k in a:
        a.remove(k)
print(len(a))

Fixed submission:
n=int(input())
a=sorted([int(input()) for _ in range(n)])

ptr=0
res=0
while ptr<n:
    cc=a[ptr]
    f=0
    while ptr<n and a[ptr]==cc: #出現回数をカウント
        f+=1
        ptr+=1
    res+=f%2 #奇数回の場合インクリメント
print(res)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)

tmp=a[0]
for i in range(n-1):
    l= 0
    if tmp == a[i+1]:
        idx = i+1
        l = tmp #lを確定させる
        break
    else:
        idx=i
        tmp=a[i+1]
        

tmp2=a[idx+1]
for j in range(idx+1,n-1):
    s=0
    if tmp2==a[j+1]:
        s = tmp2
        break
    else:
        tmp2=a[j+1]
        
print(l*s)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)

tmp1=a[0]
for i in range(n-1):
    l,s= 0,0
    if tmp1 == a[i+1]:
        idx = i+1
        l = tmp1 #lを確定させる
        #break
        tmp2=a[idx+1]
        for j in range(idx+1,n-1):
            if tmp2==a[j+1]:
                s = tmp2
                print(l*s)
                exit()
            else:
                tmp2 = a[j+1]
    else:
        idx=i
        tmp1=a[i+1]
        
print(0)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)

b = list(set(a))
b.sort(reverse=True)

for i in range(len(b)):
    if a.count(b[i])==4:
        print(b[i]**2)
        exit()
    elif a.count(b[i])==3 or a.count(b[i])==2:
        while True:
            j=i+1
            if j<n and a.count(b[j])>=2:
                print(b[i]*b[j])
                break
                exit()
            else:
                j+=1
print(0)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)

tmp1=a[0]
for i in range(n-1):
    l,s= 0,0
    if tmp1 == a[i+1]:
        idx = i+1
        l = tmp1 #lを確定させる
        #break
        tmp2=a[idx+1]
        for j in range(idx+1,n-1):
            if tmp2==a[j+1]:
                s = tmp2
                print(l*s)
                exit()
            else:
                tmp2 = a[j+1]
    else:
        idx=i
        tmp1=a[i+1]
        
print(0)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)

b = list(set(a))
b.sort(reverse=True)

for i in range(len(b)):
    if a.count(b[i])==4:
        print(b[i]**2)
    elif a.count(b[i])==3 or a.count(b[i])==2:
        while True:
            j=i+1
            if j<n and a.count(b[j])>=2:
                print(b[i]*b[j])
                break
                exit()
            else:
                j+=1
print(0)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)

tmp1=a[0]
for i in range(n-1):
    l,s= 0,0
    if tmp1 == a[i+1]:
        idx = i+1
        l = tmp1 #lを確定させる
        #break
        tmp2=a[idx+1]
        for j in range(idx+1,n-1):
            if tmp2==a[j+1]:
                s = tmp2
                print(l*s)
                exit()
            else:
                tmp2 = a[j+1]
    else:
        idx=i
        tmp1=a[i+1]
        
print(0)
Buggy python submission (verdict: Runtime Error):
n=int(input())
t=[int(input()) for _ in range(n)]

import fractions
a,b=t[0],t[1]
res=a*b//fractions.gcd(a,b)
for i in range(2,n):
    tmp=t[i]
    res = res*tmp//fractions.gcd(res,tmp)
print(res)

Fixed submission:
n=int(input())
t=[int(input()) for _ in range(n)]

import fractions
if n==1: print(t[0])
else:
    a,b=t[0],t[1]
    res=a*b//fractions.gcd(a,b)
    for i in range(2,n):
        tmp=t[i]
        res = res*tmp//fractions.gcd(res,tmp)
    print(res)

Buggy python submission (verdict: Runtime Error):
n=int(input())
t=[int(input()) for _ in range(n)]

import fractions
a,b=t[0],t[1]
res=a*b//fractions.gcd(a,b)
for i in range(2,n-1):
    a,b=t[i],t[i+1]
    res = a*b//fractions.gcd(a,b)
print(res)

Fixed submission:
n=int(input())
t=[int(input()) for _ in range(n)]

import fractions
if n==1: print(t[0])
else:
    a,b=t[0],t[1]
    res=a*b//fractions.gcd(a,b)
    for i in range(2,n):
        tmp=t[i]
        res = res*tmp//fractions.gcd(res,tmp)
    print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 9)

n = int(input())
tree = [[] for _ in range(n)]
for i in range(n - 1):
    a, b, c = map(int, input().split())
    a, b, c = a - 1, b - 1, c
    tree[a].append((b, c))
    tree[b].append((a, c))

limit = 100010
depth = [0] * limit

def dfs(v, p, d): # (現在の頂点v, vの親, 現在の距離)
    depth[v] = d
    for e in tree[v]:
        if e[0] == p: continue
        dfs(e[0], v, d + e[1])

q, k = map(int, input().split())
k -= 1
dfs(k, -1, 0)
for i in range(q):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    res = depth[x] + depth[y]
    print(res)

Fixed submission:
n = int(input())
tree = [[] for _ in range(n)]
for i in range(n - 1):
    a, b, c = map(int, input().split())
    a, b, c = a - 1, b - 1, c
    tree[a].append((b, c))
    tree[b].append((a, c))

from heapq import heappush, heappop
INF = 10 ** 18
def dijkstra(s, n): # (始点, ノード数)
    dist = [INF] * n
    hq = [(0, s)] # (distance, node)
    dist[s] = 0
    seen = [False] * n # ノードが確定済みかどうか
    while hq:
        v = heappop(hq)[1] # ノードを pop する
        seen[v] = True
        for to, cost in tree[v]: # ノード v に隣接しているノードに対して
            if seen[to] == False and dist[v] + cost < dist[to]:
                dist[to] = dist[v] + cost
                heappush(hq, (dist[to], to))
    return dist

q, k = map(int, input().split())
k -= 1
dist = dijkstra(k, n)
for i in range(q):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    res = dist[x] + dist[y]
    print(res)

Buggy python submission (verdict: Runtime Error):
n = int(input())
tree = [[] for _ in range(n)]
for i in range(n - 1):
    a, b, c = map(int, input().split())
    a, b, c = a - 1, b - 1, c
    tree[a].append((b, c))
    tree[b].append((a, c))

limit = 100010
depth = [0] * limit

def dfs(v, p, d): # (現在の頂点v, vの親, 現在の距離)
    depth[v] = d
    for e in tree[v]:
        if e[0] == p: continue
        dfs(e[0], v, d + e[1])

q, k = map(int, input().split())
k -= 1
dfs(k, -1, 0)
for i in range(q):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    res = depth[x] + depth[y]
    print(res)

Fixed submission:
n = int(input())
tree = [[] for _ in range(n)]
for i in range(n - 1):
    a, b, c = map(int, input().split())
    a, b, c = a - 1, b - 1, c
    tree[a].append((b, c))
    tree[b].append((a, c))

from heapq import heappush, heappop
INF = 10 ** 18
def dijkstra(s, n): # (始点, ノード数)
    dist = [INF] * n
    hq = [(0, s)] # (distance, node)
    dist[s] = 0
    seen = [False] * n # ノードが確定済みかどうか
    while hq:
        v = heappop(hq)[1] # ノードを pop する
        seen[v] = True
        for to, cost in tree[v]: # ノード v に隣接しているノードに対して
            if seen[to] == False and dist[v] + cost < dist[to]:
                dist[to] = dist[v] + cost
                heappush(hq, (dist[to], to))
    return dist

q, k = map(int, input().split())
k -= 1
dist = dijkstra(k, n)
for i in range(q):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    res = dist[x] + dist[y]
    print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a,b=[0]*m,[0]*m
for i in range(m):
    a[i],b[i] = map(int,input().split())
    
for i in range(m):
    if a[i]==1:
        p=b[i]
        for j in range(m):
            if a[j]==p and b[j]==n:
                print('POSSIBLE')
                exit()
print('IMPOSSIBLE')

Fixed submission:
n,m=map(int,input().split())
a,b=[0]*m,[0]*m
c=[False]*(n+1)
d=[False]*(n+1)
for i in range(m):
    a[i],b[i] = map(int,input().split())
    if a[i]==1: c[b[i]]=True
    if b[i]==n: d[a[i]]=True
for i in range(n):
    if c[i] and d[i]:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
A = list(map(int, input().split()))

# 最大公約数
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

MAX = max(A)
GCD = gcd(A[0], A[1])
for i in range(2, n):
	GCD = gcd(GCD, A[i])

if k % GCD == 0 and k <= MAX:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')

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

# 最大公約数
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

MAX = max(A)
GCD = 0
for i in range(n):
	GCD = gcd(GCD, A[i])

if k % GCD == 0 and k <= MAX:
	print('POSSIBLE')
else:
	print('IMPOSSIBLE')
Buggy python submission (verdict: Runtime Error):
o = input()
e = input()
lis = []
for i in range(min(len(o),len(e)):
    lis.append(o[i])
    lis.append(e[i])
if len(o)>len(e):
    lis.append(o[-1])
elif len(o)==len(e):
    lis.append(o[-1])
    lis.append(e[-1])

print(''.join(lis))

Fixed submission:
o = input()
e = input()
lis = []
for i in range(min(len(o),len(e))):
    lis.append(o[i])
    lis.append(e[i])
if len(o)>len(e):
    lis.append(o[-1])

print(''.join(lis))

Buggy python submission (verdict: Runtime Error):
o = input()
e = input()
lis = []
for i in range(len(o)):
  lis.append(o[i])
  lis.append(e[i])
print(''.join(lis))

Fixed submission:
o = input()
e = input()
lis = []
for i in range(min(len(o),len(e))):
    lis.append(o[i])
    lis.append(e[i])
if len(o)>len(e):
    lis.append(o[-1])

print(''.join(lis))