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

Fixed submission:
n=int(input())
a=[int(input())for _ in range(n)]
if n==2:print(abs(a[0]-a[1]));exit()
f=[-1]
for i in range(1,n-1-(n%2==0)):
  if i%2:f.append(2)
  else:f.append(-2)
if n%2:f+=[-1]
else:f+=[-2,1]
b=[]
c=[]
for i in f:
  b.append(i)
  c.append(-i)
b.sort()
c.sort()
sb=sc=0
a.sort()
for i in range(n):
  sb+=a[i]*b[i]
  sc+=a[i]*c[i]
print(max(sb,sc))

Buggy submission (verdict: Runtime Error):
from collections import deque
n=int(input())
A=deque(sorted([int(input()) for i in range(n)]))
B=deque([A.popleft()])

flag,ans=1,0
while len(A)!=0:
    if flag==1:L,R=A.pop(),A.pop()
    else:L,R=A.popleft(),A.popleft()

    if abs(L-B[0])+abs(R-B[-1])>abs(L-B[-1])+abs(R-B[0]):
        ans +=abs(L-B[0])+abs(R-B[-1])
        B.append(R)
        B.appendleft(L)
    else:
        ans +=abs(R-B[0])+abs(L-B[-1])
        B.append(L)
        B.appendleft(R)

    if len(A)==1:
        ans +=max(abs(B[0]-A[0]),abs(B[-1]-A[0]))
        break

    flag=flag*-1

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
n=int(input())
A=deque(sorted([int(input()) for i in range(n)]))
B=deque([A.popleft()])

flag,ans=1,0
while len(A)!=0:
    if flag==1:L,R=A.pop(),A.pop()
    else:L,R=A.popleft(),A.popleft()

    if abs(L-B[0])>abs(R-B[-1]):
        ans +=abs(L-B[0])+abs(R-B[-1])
        B.append(R)
        B.appendleft(L)
    else:
        ans +=abs(R-B[0])+abs(L-B[-1])
        B.append(L)
        B.appendleft(R)

    if len(A)==1:
        ans +=max(abs(B[0]-A[0]),abs(B[-1]-A[0]))
        break

    flag=flag*-1

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
n=int(input())
A=deque(sorted([int(input()) for i in range(n)]))
B=deque([A.popleft()])

flag,ans=1,0
while len(A)!=0:
    if flag==1:L,R=A.pop(),A.pop()
    elif flag==-1:L,R=A.popleft(),A.popleft()

    if abs(L-B[0])>abs(R-B[-1]):
        ans +=abs(L-B[0])+abs(R-B[-1])
        B.append(R)
        B.appendleft(L)
    else:
        ans +=abs(R-B[0])+abs(L-B[-1])
        B.append(L)
        B.appendleft(R)

    if len(A)==1:
        ans +=max(abs(B[0]-A[0]),abs(B[-1]-A[0]))
        break

    flag=flag*-1

print(ans)
Problem p03231 (python)

Fixed submission:
from fractions import gcd


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


n,m=map(int,input().split())
s=input()
t=input()
lcm=lcm(n,m)
S=[(i,int(i*(lcm/n)+1)) for i in range(n)]
L=[(i,int(i*(lcm/m)+1)) for i in range(m)]
left,right=0,0
ans=[]
while left!=n and right!=m:
    if S[left][1]==L[right][1]:
        ans.append([S[left][0],L[right][0]])
        right +=1
        left +=1
    elif S[left][1]>L[right][1]:
        right +=1
    elif S[left][1]<L[right][1]:
        left +=1
for l,r in ans:
    if s[l]==t[r]:continue
    else:print(-1);exit()
print(lcm)

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


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


n,m=map(int,input().split())
s,t=input(),input()
lcm=lcm(n,m)

if s[::(lcm/m)]!=t[::(lcm/n)]:
    print(-1);exit()

print(lcm)
Problem p03241 (python)

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

