Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# 上からm番目がx
# x以上のヒトがm人以上、x+1以上のヒトがm-1人以下
# x以上のヒトがm人以上となる最大のx
from bisect import bisect_left
from itertools import accumulate

n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ok = 0
ng = 10 ** 15

B = [0] + A[::-1]
C = list(accumulate(B))

while ng - ok > 1:
    mid = (ok + ng) // 2
    cnt = 0
    for i in range(n):
        gendo = mid - A[i]
        position = bisect_left(A, gendo)
        if position == n:
            continue
        kosuu = n - position
        cnt += kosuu
    if cnt >= m:
        ok = mid
    else:
        ng = mid
ans = 0
cnt = m
for i in range(n):
    gendo = ok - A[i]
    position = bisect_left(A, gendo)
    if position == n:
        continue
    kosuu = n - position
    ans += C[kosuu] + kosuu * A[i]
    cnt -= kosuu
ans += cnt * ok
print(ans)


Fixed submission:
# 上からm番目がx
# x以上のヒトがm人以上、x+1以上のヒトがm-1人以下
# x以上のヒトがm人以上となる最大のx
from bisect import bisect_left
from itertools import accumulate
import sys

input = sys.stdin.buffer.readline


n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ok = 0
ng = 3 * (10 ** 5)

B = [0] + A[::-1]
C = list(accumulate(B))

while ng - ok > 1:
    mid = (ok + ng) // 2
    cnt = 0
    for i in range(n):
        gendo = mid - A[i]
        position = bisect_left(A, gendo)
        if position == n:
            continue
        kosuu = n - position
        cnt += kosuu
    if cnt >= m:
        ok = mid
    else:
        ng = mid
ans = 0
cnt = m
for i in range(n):
    gendo = ok - A[i]
    position = bisect_left(A, gendo)
    if position == n:
        continue
    kosuu = n - position
    ans += C[kosuu] + kosuu * A[i]
    cnt -= kosuu
ans += cnt * ok
print(ans)
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
l=[1,2,3]
l.pop(a-1)
l.pop(b-1)
print(*l)

Fixed submission:
a=int(input())
b=int(input())
l=[1,2,3]
l[a-1]=0
l[b-1]=0
print(sum(l))

Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
print(int(((a-1)*(a-2)*(a-3)*(b-1)(b-2)(b-3))**(1/2)))

Fixed submission:
a=int(input())
b=int(input())
l=[1,2,3]
l[a-1]=0
l[b-1]=0
print(sum(l))

Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
print(int((a-1)*(a-2)*(a-3)*(b-1)(b-2)(b-3))**(1/2))

Fixed submission:
a=int(input())
b=int(input())
l=[1,2,3]
l[a-1]=0
l[b-1]=0
print(sum(l))

Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
print(int(((a-1)*(a-2)*(a-3)*(b-1)(b-2)(b-3))**(1/2)))

Fixed submission:
a=int(input())
b=int(input())
l=[1,2,3]
l[a-1]=0
l[b-1]=0
print(sum(l))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(62):
    cnt=0
    for j in range(n):
        cnt+=(A[j]>>i)&1
    ans+=cnt * (n-cnt) *(2**i)%mod
print(ans%mod)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(62):
    cnt=0
    for j in range(n):
        cnt+=(A[j]>>i)&1
    ans+=cnt * (n-cnt) *(2**i)%mod
print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int, input().split()))
B=[]
mod=10**9+7
for i in range(N-1):
    for j in range(i, N):
        B.append((A[i]^A[j])%mod)
print(sum(B)%mod)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(62):
    cnt=0
    for j in range(n):
        cnt+=(A[j]>>i)&1
    ans+=cnt * (n-cnt) *(2**i)%mod
print(ans%mod)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int, input().split()))
B=[]
mod=10**9+7
for i in range(N-1):
    for j in range(i, N):
        B.append((A[i]^A[j])%mod)
print(sum(B)%mod)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(62):
    cnt=0
    for j in range(n):
        cnt+=(A[j]>>i)&1
    ans+=cnt * (n-cnt) *(2**i)%mod
print(ans%mod)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B=[0]
c=0
for i in range(0,N):
    B.append(B[i]+A[i])
for k in range(N+1):
    for j in range(k):
        if (B[k]-B[j])%K==(k-j):
            c+=1
print(c)

Fixed submission:
from collections import defaultdict

