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):
n = int(input())
alist = list(map(int,input().split(' ')))

from collections import defaultdict

resdict = {}

from collections import Counter

c = Counter(alist)

old_cdict = dict(c)

cdict = dict((key, value) for (key, value) in old_cdict.items() if value >= 2)

# print(cdict)

maxi = 0

for k, v in cdict.items():
    maxi += v * (v - 1) // 2

for a in alist:
    num = 0
    if num in cdict:
        num = cdict[a]
    if num in resdict:
        # print('used')
        print(resdict[num])
        continue
    # print('not used')
    if a in cdict:
        cdict[a] -= 1
        temp = 0
        for k,v in cdict.items():
            temp += v*(v-1)//2
        print(temp)
        resdict[num] = temp
        cdict[a] += 1
    else:
        print(maxi)

n = int(input())
alist = list(map(int,input().split(' ')))

from collections import defaultdict

resdict = {}

from collections import Counter

c = Counter(alist)

cdict = dict(c)

# cdict = dict((key, value) for (key, value) in old_cdict.items() if value >= 2)

# print(cdict)

maxi = 0

for k, v in cdict.items():
    maxi += v * (v - 1) // 2

for a in alist:
    num = cdict[a]
    if num in resdict:
        # print('used')
        print(resdict[num])
        continue
    # print('not used')
    if a in cdict:
        cdict[a] -= 1
        temp = 0
        for k,v in cdict.items():
            temp += v*(v-1)//2
        print(temp)
        resdict[num] = temp
        cdict[a] += 1
    else:
        print(maxi)

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 numpy as np
import math

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


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

array = np.zeros(n+1)

for i in a:
    array[i] += 1

sum = 0
for i in array:
    if i > 1:
        sum += combinations_count(i, 2)

for i in a:
    tmp = sum
    if array[i] > 2:
        tmp -= (combinations_count(array[i],2) - combinations_count(array[i]-1, 2))
    elif array[i] == 2:
        tmp -= combinations_count(array[i], 2)
    elif array[i] == 1:
        tmp = tmp
    print(tmp)



from collections import Counter

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

c = Counter(a)

total = 0
for i in c.items():
    x = i[1]
    total += x*(x-1)//2

for i in a:
    ans = total
    ans -= (c[i] - 1)
    print(ans)


Verdicts: 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 = [int(i) for i in input().split()]
C = [0 for i in range(N)]
for value in A:
    C[value - 1] += 1
print(C)
ways_all = 0
for i in range(N):
    ways_all += (C[i] * (C[i] - 1)) // 2
print(ways_all)
for value in A:
    print(ways_all - C[value - 1] + 1)

N = int(input())
A = [int(i) for i in input().split()]
C = [0 for i in range(N)]
for value in A:
    C[value - 1] += 1
ways_all = 0
for i in range(N):
    ways_all += (C[i] * (C[i] - 1)) // 2
for value in A:
    print(ways_all - C[value - 1] + 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):
import collections
n = int(input())
a = list(map(int,input().split()))
tmp = {}
for i in range(n):
    if a[i] in tmp:
        print(tmp[a[i]])
    else:
        a_copy = a[:]
        a_copy.remove(a[i])
        c = collections.Counter(a_copy)
        cnt = 0
        for i in c.values():
            cnt += i * (i-1) // 2
    
        tmp[a[i]] = cnt
    
        print(cnt)

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

c = Counter(a)
#print(c)

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

