Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())
a = list(map(int, input().split()))
b = set(a)

def choose2(x):
    return int(x*(x-1)/2)
    
total = 0
for i in b:
    total += choose2(a.count(i))

for i in a:
    s = a.count(i)
    print(total - choose2(s) + choose2(s-1))

Fixed submission:

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

from collections import Counter
count = Counter(a)

def choose2(x):
    return int(x*(x-1)/2)
    
total = 0
for i in list(count.values()):
    total += choose2(i)

for i in a:
    s = count[i]
    print(total - choose2(s) + choose2(s-1))

Buggy python submission (verdict: Runtime Error):

n = int(input())
a = list(map(int, input().split()))
b = set(a)

def choose2(x):
    return int(x*(x-1)/2)
    
total = 0
for i in b:
    total += choose2(a.count(i))

for i in a:
    print(total - choose2(s[i]) + choose2(s[i]-1))

Fixed submission:

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

from collections import Counter
count = Counter(a)

def choose2(x):
    return int(x*(x-1)/2)
    
total = 0
for i in list(count.values()):
    total += choose2(i)

for i in a:
    s = count[i]
    print(total - choose2(s) + choose2(s-1))

Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())
a = list(map(int, input().split()))
b = set(a)
s = [0]*(n+1)

def choose2(x):
    return int(x*(x-1)/2)


for i in b:
    s[i] = a.count(i)
    
total = 0
for i in s:
    total += choose2(i)

ans = [0]*(n+1)
for i in b:
    ans[i] = (total - choose2(s[i]) + choose2(s[i]-1))

for i in a:
    print(ans[i])



Fixed submission:

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

from collections import Counter
count = Counter(a)

def choose2(x):
    return int(x*(x-1)/2)
    
total = 0
for i in list(count.values()):
    total += choose2(i)

for i in a:
    s = count[i]
    print(total - choose2(s) + choose2(s-1))

Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())
a = list(map(int, input().split()))
b = set(a)
s = [0]*(n+1)

def choose2(x):
    return int(x*(x-1)/2)


for i in b:
    s[i] = a.count(i)
    
total = 0
for i in s:
    total += choose2(i)


for i in a:
    ans = 0
    ans = total - choose2(s[i]) + choose2(s[i]-1)
    print(ans)



Fixed submission:

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

from collections import Counter
count = Counter(a)

def choose2(x):
    return int(x*(x-1)/2)
    
total = 0
for i in list(count.values()):
    total += choose2(i)

for i in a:
    s = count[i]
    print(total - choose2(s) + choose2(s-1))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

for _ in range(q):
    Q = list(map(str, input().split()))
    if Q[0] == "1":
        s = s[::-1]
    else:
        if Q[1] == "1":
            s = Q[2] + s
        else:
            s = s + Q[2]

print("".join(s))

Fixed submission:
s = input()
q = int(input())
count = 0
a = []
b = []

for _ in range(q):
    Q = list(map(str, input().split()))
    if Q[0] == "1":
        count += 1
    else:
        if (int(Q[1])+count)%2 == 1:
            a.append(Q[2])
        else:
            b.append(Q[2])
    
        
a = "".join(a[::-1])
b = "".join(b)
s = a + s + b
if count%2 == 1 and count != 0:
    s = s[::-1]
print("".join(s))
Buggy python submission (verdict: Runtime Error):
#Bingo
card = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]
a = [[0]*3 for _ in range(3)]
for bi in b:
    for i in range(3):
        for j in raneg(3):
            if bi == card[i][j]:
                a[i][j] = 1
                
ans = 'No'
#tate
for i in range(3):
    if a[0][i] == 1 and a[1][i] == 1 and a[2][i] == 1:
        ans = 'Yes'
            
#yoko
for i in range(3):
    if a[i][0] == 1 and a[i][1] == 1 and a[i][2] == 1:
        ans = 'Yes'
    
#naname
if a[0][0] == 1 and a[1][1] == 1 and a[2][2] == 1:
    ans = 'Yes'
if a[1][3] == 1 and a[2][2] == 1 and a[3][1] == 1:
    ans ='Yes'
