Problem:


Score : 400 points

Problem Statement

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.

Constraints

3 \leq N \leq 2 \times 10^5

1 \leq A_i \leq N

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

For each k=1,2,...,N, print a line containing the answer.

Sample Input 1

5
1 1 2 1 2

Sample Output 1

2
2
3
2
3

Consider the case k=1 for example. The numbers written on the remaining balls are 1,2,1,2.

From these balls, there are two ways to choose two distinct balls so that the integers written on them are equal.

Thus, the answer for k=1 is 2.

Sample Input 2

4
1 2 3 4

Sample Output 2

0
0
0
0

No two balls have equal numbers written on them.

Sample Input 3

5
3 3 3 3 3

Sample Output 3

6
6
6
6
6

Any two balls have equal numbers written on them.

Sample Input 4

8
1 2 1 4 2 1 4 1

Sample Output 4

5
7
5
7
7
5
7
5



Sample input:
5
1 1 2 1 2


Sample output:
2
2
3
2
3

Submission status: Wrong Answer

Solution code:
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()))

dic = Counter(A)
ans = 0
combs = {}
for k, v in dic.items():
    if v >= 2:
        combs[k] = combinations_count(v, 2)
        ans += combs[k]

for i in range(N):
    a = A[i]
    ans_k = ans
    if a in combs:
        ans_k -= combs[a]
        if dic[a] > 2:
            ans_k += combinations_count(dic[a]-1, 2)
        print(ans_k)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[0]*n
a=list(map(int,input().split()))
for i in a:
  x[i-1]+=1
for i in a:
  x[i-1]-=1
  ans=0
  for j in x:
    cnt=1
    for k in range(1,j+1):
      cnt*=k
    ans+=cnt
  print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().strip().split()))

l=[0 for n in range(N+1)]

for e in A:
    l[e]+=1

count=0
for n in range(N):
    if l[n]>=2:
        count+=l[n]*(l[n]-1)//2
            
for n in range(1,N+1):
    if count==0:
        print(0)
    else:
        print(count-l[A[n-1]]+1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy

## input

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]

# 0 0
# 1 0
# 2 1
# 3 3
# 4 6

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

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

data = collections.Counter(A)
C = list(data.values())

tmp = 0

for i in range(len(C)):
    if C[i] >= 2:
        tmp += comb(C[i],2)

for j in range(N):
    if data[A[j]] >= 3:
        print(tmp-comb(data[A[j]]-1,2))
    elif data[A[j]] == 2:
        print(tmp-1)
    else:
        print(tmp)

Submission status: Wrong Answer

Solution code:
def comb(n,k):
    nCk = 1
    MOD = 10**9+7

    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= MOD

    for i in range(1,k+1):
        nCk *= pow(i,MOD-2,MOD)
        nCk %= MOD
    return nCk
n=int(input())
ans=[0 for i in range(200001)]
a=list(map(int,input().split()))

for i in range(n):
    ans[a[i]-1]+=1
l=[0 for i in range(n)]
tmp=0
for i in range(200001):
    if ans[i]>1:
        c=comb(ans[i],2)
        tmp+=c
        l[i]=c
for i in range(n):
    tt=tmp
    t=ans[a[i]-1]
    print(tt-l[a[i]-1]+comb(t-1,2))

Submission status: Wrong Answer

Solution code:
def comb(n,k):
    nCk = 1
    MOD = 10**9+7

    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= MOD

    for i in range(1,k+1):
        nCk *= pow(i,MOD-2,MOD)
        nCk %= MOD
    return nCk
n=int(input())
ans=[0 for i in range(n)]
a=list(map(int,input().split()))

for i in range(n):
    ans[a[i]-1]+=1
l=[0 for i in range(n)]
tmp=0
for i in range(n):
    if ans[i]>1:
        c=comb(ans[i],2)
        tmp+=c
        l[i]=c
for i in range(n):
    tt=tmp
    t=ans[a[i]-1]
    print(tt-l[a[i]-1]+comb(t-1,2))

Submission status: Wrong Answer

