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

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

A_counter= collections.Counter(A)

sum = 0
for count in A_counter:
    sum += (A_counter[count]* (A_counter[count]-1)) // 2

for k in range(N):
    c_a = (A_counter[A[k]]-1) *  (A_counter[A[k]]-2)//2
    print(sum - c_a -1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import math

N = int(input())
A = [int(i) for i in input().split()]
d = defaultdict(int)
for a in A:
  d[a] += 1

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  
num = 0
for i in d.values():
  if i >= 2:
    num += combinations_count(i, 2)
    
for i in range(N):
  a = A[i]
  if d[a] > 2:
    print(num - combinations_count(d[a], 2) + combinations_count(d[a]-1, 2))
  elif d[a] == 2:
    print(num - combinations_count(d[a], 2))
  else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
A=[int(x) for x in input().rstrip().split()]
A_s=list(set(A))
A_count=[0]*N
cnt=0

for i in A:
  A_count[i-1]+=1


#A_count=[A.count(A_s[x]) for x in range(len(A_s))]
# for x in range(len(A_s)):
#   i=A.count(A_s[x])
#   A_count.append(i)



for i in A_count:
  if 2<=i:
    cnt+=(i*(i-1))//2



# [print(cnt) if A_count[A_s.index(A[i])]==1 else print(cnt-A_count[A_s.index(A[i])]+1) for i in range(N)]

for i in A:
  x=A_count[A_s.index(i)]
  if x==1:
    print(cnt)
  else:
    print(cnt-x+1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
d={}
ua=list(set(a))
total=0
print('hoge')
for x in ua:
    y=a.count(x)
    d[x]=y
    total+=(y-1)*y//2
for x in a:
    print(total-d[x]+1)

Submission status: Wrong Answer

Solution code:
import itertools
import math 
def C(n,r): return n*(n-1)/r

n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
    d[i] = d.get(i, 0)+1

c = 0
cc = {}
for key, val in d.items():
    temp = C(val,2)
    c += temp
    if cc.get(key) is None:
        cc[key] = temp - C(val-1,2)
for i in a:
    print(c - cc[i])

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    N = int(input())
    A = list(map(int, input().split()))
    c = Counter(A)
    comb = 0
    for i in c.values():
        if i >= 2:
            comb += i*(i-1)/2
    for i in range(N):
        print(comb - (c[A[i]] - 1))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
from collections import defaultdict

max = 10**6+1
mod = 10**9+7
fac = [None]*max
finv = [None]*max
inv = [None] * max

def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[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,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k]*finv[n-k]%mod)%mod

def main():
    N = int(input())
    A = list(map(int, input().split()))
    c = Counter(A)
    d = defaultdict(lambda: -1)
    COMinit()
    for i in range(N):
        ans = 0
        if d[A[i]] != -1:
            ans += d[A[i]]
        else:
            c[A[i]] -= 1
            v = list(c.values())
            for j in v:
                if j >= 2:
                    ans += COM(j,2)
            d[A[i]] = ans
            c[A[i]] += 1
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
d={}
for x in a:
    if d.get(x):
        d[x]+=1
        continue
    d[x]=1
total=sum(d.values())
for x in a:
    print(total-d[x]+1)

Submission status: Wrong Answer

Solution code:
import itertools
import math 
def C(n,r):
    if n-r < 0:
        return 0 
    return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
    d[i] = d.get(i, 0)+1

c = 0
for i in d.values():
    c += C(i,2)
print(d)
for i in a:
    print(c - (C(d[i],2)-C(d[i]-1,2)))

Submission status: Wrong Answer

Solution code:
import sys
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
N = II()
A = list(MI())
ans = 0
cum = {}
def couple_combination(n):
    if n >= 2:
        return int(n * (n - 1) / 2)
    else:
        return 0
for unique in list(set(A)):
    cum_count = A.count(unique)
    cum[unique] = cum_count
    ans += couple_combination(cum_count)
for i in A:
    print(ans - cum[i])

Submission status: Wrong Answer

Solution code:
import collections
def C(n):
    return n * (n-1) // 2
N = int(input())
A = list(map(int,input().split()))
c = collections.Counter(A)
d = {}
sm = 0
for k,v in c.most_common():
    d[k] = v
    sm += C(v)
for a in A:
    print (sm - 1 + d[a])

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split() ))
from collections import Counter
d=dict(Counter(A))
print(d)
cnt=0
for item in d:
    cnt += (d[item])*(d[item]-1)//2

