TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
def resolve():
    n = int(input())
    a = tuple(map(int,input().split()))
    A = collections.Counter(a)
    cnt_0 = 0
    for i in A.values():
        cnt_0 += int(i*(i-1)/2)
    for i in a:
        cnt_1 = A[i]-1
        print(cnt_0-cnt_1)
resolve()

import collections
def resolve():
    n = int(input())
    a = tuple(map(int,input().split()))
    A = collections.Counter(a)
    cnt_0 = 0
    for i in A.values():
        cnt_0 += int(i*(i-1)/2)
    for i in a:
        cnt_1 = A[i]-1
        print(cnt_0-cnt_1)
resolve()

Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))
dic1 = {}
dic2 = {}
for i in range(N):
  if A[i] in dic1:
    dic1[A[i]] += 1
    dic2[A[i]].append(i)
  else:
    dic1[A[i]] = 1
    dic2[A[i]].append(i)

for j in range(N):
  ans = 0
  for k, v in dic1.items():
    if j in dic2[k]:
      ans += ((v-1)*(v-2))//2
    else:
      ans += (v*(v-1))//2
  print(ans)

N = int(input())
A = list(map(int, input().split()))
dic1 = {}
dic2 = {}
for i in range(N):
  if A[i] in dic1:
    dic1[A[i]] += 1
  else:
    dic1[A[i]] = 1
ans = 0
for v in dic1.values():
  ans += (v*(v-1))//2
for j in range(N):
  w = dic1[A[j]]
  v = w-1
  comb = ans -(w*(w-1))//2 + (v*(v-1))//2
  print(comb)


Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import math

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)

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

dic = {}
for i in range(N):
  if A[i] in dic:
    dic[A[i]] += 1
  else:
    dic[A[i]] = 1

memo = 
ans = 0
for k in dic:
  tmp  =dic[k]
  if tmp >= 2:
    memo[k] = C(tmp, 2)
    ans += memo[k]

for i in range(N):
  tmp = dic[A[i]]
  if tmp == 1:
    print(ans)
  elif tmp == 2:
    print(ans - 1)
  else
    print(ans - (memo[A[i]] - C(tmp-1, 2)))


import math

def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)

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

dic = {}
for i in range(N):
  if A[i] in dic:
    dic[A[i]] += 1
  else:
    dic[A[i]] = 1

memo = [0 for i in range(10 ** 6)]
ans = 0
for k in dic:
  tmp  =dic[k]
  if tmp >= 2:
    if memo[tmp] == 0:
      memo[tmp] = C(tmp, 2)
      ans += memo[tmp]
    else:
      ans += memo[tmp]

for i in range(N):
  tmp = dic[A[i]]
  if tmp == 1:
    print(ans)
  elif tmp == 2:
    print(ans - 1)
  else:
    print(ans)


import math

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

dic = {}
for i in range(N):
  if A[i] in dic:
    dic[A[i]] += 1
  else:
    dic[A[i]] = 1

memo = [0 for i in range(10 ** 6)]
ans = 0
for k in dic:
  tmp  =dic[k]
  if tmp >= 2:
    if memo[tmp] == 0:
      memo[tmp] = tmp * (tmp - 1) // 2
      ans += memo[tmp]
    else:
      ans += memo[tmp]

