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

Fixed submission:
class UnionFindTree():
    def __init__(self, N):
        self.parent = [-1]*(N+1)
        self.rank = [1]*(N+1)
        self.size = [1]*(N+1)
        self.hubensa = N*(N-1)//2

    def find(self, i):
        if self.parent[i] == -1:
            group = i
        else:
            group = self.find(self.parent[i]) 
            self.parent[i] = group
        return group
      
    def unite(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px != py:
            if self.rank[px] == self.rank[py]: # rank is same
                self.rank[px] += 1
            elif self.rank[px] < self.rank[py]:
                px, py = py, px
                
            self.parent[py] = px
            self.hubensa -= self.size[px] * self.size[py]
            self.size[px] += self.size[py]

N, M = list(map(int, input().split()))
A = [0 for _ in range(M)]
B = [0 for _ in range(M)]

for i in range(M):
    A[i], B[i] = list(map(int, input().split()))

ans = []
UFT = UnionFindTree(N)

# 後ろから処理
for i in range(M-1, -1, -1):
    ans.append(UFT.hubensa)
    UFT.unite(A[i], B[i])

print(*ans[::-1], sep="\n")

Buggy submission (verdict: Runtime Error):
class UnionFindTree():
    def __init__(self, N):
        self.parent = [-1]*(N+1)
        self.size = [1]*(N+1)
        self.hubensa = N*(N-1)//2
  
    def find(self, i):
        if self.parent[i] == -1:
            group = i
        else:
            group = self.find(self.parent[i]) 
            self.parent[i] = group
        return group
      
    def unite(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px != py:
            if self.rank[px] == self.rank[py]: # rank is same
                self.rank[px] += 1
            elif self.rank[px] < self.rank[py]:
                px, py = py, px
                
            self.parent[py] = px
            self.hubensa -= self.size[px] * self.size[py]
            self.size[px] += self.size[py]

N, M = list(map(int, input().split()))
A = [0 for _ in range(M)]
B = [0 for _ in range(M)]

for i in range(M):
    A[i], B[i] = list(map(int, input().split()))

ans = []
UFT = UnionFindTree(N)

# 後ろから処理
for i in range(M-1, -1, -1):
    ans.append(UFT.hubensa)
    UFT.unite(A[i], B[i])

print(*ans[::-1], sep="\n")
Problem p03137 (python)

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

if N == 1:
    ans = max(X) - min(X)
    print(ans)
    exit()

if ((M == 1) or (N >= M)):
    ans = 0
    print(ans)
    exit()

Xs = sorted(X)

diff = []
for i in range(M - 1):
    tmp = Xs[i + 1] - Xs[i]
    diff.append(tmp)

diffs = sorted(diff)
print(sum(diffs[:(M - 1) - (N - 1)]))

Buggy submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))

if N == 1:
    ans = max(X) - min(X)
    print(ans)
    exit()

if M == 1:
    ans = 0
    print(ans)
    exit()

Xs = sorted(X)

diff = []
for i in range(M - 1):
    tmp = Xs[i + 1] - Xs[i]
    diff.append(tmp)

rest = N - 2
for _ in range(rest):
    if diff[0] > diff[len(diff) - 1]:
        diff.pop(0)
    else:
        diff.pop()

ans = 0

for _ in range(len(diff) - 1):
    if diff[0] > diff[len(diff) - 1]:
        ans += diff[len(diff) - 1]
        diff.pop()
    else:
        ans += diff[0]
        diff.pop(0)

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))

if M == 1:
    ans = max(X) - min(X)
    print(ans)
    exit()

Xs = sorted(X)

diff = []
for i in range(M - 1):
    tmp = Xs[i + 1] - Xs[i]
    diff.append(tmp)

rest = N - 2
for _ in range(rest):
    if diff[0] > diff[len(diff) - 1]:
        diff.pop(0)
    else:
        diff.pop()

ans = 0