Solution code:
def comb(n,k):
    nCk = 1
    MOD = 10**9+7

    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= MOD

    for i in range(1,k+1):
        nCk *= pow(i,MOD-2,MOD)
        nCk %= MOD
    return nCk
n=int(input())
ans=[0 for i in range(n)]
a=list(map(int,input().split()))

for i in range(n):
    ans[a[i]-1]+=1
l=[0 for i in range(n)]
tmp=0
for i in range(n):
    if ans[i]>1:
        c=comb(ans[i],2)
        tmp+=c
        l[i]=c
for i in range(n):
    tt=tmp
    t=ans[a[i]-1]
    if t<2:
        print(tt)
    elif 2<=t<3:
        print(tt-l[a[i]-1])
    elif t>3:
        print(tt-l[a[i]-1]+comb(t-1,2))

Submission status: Wrong Answer

Solution code:
def comb(n,k):
    nCk = 1
    MOD = 10**9+7

    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= MOD

    for i in range(1,k+1):
        nCk *= pow(i,MOD-2,MOD)
        nCk %= MOD
    return nCk
n=int(input())
ans=[0 for i in range(n)]
a=list(map(int,input().split()))

for i in range(n):
    ans[a[i]-1]+=1
l=[0 for i in range(n)]
tmp=0
for i in range(n):
    if ans[i]>1:
        c=comb(ans[i],2)
        tmp+=c
        l[i]=c
for i in range(n):
    tt=tmp
    t=ans[a[i]-1]
    if t<2:
        print(tt)
    elif 2<=t<3:
        print(tt-l[a[i]-1])
    else:
        print(tt-l[a[i]-1]+comb(ans[a[i]-1]-1,2))

Submission status: Wrong Answer

Solution code:
import collections
a=int(input())
b=list(map(int,input().split()))

c=collections.Counter(b)
n,m=zip(*c.most_common())
m=list(m)
n=list(n)
print(n,m)
q=0
for i in range(len(m)):
    t=(m[i]*(m[i]-1))//2
    q+=t

for i in range(a):
    w=m[n.index(b[i])]-1
    print(q-w)

Submission status: Wrong Answer

Solution code:
import numpy as np

N=int(input())
A=np.array(list(map(int,input().split())))
'''
以下、方針
・Aから、各要素の出現回数を取得する。
・出現回数から、組み合わせを計算する。
'''
uni,cou=np.unique(A,return_counts=True)
# print(uni)
# print(cou)
com=[]
for i in range(len(cou)):
    c=(cou[i]*(cou[i]-1))//2
    com.append(c)
# com=np.array(com)
# print(com)
totalcombination=sum(com)

'''
以下方針
・Aから数字を取得
・その数字に対応する組み合わせを減らす。
・その数字の出現回数を1減らした状態の組み合わせの数を足す。
'''
for j in range (N):
    n=A[j] #nはAの数列の数字
    f=np.where(uni==n)[0][0]
    t=com[f]
    if t<=2:
        print(totalcombination-1)
    else:
        e=(cou[f]-1)*(cou[f]-2)//2
        print(totalcombination-t+e)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
count=[0]*(N+1)
for a in A:
    count[a]+=1
combination=0
for i in range(N):
    if count[i]!=0:
        combination+=count[i]*(count[i]-1)//2
for a in A:
    print(combination-(count[a]-1))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
l = []
total = 0

m = max(a)

for i in range(1, m+1):
    if a.count(i):
        total += (a.count(i)*(a.count(i)-1))/2
    l.append(a.count(i))

print(l)
print(total)

for k in range(n):
    score = total
    if l[a[k]-1]:
        score -= (l[a[k]-1]-1)
    print(int(score))

Submission status: Wrong Answer

Solution code:
import collections
import math
N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)