for i in range(n):
    print(s - c[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):
N = int(input())
A = list(map(int, input.split()))
L = [0 for i in range(N)]

total = 0

for i in range(N):
  r = 0
  for j in range(N):
    if i != j and A[i] == A[j]:
      r += 1
  L[i] = r
  total += r

total = total // 2

for i in L:
  print(total - L[i])

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

dict = {}

for i in A:
  if i in dict:
    dict[i] = dict[i] + 1
  else:
    dict[i] = 1

print(dict)
total = 0;
for i in dict:
#  print("i:" + str(i) + " " + str(dict[i]))
  total += dict[i]*(dict[i]-1) // 2

#print("T:" + str(total))

for i in A:
  print(total - dict[i] + 1)

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

dict = {}

for i in A:
  if i in dict:
    dict[i] = dict[i] + 1
  else:
    dict[i] = 1

#print(dict)
total = 0;
for i in dict:
#  print("i:" + str(i) + " " + str(dict[i]))
  total += dict[i]*(dict[i]-1) // 2

#print("T:" + str(total))

for i in A:
  print(total - dict[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):
n = int(input())
A = list(map(int,input().split()))
from collections import Counter

c = Counter(A)
print(c)
cou = 0
for x in c:
    if c[x]>1:
        y = c[x]
        cou+=y*(y-1)//2
    else:
        break


for i in A:
    X = c[i]
    ans = cou - X*(X-1)//2 + (X-1)*(X-2)//2
    print(ans)


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

c = Counter(A)
# print(c)
cou = 0
for x in c:
    # print(x,c[x])
    if c[x]>1:
        y = c[x]
        cou+=y*(y-1)//2



for i in A:
    X = c[i]
    ans = cou - X*(X-1)//2 + (X-1)*(X-2)//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 collections

def check(A):
    count = 0
    for j in A:
        n = A[j]
        if n > 1:
            count += n * (n - 1) / 2
            
    return int(count)


N = int(input())
A = list(map(int, input().split(" ")))
A2 = collections.Counter(A)
print(A2)
Nsum = check(A2)
# print(Nsum)
for i in range(0,N):
    num = A[i]
    count = A2[num]
    out = Nsum - ( count - 1 )
    print(out)

import collections

def check(A):
    count = 0
    for j in A:
        n = A[j]
        if n > 1:
            count += n * (n - 1) / 2
            
    return int(count)


N = int(input())
A = list(map(int, input().split(" ")))
A2 = collections.Counter(A)
# print(A2)
Nsum = check(A2)
# print(Nsum)
for i in range(0,N):
    num = A[i]
    count = A2[num]
    out = Nsum - ( count - 1 )
    print(out)

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 com(n):
    return n*(n-1)//2
ans=0
n=int(input())
a=list(map(int,input().split()))
coun=[0]*n
for i in range(n):
    coun[a[i]]+=1
foi i in range(n):
    ans+=com(coun[i])
for i in range(n):
    m=com(coun[a[i]]-1)
    o=com(coun[a[i]])
    print(ans-o+m)
 

import collections
N=int(input())
lst=input().split()
s=0
dic=collections.Counter(lst)
for i in dic.values():
    s+=(i*i-i)//2
for i in lst:
    print(s+1-dict[i])

import collections
N=int(input())
lst=input().split()
s=0
dic=collections.Counter(lst)
for i in dic.values():
    s+=(i*i-i)//2
for i in lst:
    print(s+1-dic[i])

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):
import collections

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

c=collections.Counter(a)

print(c)

for i in c.values():
  s+=i*(i-1)//2 

for j in a:
  f=c[j]
  print(s-(f-1)) 




import collections

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

c=collections.Counter(a)

print(c)

s=0

for i in c.values():
  s+=i*(i-1)//2 

for j in a:
  f=c[j]
  print(s-(f-1)) 



import collections

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

c=collections.Counter(a)
s=0

for i in c.values():
  s+=i*(i-1)//2 

for j in a:
  f=c[j]
  print(s-(f-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
from collections import Counter

def cmb(n,r):
    if n < r:
        return 0
    else:
        math.factorial(n,r)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    count = Counter(A)
    sum_ = sum([cmb(i,2) for i in count.values()])

    for i in range(len(A)):
        remain = A[:i] + A[i+1:]
        took_count = count[A[i]]
        sub = took_count - 1
        print(int(sum_ - sub))

if __name__ == '__main__':
    main()

import math
from collections import Counter

def cmb(n,r):
    if n < r:
        return 0
    return math.factorial(n)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    count = Counter(A)
    sum_ = sum([cmb(v,2) for v in count.values()])

    for i in range(len(A)):
        remain = A[:i] + A[i+1:]
        took_count = count[A[i]]
        sub = took_count - 1
        print(int(sum_ - sub))

if __name__ == '__main__':
    main()

import math
from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    count = Counter(A)
    sum_ = sum([math.factorial(i,2) for i in count.values()])

    for i in range(len(A)):
        remain = A[:i] + A[i+1:]
        took_count = count[A[i]]
        sub = took_count - 1
        print(int(sum_ - sub))

if __name__ == '__main__':
    main()

from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    count = Counter(A)
    sum_ = sum([v*(v-1)/2 for v in count.values()])

    for i in range(len(A)):
        took_count = count[A[i]]
        sub = took_count - 1
        print(int(sum_ - sub))

if __name__ == '__main__':
    main()

Verdicts: Runtime Error

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):
# -*- coding: utf-8 -*-
n = int(input())
numlist = list(map(int, input().split()))
dic = {}
for num in numlist:
  if num not in dic:
    dic[num] = 1
  else:
    dic[num] += 1
    
ansdic = {}
for key in dic.keys():
  n = dic[key]
  ansdic[key] = [int(n*(n-1)/2),int((n-1)*(n-2)/2)]
      
ansdic2 = {}
for key in ansdic.keys():
  sum = 0
  for key2 in ansdic.keys():
    if key == key2:
      sum += ansdic[key][1]
    else:
      sum += ansdic[key][0]
    ansdic2[key] = sum  
    
for num in numlist:
  print(ansdic2[num])

# -*- coding: utf-8 -*-
n = int(input())
numlist = list(map(int, input().split()))
dic = {}
for num in numlist:
  if num not in dic:
    dic[num] = 1
  else:
    dic[num] += 1
    
tmpsum = 0
for value in dic.values():
  tmpsum += int(value*(value-1)/2)
ansdic = {}
for key in dic.keys():
  n = dic[key]
  ansdic[key] = tmpsum - n + 1      
    
for num in numlist:
  print(ansdic[num])

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):
rom collections import Counter
N=int(input())
A=list(map(int, input().split()))
 
count = Counter(A)
vals = count.values()
sum_ = 0
for v in vals:
  if v >= 2: sum_ += v*(v-1)
sum_ //= 2
 
for k in range(N):
  if count[A[k]] < 2: print(sum_)
  else:print(sum_ + 1 - count[A[k]])

import numpy as np
n = int(input())
a = list(map(int,input().split()))
s = np.zeros(n+1)
for i in a:
    s[i]+=1
al = sum((s*(s-1))/2)
for i in range(n):
    ans=al-(s[a[i]]-1)
    print(int(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):
import collections

# input
N = int(input())
A = map(int,input().split())
# calculatioin
cnt = collections.Counter(A)
full_cnt = int(sum(cnt[key]*(cnt[key]-1)/2 for key in cnt))
for i in range(N):
  print(full_cnt - cnt[A[i]]+1)

import collections

# input
N = int(input())
A = input().split()
# calculatioin
cnt = collections.Counter(A)
full_cnt = int(sum(cnt[key]*(cnt[key]-1)/2 for key in cnt))
for i in range(N):
  print(full_cnt - cnt[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):
from math import factorial

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

def combination(n,r):
  if n < 2:
    return 0
  else:
    print(factorial(n) / factorial(r) / factorial(n-r) )
    return factorial(n) / factorial(r) / factorial(n-r)

lens = []
ans = 0
for p in range(N):
  lens.append(An.count(p))
for p in range(N):
  lend = lens.copy()
  if lend[p] == 0:
    continue
  else:
    lend[p] -= 1
  for k in range(N):
    ans += combination(lend[k], 2)

print(int(ans))

from math import factorial

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

def combination(n,r):
  if n < 2:
    return 0
  else:
    return factorial(n) / factorial(r) / factorial(n-r)

lens = []
ans = 0
for p in range(N):
  lens.append(An.count(p))
for p in range(N):
  lend = lens.copy()
  if lend[p] == 0:
    continue
  else:
    lend[p] -= 1
  for k in range(N):
    ans += combination(lend[k], 2)

print(int(ans))


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

# n(n-1)/2 - (n-1)(n-2)/2 = n-1
dic = {}
su = 0
m = 0
for a in An:
  dic[a] = 0
for a in An:
  dic[a] += 1 
for d,i in enumerate(dic):
  su += dic[i] * (dic[i]-1) / 2
for a in An:
  print(int(su - dic[a] + 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):
from collections import Counter
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()))

a_cnt = Counter(a)

a_comb = {}
for key, val in a_cnt.items():
    if val >= 2:
        a_comb[key] = combinations_count(val, 2)
    else:
        a_comb[key] = 0
print(a_cnt)
print(a_comb)

for num in a:
    dic = a_comb.copy()
    if dic[num] <= 1:
        dic[num] = 0
    else: 
        dic[num] = combinations_count(a_cnt[num]-1, 2)
    print(int(sum(dic.values())))

from collections import Counter
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()))

