Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
A, B, K = input().split()

C = int(K)-int(A)
B = int(B)-C

print(str(C) +" "+ str(B))

Fixed submission:
S, T = input().split()

print(T+S)
Buggy python submission (verdict: Runtime Error):
A, B, K = input().split()

C = int(K)-int(A)
if(C >= 0):
    B = int(B)-C
    A = 0
else:
    A = int(A)-int(break)

print(str(A) +" "+ str(B))

Fixed submission:
A, B, K = input().split()
C = int(K)-int(A)
D = int(K)-int(B)

if(int(A)==0):
    if(int(B)==0):
        print(str(A) +" "+ str(B))
    else:
        if(D>=0):
            B = 0
        else:
            B = -D
        print(str(A) +" "+ str(B))
else:
    if(C >= 0):
        B = int(B)-C
        A = 0
        if(B<0):
            B = 0
    else:
        A = int(A)-int(K)
    print(str(A) +" "+ str(B))
Buggy python submission (verdict: Runtime Error):
r = input()
a = r*r
print(a)

Fixed submission:
r = int(input())
if int(r):
    print(r*r)
Buggy python submission (verdict: Runtime Error):

def solve():
    n,m=map(int,input().split()[0:2])

    fa=list(range(0,n+1))
    sz=[1]*(n+1)
    def gf(x) :
        if x==fa[x] :
            return x
        fa[x]=gf(fa[x])
        return fa[x]

    for i in range(m) :
        a,b=map(gf,map(int,input().split()[0:2]))
        if a!=b :
            fa[a]=b
            sz[b]+=sz[a]

    ans=1
    for i in range(1,n+1) :
        ans=max(ans,sz[gf(i)])
    return ans

print(solve())


Fixed submission:

import sys
sys.setrecursionlimit(int(2e5+999))

def solve():
    n,m=map(int,input().split()[0:2])

    fa=list(range(0,n+1))
    sz=[1]*(n+1)
    def gf(x) :
        if x==fa[x] :
            return x
        fa[x]=gf(fa[x])
        return fa[x]

    for i in range(m) :
        a,b=map(gf,map(int,input().split()[0:2]))
        if a!=b :
            fa[a]=b
            sz[b]+=sz[a]

    ans=1
    for i in range(1,n+1) :
        ans=max(ans,sz[gf(i)])
    return ans

print(solve())

Buggy python submission (verdict: Runtime Error):

def solve():
    n,m=map(int,input().split())

    fa=list(range(0,n+1))
    sz=[1]*(n+1)
    def gf(x) :
        if x==fa[x] :
            return x
        fa[x]=gf(fa[x])
        return fa[x]

    for i in range(m) :
        a,b=map(gf,map(int,input().split()))
        if a!=b :
            fa[a]=b
            sz[b]+=sz[a]

    ans=1
    for i in range(1,n+1) :
        ans=max(ans,sz[gf(i)])
    return ans

print(solve())


Fixed submission:

import sys
sys.setrecursionlimit(int(2e5+999))

def solve():
    n,m=map(int,input().split()[0:2])

    fa=list(range(0,n+1))
    sz=[1]*(n+1)
    def gf(x) :
        if x==fa[x] :
            return x
        fa[x]=gf(fa[x])
        return fa[x]

    for i in range(m) :
        a,b=map(gf,map(int,input().split()[0:2]))
        if a!=b :
            fa[a]=b
            sz[b]+=sz[a]

    ans=1
    for i in range(1,n+1) :
        ans=max(ans,sz[gf(i)])
    return ans

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

for i in range(0, N):
    f_nums = nums[:i]
    l_nums = nums[i+1:]
    f_nums.extend(l_nums)
    print(max(f_nums))

Fixed submission:
N = int(input())
nums = [int(input()) for i in range(N)]

_nums = sorted(nums, reverse=True)
max1 = _nums[0]
max2 = _nums[1]
for i in range(0, N):
    if nums[i] == max1:
        print(max2)
    else:
        print(max1)

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

