Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02853 (python)

Fixed submission:
x, y = (max(4 - int(i), 0) for i in input().split())
print((x + y + 4*(x==y==3)) * 10**5)

Buggy submission (verdict: Runtime Error):
x, y = (max(4 - int(i), 0) or i in input().split())
print((x + y + 4*(x==y==3)) * 10**5)

Buggy submission (verdict: Runtime Error):
x, y = (max(4 - int(i), 0) or i in input().split())
print((x + y + 4*(x==y==3)) * 10**5)
Problem p02888 (python)

Fixed submission:
from bisect import*
n, *l = map(int, open(0).read().split())
l.sort();c=0
for i in range(n):
  for j in range(i+1, n):
    d = bisect_left(l, l[i] + l[j])
    c += max(0, d-j-1)
print(c)

Buggy submission (verdict: Runtime Error):
from bisect import*
l = sorted(map(int, open(0).read().split()[1:]))
print(sum(max(0, bisect_left(l, l[i] + l[j]) - j - 1) for i in range(n) for j in range(i+1, n)))
Problem p02903 (python)

Fixed submission:
import numpy as np
*s, a, b = map(int, input().split())
p = np.ones(s, dtype=np.int)
p[:b,:a] = 0
p[b:,a:] = 0
print('\n'.join(''.join(q) for q in p.astype(str)))

Buggy submission (verdict: Runtime Error):
import numpy as np
*s, a, b = map(int, input().split())
p = np.ones(s, dtype=np.int)
p[:b,:a] = 0
p[b:,a:] = 0
print('\n'.join(''.join(q) for q in m.astype(str)))
Problem p02913 (python)

Fixed submission:
def Z(S):
    n = len(S)
    LCP = [0]*n
    i = 1
    j = c = 0
    # c : 最も末尾側までLCPを求めたインデックス
    for i in range(1, n):
        # i番目からのLCPが以前計算したcからのLCPに含まれている場合
        if i+LCP[i-c] < c+LCP[c]:
            LCP[i] = LCP[i-c]
        else:
            j = max(0, c+LCP[c]-i)
            while i+j < n and S[j] == S[i+j]: j+=1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP

a = 0
n, s = open(0)
for i in range(int(n)):
    for j, l in enumerate(Z(s[i:])):
        a = max(a, min(l, j))
print(a)

Buggy submission (verdict: Runtime Error):
n,s=open(0)
a=0
for i in range(int(n)):
 if N-i<a:break
 a+=s[i+1:].find(s[i-a:i+1])>=0
print(a)
Problem p02917 (python)

Fixed submission:
n, *b = map(int, open(0).read().split())
a = [0]*n
b.append(float("inf"))
for i in range(n):
  a[i] = min(b[i-1], b[i])
print(sum(a))

Buggy submission (verdict: Runtime Error):
n, *b = map(int, open(0).read().split())
a = [0]*n
b += float("inf")
for i in range(n):
  a[i] = min(b[i-1], b[i])
print(sum(a))
Problem p02934 (python)

Fixed submission:
_ = input()
print("{:.16g}".format(1 / sum(1 / x for x in map(int, input().split()))))

Buggy submission (verdict: Runtime Error):
_ = input()
print(f"{(1 / sum(1 / x for x in map(int, input().split()))):.16g}")
Problem p02939 (python)

Fixed submission:
c = 0
s = f = ""
for i in input():
  s += i
  if s != f:
    c += 1
    s, f = "", s
print(c)

Buggy submission (verdict: Runtime Error):
k = 0
s = t = ""
for i in input():
	s += i
    if s != t:
		k += 1
		s, t = "", s
print(k)
Problem p02947 (python)

Fixed submission:
d = {}
c = 0
for i in open(0):
    i = str(sorted(i))
    t = d.get(i, 0)
    c += t
    d[i] = t + 1
print(c)

Buggy submission (verdict: Runtime Error):
from itertools import combinations as c
n, *d = map(sorted, open(0).read().split())
print(sum(d[i[0]] == d[i[1]] for i in c(range(int(*n)), 2)))
Problem p02958 (python)

Fixed submission:
n, *p = map(int, open(0).read().split())
t = 0
for i in range(n):
    t += p[i] != sorted(p)[i]