a_cnt = Counter(a)

a_comb = {}
for key, val in a_cnt.items():
    if val >= 2:
        a_comb[key] = combinations_count(val, 2)
    else:
        a_comb[key] = 0

sum_v = sum(a_comb.values())

for num in a:
    print(sum_v-a_cnt[num]+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):
import collections
N = int(input())
A = list(map(int,input().split()))
CA = collections.Counter(A)
S = 0
for i in CA.values():
    S += i*(i-1)//2
for x in range(A):
    print(S - count[x] + 1)

import collections
N = int(input())
A = list(map(int,input().split()))
CA = collections.Counter(A)
S = 0
for i in CA.values():
    S += i*(i-1)//2
for x in A:
    print(S - count[x] + 1)

import collections
N = int(input())
A = list(map(int,input().split()))
CA = collections.Counter(A)
S = 0
for i in CA.values():
    S += i*(i-1)/2
for k in range(N):
    print(S - A.count(A[k]) + 1)

import collections
N = int(input())
A = list(map(int,input().split()))
CA = collections.Counter(A)
S = 0
for i in CA.values():
    S += i*(i-1)//2
for x in range(A):
    print(S - A.count(x) + 1)

import collections
N = int(input())
A = list(map(int,input().split()))
CA = collections.Counter(A)
S = 0
for i in CA.values():
    S += i*(i-1)/2