for i in range(0, N):
    f_nums = nums[:i]
    l_nums = nums[i+1:]
    f_nums.extend(l_nums)
    print(max(f_nums))

Fixed submission:
N = int(input())
nums = [int(input()) for i in range(N)]

_nums = sorted(nums, reverse=True)
max1 = _nums[0]
max2 = _nums[1]
for i in range(0, N):
    if nums[i] == max1:
        print(max2)
    else:
        print(max1)

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

max_list = []
for i in range(0, N):
    f_nums = nums[:i]
    l_nums = nums[i+1:]
    f_nums.extend(l_nums)
    _max = max(f_nums)
    max_list.append(_max)

for x in max_list:
    print(x)
    




Fixed submission:
N = int(input())
nums = [int(input()) for i in range(N)]

_nums = sorted(nums, reverse=True)
max1 = _nums[0]
max2 = _nums[1]
for i in range(0, N):
    if nums[i] == max1:
        print(max2)
    else:
        print(max1)

Buggy python submission (verdict: Runtime Error):
N = int(input())
nums = [input() for i in range(N)]

max_list = []

for i in range(0, N):
    f_nums = nums[:i-1]
    l_nums = nums[i+1:]
    f_nums.extend(l_nums)
    _max = max(f_nums)
    max_list.append(_max)

for x in max_list:
    print(x)
    




Fixed submission:
N = int(input())
nums = [int(input()) for i in range(N)]

_nums = sorted(nums, reverse=True)
max1 = _nums[0]
max2 = _nums[1]
for i in range(0, N):
    if nums[i] == max1:
        print(max2)
    else:
        print(max1)
Buggy python submission (verdict: Runtime Error):
def nums (X,Y):
   B = (X*4-Y)/(4-2)
    D = X-B
    if B + D == X and Y == (B*2 + D*4):
          print("True")
    else:
           print("False")


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

a = (4*x - y)/2
b = (y-2*x)/2
if y % 2 == 0 and a >= 0 and b >= 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())

ans = {}
done = []
ac = 0
p = 0

for i in range(M):
    a,b = map(str, input().split())
    if not a in ans:
        ans[a] = 0
    if b == 'WA':
        ans[a] += 1
    if b == 'AC' and a not in done:
        ac += 1
        p += ans[a]
        ans[a] = 0
        done.append(a)

print(ac,p)

Fixed submission:
N,M = map(int, input().split())
ans = [0]*N
ac = 0
p = 0

for m in range(M):
    a,b = map(str, input().split())
    a = int(a) - 1

    if ans[a] != -1 and b == 'WA':
        ans[a] += 1
    if ans[a] != -1 and b == 'AC':
        ac += 1
        p += ans[a]
        ans[a] = -1

print(ac,p)
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())

A = [int(input()) for _ in range(M)]

lis = [0]*(N+1)
lis[0] = 1


for i in range(1,N+1):
    lis[i] = (lis[i-1] + lis[i-2])%(10**9+7)
    if i in A:
        lis[i] = 0

print(lis[N])



Fixed submission:

n,m = map(int, input().split())
a = set([int(input()) for i in range(m)])

dp = [0]*(n+1)
dp[0] = 1
for i in range(1,n+1):
    dp[i] = (dp[i-1] + dp[i-2]) % (10**9+7)
    if i in a:
        dp[i] = 0
print(dp[n])
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = str(input())
k = int(input())

a = []
for i in s:
    
    if i != s[k]:
        a.append('*')
    else:
        a.append(i)

print(*[i for i in a],sep='')

Fixed submission:
n = int(input())
s = str(input())
k = int(input())

a = []
for i in s:
    
    if i != s[k-1]:
        a.append('*')
    else:
        a.append(i)

print(*[i for i in a],sep='')

Buggy python submission (verdict: Runtime Error):

