Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))

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

a,b=min(l),max(l)

y=[]
for j in range(a,b+1):
    x=0
    for k in range(n):
        #print(abs(l[k]-j))
        x+=abs(l[k]-j)
    y.append(x)
    #print(x)

#print(n,l,y)
print(min(y))




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

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

from statistics import mean, median,variance,stdev
z=int(median(l))

x=0
for j in range(n):
    x+=abs(l[j]-z)

print(x)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=list(input())

l=[]
for i in range(n):
    x = s[:i].count('W') + s[i:].count('E')
    l.append(x)
    x=0

print(min(l))

Fixed submission:
n=int(input())
s=list(input())
t=list(reversed(s))
#print(s,t)

S,T=[],[]
x,y=0,0
for i in range(n):
    if s[i]=='W':
        x+=1
        S.append(x)
    else:
        S.append(x)
    
    if t[i]=='E':
        y+=1
        T.append(y)
    else:
        T.append(y)

S=[0]+S
T=[0]+T

T.reverse()
#print(S,T)

z=3*(10**5)
for j in range(n):
    z=min(z,S[j]+T[j+1])
    #print(S[j],T[j+1])

print(z)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c, k = map(int,input().split())

if a==b==c:
    print(0)
    exit()
    
for i in range(k):
    a_=b+c
    b_=a+c
    c_=a+b
    if abs(a_-b_) > 10**18:
        print('Unfair')
        exit()
    a=a_
    b=b_
    c=c_

if k==0:
    print(a-b)
else:
    print(a_-b_)


Fixed submission:
a, b, c, k = map(int,input().split())

if a==b==c:
    print(0)
    exit()
    
a_=b+c
b_=a+c
c_=a+b

if k==0:
    print(a-b)
elif k%2==0:
    print(a-b)
else:
    print(a_-b_)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ary = list(map(int, input().split()))

ary_2 = [ary[0]]
for i in range(1, n):
    ary_2.append(ary[i] + ary_2[i-1])
ary_2 = [0] + ary_2

ans = 0
for j in range(n):
    for k in range(j+1, n+1):
        if ary_2[j] == ary_2[k]:
            ans += 1

print(ans)

Fixed submission:
n = int(input())
ary = list(map(int, input().split()))
#print(n,ary)

ary_2 = [ary[0]]
for i in range(1, n):
    ary_2.append(ary[i] + ary_2[i-1])
ary_2 = [0] + ary_2
#print(ary_2)

from collections import Counter
c = Counter(ary_2)
v = (c.values())
#print(v)

from math import factorial
def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

ans = 0
for j in v:
    if j >1:
        ans += combinations_count(j,2)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ary = list(map(int, input().split()))

ary_2 = [ary[0]]
for i in range(1, n):
    ary_2.append(ary[i] + ary_2[i-1])
ary_2 = [0] + ary_2

ans = 0
for j in range(n):
    for k in range(j+1, n+1):
        if ary_2[j] == ary_2[k]:
            ans += 1

print(ans)

Fixed submission:
n = int(input())
ary = list(map(int, input().split()))
#print(n,ary)

ary_2 = [ary[0]]
for i in range(1, n):
    ary_2.append(ary[i] + ary_2[i-1])
ary_2 = [0] + ary_2
#print(ary_2)

from collections import Counter
c = Counter(ary_2)
v = (c.values())
#print(v)

from math import factorial
def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

ans = 0
for j in v:
    if j >1:
        ans += combinations_count(j,2)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from statistics import median
n=int(input())
l=list(map(int,input().split()))

for i in range(n):
    x=l[:]
    x.pop(i)
    print(median(x))

Fixed submission:
from statistics import median, median_low, median_high

n=int(input())
l=list(map(int,input().split()))

m_l=median_low(l)
m_h=median_high(l)

for i in range(n):
    if l[i] <= m_l:
        print(m_h)
    elif l[i] >= m_h:
        print(m_l)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k = map(int, input().split())
l = [i for i in range(a,b+1)]
#print(l)
c = b-a+1