print(ans)

Fixed submission:
#Bingo
card = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = list([int(input()) for _ in range(N)])
a = [[0]*3 for _ in range(3)]
for bi in b:
    for i in range(3):
        for j in range(3):
            if bi == card[i][j]:
                a[i][j] = 1
                
ans = 'No'
#tate
for i in range(3):
    if a[0][i] == 1 and a[1][i] == 1 and a[2][i] == 1:
        ans = 'Yes'
            
#yoko
for i in range(3):
    if a[i][0] == 1 and a[i][1] == 1 and a[i][2] == 1:
        ans = 'Yes'
    
#naname
if a[0][0] == 1 and a[1][1] == 1 and a[2][2] == 1:
    ans = 'Yes'
if a[0][2] == 1 and a[1][1] == 1 and a[2][0] == 1:
    ans ='Yes'
print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
count = 0
while n >0:
    n //= k
    count += 1
print(count)

Fixed submission:
n, r = map(int, input().split())
if n >= 10:
  print(r)
else:
  print(r + 100*(10-n))

Buggy python submission (verdict: Runtime Error):
n, r = map(int, input().split())
if n >= 10:
  print(r)
else:
  print(r - 100:(10-n))

Fixed submission:
n, r = map(int, input().split())
if n >= 10:
  print(r)
else:
  print(r + 100*(10-n))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
count = 0
while n >=0:
    n //= k
    count += 1
print(count)

Fixed submission:
n, k = map(int, input().split())
count = 0
while n >0:
    n //= k
    count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
n, k = map(int, input().split())
p = list(map(int, input().split()))
ps =[0] + list(accumulate(p))
a = 0
b = []
for i in range(n+1- k):
    if a < ps[i+k] - ps[i]:
        a = ps[i+k] - ps[i]
        b = p[ i : i + k ]
        
x = 0
for i in b:
    for j in range(i+1):
        x += j/i
print(x)
    

Fixed submission:
from itertools import accumulate
n, k = map(int, input().split())
P= list(map(int, input().split()))
e = [(1+p) / 2 for p in P]
ps =[0] + list(accumulate(e))
a = 0
for i in range(n+1- k):
    if a < ps[i+k] - ps[i]:
        a = ps[i+k] - ps[i]

print(a)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = list(map(int, input().split()))
a = 0
b = []
for i in range(n-k+1):
    if a < sum(p[ i : i + k ]):
        a = sum(p[ i : i + k ])
        b = p[ i : i + k ]
        
x = 0
for i in b:
    for j in range(i+1):
        x += j/i
print(x)
    

Fixed submission:
from itertools import accumulate
n, k = map(int, input().split())
P= list(map(int, input().split()))
e = [(1+p) / 2 for p in P]
ps =[0] + list(accumulate(e))
a = 0
for i in range(n+1- k):
    if a < ps[i+k] - ps[i]:
        a = ps[i+k] - ps[i]

print(a)
Buggy python submission (verdict: Runtime Error):
k. x = map(int, input().split())
if k*500 >= x:
  print('Yes')
else:
  print('No')

Fixed submission:
k, x = map(int, input().split())
if k*500 >= x:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import collections
n, k = map(int, input().split())
r,s,p = map(int, input().split())
t = input()

for j in range(k, len(t)):
    if t[j] == t[j-k]:
        t = list(t)
        t[j] = 'q'
        t = "".join(t)
ts = collections.Counter(t)
print(ts['p']*s + ts['s']*r + ts['r']*p)

Fixed submission:
import collections
n, k = map(int, input().split())
r,s,p = map(int, input().split())
t = list(input())

for j in range(k, len(t)):
    if t[j] == t[j-k]:
        t[j] = ''
ts = collections.Counter(t)
print(ts['p']*s + ts['s']*r + ts['r']*p)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
r,s,p = map(int, input().split())
t = input()

for j in range(k, len(t)):
    if t[j] == t[j-k]:
        t = list(t)
        t[j] = 'q'
        t = "".join(t)
count = 0
for i in range(len(t)):
    if t[i] == 'r':
        count += p
    elif t[i] == 's':
        count += r
    elif t[i] == 'p':
        count += s
    else:
        continue
