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 sys import stdin, setrecursionlimit


def initialize_cmb(m, mod=10 ** 9 + 7):
    fac = [1]
    finv = [1]
    inv = [0] * (m + 1)
    if m > 1:
        fac.append(1)
        finv.append(1)
        inv[1] = 1
        pre_fac = 1
        pre_finv = 1
        for i in range(2, m + 1):
            pre_fac = pre_fac * i % mod
            fac.append(pre_fac)
            inv[i] = mod - inv[mod % i] * (mod // i) % mod
            pre_finv = pre_finv * inv[i] % mod
            finv.append(pre_finv)
    return fac, finv


def cmb(n, k, fac, finv, mod=10 ** 9 + 7):
    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():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))

    fac, finv = initialize_cmb(n)

    c_n = []
    for i in range(n + 1):
        c_n.append(cmb(i, 2, fac, finv))

    sorted_a = sorted(a)
    g = {}
    count = 1
    tmp = 0
    for ai in sorted_a:
        if tmp == ai:
            count += 1
        else:
            g[tmp] = count
            count = 1
        tmp = ai
    g[tmp] = count

    ans = 0
    for k in g:
        ans += c_n[g[k]]

    for ai in a:
        print(ans - g[ai] + 1)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
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(" ")))
temp = [0 for i in range(n + 1)]
aaa = sorted(a)
count = 0
for i in range(n - 1):
  if aaa[i] == aaa[i + 1]:
    count+= 1
  else:
    temp[aaa[i]] = count + 1
    count = 0
else:
  if len(a) == 1:
    temp[aaa[0]] = 1
  else:
    temp[aaa[-1]] = count + 1
ans = 0

#---ここまで231ms

#print(temp)#各数字の出現回数
for i in range(n + 1):
  if temp[i] >= 2:
    ans += temp[i] * (temp[i] - 1) / 2
    
#---ここまでで1553ms

#print(ans)#ansは全体の組み合わせの合計。割れない

for i in range(n):
  kotae = ans
  if temp[a[i]] >= 3:
    #print(ans, comb(temp[a[i]], 2), comb(temp[a[i]] - 1, 2))
    kotae = ans - (temp[i] * (temp[i] - 1) / 2) + (temp[i] - 1 * (temp[i] - 2) / 2)
  elif temp[a[i]] == 2:
    kotae = ans -1
  print((int)(kotae))

Submission status: Wrong Answer

Solution code:
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(" ")))
temp = [0 for i in range(n + 1)]
aaa = sorted(a)
count = 0
for i in range(n - 1):
  if aaa[i] == aaa[i + 1]:
    count+= 1
  else:
    temp[aaa[i]] = count + 1
    count = 0
else:
  if len(a) == 1:
    temp[aaa[0]] = 1
  else:
    temp[aaa[-1]] = count + 1
ans = 0
#print(temp)#各数字の出現回数

Submission status: Wrong Answer

Solution code:
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(" ")))
temp = [0 for i in range(n + 1)]
aaa = sorted(a)
count = 0
for i in range(n - 1):
  if aaa[i] == aaa[i + 1]:
    count+= 1
  else:
    temp[aaa[i]] = count + 1
    count = 0
else:
  if len(a) == 1:
    temp[aaa[0]] = 1
  else:
    temp[aaa[-1]] = count + 1
ans = 0
#print(temp)#各数字の出現回数
for i in range(n + 1):
  if temp[i] >= 2:
    ans += comb(temp[i], 2)

Submission status: Wrong Answer

Solution code:
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(" ")))
temp = [0 for i in range(n + 1)]
aaa = sorted(a)
count = 0
for i in range(n - 1):
  if aaa[i] == aaa[i + 1]:
    count+= 1
  else:
    temp[aaa[i]] = count + 1
    count = 0
else:
  if len(a) == 1:
    #print(temp)
    temp[aaa[0]] = 1
  else:
    temp[aaa[-1]] = count + 1
ans = 0
#print(temp)#各数字の出現回数
for i in range(n):
  if temp[i] >= 2:
    ans += comb(temp[i], 2)
    
#print(ans)#ansは全体の組み合わせの合計。割れない

for i in range(n):
  kotae = ans
  if temp[a[i]] >= 3:
    #print(ans, comb(temp[a[i]], 2), comb(temp[a[i]] - 1, 2))
    kotae = ans - comb(temp[a[i]], 2) + comb(temp[a[i]] - 1, 2)
  elif temp[a[i]] == 2:
    kotae = ans -1
  print(kotae)