n = int(input())
s = str(input())
k = int(input())

a = []
for i in s:
    
    if i != s[k]:
        a.append('*')
    else:
        a.append(i)

print(*[i for i in a],sep='')

Fixed submission:
n = int(input())
s = str(input())
k = int(input())

a = []
for i in s:
    
    if i != s[k-1]:
        a.append('*')
    else:
        a.append(i)

print(*[i for i in a],sep='')
Buggy python submission (verdict: Runtime Error):
import sys

a,b = [input() for i in range(2)]

length = abs(len(a)-len(b))

for i in range(length+1):
    right_length = length - i
    temp = '?'*i+b+'?'*right_length
    
    #判定
    judge = 0
    for j in range(len(a)):
        if a[j] == temp[j] or temp[j] == '?':
            judge += 1
        elif temp[j] != '?' and a[j] == '?':
            judge += 1
    if judge == len(a):
        S = ''
        for k in range(len(temp)):
            if temp[k] == '?':
                S += a[k]
            else:
                S += temp[k]
        
        print(S.replace('?','a'))
        sys.exit()


print('UNRESTORABLE')


Fixed submission:
a = input()
b = input()

length = len(a) - len(b) + 1

ans = []
for i in range(length):
    A = list('?'*i+b+'?'*(length-i-1))
    flag = True
    for j in range(len(a)):
        if a[j] == '?' or a[j] == A[j]:
            pass
        elif a[j] != '?' and A[j] == '?':
            A[j] = a[j]
        else:
            flag = False
    if flag:
        ans.append(''.join(A).replace('?','a'))

if ans:
    ans.sort()
    print(ans[0])
else:
    print('UNRESTORABLE')

Buggy python submission (verdict: Runtime Error):
a,b = [input() for i in range(2)]

length = abs(len(a)-len(b))

for i in range(length+1):
    right_length = length - i
    temp = '?'*i+b+'?'*right_length
    
    #判定
    judge = 0
    for j in range(len(a)):
        if a[j] == temp[j] or temp[j] == '?':
            judge += 1
        elif temp[j] != '?' and a[j] == '?':
            judge += 1
    if judge == len(a):
        S = ''
        for k in range(len(temp)):
            if temp[k] == '?':
                S += a[k]
            else:
                S += temp[k]
        
        print(S.replace('?','a'))
        exit()

    else:
        continue

print('UNRESTORABLE')

Fixed submission:
a = input()
b = input()

length = len(a) - len(b) + 1

ans = []
for i in range(length):
    A = list('?'*i+b+'?'*(length-i-1))
    flag = True
    for j in range(len(a)):
        if a[j] == '?' or a[j] == A[j]:
            pass
        elif a[j] != '?' and A[j] == '?':
            A[j] = a[j]
        else:
            flag = False
    if flag:
        ans.append(''.join(A).replace('?','a'))

if ans:
    ans.sort()
    print(ans[0])
else:
    print('UNRESTORABLE')
Buggy python submission (verdict: Runtime Error):
2
6 8
3 3

Fixed submission:
n =int(input())

total = 0
for i in range(n):
    a = list(map(int, input().split()))
    total += a[1] - a[0] + 1

print(total)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

s = list(map(str, input().split()))


lis = []
for i in range(n):
    lis.append(s[i])
    lis = lis[::-1]

print(*lis)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
print(*A[::-2],*A[N%2::2])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

s = list(map(str, input().split()))


lis = []
for i in range(n):
    lis.append(s[i])
    lis = lis[::-1]

print(' '.join(lis))

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
print(*A[::-2],*A[N%2::2])
Buggy python submission (verdict: Runtime Error):
o,e = [input() for i in range(2)]

print(*[o[i]+e[i] for i in range(len(o))], sep='')

Fixed submission:

o = list(input())
e = list(input())+[""]

