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,defaultdict
import sys
input = sys.stdin.readline

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 2*(10**5)
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


l = int(input())
A=list(map(int, input().split()))
S = Counter(A)

dd=defaultdict(int)
for j in S.keys():
  S[j] -= 1
  tmp = []
  for k in S.keys():
    tmp.append(cmb(S[k],2,mod))
  dd[j] += sum(tmp)
  S[j] += 1

for i in A:
  print(dd[i])


from collections import Counter

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**4
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


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

S = Counter(A)

for i in range(l):
  ans = 0
  S[A[i]] -= 1
  for j in S.keys():
    ans += cmb(S[j],2,mod)
  S[A[i]] += 1
  print(ans)


from collections import Counter
import sys
input = sys.stdin.readline

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**4
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


l = int(input())
#A=list(map(int, input().split()))
A=[int(i) for i in input().split()]

S = Counter(A)

for i in range(l):
  ans = 0
  S[A[i]] -= 1
  for j in S.keys():
    ans += cmb(S[j],2,mod)
  S[A[i]] += 1
  print(ans)


from collections import Counter
from operator import mul
from functools import reduce

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

N=int(input())
A=list(map(int,input().split()))
count=Counter(A)
com={}

for k,v in count.items():
  com[k]=combo(v)
  s=sum(com.values())
  for i in range(N):
    su=s-combo(count[A[i]])+combo(count[A[i]]-1)
    print(su)

from collections import Counter
import sys
input = sys.stdin.readline

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**4
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


l = int(input())
#A=list(map(int, input().split()))
A=[int(i) for i in input().split()]

S = Counter(A)

for i in range(l):
  tmp = []
  S[A[i]] -= 1
  for j in S.keys():
    tmp.append(cmb(S[j],2,mod))
  S[A[i]] += 1
  print(sum(tmp))


from collections import Counter

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**4
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


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

S = Counter(A)

for i in range(l):
  ans = 0
  S[A[i]] -= 1
  for j in S.keys():
    ans += cmb(S[j],2,mod)
  S[A[i]] += 1
  print(ans)
  

from collections import Counter
import sys
input = sys.stdin.readline

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 2*10**5
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


l = int(input())
A=list(map(int, input().split()))
S = Counter(A)

for i in A:
  tmp = []
  S[i] -= 1
  for j in S.keys():
    tmp.append(cmb(S[j],2,mod))
  S[i] += 1
  print(sum(tmp))


from collections import Counter
import sys
input = sys.stdin.readline

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**4
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


l = int(input())
#A=list(map(int, input().split()))
A=[int(i) for i in input().split()]

S = Counter(A)

for i in A:
  tmp = []
  S[i] -= 1
  for j in S.keys():
    tmp.append(cmb(S[j],2,mod))
  S[i] += 1
  print(sum(tmp))


from collections import defaultdict,Counter
import sys

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

d = Counter(a)
e = defaultdict(int)

base = sum(v * (v - 1) // 2 for v in d.values())
e = {k: base - (v >= 2) * (v - 1) for k, v in d.items()}

for x in a:
  print(e[x])

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Accepted