x = []
if k*2 > c:
    x = l
else:
    for j in range(k):
        x.append(l[j])
        x.append(l[-(j+1)])

print(*sorted(x), sep='\n')


Fixed submission:
a,b,k = map(int, input().split())
#print(l)
c = b-a+1

x = []
if k*2 > c:
    for i in range(a, b+1):
        x.append(i)
else:
    for j in range(a, a+k):
        x.append(j)
    for j in range(b-k+1, b+1):
        x.append(j)

print(*sorted(x), sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
a,b,k = map(int, input().split())
l = [i for i in range(a,b+1)]
#print(l)
c = len(l)

x = []
if k*2 > c:
    x = l
else:
    for j in range(k):
        x.append(l[j])
        x.append(l[-(j+1)])

print(*sorted(x), sep='\n')


Fixed submission:
a,b,k = map(int, input().split())
#print(l)
c = b-a+1

x = []
if k*2 > c:
    for i in range(a, b+1):
        x.append(i)
else:
    for j in range(a, a+k):
        x.append(j)
    for j in range(b-k+1, b+1):
        x.append(j)

print(*sorted(x), sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
a,b,k = map(int, input().split())
l = [i for i in range(a,b+1)]
#print(l)
c = len(l)
d = min(c,k)
x = []

if k*2 > c:
    x = l
else:
    for p in range(k):
        x.append(l[p])
        x.append(l[-(p+1)])

print(*sorted(x), sep='\n')


Fixed submission:
a,b,k = map(int, input().split())
#print(l)
c = b-a+1

x = []
if k*2 > c:
    for i in range(a, b+1):
        x.append(i)
else:
    for j in range(a, a+k):
        x.append(j)
    for j in range(b-k+1, b+1):
        x.append(j)

print(*sorted(x), sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
a,b,k = map(int, input().split())
l = []
for i in range(b-a+1):
    l.append(a+i)
#print(l)
c = len(l)
d = min(c,k)
x = []
for j in range(d):
    x.append(l[j])
    x.append(l[-(j+1)])

x = list(set(x))
print(*sorted(x), sep='\n')


Fixed submission:
a,b,k = map(int, input().split())
#print(l)
c = b-a+1

x = []
if k*2 > c:
    for i in range(a, b+1):
        x.append(i)
else:
    for j in range(a, a+k):
        x.append(j)
    for j in range(b-k+1, b+1):
        x.append(j)

print(*sorted(x), sep='\n')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))

s = set(l)

x=0
for i in s:
    y = l.count(i)
    if i <= y:
        x += y - i
    else:
        x += y

print(x)

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

s=set(l)

import collections
c = collections.Counter(l)

x=0
for i in s:
    y = c[i]
    if i <= y:
        x += y - i
    else:
        x += y

print(x)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))

s=list(set(l))

x=0
for i in s:
    y = l.count(i)
    if i <= y:
        x += y - i
    else:
        x += y

print(x)

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

s=set(l)

import collections
c = collections.Counter(l)

x=0
for i in s:
    y = c[i]
    if i <= y:
        x += y - i
    else:
        x += y

print(x)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))

s=list(set(l))

x=0
for i in s:
    if i <= l.count(i):
        x += l.count(i) - i
    else:
        x += l.count(i)

print(x)

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

s=set(l)

import collections
c = collections.Counter(l)

x=0
for i in s:
    y = c[i]
    if i <= y:
        x += y - i
    else:
        x += y

print(x)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd

def gcds(List):
    __ = 0
    for _ in List:
        __ = gcd(__, _)
    return __

n = int(input())
l = list(map(int, input().split()))

x = 0
y = gcds(l)

for i in range(y):
    if y % 2 ==0:
        x += 1
        y /= 2

print(x)

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

z = 0
y = []

for i in range(n):
    x = l[i]
    for j in range(max(l)):
        if x % 2 ==0:
            z += 1
            x = int(x/2)
        else:
            y.append(z)
            z = 0
            break

#print(y)
print(min(y))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

x = 0
for i in range(n+1):
    if (i**0.5) == int(i**0.5):
        x = i