for x,y in zip(o,e):print(x+y,end='')
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):
    if A[i]+A[i+1] <= X:
        continue
    else:
        while A[i]+A[i+1] > X:
            if A[i+1] > 0:
                A[i+1] -= 1
                cnt += 1
            if A[i+1] == 0:
                break
        while A[i]+A[i+1] > X:
            if A[i] > 0:
                A[i] -= 1
                cnt += 1
            if A[i] == 0:
                break
    
print(cnt)

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

A = list(map(int, input().split()))
cnt = 0

for i in range(N-1):
    temp = 0
    if A[i]+A[i+1] <= X:
        continue
    else:
        temp = A[i]+A[i+1]-X
        if A[i+1] < temp:
            A[i+1] = 0
            cnt += A[i+1]
            temp -= A[i+1]
        else:
            A[i+1] -= temp
            cnt += temp
            temp -= A[i+1]

        if A[i]+A[i+1] > X:
            A[i] -= temp
            cnt += temp

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
NUM=[i for i in range(1,N+1)]
H=list(map(int, input().split()))
L_NUM=[x+y for (x,y) in zip(NUM,H)]
R_NUM=[x-y for (x,y) in zip(NUM,H)]

ANS=0
for i in L_NUM:
    ANS+=R_NUM.count(i)
print(ANS)

Fixed submission:
import collections
N=int(input())
NUM=[i for i in range(1,N+1)]
H=list(map(int, input().split()))
L_NUM=[x+y for (x,y) in zip(NUM,H)]
R_NUM=[x-y for (x,y) in zip(NUM,H)]

L_dict=collections.Counter(L_NUM)
R_dict=collections.Counter(R_NUM)

ANS=0
for i in L_dict.keys():
    cnt=L_dict[i]*R_dict[i]
    ANS+=cnt
print(ANS)
Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
A,B,N=map(int, input().split())
NUM=0
if N<B:
    NUM=math.floor(A*N/B)-A*math.floor(N/B)
    print(NUM)
    sys.exit()
else:
    if A>B:
        for x in range(N+1,math.floor(N/4),-1):
            TGT=math.floor(A*x/B)-A*math.floor(x/B)
            if TGT>NUM:
                NUM=TGT
    else:
        for x in range(1,math.floor(N/4)+1):
            TGT=math.floor(A*x/B)-A*math.floor(x/B)
            if TGT>NUM:
                NUM=TGT
print(NUM)