l = [math.factorial(i[1]) // (math.factorial(i[1]-2) * 2) for i in c.items() if i[1] > 1]
ans = sum(l)

for i in range(N):
  if A.count(A[i]) > 2:
    pl = math.factorial(A.count(A[i])-1) // (math.factorial(A.count(A[i])-3) * 2)
    mi = math.factorial(A.count(A[i])) // (math.factorial(A.count(A[i])-2) * 2)
    dif = pl - mi
    ans += dif
    print(ans)
  elif A.count(A[i]) == 2:
    ans -= 1
    print(ans)
  ans = sum(l)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
C=Counter(a)
#print(C)
total=0
for k,v in C.items():
    if v>=2:
        total+=v*(v-1)//2
print(total)
for i in range(n):
    V=C[a[i]]
    ans=total-(V*(V-1))//2+((V-1)*(V-2))//2
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N=int(sys.stdin.readline())
L=list(map(int,sys.stdin.readline().split()))
count=[0]*N
C=list(set(L))
x=0
for i in range(len(C)):
  x += int((L.count(C[i]))*(L.count(C[i])-1)/2)  
for K in range(N):
  print(x-L.count(L[K])-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
B = [0]*n

for a in A:
    B[a-1] += 1

total = 0
for b in B:
    if b > 1:
        total += b*(b-1)//2 

C = [0]*n
for i,b in enumerate(B):
    if b == 2:
        C[i] = total - 1
    elif b > 2:
         C[i] = total + (b-1)*(b-2)//2 - (b)*(b-1)//2 

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

Submission status: Wrong Answer

Solution code:
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

Submission status: Wrong Answer

Solution code:
import math
import collections
def calc_combi2(n):
    if n<=1:
        return 0
    return math.factorial(n)/(math.factorial(n-2)*math.factorial(2))
n=int(input())
data=list(map(int,input().split()))
data_cnt=collections.Counter(data)
count=0
for i in data_cnt.values():
    if 2<=i:
        count+=calc_combi2(i)
for i in data:
    if i<=1:
        print(count)
    else:
        ans=count+(calc_combi2(data_cnt[i]-1)-calc_combi2(data_cnt[i]))
        print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b0=list(a[1:])
c0=Counter(b0)
d0=0
for i in c0:
    d0+=(c0[i])*(c0[i]-1)/2
print(d0)
for j in range(1,n-1):
    b=list(a[0:j])+list(a[j+1:])
    c=Counter(b)
    d=0
    for j in c:
        d+=(c[j])*(c[j]-1)/2
    print(d)
b2=list(a[:-1])
c2=Counter(b2)
d2=0
for k in c2:
    d2+=(c2[k])*(c2[k]-1)/2
print(d2)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

counter = [0 for _ in range(n + 1)]
for i in a:
    counter[i] += 1

MAX = 10 ** 6
MOD = 10 ** 9 + 7
fac = [0 for i in range(MAX)]
finv = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]

def comInit(mod):
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

def com(n, r, mod):
    if n < r:
        return 0
    if n < 0 or r < 0:
        return 0
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod

comInit(MOD)

total = 0 
diff = [0 for _ in range(n + 1)]
for i, c in enumerate(counter):
    x = com(c, 2, MOD)
    total += x
    if c - 1 <= 0:
        diff[i] = x
    else:
        y = com(c - 1, 2, MOD)
        diff[i] = x - y

for i in range(n):
    print(total - diff[a[i]])

Submission status: Wrong Answer

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

def factorial(n):
    v = 1
    for i in range(1, n + 1):
        v *= i
    return v

def comb(a, b):
    return factorial(a) // (factorial(b) * factorial(a - b))

from collections import Counter
acnt = dict(Counter(a))
value = list(acnt.values())
sv = 0
for i in range(len(value)):
    if value[i] > 1:
        sv += (value[i]*value[i-1])//2
for i in range(n):
    cur = a[i]
    cursv = sv
    if acnt[cur] > 2:
        cursv = cursv - acnt[cur] + 1
    elif acnt[cur] == 2:
        cursv -= 1
    print(cursv)

Submission status: Wrong Answer

Solution code:
#D
import collections
n=int(input())
a_list=list(map(int,input().split()))

b_list=[0]*n#何が何個あるかカウント
c_list=[]#aの種類をストック
for i in range(n):
    a=a_list[i]
    b_list[a-1] += 1
    if a not in c_list:
        c_list.append(a)

def getnum(n):#n個から二個選ぶ時の取り方
    if n<=1:
        return 0
    else:
        return int(n*(n-1)/2)
    
    
cnt=0    
for i in c_list:
    cnt += getnum(b_list[i-1])
#print(cnt)
ans=0
for i in range(n):
    a=a_list[i]
    if b_list[a-1]>=2:
        ans = cnt - (b_list[a-1] - 1)#ボール１つ取ったらn-1減る
        
    print(ans)
    

    
#print(b_list)
#print(c_list)

Submission status: Wrong Answer

Solution code:

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

number_set = list(set(A))
#print("number set is :", number_set)    
    
for k in range(n):
    out = 0
    ans = []
    ans += A[0:k]
    ans += A[k+1:n]
    #print(ans)
    for i in range(len(number_set)):
        #print(ans.count(number_set[i]))
        out += ans.count(number_set[i]) * (ans.count(number_set[i]-1)) //2
        
    print(out)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = [0]*max(a)
for i in a:
    x[i-1]+=1


for i in range(1,n+1):
    x[a[i-1]-1]-=1
    count = 0
    x_ = [(k*(k-1))/2 for k in x if k>=2]
    count = sum(x_)
    # for j in x:
    #     if j>=2:
    #         count += int((j*(j-1)/2))
    x[a[i-1]-1]+=1
    print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
x = [0]*max(a)
for i in a:
    x[i-1]+=1


for i in range(1,n+1):
    x[a[i-1]-1]-=1
    count = 0
    x_ = [(k*k-1)/2 for k in x if k>=2]
    count = sum(x_)
    # for j in x:
    #     if j>=2:
    #         count += int((j*(j-1)/2))
    x[a[i-1]-1]+=1
    print(count)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
al = list(map(int, input().split()))
C = Counter(al)
# print(C)
# print(C.values())
ans = 0
for i in C.values():
    ans += i * (i - 1) / 2

for a in al:
    k = C[a]
    print(ans - (k * (k - 1) / 2) + (k - 1) * (k - 2) / 2)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))
