Buggy python submission (verdict: Runtime Error):
import copy
import collections
import math
import sys
import numpy as np

def combinations_count(n, r):
    if n <= 1:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = [int(i) for i in input().split()] 

bigC = collections.Counter(A)
vals = np.array(list(bigC.values()))
if (vals >= 2).any() == False:
  for _ in range(N):
    print(0)
  sys.exit()

maxnum = max(A)
lis = [-1] * maxnum
for i, a in enumerate(A):
  if lis[a-1] < 0:
    newA = copy.deepcopy(A)
    newA.pop(i)
    c = collections.Counter(newA)
    total = 0
    for idx in c:
      total += combinations_count(c[idx], 2)
      
    lis[a-1] = total
    for x in bigC:
      if bigC[x] == bigC[a]:
        lis[x-1] = total
    print(total)
  else:
    print(lis[a-1])
    
  

Fixed submission:
import copy
import collections
import math
 
N = int(input())
A = [int(i) for i in input().split()] 
 
maxnum = max(A)
lis = [-1] * maxnum
bigC = collections.Counter(A)
for i, a in enumerate(A):
  if lis[a-1] < 0:
    newA = copy.deepcopy(A)
    newA.pop(i)
    c = collections.Counter(newA)
    total = 0
    for idx in c:
      num = c[idx]
      total += num * (num-1) // 2
      
    lis[a-1] = total
    for x in bigC:
      if bigC[x] == bigC[a]:
        lis[x-1] = total
      
    print(total)
  else:
    print(lis[a-1])

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

def combinations_count(n, r):
    if n <= 1:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = [int(i) for i in input().split()] 

maxnum = max(A)
lis = [-1] * maxnum
bigC = collections.Counter(A)
for i, a in enumerate(A):
  if lis[a-1] < 0:
    newA = copy.deepcopy(A)
    newA.pop(i)
    c = collections.Counter(newA)
    total = 0
    for idx in c:
      total += combinations_count(c[idx], 2)
      
    lis[a-1] = total
    for x in bigC:
      if bigC[x] == bigC[a]:
        lis[x-1] = total
      
    print(total)
  else:
    print(lis[a-1])
    
  

Fixed submission:
import copy
import collections
import math
 
N = int(input())
A = [int(i) for i in input().split()] 
 
maxnum = max(A)
lis = [-1] * maxnum
bigC = collections.Counter(A)
for i, a in enumerate(A):
  if lis[a-1] < 0:
    newA = copy.deepcopy(A)
    newA.pop(i)
    c = collections.Counter(newA)
    total = 0
    for idx in c:
      num = c[idx]
      total += num * (num-1) // 2
      
    lis[a-1] = total
    for x in bigC:
      if bigC[x] == bigC[a]:
        lis[x-1] = total
      
    print(total)
  else:
    print(lis[a-1])

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

def combinations_count(n, r):
    if n <= 1:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = [int(i) for i in input().split()] 

maxnum = max(A)
lis = [-1] * maxnum
bigC = collections.Counter(A)
for i, a in enumerate(A):
  if lis[a-1] < 0:
    newA = copy.deepcopy(A)
    newA.pop(i)
    c = collections.Counter(newA)
    total = 0
    for idx in c:
      total += combinations_count(c[idx], 2)
      
    lis[a-1] = total
    for x in bigC:
      if bigC[x] == bigC[a]:
        lis[x-1] = total
      
    print(total)
  else:
    print(lis[a-1])
    
  

Fixed submission:
import copy
import collections
import math
 
N = int(input())
A = [int(i) for i in input().split()] 
 
maxnum = max(A)
lis = [-1] * maxnum
bigC = collections.Counter(A)
for i, a in enumerate(A):
  if lis[a-1] < 0:
    newA = copy.deepcopy(A)
    newA.pop(i)
    c = collections.Counter(newA)
    total = 0
    for idx in c:
      num = c[idx]
      total += num * (num-1) // 2
      
    lis[a-1] = total
    for x in bigC:
      if bigC[x] == bigC[a]:
        lis[x-1] = total
      
    print(total)
  else:
    print(lis[a-1])

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

def combinations_count(n, r):
    if n <= 1:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = [int(i) for i in input().split()] 

maxnum = max(A)
lis = [-1] * maxnum
bigC = collections.Counter(A)
for i, a in enumerate(A):
  if lis[a-1] < 0:
    newA = copy.deepcopy(A)
    newA.pop(i)
    c = collections.Counter(newA)
    total = 0
    for idx in c:
      total += combinations_count(c[idx], 2)
      
    lis[a-1] = total
    for x in bigC:
      if bigC[x] == bigC[a]:
        lis[x-1] = total
      
    print(total)
  else:
    print(lis[a-1])
    
  

Fixed submission:
import copy
import collections
import math
 
N = int(input())
A = [int(i) for i in input().split()] 
 
maxnum = max(A)
lis = [-1] * maxnum
bigC = collections.Counter(A)
for i, a in enumerate(A):
  if lis[a-1] < 0:
    newA = copy.deepcopy(A)
    newA.pop(i)
    c = collections.Counter(newA)
    total = 0
    for idx in c:
      num = c[idx]
      total += num * (num-1) // 2
      
    lis[a-1] = total
    for x in bigC:
      if bigC[x] == bigC[a]:
        lis[x-1] = total
      
    print(total)
  else:
    print(lis[a-1])

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

def combinations_count(n, r):
    if n <= 1:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = [int(i) for i in input().split()] 

maxnum = max(A)
lis = [-1] * maxnum

for i, a in enumerate(A):
  if lis[a-1] < 0:
    newA = copy.deepcopy(A)
    newA.pop(i)
    c = collections.Counter(newA)
    total = 0
    for idx in c:
      total += combinations_count(c[idx], 2)
      
    lis[a-1] = total
    print(total)
  else:
    print(lis[a-1])
    
  

Fixed submission:
import copy
import collections
import math
 
N = int(input())
A = [int(i) for i in input().split()] 
 
maxnum = max(A)
lis = [-1] * maxnum
bigC = collections.Counter(A)
for i, a in enumerate(A):
  if lis[a-1] < 0:
    newA = copy.deepcopy(A)
    newA.pop(i)
    c = collections.Counter(newA)
    total = 0
    for idx in c:
      num = c[idx]
      total += num * (num-1) // 2
      
    lis[a-1] = total
    for x in bigC:
      if bigC[x] == bigC[a]:
        lis[x-1] = total
      
    print(total)
  else:
    print(lis[a-1])