print(count) 

Fixed submission:
import collections
n, k = map(int, input().split())
r,s,p = map(int, input().split())
t = list(input())

for j in range(k, len(t)):
    if t[j] == t[j-k]:
        t[j] = ''
ts = collections.Counter(t)
print(ts['p']*s + ts['s']*r + ts['r']*p)
Buggy python submission (verdict: Runtime Error):
import math
a, b = map(int, input().split())
print(a*b//math.gcd(a,b))

Fixed submission:
from fractions import gcd
a, b = map(int, input().split())
print(a*b//gcd(a,b))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))
l.sort()

ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[i] + l[j] > l[k]:
                ans += 1
            else:
                break
print(ans)

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

ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        a = bisect.bisect(l, l[i]+l[j]-1)
        ans += (a-j-1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(1, n+1):
    print(a.index(i) + 1)



Fixed submission:
n = int(input())
a = list(map(int, input().split()))
dic = {}
for i in range(n):
    dic[a[i]] = i+1
for i in range(n):
    print(dic[i+1])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(1, n+1):
    ans.append(a.index(i) + 1)
for i in ans:
    print(i)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
dic = {}
for i in range(n):
    dic[a[i]] = i+1
for i in range(n):
    print(dic[i+1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0
for i in range(n):
    ans += i
print(ans)

Fixed submission:
n = int(input())
ans = 0
print(n*(n-1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for _ in range(n)]

for i in range(n):
    b = a[i]
    a[i] = 0
    print(max(a))
    a[i] = b

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

b = sorted(a)
a1 = b[-1]
a2 = b[-2]
for i in range(n):
    if a[i] == a1:
        print(a2)
    else:
        print(a1)
Buggy python submission (verdict: Runtime Error):
s = intput()
for i in range(1,n):
  if s[i] == s[i-1]:
    print('Bad')
    exit()
print('Good')

Fixed submission:

s = input()
for i in range(1, len(s)):
    if s[i] == s[i - 1]:
        print('Bad')
        exit()
print('Good')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = []
a = 0
b = 0

for _ in range(n):
    li = list(map(int, input().split()))
    l.append(li)
    a += li[0]
    b = max(b,li[1])
    l = sorted(l, key=lambda x: x[1])


if a > b:
    print('No')
    exit()

count = 0
for i in range(n):
    count += l[i][0]
    if count <= l[i][1]:
        continue
    else:
        print('No')
        exit()
print('Yes')
    

Fixed submission:
n = int(input())
l = []
a = 0
b = 0

for _ in range(n):
    li = list(map(int, input().split()))
    l.append(li)
    a += li[0]
    b = max(b,li[1])
    
l = sorted(l, key=lambda x: x[1])
if a > b:
    print('No')
    exit()

count = 0
for i in range(n):
    count += l[i][0]
    if count <= l[i][1]:
        continue
    else:
        print('No')
        exit()
print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
broken = []
for _ in range(m):
    a = int(input())
    broken.append(a)
    
dp = [0]*(n+2)
mod = 1000000007
dp[n] = 1

for i in range(n-1,-1 , -1):
    if i in broken:
        continue
    else:
        dp[i] = dp[i+1] + dp[i+2]
print(dp[0]%mod)
    

Fixed submission:
n, m = map(int, input().split())
broken=set(int(input()) for _ in range(m))    

dp = [0]*(n+2)
mod = 1000000007
dp[n] = 1

for i in range(n-1,-1 , -1):
    if i in broken:
        continue
    else:
        dp[i] = dp[i+1] + dp[i+2]
print(dp[0]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
broken = []
for _ in range(m):
    a = int(input())
    broken.append(a)
    
dp = [0]*(n+2)
mod = 1000000007
dp[n] = 1

for i in range(n-1,-1 , -1):
    if i in broken:
        dp[i] = 0
    else:
        dp[i] = dp[i+1] + dp[i+2]
print(dp[0]%mod)
    

Fixed submission:
n, m = map(int, input().split())
broken=set(int(input()) for _ in range(m))    

dp = [0]*(n+2)
mod = 1000000007
dp[n] = 1

for i in range(n-1,-1 , -1):
    if i in broken:
        continue
    else:
        dp[i] = dp[i+1] + dp[i+2]
print(dp[0]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
broken = []
for _ in range(m):
    a = int(input())
    broken.append(a)
    
dp = [0]*(n+2)
mod = 1000000007
dp[n] = 1

for i in range(n-1,-1 , -1):
    if i in broken:
        dp[i] = 0
    else:
        dp[i] = dp[i+1] + dp[i+2]
print(dp[0]%mod)
    

Fixed submission:
n, m = map(int, input().split())
broken=set(int(input()) for _ in range(m))    

dp = [0]*(n+2)
mod = 1000000007
dp[n] = 1

for i in range(n-1,-1 , -1):
    if i in broken:
        continue
    else:
        dp[i] = dp[i+1] + dp[i+2]
print(dp[0]%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()

L = [0]*len(s)
for i in range(1,len(s)):
    if s[i-1] == "A" and s[i] == "C":
        L[i] = 1
   
for _ in range(q):
    l, r = map(int, input().split())
    print(sum(L[l:r]))
    

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

L = [0]*len(s)
for i in range(1,len(s)):
    L[i] = L[i-1]
    if s[i-1] == "A" and s[i] == "C":
        L[i] += 1


for _ in range(q):
    l, r = map(int, input().split())
    print(L[r-1]-L[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
s = input()
ans = float('inf')
e = int(s.count('E'))

for i in range(n):
    a = Counter(s[:i])['W']
    b = e - (i-a)

    ans = min(ans, a + b)

print(ans)

Fixed submission:
from collections import Counter
n = int(input())
s = input()
e = int(s.count('E'))
ans = e

a = 0
for i in range(n):
    if s[i] == 'W':
        a += 1
    b = e - ((i+1)-a)
    ans = min(ans, a+b)


print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
s = input()
ans = float('inf')

for i in range(n):
    a = Counter(s[:i])
    b = Counter(s[i+1:])

    ans = min(ans, a['W'] + b['E'])

print(ans)

Fixed submission:
from collections import Counter
n = int(input())
s = input()
e = int(s.count('E'))
ans = e

a = 0
for i in range(n):
    if s[i] == 'W':
        a += 1
    b = e - ((i+1)-a)
    ans = min(ans, a+b)


print(ans)
Buggy python submission (verdict: Runtime Error):
n, y = map(int, input().split())
for i in range(n+1):
    for j in range(n-i+1:
        if i*10000 + j*5000 + (n-i-j)*1000 == y:
            print(i, j, (n-i-j))
            exit()

print(-1, -1, -1)

Fixed submission:
n, y = map(int, input().split())
for i in range(n+1):
    for j in range(n-i+1):
        if i*10000 + j*5000 + (n-i-j)*1000 == y:
            print(i, j, (n-i-j))
            exit()

print(-1, -1, -1)

Buggy python submission (verdict: Runtime Error):
n, y = map(int, input().split())
for i in range(n+1):
    for j in range(n-i+1)
        if i*10000 + j*5000 + (n-i-j)*1000 == y:
            print(i, j, (n-i-j))
            exit()

print(-1, -1, -1)

Fixed submission:
n, y = map(int, input().split())
for i in range(n+1):
    for j in range(n-i+1):
        if i*10000 + j*5000 + (n-i-j)*1000 == y:
            print(i, j, (n-i-j))
            exit()

print(-1, -1, -1)

Buggy python submission (verdict: Runtime Error):
n, y = map(int, input().split())
for i in range(n+1):
    for j in range(n-j+1):
        if i*10000 + j*5000 + (n-i-j)*1000 == y:
            print(i, j, (n-i-j))
            exit()

print(-1, -1, -1)

Fixed submission:
n, y = map(int, input().split())
for i in range(n+1):
    for j in range(n-i+1):
        if i*10000 + j*5000 + (n-i-j)*1000 == y:
            print(i, j, (n-i-j))
            exit()

print(-1, -1, -1)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)

b1 = [i[0] for i in c.items() if i[1] >= 4]
b2 = [i[0] for i in c.items() if 4 >= i[1] >= 2]
b = b1 + b2 

b.sort()
print(b[-1]*b[-2])

Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)

b1 = [i[0] for i in c.items() if i[1] >= 4]
b2 = [i[0] for i in c.items() if i[1] >= 2]
b = b1 + b2 + [0,0]

b.sort()
print(b[-1]*b[-2])
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
s = []
g = []

for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        s.append(b)
    elif b == n:
        g.append(a)

for i in s:
    if i in g:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')



Fixed submission:
n, m = map(int, input().split())
l = [0]*n

for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        l[b] += 1
    elif b == n:
        l[a] += 1

for i in l:
    if i >= 2:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x + y + z == s:
                count += 1
print(count)

Fixed submission:
k, s = map(int, input().split())
count = 0
for x in range(k+1):
    for y in range(k+1):
        if 0<= s - x - y <= k:
            count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    A  = [int(i) for i in input().split()]
    #ax = itertools.combinations(A, 2)
    ans = 0
    for i in range(N):
        for j in range(i+1,N):
            ans = (ans + A[i]*A[j]) % 1000000007
            #print(A[i],A[j],ans)
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    A  = [int(i) for i in input().split()]
    #N = 100000
    #A = [i for i in range(1,100000)]
    sum_a = sum(A)% 1000000007
    ans = 0
    for i in range(N):
        sum_a = (sum_a - A[i])% 1000000007
        ans = (ans + sum_a*A[i] ) % 1000000007
        #print((sum_a-A[i])*A[i]/2 ,ans)
    print(ans)
if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import itertools
def main():
    N = int(input())
    A  = [int(i) for i in input().split()]
    ax = itertools.combinations(A, 2)
    ans = 0
    for a,b in ax:
        ans = (ans + a*b) % 1000000007
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    A  = [int(i) for i in input().split()]
    #N = 100000
    #A = [i for i in range(1,100000)]
    sum_a = sum(A)% 1000000007
    ans = 0
    for i in range(N):
        sum_a = (sum_a - A[i])% 1000000007
        ans = (ans + sum_a*A[i] ) % 1000000007
        #print((sum_a-A[i])*A[i]/2 ,ans)
    print(ans)
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N, M = list(map(int, input().split()))
ed = []
for _ in range(M):
    ed.append(list(map(int, input().split())))
import networkx as nx
G = nx.Graph()
G.add_edges_from(ed)
ans = 1
for comp in nx.connected_components(G):
    ans = max(ans, len(comp))
print(ans)

Fixed submission:
# -*- coding: utf-8 -*-

def main():
    #xの根を求める
    def find(x):
        if par[x] < 0:
            return x
        else:
            par[x] = find(par[x])
            return par[x]
    #xとyの属する集合の併合
    def unite(x,y):
        x = find(x)
        y = find(y)

        if x == y:
            return False
        else:
            #sizeの大きいほうがx
            if par[x] > par[y]:
                x,y = y,x
            par[x] += par[y]
            par[y] = x
            return True

    #xとyが同じ集合に属するかの判定
    def same(x,y):
        return find(x) == find(y)

    #xが属する集合の個数
    def size(x):
        return -par[find(x)]

    n, m =map(int, input().split())

    #初期化
    #根なら-size,子なら親の頂点
    par = [-1]*n
    #print(par)
    for i in range(m):
        A,B = map(int, input().split())
        unite(A-1,B-1)
    print(max([size(i) for i in range(n)]))


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N, M = list(map(int, input().split()))
edges = []
for _i in range(M):
    edges.append(list(map(int, input().split())))

import networkx as nx

G = nx.Graph()
G.add_edges_from(edges)
ans = 1
for comp in nx.connected_components(G):
    ans = max(ans, len(comp))
print(ans)


Fixed submission:
# -*- coding: utf-8 -*-

def main():
    #xの根を求める
    def find(x):
        if par[x] < 0:
            return x
        else:
            par[x] = find(par[x])
            return par[x]
    #xとyの属する集合の併合
    def unite(x,y):
        x = find(x)
        y = find(y)

        if x == y:
            return False
        else:
            #sizeの大きいほうがx
            if par[x] > par[y]:
                x,y = y,x
            par[x] += par[y]
            par[y] = x
            return True

    #xとyが同じ集合に属するかの判定
    def same(x,y):
        return find(x) == find(y)

    #xが属する集合の個数
    def size(x):
        return -par[find(x)]

    n, m =map(int, input().split())

    #初期化
    #根なら-size,子なら親の頂点
    par = [-1]*n
    #print(par)
    for i in range(m):
        A,B = map(int, input().split())
        unite(A-1,B-1)
    print(max([size(i) for i in range(n)]))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import itertools
import numpy
def main():
    H, W, M = [int(j) for j in input().split()]
    Hx = [0]*H
    Wx = [0]*W
    dict = [[0] * W for i in range(H)]
    for i in range(M):
        h, w =  [int(j) for j in input().split()]
        dict[h-1][w-1]=1
        Hx[h-1] += 1
        Wx[w-1] += 1
    ans = max(Hx)+ max(Wx)
    maxIndex_Hx = [i for i, x in enumerate(Hx) if x == max(Hx)]
    maxIndex_Wx = [i for i, x in enumerate(Wx) if x == max(Wx)]

    ax = numpy.zeros((H,1))
    for i in maxIndex_Hx:
        ax[i][0] = 1
    ay = numpy.zeros((1,W))
    for i in maxIndex_Wx:
        ay[0][i] = 1
    az = numpy.dot(ax, ay)
    dot = numpy.multiply(numpy.array(dict),az)
    #print(dot)
    if numpy.sum(dot) != numpy.sum(az):
        print(ans)
    else:
        print(ans-1)
    '''
    if ans = H+W:
        print(H+W-1)
        return
    for j in list(itertools.product(maxIndex_Hx, maxIndex_Wx)):
        if dict[j[0]][j[1]] == 0:
            print(ans)
            return
    print(ans-1)
    '''
if __name__ == "__main__":
    main()


Fixed submission:
# -*- coding: utf-8 -*-
W,H,M=[int(_) for _ in input().split()]
HW=[[int(_) for _ in input().split()]for i in range(M)]
yoko = [0]*W
tate = [0]*H
for hw in HW:
    yoko[hw[0]-1]+=1
    tate[hw[1]-1]+=1

my=max(yoko)
mt =max(tate)
ans = mt+my

cu=yoko.count(my)*tate.count(mt)
c = 0

for hw in HW:
    if yoko[hw[0]-1]==my and tate[hw[1]-1]==mt:
        c+=1
if c== cu:
    ans-=1
print(ans)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import itertools
H, W, M = [int(j) for j in input().split()]
Hx = [0]*H
Wx = [0]*W
dict = [[0] * W for i in range(H)]
for i in range(M):
    h, w =  [int(j) for j in input().split()]
    dict[h-1][w-1]=1
    Hx[h-1] += 1
    Wx[w-1] += 1
maxIndex_Hx = [i for i, x in enumerate(Hx) if x == max(Hx)]
maxIndex_Wx = [i for i, x in enumerate(Wx) if x == max(Wx)]
ans = max(Hx)+ max(Wx)
flag = 1
#print(dict)
for j in list(itertools.product(maxIndex_Hx, maxIndex_Wx)):
    if dict[j[0]][j[1]] == 0:
        print(ans)
        flag = 0
        break
if flag:
    print(ans-1)


Fixed submission:
# -*- coding: utf-8 -*-
W,H,M=[int(_) for _ in input().split()]
HW=[[int(_) for _ in input().split()]for i in range(M)]
yoko = [0]*W
tate = [0]*H
for hw in HW:
    yoko[hw[0]-1]+=1
    tate[hw[1]-1]+=1

my=max(yoko)
mt =max(tate)
ans = mt+my

cu=yoko.count(my)*tate.count(mt)
c = 0

for hw in HW:
    if yoko[hw[0]-1]==my and tate[hw[1]-1]==mt:
        c+=1
if c== cu:
    ans-=1
print(ans)