B=collections.Counter(A)
count=0
for i in range(1,N+1):
  a=B["i"]
  count+=(a*(a-1))/2

  
for i in range(1,N+1):
  a=B["i"]
  print(int(count-(a*(a-1))/2))

Submission status: Wrong Answer

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

import collections
 
c = collections.Counter(l)
ans = 0

for i in c.values():
    ans += i * (i - 1) // 2
    
for i in l:
    print(ans - c[i] - 1)

Submission status: Wrong Answer

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

li = [0] * (n+1)
tmp = 0

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

Submission status: Wrong Answer

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

li = [0] * (n+1)
tmp = 0

for i in range(n):
    li[a[i]] += 1
    
for i in range(n):
    tmp += sum(int(i) for i in range(li[i]))
    
for i in range(n):
    ans = tmp - li[a[i]] + 1
    print(ans)

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
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])

Submission status: Wrong Answer

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

from collections import Counter
counter=Counter(a)

# すべての組み合わせを事前に計算しておく
combi_sum=0
for num,cnt in counter.items():
    n_cnt=cnt
    if num==n:
        n_cnt-=1
    combi_sum+=n_cnt*(n_cnt-1)//2

for i in range(n):
    print(combi_sum - counter[a[i]] + 1)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
mx = max(a)
b=[0] * 2000000
ans = 0
for i in range(len(a)):
    b[a[i]-1] += 1

for i in range(mx):
    if(b[i] == 0 or b[i] == 1):
        ans += 0
    else:
        ans = ans + int(b[i] * (b[i]-1)/2)
ans1 = 0


for i in range(len(a)):
    ans1 = ans
    if(b[a[i]-1] >2):
        ans1 = ans1 -int((b[a[i]-1]-(b[a[i]-1]-1))/2)+ int(((b[a[i]-1]-1) * (b[a[i]-1]-2))/2)
        print(int(ans1))
    elif(b[a[i]-1] == 2):
        print(int(ans1-1))
    elif(b[a[i]-1] < 2):
        print(int(ans1))

Submission status: Wrong Answer

Solution code:
import math


def fac(x):
    w = math.factorial(x)
    if(w >= 2):
        w = int(w / math.factorial(x - 2))
    w = int (w / 2)

    return w