Fixed submission:
A,B,N = (map(int , input().split()))
min(B-1,N)
x = min(B-1,N)
print(((A*x)//B - A * (x//B)))

Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
A,B,N=map(int, input().split())
NUM=0
if N<B:
    NUM=math.floor(A*N/B)-A*math.floor(N/B)
    print(NUM)
    sys.exit()
else:
    if A>B:
        for x in range(N+1,math.floor(N/4),-1):
            TGT=math.floor(A*x/B)-A*math.floor(x/B)
            if TGT>NUM:
                NUM=TGT
    else:
        for x in range(1,math.floor(N/4)+1):
            TGT=math.floor(A*x/B)-A*math.floor(x/B)
            if TGT>NUM:
                NUM=TGT
print(NUM)

Fixed submission:
A,B,N = (map(int , input().split()))
min(B-1,N)
x = min(B-1,N)
print(((A*x)//B - A * (x//B)))

Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
A,B,N=map(int, input().split())
NUM=0
if N<B:
    NUM=math.floor(A*N/B)-A*math.floor(N/B)
    print(NUM)
    sys.exit()
else:
    if A>B:
        for x in range(N+1,math.floor(N/2),-1):
            TGT=math.floor(A*x/B)-A*math.floor(x/B)
            if TGT>NUM:
                NUM=TGT
    else:
        for x in range(1,math.floor(N/2)+1):
            TGT=math.floor(A*x/B)-A*math.floor(x/B)
            if TGT>NUM:
                NUM=TGT
print(NUM)

Fixed submission:
A,B,N = (map(int , input().split()))
min(B-1,N)
x = min(B-1,N)
print(((A*x)//B - A * (x//B)))

Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
A,B,N=map(int, input().split())
NUM=0
if N<B:
    NUM=math.floor(A*N/B)-A*math.floor(N/B)
    print(NUM)
    sys.exit()
for x in range(1,N+1):
    TGT=math.floor(A*x/B)-A*math.floor(x/B)
    if TGT>NUM:
        NUM=TGT
print(NUM)


Fixed submission:
A,B,N = (map(int , input().split()))
min(B-1,N)
x = min(B-1,N)
print(((A*x)//B - A * (x//B)))

Buggy python submission (verdict: Time Limit Exceeded):
import math
A,B,N=map(int, input().split())
NUM=0
for x in range(1,N+1):
    TGT=math.floor(A*x/B)-A*math.floor(x/B)
    if TGT>NUM:
        NUM=TGT
print(NUM)

Fixed submission:
A,B,N = (map(int , input().split()))
min(B-1,N)
x = min(B-1,N)
print(((A*x)//B - A * (x//B)))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
Boss=list(map(int, input().split()))
Boss.insert(0, 0)
for i in range(N):
    print(Boss.count(i+1))

Fixed submission:
import collections
N=int(input())
Boss=list(map(int, input().split()))
AA=collections.Counter(Boss)
for i in range(N):
    print(AA[i+1])
Buggy python submission (verdict: Runtime Error):
import  pandas as pd
N=list(range(1,int(input())+1))
df=pd.DataFrame(N,columns=["moto"])
df["3"]=df["moto"]%3
df["5"]=df["moto"]%5
print(df[(df['3']!=0) & (df['5']!=0)]["moto"].sum())

Fixed submission:
import numpy as np
N=list(range(1,int(input())+1))
a=np.asarray(N,dtype='int64')
b=a%3
c=a%5
d=np.array([a,b,c])
d=np.delete(d, np.where(d==0)[1], axis=1)
print(np.sum(d[0]))
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
K=int(input())
tgt=0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            tgt+=gcd(i, j, k)
print(tgt)

Fixed submission:
from math import gcd
K=int(input())
K1=K+1
tgt=0
for i in range(1,K1):
    for j in range(1,K1):
        for k in range(1,K1):
            tgt+=gcd(gcd(i, j), k)
print(tgt)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
ans=S.count("R")*S.count("G")*S.count("B")
for i in range(0,N-2):
    for j in range(i+1,N-1):
        try:
            if S[i]!=S[j] and S[j]!=S[2*j-i] and S[i]!=S[2*j-i]:
                ans-=1
        except:
            continue
print(ans)

Fixed submission:
N=int(input())
S=input()
ans=S.count("R")*S.count("G")*S.count("B")
for i in range(0,N-2):
    for j in range(i+1,N-1):
        if 2*j-i<N:
            if S[i]!=S[j] and S[j]!=S[2*j-i] and S[i]!=S[2*j-i]:
                ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
R=S.count("R")
G=S.count("G")
B=S.count("B")
ans=R*G*B
for i in range(0,N-2):
    for j in range(i+1,N-1):
        try:
            if S[i]!=S[j] and S[j]!=S[2*j-i] and S[i]!=S[2*j-i]:
                ans-=1
        except:
            continue
print(ans)

Fixed submission:
N=int(input())
S=input()
ans=S.count("R")*S.count("G")*S.count("B")
for i in range(0,N-2):
    for j in range(i+1,N-1):
        if 2*j-i<N:
            if S[i]!=S[j] and S[j]!=S[2*j-i] and S[i]!=S[2*j-i]:
                ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
Target=0
for i in range(0,N-2):
    A=S[i]
    for j in range(i+1,N-1):
        if S[j]!=S[i]:
            for k in range(j+1,N):
                if S[k]!=S[j] and S[k]!=S[i]:
                    if j-i!=k-j:
                        Target+=1
print(Target)

Fixed submission:
N=int(input())
S=input()
ans=S.count("R")*S.count("G")*S.count("B")
for i in range(0,N-2):
    for j in range(i+1,N-1):
        if 2*j-i<N:
            if S[i]!=S[j] and S[j]!=S[2*j-i] and S[i]!=S[2*j-i]:
                ans-=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
X,Y,A,B,C=map(int, input().split())
AA=list(map(int, input().split()))
BB=list(map(int, input().split()))
CC=list(map(int, input().split()))
AA=sorted(AA,reverse=True)
BB=sorted(BB,reverse=True)
CC=sorted(CC,reverse=True)
AAA=AA[0:X]
BBB=BB[0:Y]
for i in CC:
    if i>min(AAA)or i>min(BBB):
        if min(AAA)>min(BBB):
            BBB[-1]=i
            BBB=sorted(BBB,reverse=True)
        else:
            AAA[-1]=i
            AAA=sorted(AAA,reverse=True)
    else:
        break
print(sum(AAA)+sum(BBB))

Fixed submission:
X,Y,A,B,C=map(int, input().split())
AA=list(map(int, input().split()))
BB=list(map(int, input().split()))
CC=list(map(int, input().split()))
AA=sorted(AA,reverse=True)
BB=sorted(BB,reverse=True)
CC=sorted(CC,reverse=True)
XX=sorted(AA[0:X]+BB[0:Y]+CC,reverse=True)
XX=XX[0:X+Y]
print(sum(XX))

Buggy python submission (verdict: Time Limit Exceeded):
X,Y,A,B,C=map(int, input().split())
AA=list(map(int, input().split()))
BB=list(map(int, input().split()))
CC=list(map(int, input().split()))
AA=sorted(AA,reverse=True)
BB=sorted(BB,reverse=True)
CC=sorted(CC,reverse=True)
AAA=AA[0:X]
BBB=BB[0:Y]
for i in CC:
    if i>min(AAA)or i>min(BBB):
        if min(AAA)>min(BBB):
            BBB[-1]=i
            BBB=sorted(BBB,reverse=True)
        if min(BBB)>min(AAA):
            AAA[-1]=i
            AAA=sorted(AAA,reverse=True)
    else:
        break
print(sum(AAA)+sum(BBB))


Fixed submission:
X,Y,A,B,C=map(int, input().split())
AA=list(map(int, input().split()))
BB=list(map(int, input().split()))
CC=list(map(int, input().split()))
AA=sorted(AA,reverse=True)
BB=sorted(BB,reverse=True)
CC=sorted(CC,reverse=True)
XX=sorted(AA[0:X]+BB[0:Y]+CC,reverse=True)
XX=XX[0:X+Y]
print(sum(XX))
Buggy python submission (verdict: Runtime Error):
N,M=map(int, input().split())
A=N*(N-1)/2
B=M*(M-1)/2
printint((A+B)

Fixed submission:
import math
N,M=map(int, input().split())
def comb(N, r):
    return math.factorial(N) // (math.factorial(N - r) * math.factorial(r))
try :
    base = comb(N,2)
except:
    base=0
def comb2(M, r):
    return math.factorial(M) // (math.factorial(M - r) * math.factorial(r))
try:
    base2 = comb2(M,2)
except:
    base2=0

print(base+base2)

Buggy python submission (verdict: Runtime Error):
import math

num=int(input())
target=list(map(int, input().split()))
def comb(N, r):
    return math.factorial(N) // (math.factorial(N - r) * math.factorial(r))

for i in range(num):
    A=target.copy()
    A.pop(i)
    B=[x for x in set(A) if A.count(x) > 1]
    out=0 
    for j in B:
        base = comb(A.count(j),2)
        out=out+base
    print(out)
        

Fixed submission:
import math
N,M=map(int, input().split())
def comb(N, r):
    return math.factorial(N) // (math.factorial(N - r) * math.factorial(r))
try :
    base = comb(N,2)
except:
    base=0
def comb2(M, r):
    return math.factorial(M) // (math.factorial(M - r) * math.factorial(r))
try:
    base2 = comb2(M,2)
except:
    base2=0

print(base+base2)
Buggy python submission (verdict: Time Limit Exceeded):
import math
num=int(input())
target=list(map(int, input().split()))

def comb(N, r):
    return math.factorial(N) // (math.factorial(N - r) * math.factorial(r))

for i in range(num):
    A=target.copy()
    A.pop(i)
    out=0
    for j in set(A):
        if A.count(j)>1:
            base = comb(A.count(j),2)
            out=out+base
    print(out)

Fixed submission:
import collections
n = int(input())
arr = list(map(int, input().split()))
cnt = collections.Counter(arr)
total = 0
for i in cnt.keys():
  patern = cnt[i]*(cnt[i]-1)//2
  total += patern
for j in range(n):
  tmp = total
  total -= cnt[arr[j]]*(cnt[arr[j]]-1)//2
  total += (cnt[arr[j]]-1)*(cnt[arr[j]]-2)//2
  print(total)
  total = tmp

Buggy python submission (verdict: Runtime Error):
import math
def comb(N, r):
    return math.factorial(N) // (math.factorial(N - r) * math.factorial(r))

for i in range(num):
    A=target.copy()
    A.pop(i)
    out=0
    for j in set(A):
        if A.count(j)>1:
            base = comb(A.count(j),2)
            out=out+base
    print(out)

Fixed submission:
import collections
n = int(input())
arr = list(map(int, input().split()))
cnt = collections.Counter(arr)
total = 0
for i in cnt.keys():
  patern = cnt[i]*(cnt[i]-1)//2
  total += patern
for j in range(n):
  tmp = total
  total -= cnt[arr[j]]*(cnt[arr[j]]-1)//2
  total += (cnt[arr[j]]-1)*(cnt[arr[j]]-2)//2
  print(total)
  total = tmp

Buggy python submission (verdict: Time Limit Exceeded):
import math
 
num=int(input())
target=list(map(int, input().split()))
def comb(N, r):
    return math.factorial(N) // (math.factorial(N - r) * math.factorial(r))
 
for i in range(num):
    A=target.copy()
    A.pop(i)
    out=0
    for j in set(A):
        try :
            base = comb(A.count(j),2)
        except:
            base=0
        out=out+base
    print(out)

Fixed submission:
import collections
n = int(input())
arr = list(map(int, input().split()))
cnt = collections.Counter(arr)
total = 0
for i in cnt.keys():
  patern = cnt[i]*(cnt[i]-1)//2
  total += patern
for j in range(n):
  tmp = total
  total -= cnt[arr[j]]*(cnt[arr[j]]-1)//2
  total += (cnt[arr[j]]-1)*(cnt[arr[j]]-2)//2
  print(total)
  total = tmp

Buggy python submission (verdict: Time Limit Exceeded):
import math

num=int(input())
target=list(map(int, input().split()))
def comb(N, r):
    return math.factorial(N) // (math.factorial(N - r) * math.factorial(r))

for i in range(num):
    A=target.copy()
    A.pop(i)
    out=0
    for j in set(A):
        try :
            base = comb(A.count(j),2)
        except:
            base=0
        out=out+base
    print(out)

Fixed submission:
import collections
n = int(input())
arr = list(map(int, input().split()))
cnt = collections.Counter(arr)
total = 0
for i in cnt.keys():
  patern = cnt[i]*(cnt[i]-1)//2
  total += patern
for j in range(n):
  tmp = total
  total -= cnt[arr[j]]*(cnt[arr[j]]-1)//2
  total += (cnt[arr[j]]-1)*(cnt[arr[j]]-2)//2
  print(total)
  total = tmp