for _ in range(len(diff) - 1):
    if diff[0] > diff[len(diff) - 1]:
        ans += diff[len(diff) - 1]
        diff.pop()
    else:
        ans += diff[0]
        diff.pop(0)

print(ans)
Problem p03208 (python)

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

h = []
for _ in range(N):
    h.append(int(input()))

h.sort()
minimum = h[N - 1]- h[0]

for i in range(N - K + 1):
    minimum = min(minimum, h[i + K - 1] - h[i])
print(minimum)

Buggy submission (verdict: Runtime Error):
import pandas as pd
N, K = list(map(int, input().split()))
 
h = []
for i in range(N):
    h.append(int(input()))

h_sort = sorted(h)
df = pd.DataFrame(h_sort)
df2 = df.diff()
df3 = df2.rolling(K - 1).sum()
df4 = df3.dropna(how='all')

print(int(min(df4[0])))

Buggy submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))

h = []
for i in range(N):
    h.append(int(input()))

h_sort = sorted(h)

h_sort_diff = []

for i in range(len(h_sort) - 1):
    tmp = h_sort[i + 1] - h_sort[i]
    h_sort_diff.append(tmp)

ans = []
for i in range(len(h_sort_diff) - 1):
    tmp = 0
    for j in range(K - 1):
        tmp += h_sort_diff[i + j]
    ans.append(tmp)

print(min(ans))
Problem p02773 (python)

Fixed submission:
N = int(input())
S = {}
for i in range(N):
    s = input()
    if s in S:
        S[s] += 1
    else:
        S[s] = 1
sorted_S = sorted(S.items(), key=lambda x: x[1], reverse=True)
a = []
count = -1
for s in sorted_S:
    if count == -1:
        a.append(s[0])
        count = s[1]
    elif count == s[1]:
        a.append(s[0])
    else:
        break
sorted_a = sorted(a)
for s in sorted_a:
    print(s)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = {}
for i in range(N):
    s = input()
    if s in S:
        S[s] += 1
    else:
        S[s] = 1
sorted_S = sorted(S.items(), key=lambda x: x[1], reverse=True)
a = []
count = -1
for s in sorted_S:
    if count == -1:
        a.append(s)
        count = sorted_S[s]
    elif count == sorted_S[s]:
        a.append(s)
    else:
        break
sorted_a = sorted(a)
for s in sorted_a:
    print(s)
Problem p02831 (python)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)
A, B = input().split()
print(lcm(int(A), int(B)))

Buggy submission (verdict: Runtime Error):
A, B = input().split
print(math.gcd(int(A), int(B)))

Buggy submission (verdict: Runtime Error):
A, B = input().split()
print(math.gcd(A,B))
Problem p02835 (python)

Fixed submission:
all = input()
all = all.split(' ')
all = [int(num) for num in all]
if sum(all) >= 22:
    print('bust')
else:
    print('win')

Buggy submission (verdict: Runtime Error):
all = input()
all = [int(num) for num in all]
if sum(all) >= 22:
    print('bust')
else:
    print('win')

Buggy submission (verdict: Runtime Error):
all = input()
all = all.split(' ')
all = [int(num) for num in all]
if sum(all) >= 22:
  return'bust'
else:
  return 'win'

Buggy submission (verdict: Runtime Error):
all = input()
if sum(all) >=22:
  return 'bust'
else:
  return 'win'
Problem p02836 (python)