n, k = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
shukei = defaultdict(int)
# AiからAjまでの和→SA[j]-SA[i-1]
# SA[j]-SA[i-1]=j-(i-1)
# 今回はkで割ったあまりなのでaccumulateは使わず自力
S = [0] * (n + 1)
T = [0] * (n + 1)
for i in range(1, n + 1):
    S[i] = S[i - 1] + A[i - 1]
    S[i] %= k
    T[i] = S[i] - i
    T[i] %= k
# i>=1, i<jで同じ値になっている組み合わせを探せば良い。
# kで割ったあまりなので、要素数j−(i-1)がkより小さくないといけない
ans = 0
if k > n + 1:
    for i in range(n + 1):
        shukei[T[i]] += 1
    for key, num in shukei.items():
        ans += num * (num - 1) // 2
else:
    shukei = defaultdict(int)
    for i in range(k):
        shukei[T[i]] += 1
    for key, num in shukei.items():
        ans += num * (num - 1) // 2
    for i in range(k, n + 1):
        j = i - k
        shukei[T[j]] -= 1
        temp = T[i]
        num = shukei[temp]
        ans += num
        shukei[temp] += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
s = input()
s = s[::-1]
if s[0] == "1":
    print(-1)
    exit()
pre = [-1] * (n + 1)
stack = [0]
while stack:
    now = stack.pop()
    if now == n:
        break
    for i in range(1, m + 1):
        tsugi = now + i
        if tsugi > n:
            continue
        if s[tsugi] == "1":
            continue
        pre[tsugi] = now
        stack.append(tsugi)
else:
    print(-1)
    exit()
ato = n
mae = pre[n]
ans = []
while mae >= 0:
    ans.append(ato - mae)
    ato = mae
    mae = pre[ato]
print(*ans, sep=" ")


Fixed submission:
n, m = map(int, input().split())
s = input()
out_s='1'*(m)
if out_s in s:
    print(-1)
    exit()
s = s[::-1]
if s[0] == "1":
    print(-1)
    exit()
pre = [-1] * (n + 1)
stack = [0]
while stack:
    now = stack.pop()
    if now == n:
        break
    for i in range(1, m + 1):
        tsugi = now + i
        if tsugi > n:
            continue
        if s[tsugi] == "1":
            continue
        pre[tsugi] = now
        stack.append(tsugi)
else:
    print(-1)
    exit()
ato = n
mae = pre[n]
ans = []
while mae >= 0:
    ans.append(ato - mae)
    ato = mae
    mae = pre[ato]
print(*ans, sep=" ")

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
s = input()
s = s[::-1]
if s[0] == "1":
    print(-1)
    exit()
pre = [-1] * (n + 1)
stack = [0]
while stack:
    now = stack.pop()
    if now == n:
        break
    for i in range(1, m + 1):
        tsugi = now + i
        if tsugi > n:
            continue
        if s[tsugi] == "1":
            continue
        pre[tsugi] = now
        stack.append(tsugi)
else:
    print(-1)
    exit()
ato = n
mae = pre[n]
ans = []
while mae >= 0:
    ans.append(ato - mae)
    ato = mae
    mae = pre[ato]
print(*ans, sep=" ")


Fixed submission:
n, m = map(int, input().split())
s = input()
out_s='1'*(m)
if out_s in s:
    print(-1)
    exit()
s = s[::-1]
if s[0] == "1":
    print(-1)
    exit()
pre = [-1] * (n + 1)
stack = [0]
while stack:
    now = stack.pop()
    if now == n:
        break
    for i in range(1, m + 1):
        tsugi = now + i
        if tsugi > n:
            continue
        if s[tsugi] == "1":
            continue
        pre[tsugi] = now
        stack.append(tsugi)
else:
    print(-1)
    exit()
ato = n
mae = pre[n]
ans = []
while mae >= 0:
    ans.append(ato - mae)
    ato = mae
    mae = pre[ato]
print(*ans, sep=" ")
Buggy python submission (verdict: Time Limit Exceeded):
X, Y=list(map(int,(input().split())))
m=10**9+7
N=(X+Y)//3
bikkuri=[1 for i in range(N+2)]
gyaku=[1 for i in range(N+2)]
for i in range(1, N+1):
    bikkuri[i+1] =((i+1)*bikkuri[i])%m
    gyaku[i+1] = pow(bikkuri[i+1], m-2, m)
def comb(n, r):
    return (bikkuri[n]*gyaku[r]*gyaku[n-r])%m
if (X+Y)%3==1 or (X+Y)%3==2:
    print(0)