ans = 1
for i in range(1,int(M ** 0.5) + 1):
    if M % i == 0:
        if i >= N:
            ans = max(ans, M // i)
        if M // i >= N:
            ans = max(ans, i)
print(int(ans))

Buggy submission (verdict: Runtime Error):
import math
def get_primenumber(number):
    prime_list = []
    search_list = list(range(2,number+1))
    while True:
      if search_list[0] > math.sqrt(number):
        prime_list.extend(search_list)
        break
      else:
        head_num = search_list[0]
        prime_list.append(head_num)
        search_list.pop(0)
        search_list = [num for num in search_list if num % head_num != 0]
    return prime_list


n,m=map(int,input().split())
A=get_primenumber(m//n)
ans=2
for i in A:
    if m%i==0:ans=i
print(ans if m%n!=0 else m//n)
Problem p03263 (python)

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

C=[]
for i in range(h):
    flag=1 if i%2==0 else -1
    for j in range(w)[::flag]:
        if A[i][j]%2==1:
            if 0<=j+flag<w:
                C.append([i+1,j+1,i+1,j+flag+1])
                A[i][j+flag] +=1
            elif 0<=i+1<h:
                C.append([i+1,j+1,i+2,j+1])
                A[i+1][j] +=1

print(len(C))
for i in C:print(*i)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(h)]

B=[]
for i in range(h):
    flag=1 if i%2==0 else -1
    for j in range(w)[::flag]:
        if A[i][j]%2==1:
            if 0<=j+flag<w:
                B.append([i,j,i,j+flag])
                A[i][j+flag] +=1
            else:
                B.append([i,j,i+1,j])
                A[i+1][j] +=1

print(len(B))
for i in B:
    print(*list(map(lambda x:x+1,i)))

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(h)]

C=[]
for i in range(h):
    flag=1 if i%2==0 else -1
    for j in range(w)[::flag]:
        if A[i][j]%2==1:
            if 0<=j+flag<w:
                C.append([i,j,i,j+flag])
                A[i][j+flag] +=1
            else:
                C.append([i,j,i+1,j])
                A[i+1][j] +=1
print(len(C))
for i in C:print(*i)
Problem p03283 (python)

Fixed submission:
import numpy as np
N, M, Q = map(int, input().split())

#input
lst = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, input().split())
    lst[R][L] += 1

lst = np.array(lst)
# print (lst)

#2次元累積和
for i in range(1, N + 1):
    lst[:,i] += lst[:, i - 1]
for j in range(1, N + 1):
    lst[j,:] += lst[j - 1, :]


#output
for _ in range(Q):
    p, q = map(int, input().split())
    print (lst[q, q] - lst[p-1, q] - lst[q, p-1] + lst[p-1, p-1])

# print (lst)

Buggy submission (verdict: Runtime Error):
import numpy as np
n,m,q=map(int,input().split())
book=[[0]*(n+1) for _ in range(n+1)]
for _ in range(m):
    r,l=map(int,input().split())
    book[r][l] +=1

for i in range(n+1):
    for j in range(n+1):
        book[i][j] +=book[i][j-1]

for i in range(n+1):
    for j in range(n+1):
        book[i][j] +=book[i-1][j]

#print(np.array(book))

for x,y in [map(int,input().split()) for i in range(q)]:
    print(book[y][y]-book[y][x-1]-book[x-1][y]+book[x][x])

Buggy submission (verdict: Runtime Error):
import numpy as np
N, M, Q = map(int, input().split())

#input
lst = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, input().split())
    lst[R][L] += 1

lst = np.array(lst)
# print (lst)

#2次元累積和
for i in range(1, N + 1):
    lst[:,i] += lst[:, i - 1]
for j in range(1, N + 1):
    lst[j,:] += lst[j - 1, :]


#output
for _ in range(Q):
    p, q = map(int, input().split())
    print (lst[q, q] - lst[p-1, q] - lst[q, p-1] + lst[p-1, p-1])

# print (lst)

Buggy submission (verdict: Runtime Error):
import numpy as np
N, M, Q = map(int, input().split())
 
#input
lst = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, input().split())
    lst[R][L] += 1
 
lst = np.array(lst)
# print (lst)
 
#2次元累積和
for i in range(1, N + 1):
    lst[:,i] += lst[:, i - 1]
for j in range(1, N + 1):
    lst[j,:] += lst[j - 1, :]
 
 
#output
for _ in range(Q):
    p, q = map(int, input().split())
    print (lst[q, q] - lst[p-1, q] - lst[q, p-1] + lst[p-1, p-1])

Buggy submission (verdict: Runtime Error):
import numpy as np
N, M, Q = map(int, input().split())

#input
lst = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, input().split())
    lst[R][L] += 1

lst = np.array(lst)
# print (lst)

#2次元累積和
for i in range(1, N + 1):
    lst[:,i] += lst[:, i - 1]