print("YES" if t == 0 or t == 2 else "NO")

Buggy submission (verdict: Runtime Error):
n, *p = map(int, open(0).read().split())
t = 0
for i in range(n):
    t += 1 if p[i] != sorted(p)[i] 
print("YES" if t == 0 or t == 2 else "NO")
Problem p02971 (python)

Fixed submission:
_, *a = map(int, open(0).read().split())
s = sorted(a)
for i in a:
    print(s[(i < s[-1])-2])

Buggy submission (verdict: Runtime Error):
_, *a = map(int, open(0).read().split())
s = sorted(a)
for i in a:
    print(s[(i < b[-1])-2])
Problem p02975 (python)

Fixed submission:
_, *a = map(int, open(0).read().split());z = 0
for b in a:z ^= b
print("YNeos"[z>0::2])

Buggy submission (verdict: Runtime Error):
_, *a = map(int, open(0).read().split())
for b in a:z ^= b
print("YNeos"[z>0])
Problem p02983 (python)

Fixed submission:
l, r = map(int,input().split())
s = range(l, r+1)[:673]
print(min(i*j % 2019 for i in s for j in s if i<j))

Buggy submission (verdict: Runtime Error):
x, y = map(int,input().split())
print([x, -1][x%y])
Problem p02988 (python)

Fixed submission:
n, *p = map(int, open(0).read().split())
c = 0
for i in range(2, n):
    t = p[i-2:i+1]
    c += sorted(t)[1] == t[1]
print(c)

Buggy submission (verdict: Runtime Error):
n, *p = map(int, open(0).read().split())
for i in range(2, n):
    t = p[i-2:i+1]
    c += sorted(t)[1] == t[1]
print(c)
Problem p03037 (python)

Fixed submission:
_, __, *d = map(int, open(0).read().split())
print(max(min(d[1::2]) - max(d[::2]) + 1, 0))

Buggy submission (verdict: Runtime Error):
_, __, *d = map(int, open(0).read().split())
print(max(min(d[1::2]) - max(d[::2]) + 1), 0)
Problem p03060 (python)

Fixed submission:
n, *d = map(int, open(0).read().split())
print(sum([max(d[i] - d[i+n], 0) for i in range(n)]))

Buggy submission (verdict: Runtime Error):
n = int(input())
v = [map(int, input().split())]
c = [map(int, input().split())]
print(sum([max(v[i] - c[i], 0) for i in range(n)]))
Problem p03061 (python)

Fixed submission:
#!/usr/bin/env python3
from itertools import*
from fractions import*
ac = lambda l: list(accumulate([0] + l, gcd))
n, *a = map(int, open(0).read().split())
print(max(gcd(s, t) for s, t in zip(ac(a), ac(a[::-1])[::-1][1:])))

Buggy submission (verdict: Runtime Error):
from itertools as f;from fractions import*;c=lambda l:list(f.accumulate([0]+l,gcd));_,a=open(0);*a,=map(int,a.split());print(max(gcd(s,t)for s,t in zip(c(a),c(a[::-1])[-2::-1])))
Problem p03062 (python)

Fixed submission:
_, *a = map(int, open(0).read().split())
*z, = map(abs, a)
s = sum(z)
print(s if len([i for i in a if i<0])%2==0 or 0 in a else s-min(z)*2)

Buggy submission (verdict: Runtime Error):
_, *a = map(int, open(0).read().split())
t = map(abs, a)
s = sum(t)
print(s if len([i for i in a if i<0])%2==0 or 0 in a else s-min(t))
Problem p03076 (python)

Fixed submission:
*t, = map(int, open(0).read().split())
try:
    m = 10 - min([i%10 for i in t if i%10])
except ValueError:
    m = 0