else:
    if X<N or Y<N:
        print(0)
    else:
        print(comb((X-N)+(Y-N), Y-N))

Fixed submission:
X, Y=list(map(int,(input().split())))
m=10**9+7
N=(X+Y)//3
bikkuri=[1 for i in range(N+2)]
gyaku=[1 for i in range(N+2)]
for i in range(1, N+1):
    bikkuri[i+1] =((i+1)*bikkuri[i])%m
    gyaku[i+1] = pow(bikkuri[i+1], m-2, m)
def comb(n, r):
    return (bikkuri[n]*gyaku[r]*gyaku[n-r])%m
if (X+Y)%3==1 or (X+Y)%3==2:
    print(0)
else:
    if X<N or Y<N:
        print(0)
    else:
        print(comb((X-N)+(Y-N), Y-N))
Buggy python submission (verdict: Time Limit Exceeded):
import math
N=int(input())
c=[]
for i in range(math.ceil((4*N)**(1/2)-2), N):
    for k in range(1, i+1):
        if (1+k)*(i+1-k)==N:
            c.append(i)
print(min(c))

Fixed submission:
import math
N=int(input())
c=[]
flag=0
for x in range(1, math.ceil(pow(N,1/2))+1):
    if N%x==0:
        c.append(x+N//x-2)
print(min(c))
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort(reverse=True)
F.sort()
ng=-1
ok=10**12
while ok-ng>1:
    mid=(ok+ng)//2
    temp=0
    flag=0
    for i in range(n):
        a=mid//F[i]
        if a>A[i]:
            continue
        else:
            temp+=A[i]-a
    if temp>k:
        flag=1
    if flag:
        ng=mid
    else:
        ok=mid

print(ok)

Fixed submission:
n,k=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort(reverse=True)
F.sort()
ng=-1
ok=10**12
while ok-ng>1:
    mid=(ok+ng)//2
    temp=0
    flag=0
    for i in range(n):
        a=mid//F[i]
        if a>A[i]:
            continue
        else:
            temp+=A[i]-a
    if temp>k:
        flag=1
    if flag:
        ng=mid
    else:
        ok=mid

print(ok)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort(reverse=True)
F.sort()
ng=-1
ok=10**12
while ok-ng>1:
    mid=(ok+ng)//2
    temp=0
    flag=0
    for i in range(n):
        a=mid//F[i]
        if a>A[i]:
            continue
        else:
            temp+=A[i]-a
    if temp>k:
        flag=1
    if flag:
        ng
    else:
        right=center
temp=0
for i in range(n):
    a=center//F[i]
    if a>A[i]:
        continue
    else:
        temp+=A[i]-a
if temp<=k:
    ans=left
else:
    ans=right
print(ans)

Fixed submission:
n,k=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort(reverse=True)
F.sort()
ng=-1
ok=10**12
while ok-ng>1:
    mid=(ok+ng)//2
    temp=0
    flag=0
    for i in range(n):
        a=mid//F[i]
        if a>A[i]:
            continue
        else:
            temp+=A[i]-a
    if temp>k:
        flag=1
    if flag:
        ng=mid
    else:
        ok=mid

print(ok)
Buggy python submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))
for i in range(n):
  for j in range(i+1,n):
    ans.append(A[i]*A[j])
print(sum(ans))

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
ans=[]
for i in range(n):
    for j in range(i+1,n):
        ans.append(A[i]*A[j])
print(sum(ans))
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
A=list(map(int,input().split()))
c=0
for i in range(len(A)):
  if A[i]>=K:
    c+=1
print(c)

Fixed submission:
n,k=map(int,input().split())
A=list(map(int,input().split()))
c=0
for i in range(len(A)):
    if A[i]>=k:
        c+=1
print(c)
Buggy python submission (verdict: Runtime Error):
n=int(input())
B=map(list(int,input().split()))
c=A[0]+A[-1]
if n>=3:
	for i in range(n-2):
      c+=min(B[i],B[i+1])
print(c)

Fixed submission:
n=int(input())
B=list(map(int,input().split()))
c=B[0]+B[-1]
if n>=3:
    for i in range(n-2):
        c+=min(B[i],B[i+1])
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
SET = set()
dict = {}
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = str(s)
    if s in SET:
        if s in dict:
            dict[s] += 1
        else:
            dict[s] = 1
    SET.add(s)

for i in dict.values():
    ans += i * (i + 1) // 2
print(ans)


Fixed submission:
import sys

input = sys.stdin.readline