print("cnt",cnt)
   
for num in A:
    new = max(0, (d[num]-1)*(d[num]-2)//2)
    print(cnt- d[num]*(d[num]-1)//2 + new)

Submission status: Wrong Answer

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

B = [0] * N

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

ans = 0

for i in range(N):
	ans += B[i] * (B[i] - 1) // 2

for i in range(N):
	res = ans
	res -= B[i] * (B[i] - 1) // 2
	if B[i] >= 1:
		res += (B[i] - 1) * (B[i] - 2) // 2
	print(res)

Submission status: Wrong Answer

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

B = [0] * N

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

ans = 0

for i in range(N):
	ans += B[i] * (B[i] - 1) // 2

for i in range(N):
	ans -= B[i] * (B[i] - 1) // 2
	if B[i] >= 1:
		ans += (B[i] - 1) * (B[i] - 2) // 2
	print(ans)

Submission status: Wrong Answer

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

#aに含まれる要素とその個数を取得する
d = {}
for i in range(n):
	d[a[i]] = d.get(a[i], 0) + 1

# print(d)

for i in range(n):
	tmp = a[i]
	print(d[tmp] - 1)

Submission status: Wrong Answer

Solution code:
def nC2(n):
    return n*(n-1)/2

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

cnt = [0]*(n+1)
total = 0
ans = 0

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

for i in range(n):
    total += nC2(cnt[i])

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

Submission status: Wrong Answer

Solution code:
def nC2(n):
    return n*(n-1)//2

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

cnt = [0]*(n+1)
total = 0
ans = 0

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

for i in range(n):
    total += nC2(cnt[i])

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

Submission status: Wrong Answer

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

#output
from collections import  Counter
L = Counter(A)

original_answer = 0
for i in range(1, N):
    original_answer += ( L[i] * (L[i]-1) )// 2

for i in range(N):
    print(original_answer - (L[A[i]]*(L[A[i]]-1))//2 + ((L[A[i]]-1)*(L[A[i]]-2))//2)

Submission status: Wrong Answer

Solution code:
def comb(n):
    if n < 2:
        return 0
    else:
        return int(n*(n-1)/2)
        
def sabun(n):
    if n < 2:
        return 0
    else:
        return n-1

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

origin = list(set(AS))
num = []
for i in origin:
    num.append(AS.count(i))

all_num = 0
for i in num:
    all_num += comb(i)
    
for i in range(n):
    j = num[origin.index(AS[i])]
    ans = all_num - sabun(n)
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections

num = int(input())
a_i = list(map(int, input().split()))
anslist = collections.Counter(a_i)
ans = sum(anslist.values())
for x in range(num):
    val = a_i[x]
    cnt = a_i.count(val)
    sa = (cnt - 1)
    print(ans - sa)

Submission status: Wrong Answer

Solution code:

n = int(input())
num_list =  list(map(int,input().split()))
num_list2 = [0]*n
num_list3 = [0]*n
for i in num_list:
    num_list2[i-1] += 1
for i in range(n):
    num_list3[i-1] = n*(n-1) // 2

for i in num_list:
    ans = n*(n-1) // 2
    print(ans-num_list3[i-1]+sum(num_list3))
  #  elif size == 1:
        #ans = 0
   # else :
    #    ans = 0 
    #num_list5[num_list2[i]-1] = ans

Submission status: Wrong Answer

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

#output
from collections import  Counter
L = Counter(A)

original_answer = 0
for i in range(1, N):
    if L[i] >= 2:
        original_answer += ( L[i] * (L[i]-1) )// 2

for i in range(N):
    if L[A[i]] == 1:
        print(original_answer)
    elif L[A[i]] == 2:
        print(original_answer -1)
    elif L[A[i]] > 2:
        print(original_answer - L[A[i]]*(L[A[i]]-1)//2 + (L[A[i]]-1)*(L[A[i]]-2)//2)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
def comb(n, r):
    if n == -1:
        n = 0
    return n*(n-1) // 2
n = int(input())
num_list =  map(int,input().split())
num_list2 = [0]*n
num_list3 = [0]*n
for i in num_list:
    num_list2[i-1] += 1
for i in range(n):
   # size = max(0 , num_list3[num_list2[i]-1])
#    if size >= 2:
    ans = comb(num_list2[i-1],2)
  #  elif size == 1:
   #     ans = 0
   # else :
    #    ans = 0 
    num_list3[i-1] = ans

for i in num_list:
  #  size = max(0 , num_list3[num_list2[i]-1]-1)
   # if size >= 2:
    ans = comb(num_list2[i-1]-1,2)
    print(ans-num_list3[i-1]+np.sum(num_list3))
  #  elif size == 1:
        #ans = 0
   # else :
    #    ans = 0 
    #num_list5[num_list2[i]-1] = ans

Submission status: Wrong Answer

Solution code:
import numpy
N = int(input())
E= list(map(int,input().split()))
ans = [0 for _ in range(N)]
unique = list(numpy.unique(E))
for s in range(len(unique)):
    unique[s] = int(unique[s])
uniqueNum = [0 for _ in range(len(unique))]

for t in range(len(unique)):
    uniqueNum[t] = E.count(unique[t])
uniqueAns = [0 for _ in range(len(unique))]
full =0
for l in range(len(unique)):
    full = full + uniqueNum[l] * (uniqueNum[l]-1)/2
for m in range(len(unique)):
    uniqueAns[m] = full - uniqueNum[m]+1
for k in range(N):
    ans[k] = uniqueAns[unique.index(int(E[k]))]
    print(ans[k])

Submission status: Wrong Answer

Solution code:
import copy
n=int(input())
a=list(map(int,input().split()))
aset=list(set(a))
ans=0
alist=[ 0 for i in range(n)]
for _ in a:
    alist[_ - 1] += 1
for j in aset:
    ans += (a.count(j)*a.count(j)-1) // 2
for u in a:
    print(ans - alist[u - 1])

Submission status: Wrong Answer

Solution code:
import numpy
import copy
N = int(input())
E=input().split()
ans = [0 for _ in range(N)]
unique = list(numpy.unique(E))
for s in range(len(unique)):
    unique[s] = int(unique[s])
uniqueNum = [0 for _ in range(len(unique))]

for t in range(len(unique)):
    uniqueNum[t] = int(E.count(unique[t]))
uniqueAns = [0 for _ in range(len(unique))]
full =0
for l in range(len(unique)):
    full = full + uniqueNum[l] * (uniqueNum[l]-1)/2
for m in range(len(unique)):
    uniqueAns[m] = full - uniqueNum[m]+1
for k in range(N):
    ans[k] = uniqueAns[unique.index(int(E[k]))]
for i in range(N):
    print(int(ans[i]))

Submission status: Wrong Answer

Solution code:
import numpy
import copy
N = int(input())
E=input().split()
ans = [0 for _ in range(N)]
unique = list(numpy.unique(E))
for s in range(len(unique)):
    unique[s] = int(unique[s])
uniqueNum = [0 for _ in range(len(unique))]

for t in range(len(unique)):
    uniqueNum[t] = int(E.count(str(unique[t])))
uniqueAns = [0 for _ in range(len(unique))]
full =0
for l in range(len(unique)):
    full = full + uniqueNum[l] * (uniqueNum[l]-1)/2
for m in range(len(unique)):
    uniqueAns[m] = full - uniqueNum[m]+1
for k in range(N):
    ans[k] = uniqueAns[unique.index(int(E[k]))]
for i in range(N):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
N=int(input())
list1=list(map(int,input().split()))
list2=[0]*N

for i in range(N):
    list2[i]=list1.count(i+1)

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

total=0
for i in list2:
    total+=choose2(i)


for i in list1:
    ans=total-(list2[i-1]-1)
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy
import copy
N = int(input())
E=input().split()
ans = [0 for _ in range(N)]
unique = list(numpy.unique(E))
for s in range(len(unique)):
    unique[s] = int(unique[s])
uniqueNum = [0 for _ in range(len(unique))]

for t in range(len(unique)):
    uniqueNum[t] = int(E.count(str(unique[t])))
uniqueAns = [0 for _ in range(len(unique))]
full =0
for l in range(len(unique)):
    full = full + uniqueNum[l] * (uniqueNum[l]-1)/2
for m in range(len(unique)):
    uniqueAns[m] = full - uniqueNum[m]+1
for k in range(N):
    ans[k] = int(uniqueAns[unique.index(int(E[k]))]) - 1
for i in range(N):
    print(int(ans[i]))

Submission status: Wrong Answer

Solution code:
import collections

def combinations_count(n, r):
    return n * (n-1) // r


n = int(input())
l = [int(x) for x in input().split()]

l1 = []
l2 = []
c = collections.Counter(l)

total = sum([combinations_count(i, 2) for i in c.values()])

for a in l:
    l1.append(combinations_count(c[a], 2))
    l2.append(combinations_count(c[a]-1, 2))
print(l1, l2)
for i in range(len(l)):
    print(total-l1[i]+l2[i])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
n = int(input())
s = list(map(int,input().split()))
ans = {}
#各番号がいくつずつあるのかを整理
#keyに番号、valueにその番号が書かれてあるボールの数
for i in range(n):
    if not s[i] in ans.keys():
        ans[s[i]] = 1
    else:
        ans[s[i]] += 1
#iC2の総和
answer = 0
for i in ans.values():
    answer += i
#answer-nC2+(n-1)C2 = answer-n+1
#nはans[s[i]],よって以下の出力で求められる
for i in range(n):
    print(answer-ans[s[i]]+1)

Submission status: Wrong Answer

Solution code:
import math
import collections
m=int(input())
a=list(map(int,input().split()))
A=collections.Counter(a)
total=0
for j in A.values():
    total = total + j*(j-1)/2
for k in range(m):
    s=A[a[k]]
    d=total-s+1
    print(d)

Submission status: Wrong Answer

Solution code:
import collections
def I(): return int(input())
def LI(): return list(map(int,input().split()))
##################################################
N = I()
A = LI()
count = collections.Counter(A)
nC2 = {}
for x in count.values():
    nC2[x] = x*(x-1)//2
sum = sum(nC2.values())
for x in A:
    if x-1 in nC2:
        minus = nC2[x-1]
    else:
        minus = (x-1)*(x-2)//2
        nC2[x-1] = minus
    print(sum-x+minus)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
C=[0]*(N+1)

ans1=0
s=0

for A_i in A:
    C[A_i]+=1

for j in range(N):
    c=C[j]
    if c>1:
        s=c*(c-1)/2
        ans1=ans1+s
        
for A_k in A:
    d=C[A_k]
    if d<2:
        ans=ans1
    else:
        ans=ans1-(d-1)
    print(int(ans))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
C=[0]*(N+1)

ans1=0
s=0

for A_i in A:
    C[A_i]+=1

for j in range(N):
    c=C[j]
    if c>1:
        s=c*(c-1)/2
        ans1=ans1+s
        
for k in range(N):
    b=A[k]
    d=C[b]
    if d<2:
        ans=ans1
    else:
        ans=ans1-(d-1)
    print(int(ans))

Submission status: Wrong Answer

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

#output
from collections import  Counter
L = Counter(A)

original_answer = 0
for i in range(1, N):
    if L[i] >= 2:
        original_answer +=( L[i] * (L[i]-1) )// 2

for i in range(N):
    if L[A[i]] <= 1:
        print(original_answer)
    elif L[A[i]] == 2:
        print(original_answer -1)
    elif L[A[i]] > 2:
        print(original_answer - L[A[i]]*(L[A[i]]-1)//2 + (L[A[i]]-1)*(L[A[i]]-2)//2)

Submission status: Wrong Answer

Solution code:
import numpy
import copy
N = int(input())
E= list(map(int,input().split()))
ans = [0 for _ in range(N)]
unique = numpy.unique(E)
#for s in range(len(unique)):
#unique = int(unique)
uniqueNum = [0 for _ in range(len(unique))]

uniqueAns = [0 for _ in range(len(unique))]

y =0
for t in range(len(unique)):
    uniqueNum[t] = E.count(unique[t])
for g in range(len(unique)):
    uni = copy.copy(uniqueNum)
    uni[g] = uni[g] -1
    for h in range(len(unique)):
        y = y + uni[h] * (uni[h]-1)/2
    uniqueAns[g] =  y
for k in range(N):
    for w in range(len(uni)):
        if unique[w] == E[k]:
            ans[k] = uniqueAns[w]
            break
for i in range(N):
    print(int(ans[i]))

Submission status: Wrong Answer

Solution code:
import collections


m = int(input())
A = list(map(int,input().split()))[:m]
c = collections.Counter(A)
 
def hoge(n):
    if n <= 2:return 1 
    return n * (n - 1) // 2


full = sum([ hoge(n) for n in c.values()])

for a in A:
    print(full - (c[a]) + hoge(c[a]-1))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a)-1 for a in input().split()]
X = [0] * N
for a in A:
	X[a] += 1
s = 0
for x in X:
	s += x * (x-1) // 2
print(s)
for a in A:
	print(s - (X[a] - 1))

Submission status: Wrong Answer

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

#output
from collections import  Counter
L = Counter(A)

original_answer = 0
for i in range(1, N):
    if L[i] >= 2:
        original_answer += L[i] * (L[i]-1) // 2

for i in range(N):
    if L[A[i]] == 1:
        print(original_answer)
    elif L[A[i]] == 2:
        print(original_answer -1)
    elif L[A[i]] > 2:
        print(original_answer - L[A[i]]*(L[A[i]]-1)//2 + (L[A[i]]-1)*(L[A[i]]-2)//2)

Submission status: Wrong Answer

Solution code:
import bisect
import copy
N = int(input())
a = list(map(int, input().split()))
b = sorted(a)
c = list(set(b))
length = 0
l = []
num = []
sumlen = 0
for i in c:
    bs = bisect.bisect_right(b, i)
    length = bs - sumlen
    sumlen += length
    l.append(length)
    num.append(int((length * (length - 1)) / 2))
for k in a:
    idx = c.index(k)
    n = l[idx]
    number = copy.copy(num)
    number[idx] = number[idx] * (n-2) / n
    print(int(sum(number)))

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


n = int(input())
l = [int(x) for x in input().split()]

ll = [x for x in set(l) if l.count(x) > 1]

sm = 0
m = [1 for x in range(n)]
for i in ll:
    t = l.count(i)
    sm += combinations_count(t, 2)
    m[i-1] = t

print("unchi")

for i in l:
    print(sm-(m[i-1]-1))

Submission status: Wrong Answer

Solution code:
import numpy
import copy
N = int(input())
E=input().split()

ans = [0 for _ in range(N)]
unique = numpy.unique(E)

for s in range(len(unique)):
    unique[s] = int(unique[s])
uniqueNum = [0 for _ in range(len(unique))]
uniqueAns = [0 for _ in range(len(unique))]
y =0
for t in range(len(unique)):
    uniqueNum[t] = int(E.count(str(unique[t])))
for g in range(len(unique)):
    uni = copy.copy(uniqueNum)
    uni[g] = uni[g] -1
    for h in range(len(unique)):
        y = y + uni[h] * (uni[h]-1)/2
    uniqueAns[g] =  y

for k in range(N):
    for w in range(len(uni)):
        if unique[w] == E[k]:
            ans[k] = uniqueAns[w]
            break
for i in range(N):
    print(int(ans[i]))

Submission status: Wrong Answer

Solution code:
import math
import collections
import numpy as np

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

c = collections.Counter(A)
ans = 0
for k, v in c.items():
    if v > 1:
        ans = ans + combinations_count(v, 2)

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

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a_list = list(map(int,input().split()))
c=collections.Counter(a_list)
result=0
print(c)

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

for a in a_list:
    print(result - c[a] + 1)

Submission status: Wrong Answer

Solution code:
import numpy
import copy
N = int(input())
E=input().split()
ans = [0 for _ in range(N)]
unique = list(numpy.unique(E))
for s in range(len(unique)):
    unique[s] = int(unique[s])
uniqueNum = [0 for _ in range(len(unique))]
uniqueAns = [0 for _ in range(len(unique))]
y =0

for t in range(len(unique)):
    uniqueNum[t] = int(E.count(str(unique[t])))
for g in range(len(unique)):
    uni = copy.copy(uniqueNum)
    uni[g] = uni[g] -1
    for h in range(len(unique)):
        y = y + uni[h] * (uni[h]-1)/2
    uniqueAns[g] =  y
for k in range(N):
    for w in range(len(uni)):
        if unique[w] == E[k]:
            ans[k] =uniqueAns[w]
            break
for i in range(N):
    print(int(ans[i]))

Submission status: Wrong Answer

Solution code:
#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():#辞書に含まれる値をすべて取り出す
    print(i)  #1,2,3･･･の回数
    val += i * (i - 1) // 2  #整数が同じボールを選ぶ組み合わせ
    # val+=sum(range(i-1))
for i in range(n):
    b = c[a[i]]  #i番目の出現回数
    print(val - b + 1)  #bを除いたボールから整数が同じボールを選ぶ組み合わせ

Submission status: Wrong Answer

Solution code:
from scipy.misc import comb

N = int(input())
num_list = list(map(int, input().split()))
num_set = set(num_list)
num_dict = {}

for i in num_set:
  if num_list.count(i) == 1:
    pass
  else:
    num_dict[i] = num_list.count(i)

# 全数あるときの組み合わせ
ans_dict_1 = {}
# 1個抜いたときの組み合わせ
ans_dict_2 = {}

for k, v in num_dict.items():
  ans_dict_1[k] = comb(v,2,exact=True)
  ans_dict_2[k] = comb(v-1,2,exact=True)

total = sum(ans_dict_1.values())

for i in num_list:
  if i not in ans_dict_1:
    print(0)
  else:
    print(total - ans_dict_1[i] + ans_dict_2[i])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
 
def permutations_count(n, r):
    if r == 2:
        return int( (n*(n-1) ) / r )
    if r == 1:
        return n
 
 
N = int(input())
A = list(map(int,input().split()))
 
data = [0] * (N+1)
 
for i in range(N):
    data[A[i]] += 1
 
total = 0
 
for i in range(N+1):
    if data[i] >= 2:
        total += permutations_count(data[i],2)
 
 
 
for i in range(N):
    if data[A[i]] - 1 > 0 :
        print( total - permutations_count(data[A[i]]-1,1) )
    else:
        print(total)

print(permutations_count(3,1))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import math
import collections

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

_ = int(input())
ns = input().split(" ")
cs = collections.Counter(ns)

c = 0
for n in ns:
	for k, v in cs.items():
		if v==1:
			c += 0
		elif n==k:
#			c += math.factorial(v-2)
			c += combinations_count(v-1, 2)
		else:
#			c += math.factorial(v-1)
			c += combinations_count(v, 2)
	print(c)
	c = 0

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
keys=[]
values=[]
for i in A:
  if i in keys:
    pass
  else:
    counts=A.count(i)
    keys.append(i)
    values.append(counts)
ans=0
for j in values:
  ans+=j*(j-1)/2
for k in A:
  a=keys.index(k)
  print(ans-values[a]+1)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
c = Counter(a)
print(c.items())
all=0
for i,j in c.items():
    all += j*(j-1)//2
for i in range(N):
    print(all-(c[a[i]]-1))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
c = Counter(a)
print(c.items())
all=0
for i,j in c.items():
    all += j*(j-1)//2
for i in range(N):
    print(all-(a.count(a[i])-1))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
from collections import Counter


N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
np_A = np.array(A)

# 全体を求める
tmp_all = np.array(A)
unique = np.unique(tmp_all)
print("unique:", unique)
ans_all = 0
for u in unique:
    count_u = c[u]
    # print(f"u:{u}, count_u:{count_u}")
    if count_u < 2:
        continue
    # (count_u) C 2
    tmp = int(count_u*(count_u-1)/2)
    ans_all += tmp
# print("all", ans_all)


# kごとのケースを求めて、全体から引く
for i in A:
    print(ans_all - c[i] + 1)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = tuple(map(int, input().split()))
for k in range(N):
  c = 0
  A = list(a)
  del A[k]
  while len(A) > 0:
    y = A.count(A[0])
    c += y*(y-1)//2
    x = A[0]
    while x in A:
        A.remove(x)
    print(A)
  print(c)

Submission status: Wrong Answer

Solution code:
import math

def countComb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

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

memo = [0 for _ in range(N)]
for a in A:
  memo[a-1] += 1

memo1 = [0 for _ in range(N)]
for n in range(N):
  memo1[n] = countComb(memo[n], 2)

total = sum(memo1)
for k in range(N):
  a = A[k]-1
  if memo[a] < 2:
    print(total)
    continue
  answer = 0
  answer += total
  answer -= memo1[a]
  answer += countComb(memo[a] - 1, 2)
  print(answer)

Submission status: Wrong Answer

Solution code:
import collections
from collections import defaultdict

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

dict = defaultdict(int)
for i in l:
    dict[i]+=1
print(dict)

ans = 0
for v in dict.values():
    ans += int((v*(v-1)) // 2)

for k in l:
    print(ans - (dict[k] - 1))

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

# kごとに、
# 異なる数がいくつあるかを調べる
# (2以上要素が存在する)異なる数ごとに、
# (要素数)C2を解く。

np_A = np.array(A)

# 辞書作成
dic = {}


# 全体を求める
tmp_all = np.array(A)
unique = np.unique(tmp_all)
print("unique:", unique)
ans_all = 0
for u in unique:
    count_u = np.count_nonzero(tmp_all==u)
    # print(f"u:{u}, count_u:{count_u}")
    if count_u < 2:
        continue
    # (count_u) C 2
    tmp = int(count_u*(count_u-1)/2)
    ans_all += tmp
# print("all", ans_all)


# kごとのケースを求めて、全体から引く
for k in range(N):
    k_num = A[k]
    count_u = np.count_nonzero(tmp_all==k_num)    
    print(ans_all-count_u+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
ao = list(map(int, input().split(' ')))
a = list(set(ao))
ac = 0
acount = {}
for i in a:
    c = ao.count(i)
    ac += c
    acount[i] = c-1
ac = int((ac**2 - ac)/2)
for i in ao:
    print(ac-acount[i])

Submission status: Wrong Answer

Solution code:
import math


def kumiawase(n):
    if n == 0 or n == 1:
        return 0
    return 5 * n + 5


n = int(input())
aL = list(map(int, input().split(" ")))

d = {}

for ai in aL:
    if ai in d:
        d[ai] += 1
    else:
        d[ai] = 1

for ai in aL:
    sm = 0
    for dk, di in d.items():
        if dk == ai:
            sm += kumiawase(di - 1)
        else:
            sm += kumiawase(di)
    print(sm)

Submission status: Wrong Answer

Solution code:
N_ = int(input())

A_ = list(map(int,input().split()))
#A_.remove(1)
#print(A_)
def xC(num):
    return (num * (num - 1)) //2

def Re_(reA,t):
    Dup = []
    num = 0
    #print(reA)
    for i in range(len(reA)):
        if Dup.count(reA[i]) == 0:
            Dup.append(reA[i])
        else:
            pass
    for i in range(len(Dup)):
        num += xC(reA.count(Dup[i]))
    return num

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
sum=0
m=len(a)
c=list(set(a))
sum1=0

for i in range(len(c)):
    k=c.count(c[i])
    sum1+=k*(k-1)//2
    
for j in range(m):
    g=a.count(a[i])
    t=sum1-(g*(g-1))//2+((g-1)*(g-2))//2
    print(t)

Submission status: Wrong Answer

Solution code:
import math

def countComb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
NN = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, NN + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

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

memo = [0 for _ in range(N)]
for a in A:
  memo[a-1] += 1

memo1 = [0 for _ in range(N)]
for n in range(N):
  memo1[n] = countComb(memo[n], 2, p)

total = sum(memo1)
for k in range(N):
  a = A[k]-1
  if memo[a] < 2:
    print(total)
    continue
  answer = 0
  answer += total
  answer -= memo1[a]
  answer += countComb(memo[a] - 1, 2, p)
  print(answer)