Fixed submission:
S = input()
count = 0
for i in range(len(S)//2):
    if S[i] is not S[len(S)-1-i]:
        count += 1
print(count)

Buggy submission (verdict: Runtime Error):
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13 7 2\n"
     ]
    }
   ],
   "source": [
    "all = input()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "all = input()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['13', '7', '2']"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "all"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "all = [int(num) for num in all]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[13, 7, 2]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "all"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'list' object has no attribute 'sum'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-19-1727d8e1239d>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mall\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msum\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mAttributeError\u001b[0m: 'list' object has no attribute 'sum'"
     ]
    }
   ],
   "source": [
    "all.sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bust\n"
     ]
    }
   ],
   "source": [
    "if sum(all) >= 22:\n",
    "    print('bust')\n",
    "else:\n",
    "    print('win')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
Problem p02793 (python)

Fixed submission:
from fractions import gcd

def lcm_base(x, y):
  return x * y // gcd(x, y)

d = int(input())
nums = list(map(int, input().split(' ')))

lcm_num = 1
for n in nums:
  lcm_num = lcm_base(lcm_num, n)

ans = 0
mod = 10**9 + 7
for n in nums:
  ans += lcm_num//n
print(ans % mod)

Buggy submission (verdict: Runtime Error):
from fractions import gcd

d = int(input())
nums = list(map(int, input().split(' ')))

def lcm_base(x, y):
  return (x * y) // gcd(x, y)


lcm_num = 1
for i in range(len(nums)):
  lcm_num = lcm_base(lcm_num, nums[i])

ans = 0
for n in nums:
  ans += int(lcm_num / n)
print(ans % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
from fractions import gcd

d = int(input())
nums = list(map(int, input().split(' ')))

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

if d == 1:
  print(1)
else:
  lcm_num = nums[0]
  for i in range(len(nums)-1):
    lcm_num = lcm_base(lcm_num, nums[i+1])

  min_nums = []
  for n in nums:
    min_nums.append(int(lcm_num / n))
  ans = sum(min_nums)
  print(ans % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
from fractions import gcd

d = int(input())
nums = list(map(int, input().split(' ')))

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

if d == 1:
  print(1)
else:
  lcm_num = nums[0]
  for i in range(len(nums)-1):
    lcm_num = lcm_base(lcm_num, nums[i+1])

min_nums = []
for n in nums:
  min_nums.append(int(lcm_num / n))
ans = sum(min_nums)
print(ans % (10**9 + 7))
Problem p02989 (python)

Fixed submission:
n = int(input())
sorted_nums = sorted(list(map(int, input().split())))
center = len(sorted_nums) // 2
ans = sorted_nums[center] - sorted_nums[center-1]
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
sorted_nums = sorted(list(map(int, input().split())))
center = len(sorted_nums // 2)
ans = sorted_nums[center] - sorted_nums[center-1]
print(ans)
Problem p02785 (python)

Fixed submission:
N, K = map(int, input().split())
H = sorted([int(x) for x in input().split()])
#print(H)

if N<K:
	K=N

for i in range(K):
	H.pop((N-1)-i)

#print(H)

print(sum(H))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
H = sorted([int(x) for x in input().split()])
#print(H)

for i in range(K):
	H.pop((N-1)-i)

#print(H)

print(sum(H))
Problem p02915 (python)

Fixed submission:
n=int(input())
print(n**3)

Buggy submission (verdict: Runtime Error):
N=int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans=0
j=0

for i in range(N):
	ans+=B[A[i]-1]
	if A[i]-j==1 and i>=1:
		ans+=C[j-1]
	j=A[i]

print(ans)
Problem p02835 (python)

Fixed submission:
A = list(map(int,input().split()))
if sum(A) >= 22:
    print('bust')
else:
    print('win')

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
data_xy = []
for i in range(N):
    A = int(input())
    xy = []
    for i in range(A):
        [x,y] = list(map(int,input().split()))
        xy.append([x-1, y])
    data_xy.append(xy)
data_xy = np.array(data_xy,dtype=np.int64)
ans = 0
for i in range(2**N):
    p_list = [0]*N
    for j in range(N):
        if (i>>j) & 1 == 1:
            p_list[j] = 1
    flag = True
    for j in range(N):
        if p_list[j] == 1:
            for k in range(len(data_xy[j])):
                x = data_xy[j][k][0]
                y = data_xy[j][k][1]
                if p_list[x] != y:
                    flag = False
    if flag == True:
        ans = max(sum(p_list),ans)
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
data_xy = []
for i in range(N):
    A = int(input())
    xy = []
    for i in range(A):
        [x,y] = list(map(int,input().split()))
        xy.append([x-1, y])
    data_xy.append(xy)
ans = 0
for i in range(2**N):
    p_list = [0]*N
    for j in range(N):
        if (i>>j) & 1 == 1:
            p_list[j] = 1
    flag = True
    for j in range(N):
        if p_list[j] == 1:
            for k in range(len(data_xy[j])):
                x = data_xy[j][k][0]
                y = data_xy[j][k][1]
                if p_list[x] != y:
                    flag = False
    if flag == True:
        ans = max(sum(p_list),ans)
print(ans)
Problem p02954 (python)

Fixed submission:
S = input()
S = list(S.replace('RL', '11'))
lp,rp = 0,0
for i,s in enumerate(S):
    #l並びが終わったとき
    if (lp>0)&(s!='L'):
        S[i-lp-1] = int(S[i-lp-1])+lp//2
        S[i-lp-2] = int(S[i-lp-2])+lp-lp//2
        lp = 0
    #最後がL(RLで11になっていない)
    if (i==len(S)-1)&(s=='L'):
        lp += 1
        S[i] = 0
        S[i-lp] = int(S[i-lp])+lp//2
        S[i-lp-1] = int(S[i-lp-1])+lp-lp//2
    elif s=='L':
        lp += 1
        S[i] = 0
    elif s=='R':
        rp += 1
        S[i] = 0
    #R並びが終わったとき
    elif rp>0:
        S[i] = int(S[i+1]) + rp//2
        S[i+1] = int(s) + rp-rp//2
        rp = 0
print(' '.join(map(str, S)))

Buggy submission (verdict: Runtime Error):
S = input()
S = list(S.replace('RL', '11'))
lp,rp = 0,0
for i,s in enumerate(S):
    #l並びが終わったとき
    if (lp>0)&(!='L'):
        S[i-lp-1] = int(S[i-lp-1])+lp//2
        S[i-lp-2] = int(S[i-lp-2])+lp-lp//2
        lp = 0
    #最後がL(RLで11になっていない)
    if (i==len(S)-1)&(s=='L'):
        lp += 1
        S[i] = 0
        S[i-lp] = int(S[i-lp])+lp//2
        S[i-lp-1] = int(S[i-lp-1])+lp-lp//2
    elif s=='L':
        lp += 1
        S[i] = 0
    elif s=='R':
        rp += 1
        S[i] = 0
    #R並びが終わったとき
    elif rp>0:
        S[i] = int(S[i+1]) + rp//2
        S[i+1] = int(s) + rp-rp//2
        rp = 0
print(' '.join(map(str, S)))
Problem p03785 (python)

Fixed submission:
n, c, k = map(int, input().split())
t = [int(input()) for i in range(n)]
t.sort()

result = 1
count = 0
f = 0

for i in range(n):
  if (t[i] - t[f]) > k or c == count:
    result += 1
    count = 1
    f = i
  else:
    count += 1
print(result)

Buggy submission (verdict: Runtime Error):
n, c, k = map(int, input().split())
t = []
for i in range(n):
  t.append(int(input()))
t.sort()
result = 1
j = 0

for i in range(n):
  if (t[j] - t[0]) > k or c == count:
    result += 1
    t = t[j:]
    j = 1
  else:
    j += 1
print(result)
Problem p02779 (python)

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

answer = 'YES'
check_dic = {}
for a in A:
    if a in check_dic:
        answer = 'NO'
        break
    else:
        check_dic[a] = True
print(answer)

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

answer = 'YES'
max_val = max(A) + 1
check = [False] * max_val
for a in A:
    if check[a] == True:
        answer = 'NO'
        break
    else:
        check[a] = True
print(answer)

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

answer = 'YES'
check = [False] * max(A)
for a in A:
    if check[a-1] == True:
        answer = 'NO'
        break
    else:
        check[a-1] = True
print(answer)
Problem p02862 (python)

Fixed submission:
MOD = 10**9+7
fact = [1, 1]
for i in range(2, 10**6+1):
    fact.append((fact[i-1] * i) % MOD)


def comb(n, k):
    return (fact[n] * pow(fact[k], MOD-2, MOD) * pow(fact[n-k], MOD-2, MOD)) % MOD


X, Y = [int(x) for x in input().split(" ")]

n = (2 * X - Y) / 3
m = (2 * Y - X) / 3

if n < 0 or n != int(n):
    print(0)
elif m < 0 or m != int(m):
    print(0)
else:
    n = int(n)
    m = int(m)
    ans = comb(n+m, n)
    print(ans)

Buggy submission (verdict: Runtime Error):
import math

X, Y = [int(x) for x in input().split(" ")]

N = (X + Y) / 3
i = (2 * X - Y) / 3
if N < 0 or N != int(N):
    print(0)
if i < 0 or i != int(i):
    print(0)

N = int(N)
i = int(i)

ans = math.factorial(N) / (math.factorial(i) * math.factorial(N-i))
print(ans)
Problem p02964 (python)

Fixed submission:
import sys
input = sys.stdin.readline

N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
L = [0]*N
P = [-1]*(2*10**5+1)
for i in range(2*N):
    j = i%N
    a = A[j]
    if P[a] == -1:
        P[a] = i
    else:
        L[P[a]] = j
        P[a] = j
s = 0
start = 0
v = [True]*N
h = [(0, 0)]
h_app = h.append
while v[start]:
    v[start] = False
    if start < L[start]:
        s += (L[start] - start +1)
    else:
        s += (L[start] - start +N +1)
    start = (L[start]+1)%N
    h_app((s, start))

r = (N*K)%s
import bisect
if r == 0:
    print("")
else:
    res = bisect.bisect(h, (r, 10**10))-1
    s, start = h[res]
    s = r-s
    ans = []
    P = [-1]*(2*10**5+1)
    if s:
        cou = 0
        for i in range(s):
            if P[A[(start+i)%N]] == -1:
                P[A[(start+i)%N]] = cou
                ans.append(str(A[(start+i)%N]))
            else:
                sr = P[A[(start+i)%N]]
                P[A[(start+i)%N]] = -1
                for j in range(cou-sr):
                    a = ans.pop()
                    P[int(a)] = -1
                cou = sr-1
            cou += 1
    print(" ".join(ans))

Buggy submission (verdict: Runtime Error):
N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
L = [0]*N
P = [-1]*(2*10**5+1)
for i in range(2*N):
    j = i%N
    a = A[j]
    if P[a] == -1:
        P[a] = i
    else:
        L[P[a]] = j
        P[a] = j
s = 0
start = 0
v = [True]*N
h = [(0, 0)]
h_app = h.append
while v[start]:
    v[start] = False
    if start < L[start]:
        s += (L[start] - start +1)
    else:
        s += (L[start] - start +N +1)
    start = (L[start]+1)%N
    h_app((s, start))

r = (N*K)%s
import bisect
if r == 0:
    print("")
else:
    res = bisect.bisect(h, (r, 10**10))-1
    s, start = h[res]
    s = r-s
    ans = []
    P = [-1]*(2*10**5+1)
    if s:
        cou = 0
        for i in range(s):
            if P[A[(start+i)%N]] == -1:
                P[A[(start+i)%N]] = i
                ans.append(str(A[(start+i)%N]))
            else:
                sr = P[A[(start+i)%N]]
                P[A[(start+i)%N]] = -1
                for j in range(cou-sr):
                    ans.pop()
                cou = sr-1
            cou += 1
    print(" ".join(ans))
Problem p03033 (python)

Fixed submission:
import sys
input = sys.stdin.readline

import heapq
N, Q = (int(i) for i in input().split())
L = [0] * (2 * N + Q)
for i in range(N):
    S, T, X = (int(i) for i in input().split())
    L[2 * i] = (S-X, 1, X)
    L[2 * i + 1] = (T-X, -1, X)
for i in range(Q):
    D = int(input())
    L[2 * N + i] = (D, 2, 0)
L.sort()

Xs = set([])
XH = []
heapq.heapify(XH)
for t, f, X in L:
    if f == 1:
        Xs.add(X)
        heapq.heappush(XH, X)
    elif  f == -1:
        Xs.remove(X)
    else:
        if Xs:
            while XH[0] not in Xs:
                X = heapq.heappop(XH)
            print(XH[0])
        else:
            print("-1")

Buggy submission (verdict: Runtime Error):
import heapq
N, Q = (int(i) for i in input().split())
L = [0] * 2 * N
for i in range(N):
    S, T, X = (int(i) for i in input().split())
    L[2 * i] = (S-X, X, 1)
    L[2 * i + 1] = (T-X, X, 0)

L.sort(reverse=True)

Xs = set([])
XH = []
heapq.heapify(XH)
for i in range(Q):
    D = int(input())
    ans = 0
    while True:
        if L:
            t, X, f = L.pop()
            if t <= D:
                if f == 1:
                    Xs.add(X)
                    heapq.heappush(XH, X)
                else:
                    Xs.remove(X)
            else:
                L.append((t, X, f))
                break
        else:
            break
    if Xs:
        while True:
            X = heapq.heappop(XH)
            if X in Xs:
                print(X)
                break
    else:
        print("-1")
Problem p03104 (python)

Fixed submission:
A, B = (int(i) for i in input().split())
if A%2 == 0:
  a = 0
else:
  a = A
  A = A + 1
if B%2 == 1:
  b = 0
else:
  b = B
  B = B - 1
if (B-A+1)%4==0:
  c = 0
else:
  c = 1
print(a^b^c)

Buggy submission (verdict: Runtime Error):
, B = (int(i) for i in input().split())
if A%2 == 0:
  a = 0
else:
  a = A
  A = A + 1
if B%2 == 1:
  b = 0
else:
  b = B
  B = B - 1
if (B-A+1)%4==0:
  c = 0
else:
  c = 1
print(a^b^c)
Problem p03108 (python)

Fixed submission:
import sys
input = sys.stdin.readline

sys.setrecursionlimit(100000)

N, M = (int(i) for i in input().split())
L = []
for i in range(M):
    a, b = (int(j) for j in input().split())
    L.append((a-1, b-1))
L.reverse()

uf = [-1]*N
def parent(v):
    if uf[v] < 0:
        return v
    else:
        uf[v] = parent(uf[v])
        return uf[v]

res = [0]*M
ans = (N*(N-1))//2
res[0] = ans

for i in range(1, M):
    a, b = L[i-1]
    pa = parent(a)
    pb = parent(b)
    if pa != pb:
        sa = -uf[pa]
        sb = -uf[pb]
        ans -= sa * sb
        uf[pb] = pa
        uf[pa] = -(sa + sb)
    res[i] = ans

res.reverse()
for i in range(M):
    print(res[i])

Buggy submission (verdict: Runtime Error):
N, M = (int(i) for i in input().split())
L = []
for i in range(M):
    a, b = (int(j) for j in input().split())
    L.append((a-1, b-1))
L.reverse()

uf = [-1]*N
def parent(v):
    if uf[v] < 0:
        return v
    else:
        uf[v] = parent(uf[v])
        return uf[v]

res = [0]*M
ans = (N*(N-1))//2
res[0] = ans

for i in range(1, M):
    a, b = L[i-1]
    pa = parent(a)
    pb = parent(b)
    if pa != pb:
        sa = -uf[pa]
        sb = -uf[pb]
        ans -= sa * sb
        uf[pb] = pa
        uf[pa] = -(sa + sb)
    res[i] = ans

res.reverse()
for i in range(M):
    print(res[i])