Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):

H, W = map(int, input().spilit())

hal = [H//3, H//3+1]

ans = float("inf")

for ha in hal:
    Sa = ha * W
    
    ## 横に分割
    hb = (H - ha)//2
    hc = H - ha - hb
    Sb = hb * W
    Sc = hc * W
    ans = min(ans, max(Sa, Sb, Sc) - min(Sa, Sb, Sc))
    
    ## 縦に分割
    wb = W//2
    wc = W - wb
    Sb = (H - ha) * wb
    Sc = (H - ha) * wc
    ans = min(ans, max(Sa, Sb, Sc) - min(Sa, Sb, Sc))

wal = [W//3, W//3+1]

for wa in wal:
    Sa = H * wa
    
    ## 横に分割
    hb = H//2
    hc = H - hb
    Sb = hb * (W - wa)
    Sc = hc * (W - wb)
    ans = min(ans, max(Sa, Sb, Sc) - min(Sa, Sb, Sc))
    
    ## 縦に分割
    wb = (W - wa)//2
    wc = W - wa - wb
    Sb = H * wb
    Sc = H * wc
    ans = min(ans, max(Sa, Sb, Sc) - min(Sa, Sb, Sc))

print(ans)


Fixed submission:

H, W = map(int, input().split())

ans = min(H, W)

for h in range(H // 3, H // 3 + 3):
    w = W // 2
    s1 = h*W
    s2 = (H-h)*w
    s3 = (H-h)*(W-w)
    ans = min(ans, max(s1,s2,s3) - min(s1,s2,s3))

for w in range(W // 3, W // 3 + 3):
    h = H // 2
    s1 = w*H
    s2 = (W-w)*h
    s3 = (W-w)*(H-h)
    ans = min(ans, max(s1,s2,s3) - min(s1,s2,s3))
    
if H % 3 == 0 or W % 3 == 0:
    ans = 0
    
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

gr = set()

for i in range(N):
    a, b = map(int, input().split())
    gr |= {(a-1,b-1),(b-1,a-1)}

from itertools import permutations

ans = 0
for p in permutations(range(N)):
    if p[0]==0:
        cnt = 0
        cntp = 0
        for i in range(N-1):
            cnt += 1
            if (p[i],p[i+1]) in gr:
                cntp += 1
            else:
                break
        if cnt == cntp:
            ans += 1
print(ans)

Fixed submission:
from itertools import permutations

N, M = map(int, input().split())
gr = set()

for i in range(M):
    a, b = map(int, input().split())
    gr |= {(a-1,b-1),(b-1,a-1)}

ans = 0
for p in permutations(range(N)):
    if p[0]==0:
        cnt = 0
        cntp = 0
        for i in range(N-1):
            cnt += 1
            if (p[i],p[i+1]) in gr:
                cntp += 1
            else:
                break
        if cnt == cntp:
            ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, x = map(int, input().split())
A = list(map(int, input().split()))
cnt = 0
for i in range(N-1):
    while (A[i]+A[i+1])>x:
        if A[i+1]>0:
            A[i+1] -= 1
        else:
            A[i] -= 1
        cnt += 1
print(cnt)

Fixed submission:
N, x = map(int, input().split())
A = list(map(int, input().split()))
cnt = 0
for i in range(N-1):
    if A[i] + A[i+1] > x:
        diff = A[i] + A[i+1] - x
        if A[i+1]>diff:
            A[i+1] -= diff
        else:
            A[i+1] = 0
        cnt += diff
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
T = []
A = []
for i in range(N):
    t, a = map(int, input().split())
    T.append(t)
    A.append(a)
    
v1 = T[0]
v2 = A[0]

for i in range(1, N):
    n = 1
    if v1<=T[i] and v2<=A[i]:
        v1 = T[i]
        v2 = A[i]
    else:
        while v1>n*T[i] or v2>n*A[i]:
            n += 1
        v1 = T[i]*n
        v2 = A[i]*n

print(v1+v2) 

Fixed submission:
N = int(input())
T = []
A = []
for i in range(N):
    t, a = map(int, input().split())
    T.append(t)
    A.append(a)
    
v1 = 1
v2 = 1

for i in range(N):
    n = max((v1+T[i]-1)//T[i],(v2+A[i]-1)//A[i])
    v1 = T[i]*n
    v2 = A[i]*n

print(v1+v2)
Buggy python submission (verdict: Runtime Error):
Sl = list(input())

def func(n, s):
    n += 1
    if n==len(Sl)-1:
        a = sum([int(i) for i in (s+Sl[n]).split("+")])
        b = sum([int(i) for i in (s+"+"+Sl[n]).split("+")])
        return a + b
    else:
        return func(n, s+Sl[n]) + func(n, s+"+"+Sl[n])

print(func(0, Sl[0]))

Fixed submission:
S = input()
n = len(S)

def SplitSum(i, t):
    if i == n-1:
        return sum(list(map(int, t.split('+'))))
    
    return SplitSum(i+1, t+S[i+1]) + SplitSum(i+1, t+'+'+S[i+1])

print(SplitSum(0, S[0]))
Buggy python submission (verdict: Runtime Error):
N, A = map(int, input().split())
X = list(map(int, input().split()))

X2 = [0]*N

for i in range(N):
    X2[i] = X[i] - A

C = Counter([0, X2[0]])

for x in X2[1:]:
    C2 = Counter()
    for s, c in C.items():
        C2[s+x] += c
    C += C2

print(C[0]-1)


Fixed submission:
from collections import Counter

N, A = map(int, input().split())
X = list(map(int, input().split()))

X2 = [0]*N

for i in range(N):
    X2[i] = X[i] - A

C = Counter([0, X2[0]])

for x in X2[1:]:
    C2 = Counter()
    for s, c in C.items():
        C2[s+x] += c
    C += C2

print(C[0]-1)

Buggy python submission (verdict: Runtime Error):
from collections import Counter

N, A = map(int, input().split())
X = list(map(int, input().split))

X2 = [0]*N

for i in range(N):
    X2[i] = X[i] - A

C = Counter([0, X2[0]])

for x in X2[1:]:
    C2 = Counter()
    for s, c in C.items():
        C2[s+x] += c
    C += C2

print(C[0]-1)

Fixed submission:
from collections import Counter

N, A = map(int, input().split())
X = list(map(int, input().split()))

X2 = [0]*N

for i in range(N):
    X2[i] = X[i] - A

C = Counter([0, X2[0]])

for x in X2[1:]:
    C2 = Counter()
    for s, c in C.items():
        C2[s+x] += c
    C += C2

print(C[0]-1)

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

import itertools

cnt = 0
for i in range(1, N+1):
    for v in itertools.combinations(X, i):
        if sum(v)/i==A:
            cnt += 1
print(cnt)

Fixed submission:
from collections import Counter

N, A = map(int, input().split())
X = list(map(int, input().split()))

X2 = [0]*N

for i in range(N):
    X2[i] = X[i] - A

C = Counter([0, X2[0]])

for x in X2[1:]:
    C2 = Counter()
    for s, c in C.items():
        C2[s+x] += c
    C += C2

print(C[0]-1)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
a = list(map(int,input().split()))
mod = 1000000007
ans = 0
while True:
    l_f = a[0]
    del a[0]
    if len(a) < 1: break
    for i in a:
        ans += l_f * i
print(ans%mod)

Fixed submission:
s = int(input())
a = list(map(int,input().split()))
mod = 10 ** 9 + 7
ans = 0
sum_a = sum(a)
for i in range(s):
    sum_a -= a[i]
    ans += sum_a * a[i] % mod
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
from collections import deque
n, m = map(int,input().split())
def vertex_node()  -> list:
    v_c = [[] for _ in range(n+1)]
    v = [i.split() for i in q.split("\n")]
    for i in range(m):
        a,b = map(int,input().split())
        v_c[a].append(b)
        v_c[b].append(a)
    return v_c

def bfs(l) -> list:
    dist = [-1] * (n+1)
    dist[0] = 0
    dist[1] = 0
    d = deque()
    d.append(1)
    while d:
        v = d.popleft()
        for i in l[v]:
                if dist[i] != -1:
                    continue
                dist[i] = dist[v] + 1
                d.append(i)
    return dist
if __name__ == "__main__":
    i = vertex_node()
    ans = bfs(i)[2:]
    print(*ans)

Fixed submission:
from collections import deque
n, m = map(int,input().split())
def vertex_node()  -> list:
    v_c = [[] for _ in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        v_c[a].append(b)
        v_c[b].append(a)
    return v_c

def bfs(l) -> list:
    dist = [-1] * (n+1)
    dist[0] = 0
    dist[1] = 0
    d = deque()
    d.append(1)
    while d:
        v = d.popleft()
        for i in l[v]:
                if dist[i] != -1:
                    continue
                dist[i] = v
                d.append(i)
    return dist
if __name__ == "__main__":
    i = vertex_node()
    ans = bfs(i)[2:]
    print("Yes")
    for i in ans:
        print(i)
Buggy python submission (verdict: Runtime Error):
    QUE=input("")
    EatSM=0
    Sum=QUE.count("+")
    Minus=QUE.count("-")
    print(EatSM+Sum-Minus)

Fixed submission:
import sys
import io

# 関数 solve は，もちろん，問題に応じて書き換える
def solve(n):
    QUE=n
    EatSM=0
    Sum=QUE.count("+")
    Minus=QUE.count("-")
    return EatSM+Sum-Minus

def readQuestion():
    line = sys.stdin.readline().rstrip()
    return line

def main():
    n = readQuestion()
    answer = solve(n)
    print(answer)
    
if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
    QUE=input("")
    EatSM=0
    Sum=QUE.count("+")
    Minus=QUE.count("-")
    return EatSM+Sum-Minus

Fixed submission:
import sys
import io

# 関数 solve は，もちろん，問題に応じて書き換える
def solve(n):
    QUE=n
    EatSM=0
    Sum=QUE.count("+")
    Minus=QUE.count("-")
    return EatSM+Sum-Minus

def readQuestion():
    line = sys.stdin.readline().rstrip()
    return line

def main():
    n = readQuestion()
    answer = solve(n)
    print(answer)
    
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys

# 関数 solve は，もちろん，問題に応じて書き換える
def solve(n, k, as):
    if (n-1)%(k-1)==0:
        return (n-1)/(k-1)
    else:
        return round((n-1)/(k-1))

# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_n, str_k] = line.split(' ')
    line = sys.stdin.readline().rstrip()
    as = line.split(' ')
    return (int(str_n), int(str_k), [int(a) for a in as])

def main():
    n, k, as = readQuestion()
    answer = solve(n, k, as)
    print(answer)
    
if __name__ == '__main__':
    main()

Fixed submission:
import sys

# 関数 solve は，もちろん，問題に応じて書き換える
def solve(n, k, as1):
    if (n-1)%(k-1)==0:
        return (n-1)//(k-1)
    else:
        return (n-1)//(k-1)+1

# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_n, str_k] = line.split(' ')
    line = sys.stdin.readline().rstrip()
    as1 = line.split(' ')
    return (int(str_n), int(str_k), [int(a) for a in as1])

def main():
    n, k, as1 = readQuestion()
    answer = solve(n, k, as1)
    print(answer)
    
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys

# 関数 solve は，もちろん，問題に応じて書き換える
 def solve(d,n):
    if  n != 100 :
        return (100**d)*n
    elif n == 100:
         return (d**100)*101 
    else:
        return n

# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_a, str_b] = line.split(' ')
    return (int(str_a), int(str_b))

def main():
    a, b = readQuestion()
    answer = solve(a, b)
    print(answer)
    
if __name__ == '__main__':
    main()

Fixed submission:
import sys

# 関数 solve は，もちろん，問題に応じて書き換える
def solve(d,n):
    if  n != 100 :
        return (100**d)*n
    elif n == 100:
         return (100**d)*101 
    else:
        return n

# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_a, str_b] = line.split(' ')
    return (int(str_a), int(str_b))

def main():
    a, b = readQuestion()
    answer = solve(a, b)
    print(answer)
    
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
x = A+B
y = A-B
z = A*B

print(max(x,y,z))

Fixed submission:
A, B = map(int, input().split())
x = A+B
y = A-B
z = A*B

print(max(x,y,z))

Buggy python submission (verdict: Runtime Error):
x = A+B
Y = A-B
Z = A*B

print(max(X,Y,Z))

Fixed submission:
A, B = map(int, input().split())
x = A+B
y = A-B
z = A*B

print(max(x,y,z))
Buggy python submission (verdict: Time Limit Exceeded):
A=input()
a=int(A)
n2=1
for i in range(a):
    for x in range(a):
        if n2 <= a:
            n1=(i+2)**(x+2)
            if n2 <= n1 and n1 <= a:
                n2 = n1
                #print(n2)
                n1
print(n2)

Fixed submission:
A=input()
a=int(A)
b=round(a*(1/2))
n2=1
for i in range(2,b):
    for x in range(2,b):
        if n2 <= a:
            n1=(i)**(x)
            if n2 <= n1 and n1 <= a:
                n2 = n1
                #print(n2)
                n1
print(n2)

Buggy python submission (verdict: Time Limit Exceeded):
A=input()
a=int(A)
n1=0
n2=1
for i in range(a):
    for x in range(a):
        if n2 <= a:
            n1=(i+2)**(x+2)
            if n2 <= n1 and n1 <= a:
                n2 = n1
                #print(n2)
                n1
print(n2)

Fixed submission:
A=input()
a=int(A)
b=round(a*(1/2))
n2=1
for i in range(2,b):
    for x in range(2,b):
        if n2 <= a:
            n1=(i)**(x)
            if n2 <= n1 and n1 <= a:
                n2 = n1
                #print(n2)
                n1
print(n2)
Buggy python submission (verdict: Runtime Error):
a ,b= map(int,input().split())
ans ,x , y ,c= 0 ,int(math.sqrt(a * a)) ,int(math.sqrt(b * b)),0
if x == 0:
    x = 1
    c += 1
    if b < 0:
        c += 1 
elif y == 0:
    y = 1
    c += 1
if (a < 0 and b < 0) and (a > b):
    ans = abs(x - y)
    c += 2
elif (a < 0 and b > 0) or (a > 0 and b < 0):
    ans = abs(x - y)
    c += 1
else:
    ans = abs(x - y)
print(ans + c)

Fixed submission:
import math
a ,b= map(int,input().split())
ans ,x , y ,c = 0 ,int(math.sqrt(a * a)) ,int(math.sqrt(b * b)),0
if x == 0:
    if b < a:
         c += 1 
elif y == 0:
    c += 1
    if a < b:
        c -= 1
if (a < 0 and b < 0) and (a > b):
    ans = abs(x - y)
    c += 2
elif (a < 0 and b > 0) or (a > 0 and b < 0):
    ans = abs(x - y)
    c += 1
else:
    ans = abs(x - y)
    if a > b and a > 0 and b > 0:
        c += 2
print(ans + c)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
fumidai_list, A_after = [], 0

for count_a in range(len(A)):
    fumidai = 0

    if(A[count_a] >= A_after):
        A_after = A[count_a]
        fumidai_list.append(fumidai)

    elif(A[count_a] < A_after):

        while True:
            fumidai = fumidai + 1
            A[count_a] = A[count_a] + fumidai
            if(A[count_a] >= A_after):
                break

        fumidai_list.append(fumidai)

print(sum(fumidai_list))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
fumidai_list, A_after = [], 0

for count_a in range(len(A)):
    fumidai = 0

    if(A[count_a] >= A_after):
        A_after = A[count_a]
        fumidai_list.append(fumidai)

    elif(A[count_a] < A_after):
        fumidai = A_after - A[count_a]
        fumidai_list.append(fumidai)

print(sum(fumidai_list))
Buggy python submission (verdict: Runtime Error):
from string import ascii_lowercase
N = int(input())

k = [0, 26]
for i in range(1, 13):
    k.append(26 * (k[i] + 1))

    for i in range(13):
        if k[i] + 1 <= N <= k[i+1]:
            n = N - (k[i] + 1)
            for j in range(i, -1, -1):
                print(ascii_lowercase[(n//26**j) % 26], end="")


Fixed submission:
N = int(input())
L = list("abcdefghijklmnopqrstuvwxyz")
a = 1
while N > 26**a:
    N = N - 26**a
    a += 1
 
pre = []
for i in reversed(range(1,a)):
    r = (N-1) // 26**i
    pre.append(r)
    N = int(N%(26**i))
 
ans = ''
for i in pre:
    ans += L[i]
print(ans+L[N-1])

Buggy python submission (verdict: Runtime Error):

from string import ascii_lowercase
N = int(input())
     
k = [0, 26]
for i in range(1, 13):
  k.append(26 * (k[i] + 1))
     
  for i in range(13):
    if k[i] + 1 <= N <= k[i+1]:
      n = N - (k[i] + 1)
     
      for j in range(i, -1, -1):
        print(ascii_lowercase[(n//26**j) % 26], end="")


Fixed submission:
N = int(input())
L = list("abcdefghijklmnopqrstuvwxyz")
a = 1
while N > 26**a:
    N = N - 26**a
    a += 1
 
pre = []
for i in reversed(range(1,a)):
    r = (N-1) // 26**i
    pre.append(r)
    N = int(N%(26**i))
 
ans = ''
for i in pre:
    ans += L[i]
print(ans+L[N-1])
Buggy python submission (verdict: Runtime Error):
X, Y = map(int, input().split())

for i in range(X+1):
    for j in range(X+1):
        if(i+j > X):
            continue

        if(Y == 4*i+2*j):
            print("Yes")
            exit()

print("No")


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

for count, i in enumerate(x):
    if(i == 0):
        print(count+1)

Buggy python submission (verdict: Runtime Error):
X, Y = map(int, input().split())

for i in range(X+1):
    for j in range(X+1):
        if(i+j > X):
            continue
        if(Y == 4*i+2*j):
            print("Yes")
            exit()
 
print("No")


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

for count, i in enumerate(x):
    if(i == 0):
        print(count+1)
Buggy python submission (verdict: Runtime Error):
import collections
N = int(input()）
strA = input().split()
ans = collections.Counter(strA)
for i in range(1,N+1):
        
	print(ans[str(i)])


Fixed submission:
import math
a = float(input())
print(2 * a * math.pi )

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
result = {}
count = []
count = [0 for i in range(N)]

for i in range(1, len(A)+2):
    for j in A:
        if(j == i):
            count[i-1] = count[i-1]+1
for i in range(i):
    print(count[i])


Fixed submission:
import math
a = float(input())
print(2 * a * math.pi )
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
result = {}
count = []
count = [0 for i in range(N)]

for i in range(1, len(A)+2):
    for j in A:
        if(j == i):
            count[i-1] = count[i-1]+1
            
for i in range(i):
    print(count[i])


Fixed submission:
import collections
N = int(input())
strA = input().split()
ans = collections.Counter(strA)
for i in range(1, N+1):
    print(ans[str(i)])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
result = {}
for i in range(1, len(A)+2):
    print(A.count(i))


Fixed submission:
import collections
N = int(input())
strA = input().split()
ans = collections.Counter(strA)
for i in range(1, N+1):
    print(ans[str(i)])

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

result = {}

for count, i in enumerate(A):
    result[count+1] = i

for i in range(N):
    print(list(result.values()).count(i+1))


Fixed submission:
import collections
N = int(input())
strA = input().split()
ans = collections.Counter(strA)
for i in range(1, N+1):
    print(ans[str(i)])
Buggy python submission (verdict: Runtime Error):
def keta(n,k):
  cnt=0
  while(n!=0):
   	n//=k
 	cnt+=1
   	return cnt
     
N,K=map(int,input().split())
print(keta(N,K))

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

if(N >= 10):
    print(R)
else:
    K = N
    print(R+100*(10-K))
Buggy python submission (verdict: Runtime Error):
    n = input()
    if "1" in n and "9" in n and "7" in n and "4" in n:
        print("YES")
    else:
        print("NO")

Fixed submission:
n = input()
if "1" in n and "9" in n and "7" in n and "4" in n:
	print("YES")
else:
	print("NO")
Buggy python submission (verdict: Runtime Error):
x=input()
count=0
x_count=0
o=None
judge=[]
string=["k","e","y","e","n","c","e"]
for i in x:
    if(i==string[count] and count<=6):
        judge.append(i)
        count=count+1

for i in judge:        
    if(i==string[x_count]):
        o=True
        x_count=x_count+1
    else:
        x_count=x_count+1
        o=False
        break

if(o==True):
    print("YES")
else:
    print("NO")


Fixed submission:
S = input()
KEYENCE = "keyence"
 
 
isKeyence = False
for i in range(len(S)):
    for j in range(i, len(S)):
        s = S[:i] + S[j:]
        if s == KEYENCE:
            isKeyence = True
if isKeyence:
    print("YES")
else:
    print("NO")

Buggy python submission (verdict: Runtime Error):
x=input()
count=0
x_count=0
judge=[]
string=["k","e","y","e","n","c","e"]
for i in x:
    if(i==string[count] and count<=6):
        judge.append(i)
        count=count+1

for i in judge:        
    if(i==string[x_count]):
        o=True
        x_count=x_count+1
    else:
        x_count=x_count+1
        o=False
        break

if(o==True):
    print("YES")
else:
    print("NO")


Fixed submission:
S = input()
KEYENCE = "keyence"
 
 
isKeyence = False
for i in range(len(S)):
    for j in range(i, len(S)):
        s = S[:i] + S[j:]
        if s == KEYENCE:
            isKeyence = True
if isKeyence:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

A, B, x, mid, count = map(int, input().split()), [], 2, 0
for i in range(A, B):
    while(i > 10):
        x.append(i % 10)
        i = int(i/10)
    count = count+1 if(x[0:mid] == x[mid:len(x)]
                       and len(x) > 0) else None
    x.clear()
print(count)


Fixed submission:
A, B = map(int, input().split())
cnt = 0
for i in range(A, B+1):
    j = list(str(i))
    if j[0] == j[4] and j[1] == j[3]:
        cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
ab = set([tuple(map(int, input().split())) for _ in range(m)])

c = []
for i in ab:
    a, b = i[0], i[1]
    for i in c:
        if a in i or b in i:
            i.add(a)
            i.add(b)
            break
    else:
        c.append(set())
        c[-1].add(a)
        c[-1].add(b)
if m == 0:
    print(1)
else:
    print(max(map(len, c)))

Fixed submission:
class Union:
    def __init__(self, n):
        self.parents = [-1] * n
    
    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            return self.root(self.parents[x])
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(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
    
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

uni = Union(n)
for a, b in ab:
    a -= 1
    b -= 1
    uni.unite(a, b)
print(-min(uni.parents))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

h, w = map(int, input().split())
c = list(map(int, input().split()))
d = list(map(int, input().split()))
s = [list(input()) for _ in range(h)]

c = [i-1 for i in c]
d = [i-1 for i in d]

t0 = [(0, 1), (0, -1), (1, 0), (-1, 0)]
t1 = []
for i in range(-2, 3):
    for j in range(-2, 3):
        t1.append((i, j))
for i in t0:
    t1.remove(i)
t1.remove((0, 0))

check = [[-1]*w for _ in range(h)]
q = deque()
q.appendleft((c[0], c[1], 0))

while q:
    y, x, b = q.pop()
    if x == d[1] and y == d[0]:
        print(b)
        exit()
    if check[y][x] == -1:
        check[y][x] = b
        for dy, dx in t0:
            ydy, xdx = y+dy, x+dx
            if (0 <= xdx < w) and (0 <= ydy < h):
                if s[ydy][xdx] == '.' and check[ydy][xdx] == -1:
                    q.append((ydy, xdx, b))
        for dy, dx in t1:
            ydy, xdx = y+dy, x+dx
            if (0 <= xdx < w) and (0 <= ydy < h):
                if s[ydy][xdx] == '.' and check[ydy][xdx] == -1:
                    q.appendleft((ydy, xdx, b+1))
print(-1)

Fixed submission:
from collections import deque

h, w = map(int, input().split())
c = list(map(int, input().split()))
d = list(map(int, input().split()))
s = [list(input()) for _ in range(h)]

c = [i-1 for i in c]
d = [i-1 for i in d]

t0 = [(0, 1), (0, -1), (1, 0), (-1, 0)]
t1 = []
for i in range(-2, 3):
    for j in range(-2, 3):
        t1.append((i, j))
for i in t0:
    t1.remove(i)
t1.remove((0, 0))

check = [[-1]*w for _ in range(h)]
q = deque()
q.appendleft((c[0], c[1], 0))

while q:
    y, x, b = q.pop()
    if x == d[1] and y == d[0]:
        print(b)
        exit()
    if check[y][x] == -1:
        check[y][x] = b
        for dy, dx in t0:
            ydy, xdx = y+dy, x+dx
            if (0 <= xdx < w) and (0 <= ydy < h):
                if s[ydy][xdx] == '.' and check[ydy][xdx] == -1:
                    q.append((ydy, xdx, b))
        for dy, dx in t1:
            ydy, xdx = y+dy, x+dx
            if (0 <= xdx < w) and (0 <= ydy < h):
                if s[ydy][xdx] == '.' and check[ydy][xdx] == -1:
                    q.appendleft((ydy, xdx, b+1))
print(-1)