print(x)


Fixed submission:
n = int(input())

print((int(n**0.5))**2)
Buggy python submission (verdict: Runtime Error):
if a==b: print(c)
elif a==c: print(b)
else: print(a)

Fixed submission:
a, b, c = map(int,input().split())

if a==b: print(c)
elif a==c: print(b)
else: print(a)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l1 = list(map(int,input().split()))
m = int(input())
l2 = list(map(int,input().split()))

for i in range(m):
    if l2[i] in l1:
        l1.remove(l2[i])
    else:
        print('NO')
        break
else:
    print('YES')

Fixed submission:
from collections import Counter

n = int(input())
l1 = list(map(int,input().split()))
l1_cnt = Counter(l1) 

m = int(input())
l2 = list(map(int,input().split()))
l2_cnt = Counter(l2) 
l2_set=set(l2)

for i in l2_set:
    if l2_cnt[i]<=l1_cnt[i]:
        continue
    else:
        print('NO')
        break
else:
    print('YES')

Buggy python submission (verdict: Time Limit Exceeded):
def list_difference(list1, list2):
    result = list1.copy()
    for value in list2:
        if value in result:
            result.remove(value)

    return result

n=int(input())
l1=list(map(int,input().split()))
m=int(input())
l2=list(map(int,input().split()))

x=list_difference(l2,l1)


if x==[]: print('YES')
else: print('NO')

Fixed submission:
from collections import Counter

n = int(input())
l1 = list(map(int,input().split()))
l1_cnt = Counter(l1) 

m = int(input())
l2 = list(map(int,input().split()))
l2_cnt = Counter(l2) 
l2_set=set(l2)

for i in l2_set:
    if l2_cnt[i]<=l1_cnt[i]:
        continue
    else:
        print('NO')
        break
else:
    print('YES')

Buggy python submission (verdict: Time Limit Exceeded):
def list_difference(list1, list2):
    result = list1.copy()
    for value in list2:
        if value in result:
            result.remove(value)
    return result

n=int(input())
l1=list(map(int,input().split()))
m=int(input())
l2=list(map(int,input().split()))

x=list_difference(l2,l1)

if x==[]: print('YES')
else: print('NO')

Fixed submission:
from collections import Counter

n = int(input())
l1 = list(map(int,input().split()))
l1_cnt = Counter(l1) 

m = int(input())
l2 = list(map(int,input().split()))
l2_cnt = Counter(l2) 
l2_set=set(l2)

for i in l2_set:
    if l2_cnt[i]<=l1_cnt[i]:
        continue
    else:
        print('NO')
        break
else:
    print('YES')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))

x = []
for i in range(n):
    if i%2 == 1:
        x.append(l[i])
    else:
        x.insert(0,l[i])

if n%2 == 0:
    x.reverse()
    print(*x)
else:
    print(*x)

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

odd, even = [], []

for i in range(n):
    if (i + 1) % 2 ==1:
        odd += [l[i]]
    else:
        even += [l[i]]

even.reverse()
e_o = even + odd

if n % 2 == 1:
    e_o.reverse()
    print(*e_o)
else:
    print(*e_o)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = [list(list(input())) for _ in range(n)]

x = []
for i in range(len(l[0])):
    if (l[0][i] in l[1]) and (l[0][i] in l[2]):
        x.append(l[0][i])
        l[1].remove(l[0][i])
        l[2].remove(l[0][i])

print(''.join(sorted(x)))

Fixed submission:
n = int(input())
l = [list(list(input())) for _ in range(n)]

l = sorted(l, key = len)

x = []
for i in range(len(l[0])):
    y = 0
    for j in range(n):
        if l[0][i] in l[j]:
            y +=1
            if y == n:
                x.append(l[0][i])
                for k in range(1, n):
                    l[k].remove(l[0][i])

print(''.join(sorted(x)))

Buggy python submission (verdict: Runtime Error):
n = int(input())
l = [list(list(input())) for _ in range(n)]
for i in range(n):
    l[i].sort()