for j in range(1, N + 1):
    lst[j,:] += lst[j - 1, :]


#output
for _ in range(Q):
    p, q = map(int, input().split())
    print (lst[q, q] - lst[p-1, q] - lst[q, p-1] + lst[p-1, p-1])

# print (lst)

Buggy submission (verdict: Runtime Error):
import numpy as np
N, M, Q = map(int, input().split())

#input
lst = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, input().split())
    lst[R][L] += 1

lst = np.array(lst)
# print (lst)

#2次元累積和
for i in range(1, N + 1):
    lst[:,i] += lst[:, i - 1]
for j in range(1, N + 1):
    lst[j,:] += lst[j - 1, :]


#output
for _ in range(Q):
    p, q = map(int, input().split())
    print (lst[q, q] - lst[p-1, q] - lst[q, p-1] + lst[p-1, p-1])

# print (lst)
Problem p03294 (python)

Fixed submission:
n=int(input())
s=list(map(int,input().split()))
print(sum(s)-n)

Buggy submission (verdict: Runtime Error):
n=input()
box=[int(input())-1 for i in range(int(n))]
print(sum(box))

Buggy submission (verdict: Runtime Error):
import math
n=int(input())
box=list(map(int,input().split()))
count=box[0]

for i in range(1,n):
    count=(box[i]*count)//math.gcd(box[i],count)

point=0
count -=1
for i in box:point +=count%i

print(point)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
n=int(input())
box=list(map(int,input().split()))

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

def lcm_list(numbers):
    return reduce(lcm_base,numbers,1)

point=0
count=lcm_list(box)-1
for i in box:
    point +=count%i

print(point)
Problem p03309 (python)

Fixed submission:
import statistics
n=int(input())
box=list(map(int,input().split()))
box_another=sorted(list(y-(x+1) for x,y in enumerate(box)))
median=int(statistics.median(box_another))
count=0
for x,y in enumerate(box):
    count +=abs(y-(x+1+median))
print(count)

Buggy submission (verdict: Runtime Error):
import statistics
n=int(input())
box=list(map(int,input().split()))
box_another=sorted(list(y-(x+1) for x,y in enumerate(box)))
median=int(statistics.median(box_another))
count=0
for x,y in enumerate(box):
    count +=abs(y-(x+1+median))
print(count)

Buggy submission (verdict: Runtime Error):
import statistics
n=int(input())
box=list(map(int,input().split()))
box_m=sorted(list(y-(x+1) for x,y in enumerate(box)))
median=int(statistics.median(box_m))
count=0
for x,y in enumerate(box):
    count += abs(y-(median+x+1))
print(count)

Buggy submission (verdict: Runtime Error):
import statistics
n=int(input())
box=list(map(int,input().split()))
box_m=sorted(list(y-(x+1) for x,y in enumerate(box)))
median=int(statistics.median(box_m))
count=0
for x,y in enumerate(box):
    count +=abs(y-(median+x+1))
print(count)

Buggy submission (verdict: Runtime Error):
import statistics
n=int(input())
box=list(map(int,input().split()))
box_m=sorted([y-(x+1) for x,y in enumerate(box)])
median=int(statistics.median(box_m))
count=0
for x,y in enumerate(box):
    count +=abs(y-(median+x+1))
print(count)
Problem p03379 (python)