n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
b.append('i')
cnt =[0] * b[n-1]
tmp = 1
tmp1 =  b[0]
ans = 0
for i in range(n):
    if(tmp1 == b[i + 1]):
        tmp += 1
    elif(tmp1 != b[i+1]):
        if(tmp <= 1):
            cnt[tmp1-1] = 0
        else:
            cnt[tmp1-1] = tmp 
            ans = ans +  fac(tmp) 
        tmp = 1
    tmp1 = b[i + 1]
ans1 = ans

for i in range(n):
    if(cnt[a[i] - 1] != 0):
        ans1 = ans - fac(cnt[a[i]-1]) + fac(cnt[a[i]-1] -1)
    print(ans1)

Submission status: Wrong Answer

Solution code:
import math


def fac(x):
    w = math.factorial(x)
    if(w >= 2):
        w = int(w / math.factorial(x - 2))
    w = int (w / 2)

    return w

n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
b.append('i')
cnt =[0] * b[n-1]
tmp = 1
tmp1 =  b[0]
for i in range(n):
    if(tmp1 == b[i + 1]):
        tmp += 1
    elif(tmp1 != b[i+1]):
        if(tmp <= 1):
            cnt[tmp1-1] = 0
        else:
            cnt[tmp1-1] = tmp   
        tmp = 1
    tmp1 = b[i + 1]
ans = 0
for i in range(len(cnt)):
    if(cnt[i] == 0):
        ans += 0
    else:
        ans = ans +  fac(cnt[i])
ans1 = ans

for i in range(n):
    if(cnt[a[i] - 1] != 0):
        ans1 = ans - fac(cnt[a[i]-1]) + fac(cnt[a[i]-1] -1)
    print(ans1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)
B.append(0)
p = B[0]
y = dict()
u = 0
for k in range(N+1):
    q = B[k]
    if p != q:
        y[p] = u
        u = 0
    u += 1
    p = q
All = 0
for l in y.values():
    All +=l*(l-1)//2