for i in range(N):
  tmp = dic[A[i]]
  if tmp == 1:
    print(ans)
  elif tmp == 2:
    print(ans - 1)
  else:
    print(ans - tmp * (tmp - 1) // 2 + (tmp - 1) * (tmp - 2) // 2)




Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
N = int(input())
A = list(map(int,input().split()))

ans = [-1] * N

for A_ in range(len(A)):
    K = A[A_]
    for B_ in range(len(A)):
        if K == A[B_]:
            ans[A_] += 1
    print(ans[A_])


N = int(input())
A = list(map(int, input().split()))
CNT = [0] * (N+1)

for i in A:
    CNT[i] += 1

CONB = [CNT[j]*(CNT[j]-1)//2 for j in range(len(CNT))]

SUM = sum(CONB)
for i in A:
    ans = SUM - CNT[i] + 1
    print(ans)


Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from scipy.misc import comb

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

K = {}
for row in A:
    if row in K:
        K[row] += 1
    else:
        K[row] = 1


D = {}
for row in A:
    ans = 0
    if row not in D:
        for i in K:
            if i == row:
                ans += comb(K[i]-1, 2, exact=True)
            else:
                ans += comb(K[i], 2, exact=True)
        D[row] = int(ans)
        print(D[row])
    else:
        print(D[row])

from scipy.misc import comb

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

K = {}
for row in A:
    if row in K:
        K[row] += 1
    else:
        K[row] = 1


D = {}
C = {}
for row in A:
    ans = 0
    if row not in D:
        for i in K:
            tmp = 0
            if i == row:
                tmp = K[i]-1
            else:
                tmp = K[i]
            if tmp not in C:
                ans += comb(tmp, 2, exact=True)
            else:
                ans += C[tmp]
        D[row] = int(ans)
        print(D[row])
    else:
        print(D[row])


from scipy.misc import comb

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

K = {}
for row in A:
    if row in K:
      K[row] += 1
    else:
      K[row] = 1


for row in A:
    ans = 0
    for i in K:
        if i == row:
            ans += comb(K[i]-1,2,exact=True)
        else:
            ans += comb(K[i],2,exact=True)
    print(int(ans))


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

K = {}
for row in A:
  if row in K:
    K[row] += 1
  else:
    K[row] = 1
        

max = 0
for i in K:
  max += int(K[i]*(K[i]-1)/2)


for i in A:
  print(max - int(K[i]*(K[i]-1)/2) + int((K[i]-1)*(K[i]-2)/2) )

Verdicts: Time Limit Exceeded

Time Limit Exceeded

Time Limit Exceeded

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
N=int(input())
A=list(map(int,input().split()))
dic={}
for i in set(A):
  dic[i]=A.count(i) 
def ans(k,dic):
  dic[A[k-1]]+=-1
  c=0
  for i in dic.values():
    c+=i*(i-1)/2
  dic[A[k-1]]+=1  
  return int(c)
for k in range(1,N+1):

N=int(input())
A=list(map(int,input().split()))
dic={}
for a in A:
  if a in dic:
    dic[a]+=1
  else:
    dic[a]=1
   
print(dic)
c=0
for i in dic.values():
  c+=i*(i-1)/2
for j in range(1,N+1):
  d=c-dic[A[j-1]]+1
  print(int(d))
  

n=int(input())
cnt=[0]*(n+1)
a=list(map(int,input().split()))
for i in range(n):
  cnt[a[i]]+=1 
ans=0  
for i in range(1,n+1):
  if cnt[i]>=1:
    ans+=cnt[i]*(cnt[i]-1)//2
for i in range(n):
  print(ans-cnt[a[i]]+1)
  

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import math

def combinations_count(n, memo_fact):
    return memo_fact[n] // (memo_fact[n - 2] * 2)

n = int(input())
a = list(map(int,input().split()))
print(len(a))
n_list = [0 for i in range(n)]
len_list = [0 for i in range(n)]

memo_fact = [1]

for i in range(1, n+1):
    memo_fact.append(memo_fact[i-1]*i)

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

sum_len = 0

for i in range(n):
    if n_list[i] == 0:
        len_list[i] == 0
    elif n_list[i] == 1:
        len_list[i] == 1
    else:
        len_list[i] = combinations_count(n_list[i], memo_fact)
    sum_len += len_list[i]

for i in range(n):
    if len_list[a[i]-1] == 0:
        print(sum_len)
    elif len_list[a[i]-1] == 1 or len_list[a[i]-1] == 2:
        print(sum_len - 1)
    else:
        print(sum_len - len_list[a[i]-1] + combinations_count(n_list[a[i]-1] - 1, memo_fact))


import math

def combinations_count(n):
    return math.factorial(n) / (math.factorial(n - 2) * math.factorial(2))

n = int(input())
a = list(map(int,input().split()))
n_list = [[] for i in range(n)]
len_list = [0 for i in range(n)]

for i in range(n):
    n_list[a[i]-1].append(i)

for i in range(n):
    if len(n_list[i]) == 0:
        len_list[i] == 0
    elif len(n_list[i]) == 1:
        len_list[i] == 1
    else:
        len_list[i] = combinations_count(len(n_list[i]))

sum_len = sum(len_list)
ans_list = [sum_len for i in range(n)]

for i in range(n):
    if len_list[a[i]-1] == 0:
        continue
    elif len_list[a[i]-1] == 1:
        ans_list[i] = ans_list[i] - 1
    elif len_list[a[i]-1] == 2:
        ans_list[i] = ans_list[i] - 1
    else:
        ans_list[i] = ans_list[i] - len_list[a[i]-1] + combinations_count(len(n_list[a[i]-1]) - 1)

for i in range(n):
    print(ans_list[i])


import math

def combinations_count(n):
    return math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))

n = int(input())
a = list(map(int,input().split()))
n_list = [0 for i in range(n)]
len_list = [0 for i in range(n)]

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

sum_len = 0

for i in range(n):
    if n_list[i] == 0:
        len_list[i] == 0
    elif n_list[i] == 1:
        len_list[i] == 1
    else:
        len_list[i] = combinations_count(n_list[i])
    sum_len += len_list[i]

for i in range(n):
    if len_list[a[i]-1] == 0:
        print(sum_len)
    elif len_list[a[i]-1] == 1 or len_list[a[i]-1] == 2:
        print(sum_len - 1)
    else:
        print(sum_len - (n_list[a[i]-1] - 1))


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))
l=[0]*(n)
l1=[0]*(n)
for i in range(n):
    l[a[i]-1]+=1
    