Submission status: Wrong Answer

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

x = [0]*(n+1)
for i in range(1, n+1):
    x[a[i-1]] += 1
print(x)
sumx = 0
for i in range(1, n+1):
    sumx += x[i] * (x[i]-1) // 2

for i in range(1, n+1):
    print(sumx - x[a[i-1]] * (x[a[i-1]]-1) // 2 + (x[a[i-1]]-1) * (x[a[i-1]]-2) // 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())

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

cnt=[0]*(n+1)
for i in range(n):
    cnt[a[i]]+=1 
aa=0
ans=[]
for i in range(n):
    aa+=(cnt[i]*(cnt[i]-1)//2)
for i in range(n):
    print(aa-(cnt[a[i]]*(cnt[a[i]]-1))//2 +((cnt[a[i]]-1)*(cnt[a[i]]-2))//2, end ="\n")

Submission status: Wrong Answer

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

allCount = 0
c = Counter(A)

for i, v in c.items():
    if (v == 1):
        continue
    else:
        allCount += v * (v - 1) // 2


if (allCount == 0):
    for i in range(N):
        print(0)
    exit()

for i in range(N):
    a = allCount
    num = c[A[i]] - 1
    if (num == 1 or num == 0):
        print(allCount - num)
        continue
    old = A[i] * (A[i] - 1) // 2
    count = num * (num - 1) // 2
    print(a - old + count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
c = [0 for i in range(n+1)]
b = sorted(a)
cnt = 1
for i in range(n-1):
  if b[i]==b[i+1]:
    cnt += 1
  else:
    c[b[i]] = cnt
    cnt = 1
  if i==n-2:
    c[b[n-1]] = cnt
ans = 0
for i in range(n):
  ans += int(c[i]*(c[i]-1)/2)
for i in range(n):
  print(ans-(c[a[i]]-1))

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = tuple(map(int, input().split()))
    ans = 0
    lim = max(a)
    amount = [0]*lim
    for i in range(lim):
        amount[0] = a.count(i+1)
        ans += amount[i]*(amount[i]-1)//2
    #print(ans)
    for j in range(n):
        ansout = ans
        #print(amount[a[j]-1])
        ansout -= amount[a[j]-1] -1
        print(ansout)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
total=0
A_li=[0]*(1+2*10**5)
for i in range(N):
    A_li[A[i]]+=1
for i in range(1+2*10**5):
    total+=A_li[i]*(A_li[i]-1)//2
for i in range(1,N+1):
    if A_li[A[i-1]]>1:
        print(total-(A_li[A[i-1]]-1))
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
K = list(map(int,input().split()))
A = [0]*N
print(A)
for i in range(N):
    A[K[i]-1] += 1
r = 0
for k in range(N):
    r += 0.5*(A[k]*(A[k]-1))
An =[]
for j in range(N):
    D = A[K[j]-1]-1
    An.append(int(r-(0.5*(D+1)*(D))+(0.5*D*(D-1))))
for i in range(len(An)):
    print(An[i])

Submission status: Wrong Answer

Solution code:
from collections import Counter
from copy import copy
from math import factorial
def comb(x):
    if x<=2:
        return x-1
    else:
        return factorial(x)//(factorial(x-2)*factorial(2))
n = int(input())
a = list(map(int,input().split()))
c = dict(Counter(a))
for k in range(1,n+1):
    t = copy(c)
    t[a[k-1]]-=1
    print(sum([comb(i) for i in t.values()]))

Submission status: Wrong Answer

Solution code:
import collections

if __name__ == '__main__':

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

    c = collections.Counter(a)

    all = 0
    before = []
    after = []

    for i in range(n):
        for item in c.items():
            cnt = item[1]*(item[1]-1)//2
            all += cnt
            before.append(item[1]*(item[1]-1)//2)
            after.append((item[1]-1)*(item[1]-2)//2)

    for i in range(n):
        ans = all - before[i] + after[i]
        print(ans)

Submission status: Wrong Answer

Solution code:
import collections

mod = pow(10,9)+7

#メモ
memo = {}
def combination(n, a, mod):

    if (n,a) in memo:
        return memo[(n,a)]

    x = 1
    y = 1
    for i in range(a):
        x = x * (n-i)%mod
        y = y * (a-i)%mod

    ans = x * pow(y, mod-2, mod)%mod

    memo[(n, a)] = ans
    return ans

if __name__ == '__main__':

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

    c = collections.Counter(a)

    all_cnt = 0 # 全体の合計
    a_cnt = []# そいつがいない時


    for i in range(n):
        for item in c.items():
            cnt = combination(item[1],2,mod)
            all_cnt += cnt
            a_cnt.append(cnt - combination(item[1]-1,2,mod))

    for i in range(n):
        ans = all_cnt - a_cnt[i]
        print(ans)

Submission status: Wrong Answer

Solution code:
import collections

mod = pow(10,9)+7

#メモ
memo = {}
def combination(n, a, mod):

    if (n,a) in memo:
        return memo[(n,a)]

    x = 1
    y = 1
    for i in range(a):
        x = x * (n-i)%mod
        y = y * (a-i)%mod

    ans = x * pow(y, mod-2, mod)%mod

    memo[(n, a)] = ans
    return ans

if __name__ == '__main__':

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

    c = collections.Counter(a)

    for i in range(n):
        target = a[i]
        c[target] -= 1

        cnt = 0
        for item in c.items():
            cnt += combination(item[1],2,mod)
        print(cnt)
        c[target] += 1

Submission status: Wrong Answer

Solution code:
import collections
import functools
import math

n = int(input())
l = list(map(int, input().split(" ")))
c = collections.Counter(l)

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

total = functools.reduce(lambda x, y : x + f(y, 2), c.values())

for i in l:
    print(total - f(c.get(i, 0), 2) + f(c.get(i, 0) - 1 , 2))

Submission status: Wrong Answer

Solution code:
import collections as cl
from math import factorial

def comb(n, r):
  if n >= r:
    return factorial(n) // (factorial(n - r) * factorial(r))
  elif n == 1:
      return 1
  else:
    return 0
  
n = int(input())
a = list(map(int, input().split()))

clc = cl.Counter(a)

# 1. 数字が等しいペアを選ぶ総数
npair = 0
for (k, v) in clc.items():
  npair += comb(v, 2)

# 2. (取り除いた数字と同じ数字を選ぶ総数) - (1)
for a_ in a:
  print(npair - (clc[a_] - 1))

Submission status: Wrong Answer

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

cntA={} # 同じ数字が何個あるか
for a in A:
    if a in cntA.keys():
        cntA[a]+=1
    else:
        cntA[a]=1

cntn={} #同じ数字から2種類取り出す組み合わせの数
for a in cntA.keys():
    cntn[a]=int(cntA[a]*(cntA[a]-1)/2)
print(cntA)
print(cntn)

ans=0
ansn={}
#k番目を除いた場合に同じ数字から2種類取り出す組み合わせの数
for i in cntA.keys(): 
    tmpn=copy.deepcopy(cntn)
    tmpn[i]=int((cntA[i]-1)*(cntA[i]-2)/2)
    for j in cntA.keys():
        ans=ans+tmpn[j]
    ansn[i]=ans
    ans=0

for a in A:
    print(ansn[a])

Submission status: Wrong Answer

Solution code:
import itertools

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

gr=itertools.groupby(sorted(A))
s=0
dic={}
for x,group in gr:
  l=len(list(group))
  if l >= 2:
    s+=l*(l-1)/2
  dic[x]=l

for k in range(N):
  l=dic[A[k]]
  if l >= 2:
    print(int(s-l*(l-1)/2+(l-1)*(l-2)/2))
  else:
    print(s)

Submission status: Wrong Answer

Solution code:
import itertools

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

gr=itertools.groupby(sorted(A))
s=0
dic={}
for x,group in gr:
  l=len(list(group))
  if l >= 2:
    s+=l*(l-1)/2
  dic[x]=l

for k in range(N):
  l=dic[A[k]]
  if l >= 2:
    print(int(s-l*(l-1)/2+(l-1)*(l-2)/2))
  else:
    print(0)

Submission status: Wrong Answer

Solution code:
import itertools

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

A.sort()
for k in range(N):
  a=A[:k]+A[k+1:]
  gr=itertools.groupby(a)
  s=0
  for _,group in gr:
    l=len(list(group))
    if l>=2:
      s+=int(l*(l-1)/2)
  print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# inputを高速化する。
import sys
input = sys.stdin.readline

n = int(input())

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

cnt = {}

for ball in balls:
    if ball not in cnt:
        cnt[ball] = 0
    cnt[ball] += 1

def combination(nxt, num = 0):
    return (cnt[nxt]-num) * (cnt[nxt]-1- num) // 2

total = 0
for nxt in cnt:
    total += combination(nxt)

print(total)

for ball in balls:
    ans = total -  combination(ball) + combination(ball,1)
    print(ans)

Submission status: Wrong Answer

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

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

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

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

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

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

Submission status: Wrong Answer

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

a_types = set(A)

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

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

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
num={i:0 for i in range(N)}
for i in A:
    num[i-1]+=1
def set(k):
    if k >= 2:
        return (k)*(k-1)/2
    else:
        return 0
def selfset(k):
    if k >= 2:
        return (k-1)*(k-2)/2
    else:
        return 0

setnum={i:set(num[i]) for i in range(N)}
a=sum(setnum.values())
print(setnum,A)

selfsetnum={i:selfset(num[i]) for i in range(N)}


for i in range(N):
    print(int(a-setnum[A[i]-1]+selfsetnum[A[i]-1]))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
bs = list(map(int, input().split()))
temp = []
ans = 0
for i in bs:
    temp = list(bs)
    temp.pop(i-1)
    for k in dict.fromkeys(temp):
        if(temp.count(k) == 2):
            ans += 1
        if(temp.count(k) > 2):
            ans += math.factorial(temp.count(k))//(math.factorial(temp.count(k)-2)*2)
    print(ans)
    ans = 0

Submission status: Wrong Answer

Solution code:
def fact(n):
    answer = 1
    for i in range(1, n+1):
        answer*=i
    return answer
n = int(input())
bs = list(map(int, input().split()))
temp = []
ans = 0
for i in bs:
    temp = list(bs)
    temp.pop(i-1)
    for k in dict.fromkeys(temp):
        if(temp.count(k) == 2):
            ans += 1
        if(temp.count(k) > 2):
            ans += fact(temp.count(k))//(fact(temp.count(k)-2)*2)
    print(ans)
    ans = 0

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc159/tasks/abc159_d

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

Submission status: Wrong Answer

Solution code:
import collections

N=int(input())
A=list(map(int, input().split()))
c = collections.Counter(A)
sum=0
for i, j in c.items():
    sum+=j*(j-1)//2

for i in A:
        b = c[i]
        if b >= 2:
            print(sum-b*(b-1)//2+(b-1)*(b-2)//2)
        else:
            print(0)

Submission status: Wrong Answer

Solution code:
import collections

N=int(input())
A=list(map(int, input().split()))
c = collections.Counter(A)
sum=0
for i, j in c.items():
    sum+=j*(j-1)//2

for i in A:
        b = c[i]
        if b >= 2:
            print(sum-(b-1))
        else:
            print(0)

Submission status: Wrong Answer

Solution code:
import math

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = input().split()
a_set = set(a_list)
a_dict = {}
sum_ans = 0
for a in a_set:
    a_count = a_list.count(a)
    a_dict[a] = a_count
    if a_count > 1:
        sum_ans += a_count*(a_count-1)//2
    
for a in a_list:
    a_num = a_dict[a]
    if a_num == 1:
        print(sum_ans)
    elif a_num == 2:
        print(sum_ans-1)
    else:
        ans = sum_ans - a_dict[a] + (a_num-2)*(a_num-1)//2
        print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

counts = [0] * (N+1)

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

sum_ = 0
for k in range(1, N+1):
    sum_ += counts[k] * (counts[k]-1) // 2

res = []
for k in range(1, N+1):
    # A[k]を抜くことで減る組み合わせを引く
    res.append(sum_ - (counts[A[k-1]] - 1))

print(res)

Submission status: Wrong Answer

Solution code:
import sys

from scipy.misc import comb #scipy.special

#import numpy as np

n = int(input())

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

num = [[-1,0,0]]*(200000)

asort = sorted(a)

#print(asort)

sum = 0
i = 0
while i < n-1:
    counter = 1
    index = asort[i]
    while  i < n-1 and asort[i] == asort[i+1]:
        #print("yes")
        counter +=1
        i+=1
    #print("no")
    i+=1
    num[index] = [counter,comb(counter,2),comb(counter-1,2)]
    sum+=num[index][1]




for i in a:
    print(int(sum-num[i][1]+num[i][2]))

Submission status: Wrong Answer

Solution code:
import sys

from scipy.misc import comb

#import numpy as np

n = int(input())

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

num = [[-1,0,0]]*(200000)

asort = sorted(a)

#print(asort)

i = 0
while i < n-1:
    counter = 1
    index = asort[i]
    while  i < n-1 and asort[i] == asort[i+1]:
        #print("yes")
        counter +=1
        i+=1
    #print("no")
    i+=1
    num[index] = [counter,comb(counter,2),comb(counter-1,2)]

sum=0
for i in range(200000):
    sum +=num[i][1]

for i in a:
    print(int(sum-num[i][1]+num[i][2]))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

count = [a.count(i) for i in range(1,n+1)]

for j in range(n):
    print((count[j]-1)*(count[j]-2))

Submission status: Wrong Answer

Solution code:
N = int(input())
Alist=list(map(int, input().split()))
numdic = {}
for i in Alist:
    if i in numdic:
        numdic[i] += 1
    else:
        numdic[i] = 1
Apple = 0
for i in numdic.values():
    Apple += i*(i-1)//2
for i in Alist:
    tmp = Apple
    tmp -= numdic[i]+1
    print(tmp)

Submission status: Wrong Answer

Solution code:
n=int(input())
li=list(map(int,input().split()))
d={}
dif={-1}
ans={}
for i in range(n):
    if li[i] not in dif:
        dif|={li[i]}
        if d.get(li[i])!=None:
            d[li[i]]+=1
        else:
            d[li[i]]=1
dif.remove(-1)
for i in dif:
    g=0
    for j in dif:
        if i!=j:
            g+=d[j]*(d[j]-1)//2
        else:
            g+=(d[j]-2)*(d[j]-1)//2
    ans[i]=g
for i in li:
    print(ans[i])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect

n = int(input())
a = list(map(int, input().split()))
A = sorted(a)
s = [0]*(n+1)
b = [0]*(n+1)
c = []
for i in range(1, n+1):
    x = a[i-1]
    s[i] = bisect.bisect_right(A, x) - bisect.bisect_left(A, x)
    if b[a[i-1]] == 0:
        c.append(s[i]*(s[i]-1)//2)
        b[a[i-1]] = 1
S = sum(c)
print(c)
for i in range(1, n+1):
    print(S - s[i] + 1)

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):
    print(count-l[A[n-1]]+1)

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(N):
    print(count-l[A[n]]+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
k = list(input().split())
dic = {}
c = 0

for i in range(len(k)):
    if k[i] not in dic:
        freq = k.count(k[i])
        dic[int(k[i])] = k.count(k[i])

for m in dic.values():
    c += (m*(m-1))/2


for n in range(len(k)):
    c - (dic[int(k[n])]*(dic[int(k[n])]-1)/2)
    c + ((dic[int(k[n])]-1)*((dic[int(k[n])]-2))/2)
    print(int(c))

Submission status: Wrong Answer

Solution code:
import math

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


N=int(input())
a=[int(i) for i in input().split()]
b=[0 for i in range(N)]
wa=0
for i in range(N):
    b[a[i]-1]=b[a[i]-1]+1

print(b)
for j in range(N):
    for i in range(N):
#        print('a')
        if(b[i]>1):
            #print('{},{}'.format(j,i))
            #print(b[i])

            if(a[j]==i+1):
                if(b[i]-1>1):
                    wa=combinations_count(b[i]-1,2)+wa
            else:
                wa=combinations_count(b[i],2)+wa


    print(wa)
    wa=0

Submission status: Wrong Answer

Solution code:
from math import factorial
N = int(input())
A = list(map(int, input().split()))

ret = [0 for k in range(N)]

for k in range(N):
    ret[A[k]-1] += 1

f2 = factorial(2)

result = [n*(n-2)/f2 if n > 1 else 0 for n in ret]

for k in range(N):
    i = A[k]
    print(int(sum([r if A[k]-1 != j else r*(ret[i-1]-2)/ret[i-1] for j, r in enumerate(result)])))

Submission status: Wrong Answer

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


s = [0 for i in range(N)]
for i in range(N):
    s[A[i]-1] += 1
    
s1 = copy.copy(s)
for i in range(N):
    if s[i] == 0:
        s1[i] = 0
    else:
        s1[i] -= 1

amount = sum(s)

for i in range(N):
    print(amount-s1[A[i]-1])

Submission status: Wrong Answer

Solution code:
def main():
    from collections import Counter
    n=int(input())
    a=list(map(int,input().split()))

    q = Counter(a)
    a_cn = sum(x * (x - 1) // 2 for x in q.values())

    ans = []
    for x in a:
        ans.append(a_cn - q[x] + 1)

    print(ans, sep='\n')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    B = A[:i]+A[(i+1):]
    B.sort()
    D = []
    C = B[0]
    n=0
    
    for k in range(N-1):
        if B[k] == C:
            n+=1
        else:
            C=B[k]
            D +=[n]
            n=0
    D +=[n]
    
    E=0
    for j in range(len(D)):
        if D[j] == 1:
            E += 1
        else:
            E+=int(D[j]*(D[j]-1)/2)
    print(E)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split()
for i in range(N):
    A[i] = int(A[i])
#print(A)
for i in range(N):
    B = A.copy()
    del B[i]
    #print(B)
    B.sort()
    #print(B)
    #C = collections.Counter(B)
    D = []
    C = B[0]
    n=0
    for k in range(N-1):
        if B[k] == C:
            n+=1
        else:
            C=B[k]
            D +=[n]
            n=0
    D +=[n]
    #print(C)
    #D = list(C.values())
    #print(D)
    E=0
    for j in range(len(D)):
        if D[j] == 1:
            E += 1
        else:
            E+=int(D[j]*(D[j]-1)/2)
    print(E)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
ls=[0 for _ in range(N)]
for i in range(N):
  ls[A[i]-1]+=1
s=0
print(ls)
for i in range(len(ls)):
    m=ls[i]*(ls[i]-1)//2
    s+=m
for j in range(N):
  print(s-(ls[A[j]-1]-1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = (input().split())
a_str = ''.join(a)
a_str2 = a_str
sum = 0
l_dict = {}
while len(a_str)>0:
    n = a.count(a_str[0])
    sum += int(n*(n-1)/2)
    l_dict[a_str[0]] = n
    a_str = a_str.replace(a_str[0],'')
for k in range(N):
    print(int(sum-l_dict[a_str2[k]]+1))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = (input().split())
a_str = ''.join(a)
a_str2 = a_str
sum = 0
l_dict = {}
while len(a_str)>0:
    n = a.count(a_str[0])
    sum += int(n*(n-1)/2)
    l_dict[a_str[0]] = n
    a_str = a_str.replace(a_str[0],'')
for k in range(N):
    print(sum-l_dict[a_str2[k]]+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = (input().split())
a_str = ''.join(a)
a_str2 = a_str
sum = 0
l_dict = {}
while len(a_str)>0:
    n = a.count(a_str[0])
    sum += int(n*(n-1)/2)
    l_dict[a_str[0]] = n
    a_str = a_str.replace(a_str[0],'')
print(l_dict,sum)
for k in range(N):
    print(sum-l_dict[a_str2[k]]+1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    A = list(map(int, input().split()))
    dd = defaultdict(int)
    ans = []
    for i in A:
        dd[i] += 1
    for i in range(n):
        ng = A[i]
        dd[ng] -= 1
        cnt = 0
        for key, val in dd.items():
            cnt += val * (val-1) // 2
        ans.append(cnt)
        dd[ng] += 1
    print(*ans, sep='\n')

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
c=[0]*n
for i in range(n):
  c[a[i]-1]+=1
s=sum(c)
for i in range(n):
  print(s-c[a[i]-1])

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(set(A))
p=0
C=[0]*(N+1)
for k in B:
  C[k]=A.count(k)
for i in A:
  p=0
  for j in B:
    if i==j:
      p+=(C[j]-1)*(C[j]-2)//2
    else:
      p+=C[j]*(C[j]-1)//2
    print(p)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=list(set(A))
p=0
C=[0]*(N+1)
for k in B:
  C[k]=A.count(k)
for i in A:
  p=0
  for j in B:
    if i==j:
      p+=(C[j]-1)*(C[j]-2)//2
    else:
      p+=C[j]*(C[j]-1)//2
    print(p)

Submission status: Wrong Answer

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