print(All)
for j in range(N):
    x = A[j]
    print(All+(y[x]-1)*(y[x]-2)//2-y[x]*(y[x]-1)//2)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
lia = [0]*n
sum1 = 0
for i in range(n):
    lia[li[i]-1] += 1
for i in range(n):
    if lia[i] >= 2:
        lia[i] -= 1
        sum1 += (lia[i]*(lia[i]+1)//2)
for i in range(n):
    a = lia[li[i]-1]*(lia[li[i]-1]+1)//2
    b = (lia[li[i]-1]-1)*lia[li[i]-1]//2
    if sum1-a+b >= 0:
        print(sum1-a+b)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
lia = [0]*n
sum1 = 0
for i in range(n):
    lia[li[i]-1] += 1
for i in range(n):
    if lia[i] >= 2:
        lia[i] -= 1
        sum1 += (lia[i]*(lia[i]+1)//2)
print(lia)
for i in range(n):
    a = lia[li[i]-1]*(lia[li[i]-1]+1)//2
    b = (lia[li[i]-1]-1)*lia[li[i]-1]//2
    if sum1-a+b >= 0:
        print(sum1-a+b)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
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)
ans = 0
for i in range(N):
    ans += d[A[i]]*(d[A[i]]-1)/2

for i in range(N):
    print(ans - (d[A[i]]- 1))

Submission status: Wrong Answer

Solution code:
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 a:
    ans = total
    ans -= cnt[i] * (cnt[i]-1) / 2
    ans += (cnt[i]-1) * (cnt[i]-2) / 2
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from pprint import pprint
from scipy.misc import comb

n = int(input())

a_list = list(map(int,input().split()))

a_dict = defaultdict(int)

for i in a_list:
    a_dict[i] += 1

#pprint(a_dict)

#総数から(a_dict[k]-1)の値を引いていく。
#例えば5C2のものが一つ減った場合、4C2になる。この差分は5C2-4C2=10-6=4 
#例えば6C2のものが一つ減った場合、5C2になる。この差分は6C2-5C2=15-10=5 
#例えば7C2のものが一つ減った場合、6C2になる。この差分は7C2-6C2=21-15=6

total = 0

#組み合わせの総数を求める。
for j in a_dict.values():
    if j != 1:
        total += comb(j,2)

for k in a_list:
    print(int(total - (a_dict[k]-1)))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from pprint import pprint
from scipy.misc import comb

n = int(input())

a_list = list(map(int,input().split()))

a_dict = defaultdict(int)

for i in a_list:
    a_dict[i] += 1

#pprint(a_dict)

#総数から(a_dict[k]-1)の値を引いていく。
#例えば5C2のものが一つ減った場合、4C2になる。この差分は5C2-4C2=10-6=4 
#例えば6C2のものが一つ減った場合、5C2になる。この差分は6C2-5C2=15-10=5 
#例えば7C2のものが一つ減った場合、6C2になる。この差分は7C2-6C2=21-15=6

total = 0

#組み合わせの総数を求める。
for j in a_dict.values():
    total += comb(j,2)

for k in a_list:
    print(int(total - (a_dict[k]-1) + 1))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from pprint import pprint
from scipy.misc import comb

n = int(input())

a_list = list(map(int,input().split()))

a_dict = defaultdict(int)

for i in a_list:
    a_dict[i] += 1

#pprint(a_dict)

#総数から(a_dict[k]-1)の値を引いていく。
#例えば5C2のものが一つ減った場合、4C2になる。この差分は5C2-4C2=10-6=4 
#例えば6C2のものが一つ減った場合、5C2になる。この差分は6C2-5C2=15-10=5 
#例えば7C2のものが一つ減った場合、6C2になる。この差分は7C2-6C2=21-15=6

total = 0

#組み合わせの総数を求める。
for j in a_dict.values():
    total += comb(j,2)

for k in a_list:
    print(int(total - (a_dict[k]-1)))

Submission status: Wrong Answer

Solution code:
import itertools as iter

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
import functools
import math
import collections
import scipy
import fractions
import itertools

def solve():
  n = int(input())
  a = list(map(int, input().split()))
  c = collections.Counter(a)
  s = 0
  for i in list(c.values()):
    s += i*(i-1)//2
  print(c)
  for i in a:
    print(s-(c[i]-1))
  return 0
 
if __name__ == "__main__":
  solve()

Submission status: Wrong Answer

Solution code:
import functools
import math
import collections
import scipy
import fractions
import itertools

def solve():
  n = int(input())
  a = list(map(int, input().split()))
  c = collections.Counter(a)
  s = 0
  for i in list(c.values()):
    s += i*(i-1)//2
  print(c)
  for i in a:
    print(c[i])
    print(s-(c[i]-1))
  return 0
 
if __name__ == "__main__":
  solve()

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
if len(set(l))==len(l):
    for i in range(len(l)):
        print(0)
elif len(set(l))==1:
    for i in range(n):
        print((n*(n-1)//2)-n+1)
else:
    d = {}
    for i in l:
        if i in d:
            d[i]+=1
        else:
            d[i] = 1
    for i in l:
        d[i] -= 1
        print(sum(set(d.values())))
        d[i] += 1

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
if len(set(l))==len(l):
    for i in range(len(l)):
        print(0)
elif len(set(l))==1:
    for i in range(len(l)):
        print(n+1)
else:
    kp = list(set(l))
    print(kp)
    dt = {}
    for i in range(len(kp)):
        tp = kp[i]
        l.remove(kp[i])
        dt[tp]= sum(set([l.count(i) for i in l]))
        l.insert(i,tp)
        print(dt)
    for i in l:
        print(dt[i])

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
if len(set(l))==len(l):
    for i in range(len(l)):
        print(0)
elif len(set(l))==1:
    for i in range(len(l)):
        print(n+1)
else:
    for k in range(len(l)):
        tp = l.pop(k)
        print(sum(set([l.count(i) for i in l])))
        l.insert(k,tp)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
A = list(map(int,input().split()))
B = collections.Counter(A)
C = B.copy()
total = 0
for i in B.values():
    total += i*(i-1)//2
for i in A:
    print(total - i)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

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()))
#print(n, a)

#dic1はその要素を含む、dic2はその要素を含まない解
dic1 = {}
#dic2 = {}
#a[i]の要素に対する組み合わせが計算されていない場合
#計算後辞書に保存
#辞書から解を出力
for i in range(n):
    if not a[i] in dic1: 
        ans1 = 0
        ans2 = 0
        ball_n = a.count(a[i])
        if ball_n >= 3:
            ans2 = cmb(ball_n-1, 2)
            ans1 = cmb(ball_n, 2)
        elif ball_n >= 2:
            ans2 = 0
            ans1 = cmb(ball_n, 2)
        dic1[a[i]] = ans1
        #dic2[a[i]] = ans2

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

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()))
#print(n, a)