for i in range(n):
    if l[i]>=2:
        l1[i]+=(l[i]*(l[i]-1))//2

l1sum=sum(l1)
for i in range(n):
    if l[a[i]-1]-1>=2:print(l1sum-l1[a[i]-1]+(l[a[i]-1]-1 * l[a[i]-1]-2)//2)
    else:print(l1sum-l1[a[i]-1])

n=int(input())
a=list(map(int,input().split()))
l=[0]*(n)
l1=[0]*(n)
for i in range(n):
    l[a[i]-1]+=1
    
for i in range(n):
    if l[i]>=2:
        l1[i]+=(l[i]*(l[i]-1))//2

l1sum=sum(l1)
for i in range(n):
    if l[a[i]-1]-1>=2:print(l1sum-l1[a[i]-1]+(l[i]*(l[i]-1))//2)
    else:print(l1sum-l1[a[i]-1])

n=int(input())
a=list(map(int,input().split()))
l=[0]*(n)
l1=[0]*(n)
for i in range(n):
    l[a[i]-1]+=1
    
def combinations_count(n,r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

for i in range(n):
    if l[i]>=2:
        l1[i]+=combinations_count(l[i],2)

l1sum=sum(l1)
for i in range(n):
    if l[a[i]-1]-1>=2:print(l1sum-l1[a[i]-1]+combinations_count(l[a[i]-1]-1,2))
    else:print(l1sum-l1[a[i]-1])

n=int(input())
a=list(map(int,input().split()))
l=[0]*(n)
l1=[0]*(n)
for i in range(n):
    l[a[i]-1]+=1
    
for i in range(n):
    if l[i]>=2:
        l1[i]+=l[i]*(l[i]-1)//2

l1sum=sum(l1)
for i in range(n):
    if l[a[i]-1]-1>=2:print(l1sum-l1[a[i]-1]+ (l[a[i]-1]-1)*(l[a[i]-1]-2)//2)
    else:print(l1sum-l1[a[i]-1])

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
def f(n):
  return (n*(n-1))//2
N=int(input())
A=list(map(int,input().split()))
d=dict()
ans=0

for i in range(len(A)):
  if A[i] not in d:
    d[i]=0
  d[i]+=1
for i in d:
  ans+=f(d[i])
for i in range(len(A)):
  print(ans-d[A[i]]-1)

def f(n):
  return (n*(n-1))//2
N=int(input())
A=list(map(int,input().split()))
d=dict()
ans=0

for i in range(len(A)):
  if A[i] not in d:
    d[A[i]]=0
  d[A[i]]+=1
for i in d:
  ans+=f(d[i])
for i in range(len(A)):
  print(ans-d[A[i]]+1)

Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import math
n = int(input())
a = list(map(int, input().split()))


for i in range(len(a)):
    rem_k = a[:i] + a[i + 1:]
    
    cho = []
    for j in rem_k:
        if rem_k.count(j) >= 2:
            cho.append(j)
    # print(rem_k)
    for i in cho:
        if rem_k.count(i) - 2 < 0:
            ans = 0
        else:
            ans =  math.factorial(rem_k.count(i)) // (math.factorial(rem_k.count(i) - 2) * math.factorial(2))

    print(ans)


from collections import Counter

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


cnt = 0
for v in cl.values():
    cnt += v * (v - 1) // 2 

for i in l:
    v = cl[i]
    ans = cnt - (v * (v - 1) // 2) + (v - 1) * (v - 2) // 2
    print(ans)


Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
A = [int(i) for i in input().split()]
from collections import Counter
a = Counter(A)

for i in A:
    t = 0
    for k in a.keys():
        c = a[k]
        if k == i:
            c -= 1
        t += (c * (c-1)) // 2
    print(t)    

N = int(input())
A = [int(i) for i in input().split()]
from collections import Counter
a = Counter(A)

T = 0
for k in a.keys():
    c = a[k]
    T += (c * (c-1)) // 2

for i in A:
    t = 0
    c = a[i]
    t = T
    t -= (c * (c-1)) // 2
    c -= 1
    t += (c * (c-1)) // 2
    print(t)

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
def choose2(n):
    return n * (n - 1) // 2

a = int(input())
A = list(map(int, input().split()))  
d = {}
for k in A:
  if k in d:
    d[k] += 1
  else:
    d[k] = 1
 
res = 0
for k in d.values():
  res += choose2(k, 2)

for k in A:
  temp = res
  m = d[k]
  temp -= choose2(m, 2, mod)

  d[k] -= 1
  temp += choose2(d[k], 2, mod)
  print(temp)
  d[k] += 1


def choose2(n):
    return n * (n - 1) // 2

a = int(input())
A = list(map(int, input().split()))  
d = {}
for k in A:
  if k in d:
    d[k] += 1
  else:
    d[k] = 1
 
res = 0
for k in d.values():
  res += choose2(k)

for k in A:
  temp = res
  m = d[k]
  temp -= choose2(m)

  d[k] -= 1
  temp += choose2(d[k])
  print(temp)
  d[k] += 1


Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
ans = {}
for k in cnt.keys():
    ans[k] = (cnt[k] * cnt[k]-1) // 2
s = sum(list(ans.values()))
for ai in a:
    if ai == 1:
        print(s)
    else:
        print(s - ans[ai] + (ans[ai] / cnt[ai]) * (cnt[ai] - 2))

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
ans = {}
for k in cnt.keys():
    ans[k] = (cnt[k] * cnt[k]-1) // 2
s = sum(list(ans.values()))
for ai in a:
    if cnt[ai] == 1:
        print(s)
    else:
        print(s - ans[ai] + (ans[ai] / cnt[ai]) * (cnt[ai] - 2))

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
ans = {}
for k in cnt.keys():
    ans[k] = (cnt[k] * (cnt[k]-1)) // 2
s = sum(list(ans.values()))
for ai in a:
    if cnt[ai] == 1:
        print(s)
    else:
        print(s - ans[ai] + int((ans[ai] / cnt[ai]) * (cnt[ai] - 2)))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
# -*- coding: utf-8 -*-
import numpy as np 
import math


N = int(input())
A = input()

A = np.array(A.split()).astype('int')
ones = np.ones([N, N])
B = (A*ones)
for i in range(N):
  B[i, i] = 0
B = B[np.where(B != 0, True, False)].reshape(N, N-1)
B.sort()

def comb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
      
def uniq_2_comb(N, ar):
  u = np.unique(ar, return_index=True)[1]
  ans = 0
  for i in range(len(u)-1):
    n = u[i+1] - u[i]
    ans += comb(n, 2)
  return ans

ans_ar = np.apply_along_axis(lambda x : uniq_2_comb(N, x), 1, B)

for ans in ans_ar:
  print(ans)

# -*- coding: utf-8 -*-
import numpy as np 
import math


N = int(input())
A = input()

A = np.array(A.split()).astype('int')
ones = np.ones([N, N])
B = (A*ones)
for i in range(N):
  B[i, i] = 0
B = B[np.where(B != 0, True, False)].reshape(N, N-1)
B.sort()

def comb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
      
def uniq_2_comb(N, ar):
  u = np.unique(ar, return_index=True)[1]
  u = np.concatenate([u, np.array([N])])
  ans = 0
  for i in range(len(u)-1):
    n = u[i+1] - u[i]
    ans += comb(n, 2)
  return ans

ans_ar = np.apply_along_axis(lambda x : uniq_2_comb(N, x), 1, B)

for ans in ans_ar:
  print(ans)


# -*- coding: utf-8 -*-
import collections
import math


N = int(input())
A = list(input().split())

c = collections.Counter(A)

def comb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

comb_sum = 0
for i in c:
    comb_sum += comb(c[i], 2)
     
for a in A:
    ans = comb_sum
    if c[a] >= 2:
        ans -= (c[a] - 1)
    print(ans)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from collections import Counter
N = int(input())
An = list(map(int, input().split()))
counter = Counter(An)
cnt = 0
for c in counter.values():
    cnt += c * c-1 // 2
for a in An:
    print(int(cnt - (counter[a] - 1)))


from collections import Counter
from scipy.misc import comb
N = int(input())
An = list(map(int, input().split()))
counter = Counter(An)
cnt = 0
for c in counter.values():
    cnt += comb(c, 2)
for a in An:
    print(int(cnt - comb(counter[a], 2) + comb(counter[a]-1, 2)))


from collections import Counter
N = int(input())
An = list(map(int, input().split()))
counter = Counter(An)
cnt = 0
for c in counter.values():
    cnt += c * c-1 // 2
for a in An:
    print(cnt - (counter[a] - 1))


from collections import Counter
N = int(input())
An = list(map(int, input().split()))
counter = Counter(An)
cnt = 0
for c in counter.values():
    cnt += c * (c-1) // 2
for a in An:
    print(cnt - (counter[a] - 1))


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from collections import OrderedDict
N = int(input())
A = list(map(int, input().split()))

ball_values = OrderedDict()
for val in A:
  if val not in ball_values:
    ball_values[val] = 1
  else:
    ball_values[val] += 1
# get total pairs of all balls
total_possible_combos = sum(item[1]*(item[1]-1)//2 for item in ball_values.items())
# for each k, take away the loss of pairs due to removing it
k_outputs = [total_possible_combos-(ball_values[val]-1) for val in A]
print(k_outputs)

from collections import OrderedDict
N = int(input())
A = list(map(int, input().split()))

ball_values = OrderedDict()
for val in A:
  if val not in ball_values:
    ball_values[val] = 1
  else:
    ball_values[val] += 1
# get total pairs of all balls
total_possible_combos = sum(item[1]*(item[1]-1)//2 for item in ball_values.items())
# for each k, take away the loss of pairs due to removing it
k_outputs = [total_possible_combos-(ball_values[val]-1) for val in A]
[print(value) for value in k_outputs]

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import collections
n=int(input())
a = list(map(int,input().split()))
b = collections.Counter(a)
c = list()
for i in range(1,n+1):
    c.append(int((b[i]*(b[i]-1))/2))
print(c)
for i in range(n):
    d = int(a[i]-1)
    if c[d]>2:
        e = sum(c) - c[d] + int( (c[d])*(b[d+1]-2) /(b[d+1]) )
    else:
        e = sum(c) - c[d]
    print(e)

import collections
n=int(input())
a = list(map(int,input().split()))
b = collections.Counter(a)
c = list()
for i in range(1,n+1):
    c.append(int((b[i]*(b[i]-1))/2))

sum = sum(c)
for i in range(n):
    d = int(a[i]-1)
    if c[d]>2:
        e = sum - c[d] + int( (c[d])*(b[d+1]-2) /(b[d+1]) )
    else:
        e = sum - c[d]
    print(e)

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from scipy.misc import comb

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

print(int(comb(N, 2) + comb(M, 2)))


from scipy.misc import comb

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

for k, val in enumerate(A):
    count = 0
    nums = [0] * N
    for i, v in enumerate(A):
        if k == i:
            continue
        nums[v] += 1
    combs = list(map(lambda n: int(comb(n, 2)), nums))
    print(sum(combs))

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


def comb2(n):
    return n * (n - 1) // 2


counts = [0] * (N + 1)
for a in A:
    counts[a] += 1
total = sum(map(comb2, filter(lambda n: n > 1, counts)))

for a in A:
    print(total - (counts[a] - 1))


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
N=int(input())
a=list(map(int,input().split()))
b=[0]*N
sum=0
for i in range(N):
  b[a[i]]+=1

for i in range(N):
  sum+=b[i]*(b[i]-1)//2
for i in range(N):
  print(sum-b[a[i]]-1)

N=int(input())
a=list(map(int,input().split()))
b=[0]*N
sum=0
for i in range(N):
  b[a[i]-1]+=1

for i in range(N):
  sum+=b[i]*(b[i]-1)//2
for i in range(N):
  print(sum-b[a[i]-1]+1)

Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
#!/usr/bin/python
# -*- coding: utf-8 -*-







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

Number = []
Total = 0

Number = [A.count(i+1) for i in range(N)]
Total = sum([Number[i]*(Number[i]-1)/2 for i in range(N)])

#for Ak in A:
#    print(int(Total - Number[Ak-1]+1))

print('\n'.join([str(Total-Number[Ak-1]+1) for Ak in A]))


import collections



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

C = collections.Counter(A)

Total = sum([i*(i-1)/2 for i in C.values()])

for Ak in A:
    print(int(Total - C[Ak]+1))



Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
a_uni = list(set(a))

a_ol = {}
def_count = 0
for i in a_uni:
    a_co = a.count(i)
    a_ol[i] = a_co
    def_count += a_co * (a_co - 1)

def_count *= 0.5

for k in range(n):
    print(def_count - a_ol[a[k]] + 1)



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


a_ol = Counter(a)
def_count = 0
for item in a_ol.items():
    a_co = item[1]
    def_count += a_co * (a_co - 1)

def_count //= 2

for k in a:
    print(def_count - a_ol[k] + 1)



Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split()))
dic = {}
for i in a:
    s.add(i)
    if i in dic:
        dic[i] +=1
    else:
        dic[i] = 1

ans = 0
for i in dic.values():
    ans += i * (i - 1) // 2

for i in a:
    sa = dic[i] * (dic[i] - 1) // 2 - ((dic[i] - 1) * (dic[i] - 2) // 2)
    print(ans - sa)

n = int(input())
a = list(map(int,input().split()))
dic = {}
for i in a:
    if i in dic:
        dic[i] +=1
    else:
        dic[i] = 1

ans = 0
for i in dic.values():
    ans += i * (i - 1) // 2

for i in a:
    sa = dic[i] * (dic[i] - 1) // 2 - ((dic[i] - 1) * (dic[i] - 2) // 2)
    print(ans - sa)

Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
def CountFrequency_mod(my_list): 
  
    # Creating an empty dictionary  
    freq = {} 
    for item in my_list: 
        if (item in freq): 
            freq[item] += 1
        else: 
            freq[item] = 1
    
    freq_mod = freq
    freq_val = list(freq.values())
    all_sum=0
    
    for i in freq_val:
        all_sum+=i*(i-1)/2
        
    for i in freq:
        freq_mod = all_sum - freq[i]*(freq[i]-1)/2 + (freq[i]-1)*(freq[i]-2)/2
    return freq_mod


N = int(input())

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

dic = CountFrequency_mod(A)

for i in A:
    print(int(dic[i]))
    

def CountFrequency_mod(my_list): 
  
    # Creating an empty dictionary  
    freq = {} 
    for item in my_list: 
        if (item in freq): 
            freq[item] += 1
        else: 
            freq[item] = 1
    
    freq_mod = freq
    freq_val = list(freq.values())
    all_sum=0
    
    for i in freq_val:
        all_sum+=i*(i-1)/2
        
    for i in freq:
        freq_mod[i] = all_sum - freq[i]*(freq[i]-1)/2 + (freq[i]-1)*(freq[i]-2)/2
    return freq_mod


N = int(input())

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

dic = CountFrequency_mod(A)

for i in A:
    print(int(dic[int(i)]))
    

Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import collections
from sys import stdin
n = int(stdin.readline().rstrip())
ass = list(map(int, stdin.readline().rstrip().split()))

c = collections.Counter(ass)

cnum =[0]*len(c)
keys = c.keys()

cs = {}
for i in keys:
    key = c[i]
    combi = key *(key-1) / 2
    cs[i] = combi

sum = sum(cs.values())

for i in range(n):
    add = c[ass[i]]-1
    adds = add *(add-1) / 2
    ans = sum - cs[ass[i]] + adds
    print(ans)


import collections
from sys import stdin
n = int(stdin.readline().rstrip())
ass = list(map(int, stdin.readline().rstrip().split()))

c = collections.Counter(ass)

cnum =[0]*len(c)
keys = c.keys()

cs = {}
for i in keys:
    key = c[i]
    combi = key *(key-1) / 2
    cs[i] = combi

sum = sum(cs.values())

for i in range(n):
    add = c[ass[i]]-1
    adds = add *(add-1) / 2
    ans = sum - cs[ass[i]] + adds
    print(int(ans))


Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from collections import Counter
n = int(input())
num_list = list(map(int,input().split()))
a = Counter(num_list)
count = 0
for i in a.values():
  count += (i*(i-1))//2
for j in num_list:


from collections import Counter
n = int(input())
num_list = list(map(int,input().split()))
a = Counter(num_list)
count = 0
for i in a.values():
  count += (i*(i-1))//2
for j in num_list:
  print(count-(a[j]-1))

Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import collections

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

num_count = collections.Counter(a)
total = sum([num*(num-1)//2 for num in num_count.values()])

for i in range(n):
    print(total-a.count(a[i]+1))

import collections

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

num_count = collections.Counter(a)
total = sum([num*(num-1)//2 for num in num_count.values()])

for i in range(n):
    print(total-num_count[a[i]]+1)

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from collections import Counter
from math import factorial


n = int(input())
a = list(map(int, input().split()))
d = Counter(a)
c = [0 for _ in range(max(a))]
for k, v in d.items():
    if v > 2:
        c[k - 1] = factorial(v) / factorial(2) / factorial(v - 2)
    else:
        c[k - 1] = 0
        
for i in range(n):
    ans = sum(c)
    p = a[i]
    res = c[p - 1] * (d[p] - 2) / d[p]
    ans -= c[p - 1] - res
    print(int(ans))


from collections import Counter

n = int(input())
a = list(map(int, input().split()))
d = Counter(a)
c = [0 for _ in range(max(a))]
for k, v in d.items():
    c[k - 1] = v * (v - 1) / 2

ans = sum(c)
for i in range(n):
    p = a[i]
    res = c[p - 1] * (d[p] - 2) / d[p]
    ans -= c[p - 1] - res
    print(int(ans))
    ans += c[p - 1] - res


Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
val=0
for i in c.values():
    print(i)  
    val += i * (i - 1) // 2  
    # val+=sum(range(i-1))
for i in range(n):
    b = c[a[i]]  
    print(val - b + 1)  

#D AC
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
val=0
for i in c.values():
    
    val += i * (i - 1) // 2  
    # val+=sum(range(i-1))
for i in range(n):
    b = c[a[i]]  
    print(val - b + 1)  

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from collections import defaultdict

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

dic = defaultdict(int)
ans1 = defaultdict(int)
ans2 = defaultdict(int)

def calc_patern1(n, ans, dic):
    for k, v in dic.items():
        ans[k] = v * (v - 1) / 2


def calc_patern2(n, ans, dic):
    for k, v in dic.items():
        ans[k] = (v - 1) * (v - 2) / 2

for i in range(n):
    dic[a[i]] += 1
for v in dic.values():
    calc_patern1(a[i], ans1, dic)
    calc_patern2(a[i] - 1, ans2, dic)
print(ans1, ans2)
for i in range(n):
    ans = 0
    for k, v in dic.items():
        #print(ans)
        if k == a[i]:
            ans += ans2[k]
        else:
            ans += ans1[k]
    print(int(ans))

from collections import defaultdict, Counter

n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
dic = defaultdict(int)
for i in range(n):
    dic[a[i]] += 1

sum = 0
for v in dic.values():
    sum += v * (v - 1) / 2
    
for i in range(n):
    print(int(sum - (dic[a[i]] - 1)))

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
B = Counter(A)
C = {key:(B[key]*(B[key]-1)//2) for key in B}
ans = sum(B.values())
for i in A:
    if C[i] < 2:
        print(ans)
    else:
        ans = ans - C[i] +(B[key-1]*(B[key]-2)//2)
        print(ans)

from collections import Counter
N = int(input())
A = list(map(int,input().split()))
B = Counter(A)
C = {key:(B[key]*(B[key]-1)//2) for key in B}
ans = sum(C.values())
#print(C,ans)
#print(C[3])
for i in A:
    if C[i] < 1:
        print(ans)
    else:
        print(ans - C[i] + (B[i]-1)*(B[i]-2)//2)

Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import sys
sys.setrecursionlimit(10**6)
from collections import defaultdict

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

d = defaultdict(int)

for i in range(N):
    d[A[i]] += 1

print(d)
a = defaultdict(int)
b = defaultdict(int)
for key, value in d.items():
    a[key] = value * (value - 1) //2
    b[key] = value * (value - 1) //2 - (value - 1) * (value - 2) // 2
#print(a)
#print(b)
total = 0
for key, value in a.items():
    total += value
#print(total)
for i in range(N):
    ans = total - b[A[i]]
    print(ans)

import sys
sys.setrecursionlimit(10**6)
from collections import defaultdict

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

d = defaultdict(int)

for i in range(N):
    d[A[i]] += 1

#print(d)
a = defaultdict(int)
b = defaultdict(int)
for key, value in d.items():
    a[key] = value * (value - 1) //2
    b[key] = value * (value - 1) //2 - (value - 1) * (value - 2) // 2
#print(a)
#print(b)
total = 0
for key, value in a.items():
    total += value
#print(total)
for i in range(N):
    ans = total - b[A[i]]
    print(ans)

Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
N = int(input())
K = list(map(int, input().split()))
counter = dict()
for i in range(N):
  if K[i] not in counter:
  	counter[K[i]] = 1
  else:
   	counter[K[i]] += 1

results = 0
remove_counter = dict()
for key, value in counter.items():
  remove_counter[key] = (value * (value - 1) / 2) - ((value - 1) * (value - 2) / 2)
  results += value * (value - 1) / 2
for i in range(N):
  print(results - remove_counter[K[i]])

N = int(input())
K = list(map(int, input().split()))
counter = dict()
for i in range(N):
  if K[i] not in counter:
  	counter[K[i]] = 1
  else:
   	counter[K[i]] += 1

results = 0
remove_counter = dict()
for key, value in counter.items():
  remove_counter[key] = (value * (value - 1) / 2) - ((value - 1) * (value - 2) / 2)
  results += value * (value - 1) / 2
for i in range(N):
  print(int(results - remove_counter[K[i]]))


Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):

if __name__ == '__main__':

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

    
    d = Counter(A)
    
    d2 = dict()
    
    for k,v in d.items():
        d2[k] = (v*(v-1)) // 2
    ans_sum = sum(d2.values())

    
    for i in A:
        ans = 0
        if i in d2:
            
            tmp = d[i] - 1
            before= d2[i]
            after = (tmp*(tmp-1)) //2
            ans = ans_sum - (before-after)
            print(ans)
        else:
            
            print(ans_sum)


from collections import Counter

if __name__ == '__main__':

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

    
    d = Counter(A)
    
    d2 = dict()
    
    for k,v in d.items():
        d2[k] = (v*(v-1)) // 2
    ans_sum = sum(d2.values())

    
    for i in A:
        ans = 0
        if i in d2:
            
            tmp = d[i] - 1
            before= d2[i]
            after = (tmp*(tmp-1)) //2
            ans = ans_sum - (before-after)
            print(ans)
        else:
            
            print(ans_sum)


Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import collections
import math

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
cnt = 0
ansx = []
ansy = []
ansy2 = []

for x, y in c.items():
    sumall += (y*(y-1)//2)
    ansy2.append(y-1)
    ansx.append(x)

for i in A:
    print(sumall - ansy2[ansx.index(i)])


import collections
import math

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
cnt = 0
ansx = []
ansy = []
ansy2 = []

for x, y in c.items():
    sumall += (y*(y-1)//2))
    ansy2.append(y-1)
    ansx.append(x)

for i in A:
    print(sumall - ansy2[ansx.index(i)])


import collections
import math

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
cnt = 0


sumall = 0
for x, y in c.items():
    sumall += (y*(y-1)//2)

for i in range(N):
    print(sumall - c[A[i]] + 1)


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))

from collections import Counter
c = Counter(a)

print(c)
for i in range(n):
   c[a[i]] -= 1
   tmp = [x*(x-1)//2 for x in c.values()]
   print(sum(tmp))
   c[a[i]] += 1


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

from collections import Counter
c = Counter(a)
combi = {}
for k, v in c.items():
   combi[k] = v*(v-1)//2
sumc = sum(list(combi.values()))

for i in range(n):
   x = c[a[i]] - 1
   ans = sumc - combi[a[i]] + x*(x-1)//2
   print(ans)


Verdicts: Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
import copy
N = int(input())
A = list(map(int, input().split()))

a_types = set(A)
for each in a_types:
    count_dict[each - 1] += A.count(each)

count_dict = [0] * N
for each in A:
    count_dict[each - 1] += 1

all_types = 0
for value in count_dict:
    all_types += value * (value - 1) // 2

# result_dict = {}
# for each in a_types:
#     result_dict[each] = all_types - count_dict[each] + 1

for a in A:
    print(all_types - count_dict[a - 1] + 1)

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

a_types = set(A)
count_dict = [0] * N
for each in a_types:
    count_dict[each - 1] = A.count(each)

for each in A:
    count_dict[each - 1] += 1

all_types = 0
for value in count_dict:
    all_types += value * (value - 1) // 2

# result_dict = {}
# for each in a_types:
#     result_dict[each] = all_types - count_dict[each] + 1

for a in A:
    print(all_types - count_dict[a - 1] + 1)

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

a_types = set(A)

count_dict = {}
for each in a_types:
    count_dict[each] = A.count(each)
print(count_dict)

all_types = 0
for value in count_dict.values():
    all_types += value * (value - 1) / 2

for a in A:
    print(int(all_types - count_dict[a] + 1))
# no_execlusion_results = {}
# for each in a_types:
#     no_execlusion_results[each] = 
# result_dict = {}
# for each in a_types:
#     tmp_dict = copy.deepcopy(count_dict)
#     tmp_dict[each] = count_dict[each] - 1
#     combinations = 0
#     for value in tmp_dict.values():
#         combinations += int(value * (value - 1) / 2)
#     result_dict[each] = combinations
# 
# print(result_dict)
# for a in A:
#     print(result_dict[a])

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

a_types = set(A)

count_dict = [0] * N
for each in A:
    count_dict[each - 1] += 1

all_types = 0
for value in count_dict:
    all_types += value * (value - 1) // 2

# result_dict = {}
# for each in a_types:
#     result_dict[each] = all_types - count_dict[each] + 1

for a in A:
    print(all_types - count_dict[a - 1] + 1)

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
n= int(input())
a=list(map(int, input().split()))
b = [0]*(n+1)
c = [0]*(n+1)
su = 0

for x in range(n):
    b[a[x]] += 1

for y in range(len(b)):
    if b[y] >=2:
        c[y]=combinations_count(b[y], 2)
    else:
        c[y]=0
    su += c[y]

for z in range(n):
    if c[a[z]] > 0:
        ans = su - (b[a[z]] - 1)
    else:
        ans = su

    print(str(ans))

import math

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

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

for x in range(n):
    b[a[x]] += 1

for y in range(len(b)):
    if b[y] >=2:
        c[y]=combinations_count(b[y], 2)
    else:
        c[y]=0
    su += c[y]

for z in range(n):
    if c[a[z]] > 0:
        ans = su - (b[a[z]] - 1)
    else:
        ans = su

    print(str(ans))

Verdicts: Runtime Error

Accepted
Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
from collections import Counter
n = int(input())
a_input = list(map(int,input().split()))

a_count = Counter(a_input)

score_dic={}
exclude_dic={}

for k,v in enumerate(a_count.items()):
    score_dic[k]=v*(v-1)//2
    exclude_dic[k]=(v-1)*(v-2)//2

score_sum = sum(score_dic.values())

for i in range(n):
    print(score_sum-score_dic[a_input[i]]+exclude_dic[a_input[i]])

from collections import Counter
n = int(input())
a_input = list(map(int,input().split()))

a_count = Counter(a_input)

score_dic={}
exclude_dic={}

for k,v in a_count.items():
    score_dic[k]=v*(v-1)//2
    exclude_dic[k]=(v-1)*(v-2)//2

score_sum = sum(score_dic.values())

for i in range(n):
    print(score_sum-score_dic[a_input[i]]+exclude_dic[a_input[i]])



Verdicts: Runtime Error

Accepted