x = []
for i in range(len(l[0])):
    if l[0][i] == l[1][i] == l[2][i]:
        x.append(l[1][i])

print(''.join(sorted(x)))

Fixed submission:
n = int(input())
l = [list(list(input())) for _ in range(n)]

l = sorted(l, key = len)

x = []
for i in range(len(l[0])):
    y = 0
    for j in range(n):
        if l[0][i] in l[j]:
            y +=1
            if y == n:
                x.append(l[0][i])
                for k in range(1, n):
                    l[k].remove(l[0][i])

print(''.join(sorted(x)))

Buggy python submission (verdict: Runtime Error):
n = int(input())
l = [list(list(input())) for _ in range(n)]
for i in range(n):
    l[i].sort()

x = []
for i in range(len(l[0])):
    if l[0][i] == l[1][i] == l[2][i]:
        x.append(l[1][i])
print(*sorted(x))

Fixed submission:
n = int(input())
l = [list(list(input())) for _ in range(n)]

l = sorted(l, key = len)

x = []
for i in range(len(l[0])):
    y = 0
    for j in range(n):
        if l[0][i] in l[j]:
            y +=1
            if y == n:
                x.append(l[0][i])
                for k in range(1, n):
                    l[k].remove(l[0][i])

print(''.join(sorted(x)))
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
N = [list(map(int, input().split())) for _ in range(n)]
M = [list(map(int, input().split())) for _ in range(m)]

def kyori(X,Y):
    return abs(X[0]-Y[0])+abs(X[1]-Y[1])

def near_p(hito):
    temp = []
    for _ in range(n):
        temp.append(kyori(hito,M[_]))
    return temp.index(min(temp))+1

for i in range(n):
    print(near_p(N[i]))


Fixed submission:
n,m = map(int,input().split())
N = [list(map(int, input().split())) for _ in range(n)]
M = [list(map(int, input().split())) for _ in range(m)]

def kyori(X,Y):
    return abs(X[0]-Y[0])+abs(X[1]-Y[1])

def near_p(hito):
    temp = []
    for _ in range(m):
        temp.append(kyori(hito,M[_]))
    return temp.index(min(temp))+1