n = int(input())
SET = set()
dict = {}
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = str(s)
    if s in SET:
        if s in dict:
            dict[s] += 1
        else:
            dict[s] = 1
    SET.add(s)

for i in dict.values():
    ans += i * (i + 1) // 2
print(ans)

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

n = int(input())
L = []
dict = {}
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = str(s)
    if s in L:
        if s in dict:
            dict[s] += 1
        else:
            dict[s] = 1
    L.append(s)
for i in dict.values():
    ans += (math.factorial(i + 1) // (math.factorial(2))) // (math.factorial(i - 1))
print(ans)


Fixed submission:
import sys

input = sys.stdin.readline

n = int(input())
SET = set()
dict = {}
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = str(s)
    if s in SET:
        if s in dict:
            dict[s] += 1
        else:
            dict[s] = 1
    SET.add(s)

for i in dict.values():
    ans += i * (i + 1) // 2
print(ans)

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

n = int(input())
L = []
dict = {}
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = str(s)
    if s in L:
        if s in dict:
            dict[s] += 1
        else:
            dict[s] = 1
    L.append(s)
for i in dict.values():
    ans += (math.factorial(i + 1) // (math.factorial(2))) // (math.factorial(i - 1))
print(ans)


Fixed submission:
import sys

input = sys.stdin.readline

n = int(input())
SET = set()
dict = {}
ans = 0
for i in range(n):
    s = list(input())
    s.sort()
    s = str(s)
    if s in SET:
        if s in dict:
            dict[s] += 1
        else:
            dict[s] = 1
    SET.add(s)

for i in dict.values():
    ans += i * (i + 1) // 2
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
remain=A[0]
ans1=0
for i in range(n):
    if B[i]<=remain:
        ans1+=B[i]
        remain=A[i+1]
    if B[i]>remain:
        ans1+=remain
        yoryoku=B[i]-remain
        if yoryoku>A[i+1]:
            ans1+=A[i+1]
            remain=0
        else:
            ans1+=yoryoku
            remain=A[i+1]-yoryoku
rA=reversed(A)
rB=reversed(B)
remain=rA[0]
ans2=0
for i in range(n):
    if rB[i]<=remain:
        ans2+=rB[i]
        remain=rA[i+1]
    if rB[i]>remain:
        ans2+=remain
        yoryoku=rB[i]-remain
        if yoryoku>rA[i+1]:
            ans2+=rA[i+1]
            remain=0
        else:
            ans2+=yoryoku
            remain=rA[i+1]-yoryoku
print(max(ans1,ans2))

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
remain=A[0]
ans1=0
for i in range(n):
    if B[i]<remain:
        ans1+=B[i]
        remain=A[i+1]
    else:
        ans1+=remain
        yoryoku=B[i]-remain
        if yoryoku>A[i+1]:
            ans1+=A[i+1]
            remain=0
        else:
            ans1+=yoryoku
            remain=A[i+1]-yoryoku
print(ans1)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

LIS = [1]
n, *A = map(int, read().split())

for a in A:
    a *= -1
    if LIS[-1] <= a:
        LIS.append(a)
    else:
        LIS[bisect_right(LIS, a)] = a
print(len(LIS))


Fixed submission:
from bisect import bisect_left, bisect_right
from collections import deque
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
infi = 10 ** 20

# 長さがi+1のときの最長部分増加列の末尾の最小値。
n, *A = map(int, read().split())
LIS = deque([10 ** 10])
for a in A:
    a *= -1
    pos1 = bisect_left(LIS, a)
    pos2 = bisect_right(LIS, a)
    if LIS[-1] <= a:
        LIS.append(a)
    else:
        if LIS[pos1] == a:
            LIS[pos2] = a
        else:
            LIS[pos1] = a

print(len(LIS))
Buggy python submission (verdict: Runtime Error):
import math
a,b,c,d=map(int,input().split())
def gcd(a,b):
    if b>a:
        b,a=a,b
    if b==0:
        return a
    else:
        return gcd(b,a%b)


def warikiri(n,c,d):
    koubai=(c*d)//gcd(c,d)
    return n-n//d-n//c+n//koubai)
print(warikiri(b,c,d)-warikiri(a-1,c,d))

Fixed submission:
import math
a,b,c,d=map(int,input().split())
def gcd(a,b):
    if b>a:
        b,a=a,b
    if b==0:
        return a
    else:
        return gcd(b,a%b)
def warikiri(n,c,d):
    koubai=(c*d)//gcd(c,d)
    return n-n//d-n//c+n//koubai
print(warikiri(b,c,d)-warikiri(a-1,c,d))
Buggy python submission (verdict: Runtime Error):
from itertools import combinations

n, k = map(int, input().split())
star = []
max_k = (n - 1) * (n - 2) // 2
delta = max_k - k
cnt = 0
if k <= max_k:
    ans = []
    for i in range(2, n + 1):
        star.append((1, i))
        cnt += 1

    if delta > 0:
        kumiawase = list(combinations(range(2, n), 2))
        for j in range(delta):
            kumi = kumiawase[j]
            star.append(kumi)
            cnt += 1
    print(cnt)
    for pair in star:
        print(*pair, sep=" ")
else:
    print(-1)


Fixed submission:
from itertools import combinations

n, k = map(int, input().split())
star = []
max_k = (n - 1) * (n - 2) // 2
delta = max_k - k
cnt = 0
if k <= max_k:
    ans = []
    for i in range(2, n + 1):
        star.append((1, i))
        cnt += 1

    if delta > 0:
        kumiawase = list(combinations(range(2, n+1), 2))
        for j in range(delta):
            kumi = kumiawase[j]
            star.append(kumi)
            cnt += 1
    print(cnt)
    for pair in star:
        print(*pair, sep=" ")
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
w,h,x,y=map(int,input().split())
square = w*h/2
if 2x==w and 2y==h:
  flag=1
else:
  flag=0
print(square,flag)


Fixed submission:
w,h,x,y=map(int,input().split())
square = w*h/2
if 2*x==w and 2*y==h:
  flag=1
else:
  flag=0
print(square,flag)
Buggy python submission (verdict: Runtime Error):
p, q, r = map(int, input().split())
print(sum(p, q, r) - max(p, q, r))



Fixed submission:
a,b,c=map(int,input().split())
A=[a,b,c]
print(sum(A)-max(A))

Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
A=list(a,b,c)
print(sum(A)-max(A))

Fixed submission:
a,b,c=map(int,input().split())
A=[a,b,c]
print(sum(A)-max(A))
Buggy python submission (verdict: Runtime Error):
a,p=list(map(int, input().split()))
print((3a+p)//2)

Fixed submission:
a,p=map(int, input().split())
print((3*a+p)//2)

Buggy python submission (verdict: Runtime Error):
a,p=map(int, input().split())
print((3a+p)//2)

Fixed submission:
a,p=map(int, input().split())
print((3*a+p)//2)

Buggy python submission (verdict: Runtime Error):
a,p=map(int,input().split())
print((3a+p)//2)

Fixed submission:
a,p=map(int, input().split())
print((3*a+p)//2)

Buggy python submission (verdict: Runtime Error):
a,p=map(int,input().split())
pritn((3a+p)//2)

Fixed submission:
a,p=map(int, input().split())
print((3*a+p)//2)
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

n, q = map(int, input().split())
STX = [list(map(int, input().split())) for _ in range(n)]
task = []
for s, t, x in STX:
    task.append((t - x, 0, x))
    task.append((s - x, 1, x))
for i in range(q):
    d = int(input())
    task.append((d, 2, i))

task.sort()
kouho = set()
kouho_hp = []
ans = [-1] * q
for a, b, c in task:
    if b == 0:
        kouho.remove(c)
    if b == 1:
        kouho.add(c)
        heappush(kouho_hp, c)
    if b == 2:
        while kouho_hp and kouho_hp[0] not in kouho:
            heappop(kouho_hp)
        if not kouho_hp:
            continue
        else:
            ans[c] = kouho_hp[0]
        # heapは0-indexが最小値になっているからheapified_list[0]でもよい
print(*ans, sep="\n")


Fixed submission:
from heapq import heappush, heappop
import sys

input = sys.stdin.buffer.readline


n, q = map(int, input().split())
STX = [list(map(int, input().split())) for _ in range(n)]
task = []
for s, t, x in STX:
    task.append((t - x, 0, x))
    task.append((s - x, 1, x))
for i in range(q):
    d = int(input())
    task.append((d, 2, i))

task.sort()
kouho = set()
kouho_hp = []
ans = [-1] * q
for a, b, c in task:
    if b == 0:
        kouho.remove(c)
    if b == 1:
        kouho.add(c)
        heappush(kouho_hp, c)
    if b == 2:
        while kouho_hp and kouho_hp[0] not in kouho:
            heappop(kouho_hp)
        if not kouho_hp:
            continue
        else:
            ans[c] = kouho_hp[0]
        # heapは0-indexが最小値になっているからheapified_list[0]でもよい
print(*ans, sep="\n")
Buggy python submission (verdict: Runtime Error):
# union-findで行けそう。

n, m = map(int, input().split())
par = [-1] * (n + 1)


def find(a):
    if par[a] < 0:
        return a
    else:
        par[a] = find(par[a])
        return par[a]


def unite(a, b):
    a = find(a)
    b = find(b)
    if a == b:
        return False
    else:
        if par[a] < par[b]:
            a, b = b, a
        par[x] += par[y]
        par[y] = x
        return True


for i in range(m):
    x, y, z = map(int, input().split())
    unite(x, y)
cnt = 0
for i in range(n):
    if par[i + 1] < 0:
        cnt += 1
print(cnt)


Fixed submission:
# union-findで行けそう。

n, m = map(int, input().split())
par = [-1] * (n + 1)


def find(a):
    if par[a] < 0:
        return a
    else:
        par[a] = find(par[a])
        return par[a]


def unite(a, b):
    a = find(a)
    b = find(b)
    if a == b:
        return False
    else:
        if par[a] < par[b]:
            a, b = b, a
        par[a] += par[b]
        par[b] = a
        return True


for i in range(m):
    x, y, z = map(int, input().split())
    unite(x, y)
cnt = 0
for i in range(n):
    if par[i + 1] < 0:
        cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
a=int(input())
p=a%10
b=int(input())
q=b%10
c=int(input())
r=c%10
d=int(input())
s=d%10
e=int(input())
t=e%10
l=[a,b,c,d,e]
m=[p,q,r,s,t]
ans=0
minimum=min(list(set(m)-set([0])))
def func(n):
    if n%10==0:
        return n
    else:
        return (n//10)*10+10
for i in range(5):
    ans+=func(l[i])
ans=ans-10+minimum
print(ans)

Fixed submission:
a=int(input())
p=a%10
b=int(input())
q=b%10
c=int(input())
r=c%10
d=int(input())
s=d%10
e=int(input())
t=e%10
l=[a,b,c,d,e]
m=[p,q,r,s,t]
ans=0
if set(m)==set([0]):
    minimum=10
else:
    minimum=min(list(set(m)-set([0])))
def func(n):
    if n%10==0:
        return n
    else:
        return (n//10)*10+10
for i in range(5):
    ans+=func(l[i])
ans=ans-10+minimum
print(ans)

Buggy python submission (verdict: Runtime Error):
A=int(input())
a=A%10
B=int(input())
b=B%10
C=int(input())
c=C%10
D=int(input())
d=D%10
E=int(input())
e=E%10
if a=b=c=d=e=0:
  print(A-a+B-b+C-c+D-d+E-e+4*10-10*[a,b,c,d,e].count(0))
else:
  print(A-a+B-b+C-c+D-d+E-e+4*10+min(set([a,b,c,d,e])-set([0]))-10*[a,b,c,d,e].count(0))

Fixed submission:
a=int(input())
p=a%10
b=int(input())
q=b%10
c=int(input())
r=c%10
d=int(input())
s=d%10
e=int(input())
t=e%10
l=[a,b,c,d,e]
m=[p,q,r,s,t]
ans=0
if set(m)==set([0]):
    minimum=10
else:
    minimum=min(list(set(m)-set([0])))
def func(n):
    if n%10==0:
        return n
    else:
        return (n//10)*10+10
for i in range(5):
    ans+=func(l[i])
ans=ans-10+minimum
print(ans)

Buggy python submission (verdict: Runtime Error):
A=int(input())
a=A%10
B=int(input())
b=B%10
C=int(input())
c=C%10
D=int(input())
d=D%10
E=int(input())
e=E%10
print(A-a+B-b+C-c+D-d+E-e+4*10+min(set([a,b,c,d,e])-set([0]))-10*[a,b,c,d,e].count(0))

Fixed submission:
a=int(input())
p=a%10
b=int(input())
q=b%10
c=int(input())
r=c%10
d=int(input())
s=d%10
e=int(input())
t=e%10
l=[a,b,c,d,e]
m=[p,q,r,s,t]
ans=0
if set(m)==set([0]):
    minimum=10
else:
    minimum=min(list(set(m)-set([0])))
def func(n):
    if n%10==0:
        return n
    else:
        return (n//10)*10+10
for i in range(5):
    ans+=func(l[i])
ans=ans-10+minimum
print(ans)