for x in range(A):
    print(S - A.count(x) + 1)

import collections
N = int(input())
A = list(map(int,input().split()))
CA = collections.Counter(A)
S = 0
for i in range(CA.values()):
    S += int(i*(i-1)/2)
for k in range(N):
    print(S - A.count(A[k]) + 1)

N = int(input())
A = list(map(int,input().split()))
S = 0
for i in range(N):
    S += int(A[i]*(A[i]-1)/2)
for k in range(N):
    print(S - A.count(A[k]) + 1)

import collections
N = int(input())
A = list(map(int,input().split()))
CA = collections.Counter(A)
S = 0
for i in CA.values():
    S += i*(i-1)//2
for x in A:
    print(S - CA[x] + 1)

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

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())
N = list(range(1,N+1))
A = list(map(int, input().split())

for k in range(1, N+1):
         A = A.remove(A[k])
         ans = 0
         for i in range(1,N+1):
         	n = sum(A[j] == i for j in range(1,N))
         	nc2 = n * (n-1) / 2
         	ans += nc2
         
         print(ans)

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

for k in range(N):
    del A[k]
    ans = 0
    
    for i in range(1,N+1):
        n = A.count(i)
        nc2 = n * (n-1) / 2
        ans += nc2
    print(ans)

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

for k in range(N):
         del A[k]
         ans = 0
         for i in range(1,N+1):
         	n = sum(A[j] == i for j in range(1,N))
         	nc2 = n * (n-1) / 2
         	ans += nc2
         
         print(ans)

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

for k in range(1, N+1):
         A = A.remove(k)
         ans = 0
         for i in range(1,N+1):
         	n = sum(A[j] == i for j in range(1,N))
         	nc2 = n * (n-1) / 2
         	ans += nc2
         
         print(ans)

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

for k in range(N):
    del A[k]
    ans = 0
    
    for i in range(1,N+1):
        n = sum(A[j] == i for j in range(N-1))
        nc2 = n * (n-1) / 2
        ans += nc2
    print(ans)

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

for i in A:
    B[i] += 1
sum_original = sum([j*(j-1)//2 for j in B])
for k in range(N):
    print(sum_original - B[A[k]] + 1)

Verdicts: Runtime Error

Runtime Error

Runtime Error

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_l = list(map(int, input().split()))

cnt = [0 for i in range(n)]

for i in range(n):
    cnt[a_l[i]]+=1
ans = 0

for a in cnt:
    ans += a*(a-1)/2
for i in range(n):
    print(ans - (cnt[a_l[i]]-1))

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

from collections import Counter
count = Counter(A)
 
s = 0
for c in list(count.values()):
    s += c*(c-1)/2

ans = 0
for a in A:
    n = count[a]
    ans = s - n*(n-1)/2 + (n-1)*(n-2)/2
    print(int(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):
n = int(input())
l = list(map(int, input().split()))

ans = 0

k = [0 for _ in range(n+1)]

for i in range(n):
    k[l[i]] += 1
    
ll = len(k)
for i in range(ll):
    a = k[i]
    if a <= 1:
        pass
    else:
        ans += (a * (a - 1))/2
        
for i in range(n):
    a = k[l[i]]
    b = (a * (a - 1))/2
    c = a - 1
    if c <= 1:
        print(ans)
    else:
        pans = ans - b
        c = (c * (c - 1))/2
        pans = pans + c
        print(pans)

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

ans = 0

k = [0 for _ in range(n+1)]

for i in range(n):
    k[l[i]] += 1
    
ll = len(k)
for i in range(ll):
    a = k[i]
    if a <= 1:
        pass
    else:
        ans += (a * (a - 1))/2
        
for i in range(n):
    a = k[l[i]]
    b = (a * (a - 1))/2
    c = a - 1
    if c <= 1:
        print(int(ans))
    else:
        pans = ans - b
        c = (c * (c - 1))/2
        pans = pans + c
        print(int(pans))

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

ans = 0

k = [0 for _ in range(n+1)]

for i in range(n):
    k[l[i]] += 1
    
ll = len(k)
for i in range(ll):
    a = k[i]
    if a <= 1:
        pass
    else:
        ans += (a * (a - 1))/2
        
for i in range(n):
    a = k[l[i]]
    b = (a * (a - 1))/2
    c = a - 1
    if a < 1:
        print(int(ans))
    else:
        pans = ans - b
        c = (c * (c - 1))/2
        pans = pans + c
        print(int(pans))

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):
from collections import Counter
N = int(input())
B = [int(x) for x in input().split()]
A=Counter(B)
V, C = zip(*A.most_common())
count=0
for x in C:
  if x==0:
    break
  count+=x*(x-1)/2
for x in A:
  ans=count-C[V.index(x)]+1
  print(int(ans))

from collections import Counter
N = int(input())
B = [int(x) for x in input().split()]
A=Counter(B)
V, C = zip(*A.most_common())
count=0
i=0
dict={}
for x in C:
  count+=x*(x-1)/2
  dict[V[i]]=x
  i+=1
for x in B:
  ans=count-dict[x]+1
  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 operator import mul
from functools import reduce
import numpy as np

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
A = list(map(int, input().split()))
B = A[:]
B.sort()
C = [B[0]]
D = [1]
L = 0
for i in range(N-1):
    if B[i] == B[i+1]:
        D[L] += 1
    else:
        C.append(B[i+1])
        D.append(1)
        L += 1
M = len(C)
D1 = D[:]
for i in range(M):
    if D[i] > 1:
        D[i] = cmb(D[i],2)
    else:
        D[i] = 0
for i in range(M):
    if D1[i] > 2:
        D1[i] = cmb(D1[i]-1,2)
    else:
        D1[i] = 0

D = np.array(D)
D1 = np.array(D1)
E = []
E.append(D1[0]+np.sum(D[1:]))
for i in range(1,M-1):
    E.append(D1[i] + np.sum(D[0:i]) + np.sum(D[i+1:M]))
E.append(D1[M-1] + np.sum(D[:M-1]))
for i in range(N):
    print(E[C.index(A[i])])
print(E)

N = int(input())
A = list(map(int, input().split()))
C = {}
for i in A:
    if i in C.keys():
        C[i] += 1
    else:
        C[i] = 1

total = 0

for i in C.keys():
   if C[i]>1:
        total += (C[i]*(C[i]-1))//2

for i in A:
    print(total-(C[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):
import collections
_=int(input())
l = list(map(int, input().split()))
c = collections.Counter(l)
M={}

for i,v in c.items():
    if v>1:
        M[i] =  v*(v-1)/2

for k in l:
    M_ = M.copy()
    M_[k] =  M_[k]*(c[k]-2)/c[k]
    print(sum(M_.values()))

import collections
_ = int(input())
l = list(map(int, input().split()))
c = collections.Counter(l)
M=0
for v in c.values():
    if v>1:
        M +=  v*(v-1)/2

for k in l:
    print(int(M-c[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):
import copy

# N=In[0][0]
# A=In[1]
N=int(input())
I=list(map(int,input().split()))
for j in range(N):
    counter=[0 for i in range(N+1)]
    A=copy.deepcopy(I)
    A.pop(j)
    B=[]
    for i in A:
        counter[i]+=1
    for i in counter:
        if i>1:
            B.append(f(i)/(f(2)*f(i-2)))
    print(int(sum(B)))

import copy

# N=In[0][0]
# A=In[1]
N=int(input())
A=list(map(int,input().split()))
counter=[0 for i in range(N+1)]
ans2=[0 for i in range(N+1)]
B=[]
for i in A:
    counter[i]+=1
ans=[0 for i in range(N+1)]
for i,value in enumerate(counter):
    if value>0:
        ans[i]=(value*(value-1)//2)
        ans2[i]=((value-1)*(value-2)//2)
total=sum(ans)
for i in A:
    temp=total
    temp-=ans[i]
    temp+=ans2[i]
    print(temp)


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 cmb(n):
    if n < 2:
        return 0
    else:
        return (n*(n-1)/2)

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

num_dict = {i:0 for i in range(1,N+1)}
for i in range(N):
    num_dict[A[i]] += 1

S = 0
for i in range(1,N+1):
    S += cmb(num_dict[i])

for i in range(N):
    tmp = 0
    S_dif = cmb(num_dict[A[i]]-1) - cmb(num_dict[A[i]])
    tmp = S + S_dif
    print(tmp)

def cmb(n):
    if n < 2:
        return 0
    else:
        return (n*(n-1)/2)

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

num_dict = {i:0 for i in range(1,N+1)}
for i in range(N):
    num_dict[A[i]] += 1

S = 0
for i in range(1,N+1):
    S += cmb(num_dict[i])

for i in range(N):
    tmp = 0
    S_dif = cmb(num_dict[A[i]]-1) - cmb(num_dict[A[i]])
    tmp = S + S_dif
    print(int(tmp))

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
def cmb(n):
    if n < 2:
        return 0
    else:
        return (n * (n-1)) // 2

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

cs = Counter(a)
s = 0

for v in cs.values():
    s += cmb(v)

for a in ls:
    print(s - cmb(c[a]) + cmb(c[a] - 1))

from collections import Counter

def cmb(n):
    if n < 2:
        return 0
    else:
        return n * (n-1) / 2

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

cs = Counter(a)
s = 0

for v in cs.values():
    s += cmb(v)

for a in ls:
    print(s - cmb(c[a]) + cmb(c[a] - 1))

from collections import Counter
def cmb(n):
    if n < 2:
        return 0
    else:
        return (n * (n-1)) // 2

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

cs = Counter(a)
s = 0

for v in cs.values():
    s += cmb(v)

for a in ls:
    print(s - cmb(cs[a]) + cmb(cs[a] - 1))

from collections import Counter
def cmb(n):
    if n < 2:
        return 0
    else:
        return (n * (n-1)) // 2

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

cs = Counter(ls)
s = 0

for v in cs.values():
    s += cmb(v)

for a in ls:
    print(s - cmb(cs[a]) + cmb(cs[a] - 1))

Verdicts: Runtime Error

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 = [A.count(i) for i in range (N + 1)]
print(B)
C = 0
for i in range(N + 1):
  C += int(B[i] * (B[i] - 1) / 2)
for j in A:
  print(0 if B[j] < 2 else C + 1 - B[j])

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

N = int(input())
A = (input().split())
B = []
C = 0
for i in range(N + 1):
  B.append(A.count(str(i)))
  C += int(B[i] * (B[i] - 1) / 2)
print(B)
for j in range(N):
  if B[int(A[j])] > 1:
    D = C + 1 - B[int(A[j])]
    print(D)
  else:
    print(0)

N = int(input())
A = list(int(x) for x in input().split())

import collections
N = int(input())
A = list(map(int, input().split()))
B = collections.Counter(A)
L = {key:(B[key] * (B[key] - 1) // 2) for key in B}
total = sum(L.values())
#print(f"A = {A}\nB = {B}\nL = {L}\ntotal = {total}")
[print(total if L[i] == 0 else total - L[i] + ((B[i] - 1) * (B[i] - 2) // 2)) for i in A]

Verdicts: Wrong Answer

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 math import factorial

N = int(input())
nums = list(map(int, input().split()))
d = dict()

for num in nums:
    if num not in d:
        d[num] = 1
    else:
        d[num] += 1

total = 0
for i in d:
    n = d[i]
    if n == 2:
        total += 1
    elif n > 2:
        total += factorial(n) / factorial(2) / factorial(n - 2)

for num in nums:
    tmp = d[num] - 1
#    if tmp >= 2:
#        hoge = factorial(tmp) / factorial(2) / factorial(tmp - 2)
    print(total - tmp)


import math

N = int(input())
nums = list(map(int, input().split()))
numsB = nums[:]
d = dict()

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

for num in nums:
    if num not in d:
        d[num] = 1
    else:
        d[num] += 1

total = 0
for i in d:
    n = d[i]
    if n == 2:
        total += 1
    elif n > 2:
        total += combinations_count(n, 2)

for num in numsB:
    tmp = d[num] - 1
#    if tmp >= 2:
#        hoge = factorial(tmp) / factorial(2) / factorial(tmp - 2)
    print(int(total - tmp))


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 scipy.misc import comb
n = int(input())
a = list(map(int,input().split()))
for i in range(len(a)):
  o = 0
  b = a[:]
  del b[i]
  c = collections.Counter(b)
  n = len(set(b))
  for i in c.values():
    o += comb(i,2,exact=True)
  print(o)
  

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

Verdicts: 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 = []
d = {}
ans = 0
for _ in range(n):
    a.append(int(input()))
for i in a:
    d[i] = d.get(i,0) + 1
for key in d:
    ans += d[key]*(d[key]-1)//2
for i in a:
    print(ans + 1 - d[i])

n = int(input())
a = list(map(int,input().split()))
d = {}
ans = 0
for i in a:
    d[i] = d.get(i,0) + 1
for key in d:
    ans += d[key]*(d[key]-1)//2
for i in a:
    print(ans + 1 - d[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):
def main():
    import math
    import collections
    N = int(input())
    A = list(map(int, input().split()))
    tt = 0
    
    ann = 0

    def comb(m, n):
        #return math.factorial(m) // (math.factorial(n) * math.factorial(m - n))
        return ((m - 1 + 1) / 1) * (m - 2 + 1) / 2

    

    C = collections.Counter(A)
    for i in C.values():
        if i>=2:
            tt = tt + comb(i, 2)

    for i in A:
        f = C[i] #A_count(A[i])
        if f>=3:
            ann = (tt - comb(f, 2) + comb(f-1, 2))
        elif f==2:
            ann = tt - comb(f, 2)
        else:
            ann = tt
        print(ann)

    
    #    print(i)


if __name__ == '__main__':
    main()

def main():
    import math
    import collections
    N = int(input())
    A = list(map(int, input().split()))
    tt = 0
    
    ann = 0

    def comb(m, n):
        #return math.factorial(m) // (math.factorial(n) * math.factorial(m - n))
        return ((m - 1 + 1) / 1) * (m - 2 + 1) / 2

    

    C = collections.Counter(A)
    for i in C.values():
        if i>=2:
            tt = tt + comb(i, 2)

    for i in A:
        f = C[i] #A_count(A[i])
        if f>=3:
            ann = (tt - comb(f, 2) + comb(f-1, 2))
        elif f==2:
            ann = tt - comb(f, 2)
        else:
            ann = tt
        print(int(ann))

    
    #    print(i)


if __name__ == '__main__':
    main()

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()))

b = set(a)

c = {}

for i in a:
    c[i] = c.get(i, 0) + 1

d = {}

for k in a:
    if d.get(k, "hello") == "hello":
        ans = 0
        for i in b:
            if i != k:
                ans += c[i]*(c[i]-1)//2
            else:
                ans += (c[i]-1)*(c[i]-2)//2
        d[k] = ans
    else:
        ans = d[ans]
    print(ans)


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

c = {}

for i in a:
    c[i] = c.get(i, 0) + 1

ways = 0
for i in a:
    ways += c[i]*(c[i]-1)//2

for k in a:
    ans = ways-c[k]+1
    print(ans)


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

b = set(a)

c = {}

for i in b:
    c[i] = a.count(i)

for k in b:
    ans = 0
    for i in b:
        if i != k:
            ans += c[i]*(c[i]-1)//2
        else:
            ans += (c[i]-1)*(c[i]-2)//2
    print(ans)


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

b = set(a)

c = {}

for i in a:
    c[i] = c.get(i, 0) + 1

e = {}
for i in a:
    e[i] = c[i]*(c[i]-1)//2

for k in a:
    if d.get(k, "hello") == "hello":
        ans = 0
        for i in b:
            if i != k:
                ans += e[i]
            else:
                ans += e[i]+1-c[i]
        d[k] = ans
    else:
        ans = d[k]
    print(ans)


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

c = {}

for i in a:
    c[i] = c.get(i, 0) + 1

ways = 0
for i in c:
    ways += c[i]*(c[i]-1)//2

d = {}
for k in a:
    if d.get(k, "hello") == "hello":
        ans = ways-c[k]+1
        d[k] = ans
    else:
        ans = d[k]
    print(ans)


Verdicts: Runtime Error

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):
import collections
N=int(input())
A = list(map(int,input().split()))
cn = collections.Counter(A)
print(cn[A[2]])
sumC=sum([n * (n-1)//2 for n in cn.values()])
for k in range(N):
    print(sumC-cn[A[k]]+1)




import collections
N=int(input())
A = list(map(int,input().split()))
cn = collections.Counter(A)
sumC=sum([n*(n-1)//2 for n in cn.values()])
for k in range(N):
    print(sumC-cn[A[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 = list(map(int, input().split()))

box = [0] * (N + 1)
box_2 = [0] * (N + 1)
box_3 = [0] * (N + 1)

for i in range(N):
    box[A_list[i] + 1] += 1

for i in range(N):
    if box[i] > 1:
        box_2[i] = (box[i] * (box[i] - 1)) / 2
        box_3[i] = ((box[i] - 1) * (box[i] - 2)) / 2

ans_base = sum(box_2)

for i in range(N):

    if box[A_list[i]] > 0:
        diff = box_2[A_list[i]] - box_3[A_list[i]]
        print(int(ans_base - diff))
    else:
        print(int(ans_base))
    




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

box = [0] * (N + 1)
box_2 = [0] * (N + 1)
box_3 = [0] * (N + 1)

for i in range(N):
    box[A_list[i]] += 1

for i in range(N + 1):
    if box[i] > 1:
        box_2[i] = (box[i] * (box[i] - 1)) / 2
        box_3[i] = ((box[i] - 1) * (box[i] - 2)) / 2

ans_base = sum(box_2)

for i in range(N):

    if box[A_list[i]] > 0:
        diff = box_2[A_list[i]] - box_3[A_list[i]]
        print(int(ans_base - diff))
    else:
        print(int(ans_base))
    


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):
#count
for l in lis:
  if l in dic: dic[l] += 1
  else: dic[l] = 1

#dic_sum = dic.copy()
s = 0
#calcurate
for d in dic:
  s += int(dic[d]*(dic[d]-1)/2)
  
for i in range(inp):
  
  t = dic[lis[i]]
  print(s-int(t*(t-1)/2)+int((t-1)*(t-2)/2))


inp = int(input())
lis = list(map(int, input().split()))

dic = {}

#count
for l in lis:
  if l in dic: dic[l] += 1
  else: dic[l] = 1

#dic_sum = dic.copy()
s = 0
#calcurate
for d in dic:
  s += int(dic[d]*(dic[d]-1)//2)
  
for i in range(inp):
  
  t = dic[lis[i]]
  print(s-int(t*(t-1)//2)+int((t-1)*(t-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):
N = int(input())
A = list(map(int, input().split(' ')))
num_sum = 0
for i in range(1, N+1):
    c = A.count(i)
    num_sum += int(c * (c - 1) / 2)

for j in A:
    if A.count(j) == 1:
        print(sum(num_sum))
    else:
        print(sum(num_sum) - (A.count(j) - 1))

N = int(input())
A = list(map(int, input().split(' ')))
num_sum = 0
for i in range(1, N+1):
    c = A.count(i)
    num_sum += int(c * (c - 1) / 2)

for j in A:
    if A.count(j) == 1:
        print(sum(num_list))
    else:
        print(sum(num_list) - (A.count(j) - 1))


import collections
N = int(input())
A = list(map(int, input().split()))
cnt = collections.Counter(A) 
total = 0
for key in cnt.keys():
    total += cnt[key] * (cnt[key] - 1) // 2
for i in range(N):
    tmp = total
    print(tmp - (cnt[A[i]] - 1))
#    tmp -= cnt[A[i]] * (cnt[A[i]] - 1) // 2
#    tmp += (cnt[A[i]] - 1) * (cnt[A[i]] - 2) // 2

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
cnt=0
for i in a:
  b[i-1]+=1
cnt=sum(b)
for i in a:
  print(cnt+(1-b[i-1]))

n=int(input())
a=list(map(int,input().split()))
b=[0]*n
cnt=0
for i in a:
  b[i-1]+=1
for i in b:
  cnt+=i*(i-1)//2
for i in a:
  print(cnt+(1-b[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):
import copy
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def D159():
    N = int(input())
    A = input().split()
    
    for i in range(0, N):
        sum = 0
        A_ = copy.deepcopy(A)
        del A_[i]
        num = list(set(A_))
        for j in num:
            if A_.count(j) > 1:
                sum += combinations_count(A_.count(j), 2)
        print(sum)

N = int(input())
A = input().split()
tmp = 0
idx = list(set(A))
value = [ A.count(_) for _ in idx ]
for n in value:
    tmp += combi(n)

for i in A:
    j = idx.index(i)
    
    print(int(tmp - combi(value[j]) + combi(value[j]-1)))

N = int(input())
A = list(map(int, input().split()))
 
import collections
A_count = collections.Counter(A)
 
import math
sum_ = 0
for ai in A_count:
    sum_ += (A_count[ai] * (A_count[ai] - 1)) // 2
 
for ai in A:
    #print(sum_ - (A_count[ai] * (A_count[ai] - 1)) // 2 + (A_count[ai] - 1) * (A_count[ai] - 2)) // 2
    l = A_count[ai] * (A_count[ai] - 1) // 2
    m = (A_count[ai] - 1) * (A_count[ai] - 2) // 2
    print(sum_ - l + m)

Verdicts: 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):
stdin =open(0).read().split('\n')
N=int(stdin[0])
A=list(map(int,stdin[1].split()))
from collections import Counter
C=Counter(A)
ans=0
for i in set(A):
    d[i]=A.count(i)
    ans+=d[i]*(d[i]-1)//2
for a in A:
    num = C[a]
    print(ans-num*(num-1)//2+(num-1)*(num-2)//2)

stdin =open(0).read().split('\n')
N=int(stdin[0])
A=list(map(int,stdin[1].split()))
from collections import Counter
C=Counter(A)
ans=0
for i in C.values():
    ans+=i*(i-1)//2
for a in A:
    num = C[a]
    print(ans-num*(num-1)//2+(num-1)*(num-2)//2)

Verdicts: Runtime Error

Accepted