print(sum([-(-j // 10) for j in t])*10 - m)

Buggy submission (verdict: Runtime Error):
*t, = map(int, open(0).read().split())
try:
    m = 10 - min([i%10 for i in t if i%10])
except Value Error:
    m = 0
print(sum([-(-j // 10) for j in t])*10 - m)

Buggy submission (verdict: Runtime Error):
*t, = map(int, open(0).read().split())
m = min([i%10 for i in t if i%10])
print(sum([-(-j // 10) for j in t])*10-10+m)
Problem p03087 (python)

Fixed submission:
#!/usr/bin/env python3
n, q = map(int, input().split())
s = input()
t = [0] * -~n
for i in range(n):
    t[i + 1] = t[i] + (1 if s[i:i+2] == "AC" else 0)
for _ in range(q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
s = input()
t = [0] * n
for i in range(n):
    t[i + 1] = t[i] + (1 if s[i:i+2] == "AC" else 0)
for _ in range(q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
Problem p03110 (python)

Fixed submission:
print(sum(eval(input().replace(" JPY", "").replace(" BTC","*380000")) for _ in range(int(input()))))

Buggy submission (verdict: Runtime Error):
print(eval("".join(open(0).readlines()[1:]).replace(" JPY", "").replace(" BTC","*380000").replace("\n", "+")))

Buggy submission (verdict: Runtime Error):
print(eval("".join(open(0).readlines()[1:]).replace(" JPY", "").replace(" BTC","*380000").replace("\n", "+")))
Problem p03130 (python)

Fixed submission:
from collections import*
print("YNEOS"[Counter(open(0).read().split()).most_common()[0][1]==3::2])

Buggy submission (verdict: Runtime Error):
from collections import*
print("YNEOS"[Counter(open(0).read().split()).most_comon()[0][1]!=3::2])
Problem p03161 (python)

Fixed submission:
n, k, *h = map(int, open(0).read().split())
h += [0] * 200
dp = [0] + [float("inf")] * 100200
for i in range(1, n):
  dp[i] = min(dp[i-a] + abs(h[i] - h[i-a]) for a in range(1, k + 1))
print(dp[n - 1])

Buggy submission (verdict: Runtime Error):
n, k, *h = map(int, open(0).read().split())
dp = [0] + [float("inf")] * 100200
for i in range(1, n):
  dp[i] = min(dp[i-a] + abs(h[i] - h[i-a]) for a in range(1, k + 1))
print(dp[n - 1])
Problem p03165 (python)

Fixed submission:
s, t = input(), input()
n, m = len(s), len(t)
dp = [[0]*-~m for _ in [0]*-~n]
for i in range(n):
  for j in range(m):
    dp[i+1][j+1] = dp[i][j] + 1 if s[i] == t[j] else max(dp[i][j+1], dp[i+1][j])
R = ""
while n and m:
  if   dp[n][m] == dp[n-1][m]:n -= 1
  elif dp[n][m] == dp[n][m-1]:m -= 1
  else:n -= 1;m -= 1;R = s[n] + R
print(R)

Buggy submission (verdict: Runtime Error):
s, t = input(), input()
n, m = len(s), len(t)
dp = [[0]*-~m for _ in [0]*-~n]
for i in range(n):
  for j in range(m):
    dp[i+1][j+1] = dp[i][j] + 1 if s[i] == t[j] else max(dp[i][j+1], dp[i+1][j])
R = ""
while n and m:
  n -= dp[n][m] != dp[n][m-1]
  m -= dp[n][m] != dp[n-1][m]
  R = s[n] + R
print(R)
Problem p03197 (python)

Fixed submission:
_, *a = open(0)
print(["second","first"][any(int(b)%2 for b in a)])

Buggy submission (verdict: Runtime Error):
_, *a = open(0)
print(["second","first"][any(int(b)%2 for b in a)]
Problem p03200 (python)

Fixed submission:
c = b = 0
for s in input():
  c += b*(s=="W")
  b += s=="B"
print(c)

Buggy submission (verdict: Runtime Error):
s = input()
print(sum(s[:i].count("B") for i in range(len(s)) if s[i]=="W")
Problem p03219 (python)

Fixed submission:
print(eval(input().replace(" ", "+") + "//2"))

Buggy submission (verdict: Runtime Error):
print(eval(input().replace(" ", +) + "//2"))
Problem p03229 (python)

Fixed submission:
#!/usr/bin/env python3
N, *a = map(int, open(0))
n = N//2 - 1
a.sort()
print(2*sum(a[n+2:]) - 2*sum(a[:n]) + a[n+1] - a[n] - (min(a[n]+a[n+2], 2*a[n+1]) if N%2 else 0))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
N = int(input())
a = sorted(int(input()) for _ in [0]*N)
n = N//2 - 1
print(2*sum(a[n+2:]) - 2*sum(a[:n]) + a[n+1] - a[n] - [0, min(a[n]+a[n+2], 2*a[n+1])][N%2])

Buggy submission (verdict: Runtime Error):
N,*a=map(int,open(0));n=N//2-1;a.sort();print(2*sum(a[n+2:])-2*sum(a[:n])+a[n+1]-a[n]-[0,min(a[n]+a[n+2],2*a[n+1])][N%2])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
N, *a = map(int, open(0))
n = N//2 - 1
a.sort()
print(2*sum(a[n+2:]) - 2*sum(a[:n]) + a[n+1] - a[n] - [0, min(a[n]+a[n+2], 2*a[n+1])][N%2])

Buggy submission (verdict: Runtime Error):
n,*a=map(int,open(0));n=n//2-1;a.sort();print(2*sum(a[n+2:])-2*sum(a[:n])+a[n+1]-a[n]-[0,min(a[n]+a[n+2],2*a[n+1])][n%2])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
n, *a = map(int, open(0))
n = n//2 - 1;a.sort()
print(2*sum(a[n+2:]) - 2*sum(a[:n]) + a[n+1] - a[n] - [0, min(a[n]+a[n+2], 2*a[n+1])][n%2])
Problem p03240 (python)

Fixed submission:
#!/usr/bin/env python3
a = abs
z = [list(map(int, input().split())) for _ in range(int(input()))]
z.sort(key = lambda x: x[2])
x, y, h = z[-1]
r = range(101)
for c in r:
    for d in r:
        H = h + a(c-x) + a(d-y)
        if all(u == max(H - a(s-c) - a(t-d), 0) for s, t, u in z):
            print(c, d, H)
            exit()

Buggy submission (verdict: Runtime Error):
A=abs
h,y,x=max([list(map(int,t.split()[::-1]))for t in open(0)][1:])
r=range(101)
for i in r:
 for j in r:H=h+A(x-j)+A(y-i);print(*(j,i,H)*all(u==max(H-A(s-j)-A(t-i),0)for u,t,s in p))
Problem p03244 (python)

Fixed submission:
from collections import*
n, *v = map(int, open(0).read().split())
a, b = [Counter(v[i::2]).most_common() + [(0,0)] for i in (0,1)]
s, x = a[0]
t, y = b[0]
print(n - [x+y, max(x+b[1][1], y+a[1][1])][s==t])

Buggy submission (verdict: Runtime Error):
from collections import*
n, v = map(int, open(0).read().split())
def l(x):
    o = Counter(x).most_common()
    return [o[0][0], o[0][1], o[1][1]]
a, b = map(l, [v[::2], v[1::2]])
print(n-a[1]-b[1] if a[0]!=a[0] else n - max(a[1]+b[2], a[2]+b[1])
Problem p03261 (python)

Fixed submission:
n, *l = open(0).read().split()
print("Yes" if len(set(l)) == len(l) and all(l[i][-1] == l[i+1][0] for i in range(int(n)-1)) else "No")

Buggy submission (verdict: Runtime Error):
n, *l = open(0).read().split()
print("Yes" if len(set(l)) == len(l) and all(l[i][-1] == l[i+1][0] for i in range(n)) else "No")
Problem p03282 (python)

Fixed submission:
a = input()[:int(input())]
j = set(sorted(set(a), key=a.index)[:2])
j.discard("1")
print(list(j)[0] if j else 1)

Buggy submission (verdict: Runtime Error):
s = input()
print(1 if s.startswith("1"*int(input())) else s.replace("1","")[0])
Problem p03284 (python)

Fixed submission:
print(1 if eval(input().replace(" ", "%")) else 0)

Buggy submission (verdict: Runtime Error):
print(1 if evac(input().replace(" ", "%")) else 0)
Problem p03296 (python)

Fixed submission:
from itertools import*
print(sum(len(list(j))//2 for _, j in groupby(open(0).read().split()[1:])))

Buggy submission (verdict: Runtime Error):
from itertools import*
print(sum(len(j)//2 for _, j in groupby(open(0).read().split()[1:])))
Problem p03341 (python)

Fixed submission:
from itertools import*
input();s = input()
b, c = [([0]+list(accumulate(map(int, s[::a].translate(str.maketrans("EW","01"[::a])))))[:-1])[::a] for a in [-1,1]]
print(min(x+y for x, y in zip(b, c)))

Buggy submission (verdict: Runtime Error):
from itertools import*
_, s = open(0)
b, c = [([0]+list(accumulate(map(int, s[::a].translate(str.maketrans("EW","01"[::a])))))[:-1])[::a] for a in [-1,1]]
print(min(x+y for x, y in zip(b, c)))

Buggy submission (verdict: Runtime Error):
from itertools import*
_, s = open(0)
print(min(b+c for b, c in zip(*[([0]+list(accumulate(map(int, s[::a].translate(str.maketrans("EW","01"[::a])))))[:-1])[::a] for a in [-1,1]])))

Buggy submission (verdict: Runtime Error):
from itertools import*
_, s = open(0)
print(min(b+c for b, c in zip(*[([0]+list(accumulate(map(int, s[::a].translate(str.maketrans("EW","01"[::a])))))[:-1])[::a] for a in [-1,1]])))
Problem p03353 (python)

Fixed submission:
from itertools import*
s = input()
k = int(input())
l = len(s)
print(sorted(set(s[i:j] for i, j in combinations(range(l+1), 2) if j - i <= k))[k-1])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
l = len(s)
print(sorted(set(s[i:j] for i, j in combinations(range(l+1), 2) if j - i <= k))[k-1])
Problem p03362 (python)

Fixed submission:
n = int(input())
P, A = [2], []
for L in range(3, 55556, 2):
  if len(A) == n:
    break
  if all(L % M for M in P):
    P += L,
    if L % 5 == 1:
      A += L,
print(*A)

Buggy submission (verdict: Runtime Error):
n=int(input())
P,*A=[2]
for L in range(3,9999):
 if len(A)==n:break
 if all(L%M for M in P):
  P+=L,
  if L%5>3:A+=L,
print(*A)
Problem p03369 (python)

Fixed submission:
print(700 + 100*input().count("o"))

Buggy submission (verdict: Runtime Error):
print(700 + 100*input().count(o))
Problem p03385 (python)

Fixed submission:
print("YNeos"[len(set(input()))!=3::2])

Buggy submission (verdict: Runtime Error):
a, b, c = sorted(map(int, input().split()))
print(c - b + (b-a)//2 + (b-a)%2*2)
Problem p03387 (python)

Fixed submission:
#!/usr/bin/env python3
a, b, c = sorted(map(int, input().split()))
d = b - a
print(c - b + d//2 + d%2*2)

Buggy submission (verdict: Runtime Error):
input()
print(sum(map(lambda x: bin(int(x))[::-1].find("1"), input().split())))
Problem p03399 (python)

Fixed submission:
*l, = map(int, open(0).read().split())
print(min(l[:2])+min(l[2:]))

Buggy submission (verdict: Runtime Error):
from numpy import*
_,a=open(0)
a=array([0]+list(map(int,a.split()))+[0])
A=abs
c=sum(a[1:]-a[:-1])
for i,j,k in zip(a,a[1:],a[2:]):print(c-A(j-i)-A(k-j)+A(k-i))
Problem p03401 (python)

Fixed submission:
import numpy as np
b = abs
n, *a = map(int, open(0).read().split())
a = np.array([0] + a + [0])
s = sum(map(b, a[1:] - a[:-1]))
for i in range(n):
    print(s + b(a[i+2] - a[i]) - b(a[i+1] - a[i]) - b(a[i+2] - a[i+1]))

Buggy submission (verdict: Runtime Error):
import numpy as np
b = abs
n, *a = map(int, open(0).read().split())
a = np.array([0] + a + [0])
s = sum(map(b, a[1:] - a[:-1]))
for i in range(n):
    print(s + b(a[i+2] - a[i]) - b(a[i+1] - a[i]) - b(a[i+2] - a[i+1])
Problem p03417 (python)

Fixed submission:
n, m = sorted(map(int, input().split()))
print(1 if n==m==1 else m-2 if n==1 else (n-2)*(m-2))

Buggy submission (verdict: Runtime Error):
n, m = sorted(map(int, input.split()))
print(1 if n==m==1 else m-2 if n==1 else (n-2)*(m-2))
Problem p03424 (python)

Fixed submission:
print("TFhoruere"[len(set(open(0).read().split()))-4::2])

Buggy submission (verdict: Runtime Error):
print("TFhoruere"[len(set(map(int, open(0).read().split())))-4::2])

Buggy submission (verdict: Runtime Error):
print("TFhoruere"[len(set(map(int, open(0).read().split())))-3::2])
Problem p03435 (python)

Fixed submission:
*l, = map(int, open(0).read().split())
print("YNeos"[4 != sum(sum(l[j]-l[0]+l[i] == l[i+j] for i in [1,2]) for j in [3,6])::2])

Buggy submission (verdict: Runtime Error):
l = map(int, open(0).read().split())
print("YNeos"[4 != sum(sum(l[j]-l[0]+l[i] == l[i+j] for i in [1,2]) for j in [3,6])::2])
Problem p03437 (python)

Fixed submission:
x, y = map(int,input().split())
print([x, -1][x%y==0])

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

def j(b):
    print(b)
    return b, input()[0]

def q(l, r, t):
    m, rm = j((l + r + 1) // 2)
    if (m - b)%2 == (rm != t):
        q(m, r, rm)
    else:
        q(l, m-1, t)

_, s = j(0)
q(0, n-1, s)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

n = int(input())

def j(b):
    print(b)
    i = input()[0]
    if i == "V": exit()
    return b, i

def q(l, r, t):
    m, rm = j((l + r + 1) // 2)
    if (m - b)%2 == (rm != t):
        q(m, r, rm)
    else:
        q(l, m-1, t)

_, s = j(0)
q(0, n-1, s)

Buggy submission (verdict: Runtime Error):
x, y = map(int,input().split())
print([x, -1][x%y])

Buggy submission (verdict: Runtime Error):
x, y = map(int,input().split())
print([-1, x][y%x])
Problem p03438 (python)

Fixed submission:
n, *p = map(int, open(0).read().split())
s = sum(j - i - max(0, i - j) - max(0, j - i)%2 for i, j in zip(p, p[n:]))
print("Yes" if s >= 0 == s%2 else "No")

Buggy submission (verdict: Runtime Error):
n, *p = map(int, open(0).read().split())
s = sum(j - i - max(0, i - j) - max(0, j - i)%2 for i, j in zip(p, p[n:]))
print("NO" if [s >= 0 == s%2 ::2] else "Yes")
Problem p03440 (python)

Fixed submission:
#!/usr/bin/env python3
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

(n, m), a, *q = [[*map(int,o.split())] for o in open(0)]
UF = UnionFind(n)
k = (n - m - 1) * 2
if k > n:
    exit(print("Impossible"))
if not k:
    exit(print(0))

for c, f in q:
    UF.union(c, f)

from collections import*
d = defaultdict(list)
for e, i in enumerate(a):
    d[UF.find(e)] += i,

ans, b = 0, []
for r, p in d.items():
    p.sort()
    ans += p.pop(0)
    b += p
    k -= 1
b.sort()
print(ans + sum(b[:k]))

Buggy submission (verdict: Runtime Error):
s=sorted
(n,m,*b),a,*q=[map(int,t.split())for t in open(0)]
t=[-1]*n
def r(x):
 while-1<t[x]:x=t[x]
 return x
def u(x):
 x,y=map(r,x)
 if x-y:
  if t[x]>t[y]:x,y=y,x
  t[x]+=t[y];t[y]=x
*map(u,q),
i=c=0
k=j=n+~m<<1
*d,=eval('[],'*n)
for v in a:d[r(i)]+=v,;i+=1
for p in d:
 if p:x,*y=s(p);c+=x;b+=y;j-=1
print(1%k*(c+sum(s(b)[:j]),'Impossible')[k>n])

Buggy submission (verdict: Runtime Error):
from collections import*
from heapq import*
(n,m),a,*q=[[*map(int,o.split())]for o in open(0)]
t=[-1]*n
def r(x):
 while t[x]>=0:x=t[x]
 return x
def u(x,y):
 x,y=r(x),r(y)
 if x!=y:
  if t[x]>t[y]:x,y=y,x
  t[x]+=t[y];t[y]=x
d=defaultdict(list)
for x,y in q:u(x,y)
i=c=0;b=[];k=(n+~m)*2;p=print
for v in a:d[r(i)]+=v,;i+=1
if k<1:p(0)
elif k>n:p('Impossible')
else:
 for r,p in d.items():p.sort();c+=p.pop(0);b+=p;k-=1
 p(c+sum(sorted(b)[:k]))
Problem p03469 (python)

Fixed submission:
print(input().replace("2017","2018"))

Buggy submission (verdict: Runtime Error):
s = input();s[3] = "8";print(s)
Problem p03472 (python)

Fixed submission:
#!/usr/bin/env python3
n, h, *d = map(int, open(0).read().split())
a = max(d[::2])
b = sorted(b for b in d[1::2] if b >= a)[::-1]
i = 0
for b in b:
    h -= b
    i += 1
    if h <= 0:
        print(i)
        exit()
print(i + 0--h // a)

Buggy submission (verdict: Runtime Error):
n,h,*d=map(int,open(0).read().split());a=max(d[::2]);b=sorted(d[1::2]);c=0
while(h>0)*(b[-1]>a)and b:h-=b.pop();c+=1
c-=(-h//a)*(h>0)
print(c)
Problem p03475 (python)

Fixed submission:
#!/usr/bin/env python3
(n,), *d = [list(map(int, c.split())) for c in open(0)]
n -= 1
for i in range(n):
    t = 0
    for j in range(i, n):
        c, s, f = d[j]
        t = (s if t < s else t if t % f == 0 else t + f - t%f) + c
    print(t)
print(0)

Buggy submission (verdict: Runtime Error):
(n,),*d=[list(map(int,c.split()))for c in open(0)]
for i in range(n-1):t=0;exec("for j in range(i,n-1):c,s,f=d[j];t=[t+(f-t%f)%f,s][t<s]+c")print(t)
print(0)
Problem p03476 (python)

Fixed submission:
#!/usr/bin/env python3
from itertools import accumulate
def erat(m):
    p = [1] * m
    p[0] = p[1] = 0
    for x in range(2, int((~-m)**.5) + 1):
        if p[x]:
            for y in range(x*x, m, x):
                p[y] = 0
    return p

INF = 10**5 + 1
p = erat(INF)
q = [0] * INF
for n in range(INF):
    q[n] = n%2 * p[n] * p[-~n//2]
*a, = accumulate([0] + q)
for _ in [None] * int(input()):
    l, r = map(int, input().split())
    print(a[r + 1] - a[l])

Buggy submission (verdict: Runtime Error):
def era(M):
    p = [1] * M
    p[0] = p[1] = 0
    for x in range(2, int(~-M**.5) + 1):
        if p[x]:
            for y in range(x*x, M, x):
                p[y] = 0
    return p
INF = 10**5 + 1
E = erat(INF)
Q = [0] * INF
from itertools import*
for i in range(INF):
    q[i] = i%2 * p[i] * p[-~i//2]
*a, = accumulate([0] + q)
for _ in [None] * int(input()):
    l, r = map(int, input().split())
    print(a[-~r] - a[l])
Problem p03477 (python)

Fixed submission:
a, b, c, d = map(int,input().split())
print(["RLiegfhtt"[a+b > c+d::2], "Balanced"][a+b == c+d])

Buggy submission (verdict: Runtime Error):
s=input().replace(" ","+")
l,r=eval(s[:3]),eval(s[4:])
print("RLiegfhtt"[l>r::2] if l!=r else "Balanced")
Problem p03481 (python)

Fixed submission:
x, y = map(int, input().split())
print(len(bin(y//x)[2:]))

Buggy submission (verdict: Runtime Error):
x, y = map(int, input().split())
print(len(str(bin(y//x))[2:]+1)
Problem p03485 (python)

Fixed submission:
print(-(-eval(input().replace(" ","+"))//2))

Buggy submission (verdict: Runtime Error):
s=sorted;i=input
print("NYoe s"[s(i())<s(i())[::-1]::2])