#dic1はその要素を含む、dic2はその要素を含まない解
dic1 = {}
dic2 = {}
#a[i]の要素に対する組み合わせが計算されていない場合
#計算後辞書に保存
#辞書から解を出力
for i in range(n):
    if not a[i] in dic1: 
        ans1 = 0
        ans2 = 0
        ball_n = a.count(a[i])
        if ball_n >= 3:
            ans2 = cmb(ball_n-1, 2)
            ans1 = cmb(ball_n, 2)
        elif ball_n >= 2:
            ans2 = 0
            ans1 = cmb(ball_n, 2)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

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()))
#print(n, a)

#dic1はその要素を含む、dic2はその要素を含まない解
dic1 = {}
dic2 = {}
#a[i]の要素に対する組み合わせが計算されていない場合
#計算後辞書に保存
#辞書から解を出力
for i in range(n):
    if not a[i] in dic1: 
        ans1 = 0
        ans2 = 0
        ball_n = a.count(a[i])
        if ball_n >= 3:
            ans2 = cmb(ball_n-1, 2)
            ans1 = cmb(ball_n, 2)
        elif ball_n >= 2:
            ans2 = 0
            ans1 = cmb(ball_n, 2)
        dic1[a[i]] = ans1
        dic2[a[i]] = ans2

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

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()))
#print(n, a)

#dic1はその要素を含む、dic2はその要素を含まない解
dic1 = {}
dic2 = {}
#a[i]の要素に対する組み合わせが計算されていない場合
#計算後辞書に保存
#辞書から解を出力
for i in range(n):
    if not a[i] in dic1: 
        ans1 = 0
        ans2 = 0
        ball_n = a.count(a[i])
        if ball_n >= 3:
            ans2 = cmb(ball_n-1, 2)
            ans1 = cmb(ball_n, 2)
        elif ball_n >= 2:
            ans2 = 0
            ans1 = cmb(ball_n, 2)
        dic1[a[i]] = ans1
        dic2[a[i]] = ans2

print(dic1)
print(dic2)
for i in range(n):
    ans = 0
    ans = sum(dic1.values()) - dic1[a[i]] + dic2[a[i]]
    print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial

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

for i,a in enumerate(A):
  if a in dict:
    dict[a].append(i)
  else:
    dict[a]=[i]

ans = 0    
    
for k,v in dict.items():
  if len(v) >= 2:
    ans += len(v) * (len(v)-1) //2

  
for i in range(n):
  wnum = A[i]
  l=dict[wnum]
  if 2 < len(dict[wnum]):
    print(int(ans -(len(v) * (len(v)-1) //2) + len(v) * (len(v)-1) //2))
  elif 2 == len(dict[wnum]):
    print(int(ans - 1))
  else:
    print(int(ans))

Submission status: Wrong Answer

Solution code:
from math import factorial

n = int(input())
A = list(map(int,input().split()))
print(len(A))
dict = {}

for i,a in enumerate(A):
  if a in dict:
    dict[a].append(i)
  else:
    dict[a]=[i]

ans = 0    
    
for k,v in dict.items():
  if len(v) >= 2:
    ans += len(v) * (len(v)-1) //2

  
for i in range(n):
  wnum = A[i]
  l=dict[wnum]
  if 2 < len(dict[wnum]):
    print(int(ans -(len(v) * (len(v)-1) //2) + len(v) * (len(v)-1) //2))
  elif 2 == len(dict[wnum]):
    print(int(ans - 1))
  else:
    print(int(ans))