Fixed submission:
n=int(input())
x=list(map(int,input().split()))
y=sorted(x)
xr,xl=y[n//2],y[n//2-1]
for i in x:
    print(xr if i<=xl else xl)

Buggy submission (verdict: Runtime Error):
n=int(input())
x=[map(int,input().split())]
y=sorted(x)
xr,xl=y[n//2],y[n//2-1]
for i in x:
    print(xr if i<=xl else xl)

Buggy submission (verdict: Runtime Error):
n=int(input())
x=[map(int,input().split())]
y=sorted(x)
xr,xl=y[n//2],y[n//2-1]
for i in x:print(xr if i<=xl else xl)
Problem p03417 (python)

Fixed submission:
h,q=map(int,input().split())

if h==2 or q==2:print(0)
elif h==1 or q==1:
    if h!=1:print((h-2)*1)
    elif q!=1:print((q-2)*1)
    else:print(1)
else:
    print((h-2)*(q-2))

Buggy submission (verdict: Runtime Error):
import numpy as np
h,q=map(int,input().split())
#動きの確認code,0が裏,1を表
"""
box=[["*"]+["1"]*h+["*"] for i in range(q)]
box.insert(0,["*"]*(h+2))
box.append(["*"]*(h+2))
print(np.array(box))
for i in range(1,q+1):
    for j in range(1,h+1):
        try:
            seat=[[0,0],[0,1],[0,-1],[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1]]
            for x,y in seat:
                xx=i+x
                yy=j+y
                if box[xx][yy]=="1":
                    box[xx][yy]="0"
                elif box[xx][yy]=="0":
                    box[xx][yy]="1"
                elif box[xx][yy]=="*":continue
        except:continue
print(np.array(box))
"""
if h==2 or q==2:print(0)
elif h==1 or q==1:
    if h!=1:print((h-2)*1)
    elif q!=1:print((q-2)*1)
    else:print(1)
else:
    print((h-2)*(q-2))
Problem p03633 (python)

Fixed submission:
def gcd(x,y):
    while y!=0:
        x,y=y,x%y
    return x
def lcm(x,y):
    return (x*y)//gcd(x,y)
n=int(input())
t=int(input())
for i in range(n-1):
    t=lcm(t,int(input()))
print(t)

Buggy submission (verdict: Runtime Error):
from math import gcd
def lcm(x,y):
    return (x*y)//gcd(x,y)
n=int(input())
t=int(input())
for i in range(n-1):
    t=lcm(t,int(input()))
print(t)
Problem p03651 (python)

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


def gcd_list(A):
    num=A[0]
    for i in A:
        num=gcd(num,i)
    return num


n,k=map(int,input().split())
A=list(map(int,input().split()))
print("POSSIBLE" if k%gcd_list(A)==0 and k<=max(A) else "IMPOSSIBLE")

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


def gcd_list(A):
    num=A[0]
    for i in A:
        num=gcd(num,i)
    return num


n,k=map(int,input().split())
A=list(map(int,input().split()))
print("POSSIBLE" if k%gcd_list(A)==0 and k<=max(A) else "IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce


def gcd_list(A):
    return reduce(math.gcd,A)


n,k=map(int,input().split())
A=list(map(int,input().split()))
print("POSSIBLE" if k%gcd_list(A)==0 and k<=max(A) else "IMPOSSIBLE")
Problem p03681 (python)

Fixed submission:
n,m=map(int,input().split())
cnt=1
if abs(n-m)>1:print(0);exit()
elif (n+m)%2==1:
    for i in range(n):
        cnt *=(i+1)
        if cnt>=10**9+7:cnt %=10**9+7
    for j in range(m):
        cnt *=(j+1)
        if cnt >= 10 ** 9 + 7: cnt %= 10 ** 9 + 7
    print(cnt)
else:
    cnt *=(n+m)
    n -=1
    for i in range(n):
        cnt *=(i+1)
        if cnt >= 10 ** 9 + 7: cnt %= 10 ** 9 + 7
    for j in range(m):
        cnt *=(j+1)
        if cnt >= 10 ** 9 + 7: cnt %= 10 ** 9 + 7
    print(cnt)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
cnt=1
def plot():
    if cnt>=10**9+7:
        cnt %=10**9+7
    return cnt
if abs(n-m)>1:print(0);exit()
elif (n+m)%2==1:
    for i in range(n):
        cnt *=(i+1)
        plot()
    for j in range(m):
        cnt *=(j+1)
        plot()
    print(cnt)
else:
    cnt *=(n+m)
    n -=1
    for i in range(n):
        cnt *=(i+1)
        plot()
    for j in range(m):
        cnt *=(j+1)
        plot()
    print(cnt)
Problem p03761 (python)

Fixed submission:
from collections import Counter
n=int(input())
s=[input() for i in range(n)]
count=Counter(s[0])
for i in range(n):
    count &=Counter(s[i])

ans=""
for i in sorted(count.keys()):
    ans +=i*count[i]
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
s=[input() for i in range(n)]
count=Counter(s[0])
for i in range(n):
    count &=s[i]

ans=""
for i in sorted(count.keys()):
    ans +=i*count[i]
print(ans)
Problem p03910 (python)

Fixed submission:
n=int(input())
A=[]
cnt=0
add=0
for i in range(4472):
    cnt +=i+1
    A.append((cnt,i+1))
for i in range(len(A)-1):
    if A[i][0]<=n<=A[i+1][0]:
        add=(A[i+1][1],A[i+1][0]-n)
        break

for i in range(add[0]):
    if i+1==add[1]:
        continue
    print(i+1)

Buggy submission (verdict: Runtime Error):
n=int(input())
A=[]
cnt=0
add=0
for i in range(4471):
    cnt +=i+1
    A.append((cnt,i+1))
for i in range(len(A)-1):
    if A[i][0]<=n<=A[i+1][0]:
        add=(A[i+1][1],A[i+1][0]-n)
        break

for i in range(add[0]):
    if i+1==add[1]:
        continue
    print(i+1)
Problem p03994 (python)

Fixed submission:
N = 26
ord_a = ord('a')
S = [ord(s) - ord_a for s in input()]
K = int(input())


for i in range(len(S)):
    r = (N - S[i]) % N
    if K >= r:
        K -= r
        S[i] = 0


S[-1] += K % N
S[-1] %= N

answer = ''.join(chr(s + ord_a) for s in S)
print(answer)

Buggy submission (verdict: Runtime Error):
s=input()
k=int(input())
m=len(s)

word={j:26-i for i,j in enumerate([chr(_) for _ in range(97,97+26)])}
number={i:j for i,j in enumerate(chr(_) for _ in range(97,97+26))}
ans=""

for i,j in enumerate(s):
    if i==m-1 and k>0:
        k %=26
        if k>word[j]:ans +=number[k-word[j]]
        else:ans +=number[26-word[j]+k]
    elif word[j]<=k:
        k -=word[j]
        ans +="a"
    else:ans +=j
    
print(ans)
Problem p04035 (python)

Fixed submission:
n,l=map(int,input().split())
A=list(map(int,input().split()))
add=0
for i in range(1,n):
    if A[i]+A[i-1]>=l:
        add=i+1
        break
if add==0:print("Impossible");exit()
print("Possible")
for i in range(1,add-1):print(i)
for i in [j for j in range(add,n)][::-1]:print(i)
print(add-1)

Buggy submission (verdict: Runtime Error):
n,l=map(int,input().split())
A=list(map(int,input().split()))
A=list([i+1,A[i]] for i in range(n))
cnt,cnt_list=0,[]
ans=[]
for x,y in A:
    cnt +=y
    cnt_list.append(x)
    if x==n:cnt_list.pop()
    if cnt>=l:
        ans.append(cnt_list.pop())
        for i in cnt_list:
            ans.append(i)
        cnt=0
        cnt_list=[]

if len(ans)==n-1:
    print("Possible")
    for i in ans:print(i)
else:print("Impossible")
Problem p02797 (python)

Fixed submission:
MAX = int(1e9)
n, k, s = map(int, input().split())
if s != MAX:
    for _ in range(k):
        print(s, end=" ")
    for _ in range(n - k):
        print(MAX, end=" ")
else:
    for _ in range(k):
        print(s, end=" ")
    for _ in range(n - k):
        print(1, end=" ")

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

xl = (map(int, input().split()) for _ in range(n))
w = [(x - l, x + l) for x, l in xl]
w = sorted(w, key=lambda x: x[1])
cur = w[0][1]
res = 1
for l, r in w[1:]:
    if l >= cur:
        res += 1
        cur = r
print(res)
Problem p02802 (python)

Fixed submission:
import numpy as np

n, m = map(int, input().split())
is_ac = np.zeros(n, dtype=bool)
wc_count = np.zeros(n, dtype=int)

for _ in range(m):
    p, s = input().split()
    p = int(p)
    if not is_ac[p - 1]:
        if s == "WA":
            wc_count[p - 1] += 1
        else:
            is_ac[p - 1] = True
print(is_ac.sum(), wc_count[is_ac].sum())

Buggy submission (verdict: Runtime Error):
import numpy as np

n, m = map(int, input().split())
is_ac = np.zeros(n, dtype=int)
wc_count = np.zeros(n, dtype=int)

for _ in range(m):
    p, s = input().split()
    p = int(p)
    if is_ac[p - 1] == 0:
        if s == "WA":
            wc_count[p - 1] += 1
        else:
            is_ac[p - 1] = 1
print(is_ac.sum(), wc_count[is_ac].sum())
Problem p02536 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7


def init_unionfind(N):
    global parent, rank
    parent = [-1] * N
    rank = [0] * N


def find_root(x):
    p = parent[x]
    if p == -1:
        return x
    p2 = find_root(p)
    parent[x] = p2
    return p2


def unite(x, y):
    x = find_root(x)
    y = find_root(y)
    if x == y:
        return  # already united
    if rank[x] < rank[y]:
        parent[x] = y
    else:
        parent[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1


def is_connected(x, y):
    return (find_root(x) == find_root(y))


def debug(*x):
    print(*x, file=sys.stderr)


def solve(N, M, edges):
    init_unionfind(N)
    for e in edges:
        unite(e[0] - 1, e[1] - 1)

    s = set(find_root(x) for x in range(N))

    return len(s) - 1


def main():
    # parse input
    N, M = map(int, input().split())
    edges = []
    for _i in range(M):
        edges.append(tuple(map(int, input().split())))

    print(solve(N, M, edges))


# tests
T1 = """
3 1
1 2
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
1
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()

Buggy submission (verdict: Runtime Error):
"""
Union-Find Tree / Disjoint Set Union (DSU)
"""


def init_unionfind(N):
    global parent, rank, NUM_VERTEX
    NUM_VERTEX = N
    parent = [-1] * N
    rank = [0] * N


def find_root(x):
    p = parent[x]
    if p == -1:
        return x
    p2 = find_root(p)
    parent[x] = p2
    return p2


def unite(x, y):
    x = find_root(x)
    y = find_root(y)
    if x == y:
        return  # already united
    if rank[x] < rank[y]:
        parent[x] = y
    else:
        parent[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1


def is_connected(x, y):
    return (find_root(x) == find_root(y))


def num_components():
    return len(set(find_root(x) for x in range(NUM_VERTEX)))

# --- end of library ---


def main_yosupo():
    # verified: https://judge.yosupo.jp/problem/unionfind
    N, Q = [int(x) for x in input().split()]
    init_unionfind(N)
    for q in range(Q):
        typ, u, v = [int(x) for x in input().split()]
        if typ == 0:
            unite(u, v)
        else:
            print(1 if is_connected(u, v) else 0)


def main_abl():
    N, M = map(int, input().split())
    init_unionfind(N)
    for _i in range(M):
        a, b = map(int, input().split()))
        unite(a - 1, b - 1)

    return num_components() - 1


if __name__ == "__main__":
    # main_yosupo()
    main_abl()
Problem p03633 (python)

Fixed submission:
from fractions import gcd

def lcm (a, b):
    return a // gcd (a, b) * b

n, ts = int (input ()), []
for i in range (n):
    ts.append (int (input ()))

ans = 1
for i in range (n):
    ans = lcm (ans, ts[i])

print (ans)

Buggy submission (verdict: Runtime Error):
import math

def lcm (a, b):
    return a // math.gcd (a, b) * b

n, ts = int(input()), []
for i in range (n):
    ts.append (int (input ()))

ans = 1
for i in range (n):
    ans = lcm (ans, ts[i])

print (ans)
Problem p02662 (python)

Fixed submission:
import numpy as np
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
fft = np.fft.rfft
ifft = np.fft.irfft
mod = 998244353

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

dp = np.zeros(U+10, dtype=np.int64)
dp[0] = 1
for a in A:
    newDP = dp.copy() * 2
    newDP[a:] += dp[:-a]
    newDP %= mod
    dp = newDP

print(dp[S])

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
fft = np.fft.rfft
ifft = np.fft.irfft
mod = 998244353

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

dp = np.zeros(U+10, dtype=np.int64)
dp[0] = 1
for a in A:
    newDP = dp.copy() * 2
    newDP[a:] += dp[:-a]
    newDP %= mod
    dp = newDP

print(dp[S])

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
fft = np.fft.rfft
ifft = np.fft.irfft
mod = 998244353

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

dp = np.zeros(U+10, dtype=np.int64)
dp[0] = 1
for a in A:
    newDP = dp.copy() * 2
    if a <= S:
        newDP[a:] += dp[:-a]
        newDP %= mod
    dp = newDP

print(dp[S])
Problem p02675 (python)

Fixed submission:
def maiin(S):
    N = int(S[-1])

    if N == 3:
        print("bon")
    elif N in [0, 1, 6, 8]:
        print("pon")
    else:
        print("hon")

if __name__ == "__main__":
    maiin(input())

Buggy submission (verdict: Runtime Error):
N = input()
N = int(N[-1])
if N == 3:
    print("bon")
elif N in [0, 1, 6, 8]:
    print("pon")
else:
    p