for i in range(n):
    print(near_p(N[i]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

x = 1
for i in range(1,n+1):
    x = x*i

print(x%(10**9+7))


Fixed submission:
n = int(input())
inf =1000000007

x = 1
for i in range(1,n+1):
    x = x*i%inf

print(x)
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())

l = []
for i in range(k+1):
    for j in range(k+1):
        l.append([i,j])
#print(len(l))

q = 0
for r in range(k+1):
    for p in range(len(l)):
        if r + sum(l[p]) == s:
                q += 1

#print(k,s,l)
print(q)


Fixed submission:
k,s = map(int,input().split())

x = 0
l = []
for i in range(k+1):
    for j in range(k+1):
        if s-i-j >= 0 and s-i-j <= k:
            x += 1
print(x)
Buggy python submission (verdict: Runtime Error):
a=input().split()
if a[0]==a[1]==a[2]:
    print(1)
elif a[0]!=a[1]! and a[1]!=a[2] and a[0]!=a[2]:
    print(3)
else:
    print(2)


Fixed submission:
a=input().split()

if a[0]==a[1]==a[2]:
    print(1)
elif a[0]!=a[1] and a[1]!=a[2] and a[0]!=a[2]:
    print(3)
else:
    print(2)

Buggy python submission (verdict: Runtime Error):
a=input().split()
#a=int(input())
#b=int(input())
#c=int(input())
#d=int(input())
if a[0]==a[1]==a[2]:
    print(1)
elif a[0]!=a[1]! and a[1]!=a[2] and a[0]!=a[2]:
    print(3)
else:
    print(2)


Fixed submission:
a=input().split()

if a[0]==a[1]==a[2]:
    print(1)
elif a[0]!=a[1] and a[1]!=a[2] and a[0]!=a[2]:
    print(3)
else:
    print(2)

Buggy python submission (verdict: Runtime Error):
a=input().split()
#a=int(input())
#b=int(input())
#c=int(input())
#d=int(input())
if a[0]==a[1]==a[2]:
    print(1)
elif a[0]!=a[1]! and a[1]!=a[2] and a[0]!=a[2]:
    print(3)
else:
    print(2)


Fixed submission:
a=input().split()

if a[0]==a[1]==a[2]:
    print(1)
elif a[0]!=a[1] and a[1]!=a[2] and a[0]!=a[2]:
    print(3)
else:
    print(2)

Buggy python submission (verdict: Runtime Error):
a=input().split()
#a=int(input())
#b=int(input())
#c=int(input())
#d=int(input())
if a[0]==a[1]==a[2]:
    print(1)
elif a[0]!=a[1]! and a[1]!=a[2] and a[0]!=a[2]:
    print(3)
else:
    print(2)


Fixed submission:
a=input().split()

if a[0]==a[1]==a[2]:
    print(1)
elif a[0]!=a[1] and a[1]!=a[2] and a[0]!=a[2]:
    print(3)
else:
    print(2)

Buggy python submission (verdict: Runtime Error):
a=input().split()
#a=int(input())
#b=int(input())
#c=int(input())
#d=int(input())
if a[0]==a[1]==a[2]:
    print(1)
elif a[0]!=a[1]! and a[1]!=a[2] and a[0]!=a[2]:
    print(3)
else:
    print(2)


Fixed submission:
a=input().split()

if a[0]==a[1]==a[2]:
    print(1)
elif a[0]!=a[1] and a[1]!=a[2] and a[0]!=a[2]:
    print(3)
else:
    print(2)
Buggy python submission (verdict: Runtime Error):
5 2 2
ccccc

Fixed submission:
n,a,b = map(int,input().split())
s=input()

AB=0
B=0
for i in range(n):
    if s[i] =='a':
        if AB<a+b:
            AB+=1
            print('Yes')
        else:
            print('No')
    elif s[i] =='b':
        B+=1
        if AB<a+b and B<=b:
            AB+=1
            print('Yes')
        else:
            print('No')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
c=int(input())
d=int(input())
print(c*b+d*(a-b))a=int(input())


Fixed submission:
n = int(input())
k = int(input())
x = int(input())
y = int(input())

if n<=k:
    print(n*x)
else:
    print(k*x+y*(n-k))
Buggy python submission (verdict: Runtime Error):
a=input().split()
b=int(a[0])
data = [input() for i in range(+1)]
sort(data)

for j in data:
    c=c+j
    
print(c)



Fixed submission:
a=input().split()
b=int(a[0])
data = [input() for i in range(b)]
data.sort()
#print(data)

k=""
for i in data:
    k=k+i
print(k)

Buggy python submission (verdict: Runtime Error):
a=input().split()
b=int(a[0])
data = [input() for i in range(b)]
sort(data)

for j in data:
    c=c+j
    
print(c)

Fixed submission:
a=input().split()
b=int(a[0])
data = [input() for i in range(b)]
data.sort()
#print(data)

k=""
for i in data:
    k=k+i
print(k)
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=[]
for i in range(N):
    a=int(input())
    A.append(a)

def segfunc(x, y):
    return max(x,y)
ide_ele =0

class SegTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res
Ma=max(A)
Tree=[0]*(Ma+1)
seg = SegTree(Tree, segfunc, ide_ele)
ans=0
for i in range(N):
    a=A[i]
    l=max(0,a-K)
    r=min(a+K,Ma)
    Ans=seg.query(l,r+1)
    seg.update(a, Ans+1)
    ans=max(ans,Ans+1)
print(ans)

Fixed submission:
N,M=map(int,input().split())
road=[[] for _ in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    road[a-1].append(b-1)
    road[b-1].append(a-1)
ischecked=[0]*(N)
ans=0
for i in range(N):
    if ischecked[i]==1:
        continue
    ischecked[i]=1
    q=[i]
    while q:
        now=q.pop()
        nex=road[now]
        for j in nex:
            if ischecked[j]!=0:
                continue
            q.append(j)
            ischecked[j]=1
    ans+=1
print(ans-1)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
friend=[[] for _ in range(N)]
for i in range(M):
    A,B=map(int,input().split())
    friend[A-1].append(B-1)
    friend[B-1].append(A-1)
ans=0
ischecked=[0]*N
for i in range(N):
    if ischecked[i]==1:
        continue
    group=1
    ischecked[i]=1
    ship=friend[i]
    while ship:
        nex=ship.pop(0)
        if ischecked[nex]==1:
            continue
        ischecked[nex]=1
        group+=1
        ship.extend(friend[nex])
    ans=max(ans,group)
print(ans)

Fixed submission:
N,M=map(int,input().split())
friend=[[] for _ in range(N)]
for i in range(M):
    A,B=map(int,input().split())
    friend[A-1].append(B-1)
    friend[B-1].append(A-1)
ans=0
ischecked=[0]*N
for i in range(N):
    if ischecked[i]==1:
        continue
    group=1
    ischecked[i]=1
    ship=friend[i]
    while ship:
        nex=ship.pop()
        if ischecked[nex]==1:
            continue
        ischecked[nex]=1
        group+=1
        ship.extend(friend[nex])
    ans=max(ans,group)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
friend=[[] for _ in range(N)]
for i in range(M):
    A,B=map(int,input().split())
    friend[A-1].append(B-1)
    friend[B-1].append(A-1)
ans=0
ischecked=[0]*N
for i in range(N):
    if ischecked[i]==1:
        continue
    group=1
    ischecked[i]=1
    ship=friend[i]
    while ship:
        nex=ship.pop(0)
        if ischecked[nex]==1:
            continue
        ischecked[nex]=1
        group+=1
        ship.extend(friend[nex])
    ans=max(ans,group)
print(ans)

Fixed submission:
N,M=map(int,input().split())
friend=[[] for _ in range(N)]
for i in range(M):
    A,B=map(int,input().split())
    friend[A-1].append(B-1)
    friend[B-1].append(A-1)
ans=0
ischecked=[0]*N
for i in range(N):
    if ischecked[i]==1:
        continue
    group=1
    ischecked[i]=1
    ship=friend[i]
    while ship:
        nex=ship.pop()
        if ischecked[nex]==1:
            continue
        ischecked[nex]=1
        group+=1
        ship.extend(friend[nex])
    ans=max(ans,group)
print(ans)
Buggy python submission (verdict: Runtime Error):
H,W,M=map(int,input().split())
bombh=[]
bombw=[]
bomb=[[0]*W for _ in range(H)]
w=[0]*W
h=[0]*H
for i in range(M):
    hs,ws=map(int,input().split())
    w[ws-1]+=1
    h[hs-1]+=1
    bomb[hs-1][ws-1]=1
for i in range(H):
    bombh.append([h[i],i])
for i in range(W):
    bombw.append([w[i],i])
bombh.sort(reverse=True)
bombw.sort(reverse=True)
maxh=bombh[0][0]
maxw=bombw[0][0]
ans=maxh+maxw-1
for i in range(H):
    if maxh!=bombh[i][0]:
        break
    a=bombh[i][1]
    for j in range(W):
        if maxw!=bombw[j][0]:
            break
        b=bombw[j][1]
        if bomb[a][b]==0:
            ans+=1
            break
    if bomb[a][b]==0:
        break
print(ans)

Fixed submission:
H,W,M=map(int,input().split())
bombh=[]
bombw=[]
bomb=[]
w=[0]*W
h=[0]*H
for i in range(M):
    hs,ws=map(int,input().split())
    w[ws-1]+=1
    h[hs-1]+=1
    bomb.append([hs-1,ws-1])
maxh=max(h)
maxw=max(w)
ans=maxh+maxw
count=0
for i in range(M):
    if ans==h[bomb[i][0]]+w[bomb[i][1]]:
        count+=1
a=h.count(maxh)*w.count(maxw)
if a==count:
    ans-=1
print(ans)