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

c = collections.Counter(A)
ans = 0
for i in range(N):
  ans+=c[i]*(c[i]-1)//2

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

Submission status: Wrong Answer

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

c = collections.Counter(A)
ans = 0
for i in range(N):
  ans+=c[i]*(c[i]-1)//2

for i in range(N):
  print(ans-(c[A[i]]-1)) if c[A[i]]>1 else print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
num_list = list(map(int, input().split()))
all = 0

c = collections.Counter(num_list)
value_list = list(c.values())

for i in range(len(value_list)):
    if not value_list[i] == 1:
        all += value_list[i]*value_list[i-1]//2

for k in range(n):
    print(all - c[num_list[k]]-1)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
num_list = list(map(int, input().split()))
all = 0

c = collections.Counter(num_list)
value_list = list(c.values())

for i in range(len(value_list)):
    if not value_list[i] == 1:
        all += value_list[i]*value_list[i-1]//2

for k in range(n):
    print(all - num_list.count(num_list[k])-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(c) for c in input().split()]

#全部のパターン数計算→その数のときのパターン数消す
S = set(A)
print(S)
S_cnt = {}
ma = 0
for i in S:
    #S_cnt[i] = A.count(i)
    cnt = A.count(i)
    S_cnt[i] = cnt
    ma += cnt*(cnt-1)//2

for i in A:
    cnt = S_cnt[i]
    print(ma-cnt+1)

Submission status: Wrong Answer

Solution code:
""" スニペット """
def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split()))
""" スニペット """
import math
# 2つ選ぶ通り数を算出 nC2
def choose2(n):
    return n*(n-1)//2
# インプット
N = get_int()
An = get_ints()
""" 全ての要素から2つのボールを選ぶ通り数を求める """
uni = [0] * (N+1)
# ユニーク数の配列を求める
for i in range(N):
    uni[An[i]] += 1
sumWay = 0
# 各数値の2通りの選択通り数を足していく
for i in range(N):
    sumWay += choose2(uni[i])
""" 全ての要素数 - 削除する要素の通り数 + 削除する要素を引いた際の通り数 を求める """
for i in range(N):
    print((sumWay - choose2(uni[An[i]]) + choose2(uni[An[i]]-1)))

Submission status: Wrong Answer

Solution code:
""" スニペット """
def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split()))
""" スニペット """
import math
# 2つ選ぶ通り数を算出 nC2
def choose2(n):
    return math.floor(n*(n-1)/2)

# インプット
N = get_int()
An = get_ints()
""" 全ての要素から2つのボールを選ぶ通り数を求める """
uni = [0] * (N+1)
# ユニーク数の配列を求める
for i in range(N):
    uni[An[i]] += 1
sumWay = 0
# 各数値の2通りの選択通り数を足していく
for i in range(N):
    sumWay += choose2(uni[i])
""" 全ての要素数 - 削除する要素の通り数 + 削除する要素を引いた際の通り数 を求める """
# for i in range(N):
#     print(sumWay - choose2(uni[An[i]]) + choose2(uni[An[i]]-1)) 

for i in range(N):
    ans = sumWay
    ans -= choose2(uni[An[i]])
    ans += choose2(uni[An[i]]-1)
    print(ans)

Submission status: Wrong Answer

Solution code:
""" スニペット """
def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split()))
""" スニペット """
import math
# 2つ選ぶ通り数を算出 nC2
def choose2(n):
    return n*(n-1)/2
# インプット
N = get_int()
An = get_ints()
""" 全ての要素から2つのボールを選ぶ通り数を求める """
uni = [0] * (N+1)
# ユニーク数の配列を求める
for i in range(N):
    uni[An[i]] += 1
sumWay = 0
# 各数値の2通りの選択通り数を足していく
for i in range(N):
    sumWay += choose2(uni[i])
""" 全ての要素数 - 削除する要素の通り数 + 削除する要素を引いた際の通り数 を求める """
for i in range(N):
    print(math.floor(sumWay - choose2(uni[An[i]]) + choose2(uni[An[i]]-1)))

Submission status: Wrong Answer

Solution code:
""" スニペット """
def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split()))
""" スニペット """

# 2つ選ぶ通り数を算出 nC2
def choose2(n):
    return n*(n-1)/2
  
# インプット
N = get_int()
An = get_ints()
""" 全ての要素から2つのボールを選ぶ通り数を求める """
uni = [0] * (N+1)
# ユニーク数の配列を求める
for i in range(N):
    uni[An[i]] += 1
sumWay = 0
# 各数値の2通りの選択通り数を足していく
for i in range(N):
    sumWay += choose2(uni[i])
""" 全ての要素数 - 削除する要素の通り数 + 削除する要素を引いた際の通り数 を求める """
for i in range(N):
    print(sumWay - choose2(uni[An[i]]) + choose2(uni[An[i]]-1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
import math, copy

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

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

d = Counter(A)

c_table = Counter()
for v in d.values():
    if v not in c_table:
        if v >= 2:
            c_table[v] = c(v, 2)
        if v-1 >= 2:
            c_table[v-1] = c(v-1, 2)

print(c_table)

for a in A:
    x = copy.copy(d)
    x[a] -= 1
    ans = 0
    for v in x.values():
        if v >= 2:
            ans += c_table[v]
    
    print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
s=0
A=list(map(int,input().split()))
li=[0]*(2*(10**5)+1)
for i in range(N):
    li[A[i]]+=1
for j in range(N):
    s+=li[j]*(li[j]-1)//2
for k in range(N):
    print(s-li[A[k]]+1)

Submission status: Wrong Answer

Solution code:
N=int(input())
s=0
A=list(map(int,input().split()))
li=[0]*(2*(10**5)+10)
for i in range(N):
    li[A[i]]+=1
for j in range(N):
    s+=li[j]*(li[j]-1)//2
for k in range(N):
    print(s-(li[A[k]]*(li[A[k]]-1))//2+((li[A[k]]-1)*(li[A[k]]-2))//2)

Submission status: Wrong Answer

Solution code:
def main():
    import math
    n = int(input())
    inlis = list(map(int, input().split()))

    inset = set(inlis)
    indic = {}
    ansdic = {}
    total = 0

    for num in inset:
        kosuu = inlis.count(num)
        if kosuu > 1:
            indic[num] = kosuu
            total += (math.factorial(kosuu)) / (2*math.factorial(kosuu-2))
    
    for num in inlis:
        if num in ansdic:
            print(int(ansdic[num]))
        else:
            if num in indic:
                kosuu = indic[num]
                if kosuu > 2:
                    kaitou = total - kosuu + 1 
                else:
                    kaitou = total - 1
                print(int(kaitou))
                ansdic[num] = kaitou
            else:
                print(0)
        





if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import math
    n = int(input())
    inlis = list(map(int, input().split()))

    inlis2 = sorted(inlis)
    inset = set(inlis)
    indic = {}
    total = 0

    for num in inset:
        kosuu = inlis2.count(num)
        if kosuu > 1:
            indic[num] = kosuu
            total += (math.factorial(kosuu)) / (2*math.factorial(kosuu-2))
    
    for num in inlis:
        if num in indic:
            kosuu = indic[num]
            if kosuu > 2:
                kaitou = total - kosuu + 1 
            else:
                kaitou = total - 1
            print(int(kaitou))
        else:
            print(0)
    





if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
s=0
A=list(map(int,input().split()))
li=[0]*(2*(10**5)+1)
for i in range(N):
    li[A[i]]+=1
for j in range(N):
    s+=li[j]*(li[j]-1)//2
for k in range(N):
    print(s-(li[A[k]]*(li[A[k]]-1))//2+((li[A[k]]-1)*(li[A[k]]-2))//2)

Submission status: Wrong Answer

Solution code:
N=int(input())
s=0
A=list(map(int,input().split()))
li=[0]*(2*(10**5))
for i in range(N):
    li[A[i]]+=1
for j in range(N):
    s+=li[j]*(li[j]-1)//2
for k in range(N):
    print(s-(li[A[k]]*(li[A[k]]-1))//2+((li[A[k]]-1)*(li[A[k]]-2))//2)

Submission status: Wrong Answer

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

d = [0]*n
ans=0
 
for a in l:
    d[a-1] += 1
  
for a in d:
  ans+=a*(a-1)//2
  
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=list(map(int,input().split()))
tt=[0]*(n+7)

total=0

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

for t in tt:
  total += (t*(t-1)//2)

for i in range(n):
  n = tt[arr[0]]
  d = (n*(n-1)//2) - ((n-1)*(n-2)//2)
  print(total-d)
# x * x-1 // 2

Submission status: Wrong Answer

Solution code:
n = int(input())
*li,=map(int, input().split())
from collections import Counter
c = Counter()
for i in li:
    c[i] += 1
ans=0
from math import comb
for i in c.values():
    ans += comb(i, 2)
for i in li:
    print(ans - comb(c[i], 2) + comb(c[i-1], 2))

Submission status: Wrong Answer

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

ans = 0
for i in counter.values():
    ans += i * (i - 1) // 2
for ai in a:
    print(ans - (counter[ai] - 1))

Submission status: Wrong Answer

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

for ai in a:
    counter[ai] += 1

for ai in a:
    print(max(0, counter[ai]))

Submission status: Wrong Answer

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

count = [0]*(N+1)

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

total= 0
for j in range(N):
  cj = count[j]*(count[j]-1)//2
  total = total + cj

ans = total
for k in range(N):
  ans = total - (count[A[k]] - 1)
  print(ans)

Submission status: Wrong Answer

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


ans=0
for i in range(n) :
    if x[i]<2 :
         continue
    ans+=x[i]*(x[i]-1)//2

for i in a :
    n=x[i]
    ans1=ans-(n-1)
    print(ans1)

Submission status: Wrong Answer

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

def cmb(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


ans=0
for i in range(n) :
    if x[i]==0 :
         continue
    ans+=cmb(x[i],2) 

for i in range(n) :
    count=cmb(x[a[i]-1]-1,2)
    if x[a[i]-1]-1<2 :
        count=0
    ans1=ans-cmb(x[a[i]-1],2)+count
    print(ans1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]

ball_count = [0] * (n + 1)
count_count = [0] * (n + 1)

for i in a:
    ball_count[i] += 1
for i in ball_count:
    if i!=0:
        count_count[i] += 1


def get_total(count_count):
    ans = 0
    for i in range(2, n + 1):
        ans += (i * (i - 1) // 2) * count_count[i]
    return ans


total = get_total(count_count)
for i in range(1, n + 1):
    num = ball_count[a[i - 1]]
    ans = 0
    if num == 2:
        ans = total - 1
    elif num > 2:
        ans = total - ((num * (num - 1)) // 2) + (((num - 1) * (num - 2)) // 2)
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]

ball_count = [0] * (n + 1)
count_count = [0] * (n + 1)

for i in a:
    ball_count[i] += 1
for i in ball_count:
    if i!=0:
        count_count[i] += 1


def get_total(count_count):
    ans = 0
    for i in range(2, n + 1):
        ans += (i * (i - 1) // 2) * count_count[i]
    return ans


total = get_total(count_count)
for i in range(1, n + 1):
    num = ball_count[a[i - 1]]
    ans = 0
    if num == 2:
        ans = total - (num * (num - 1) // 2)
    elif num > 2:
        ans = total - (num * (num - 1) // 2) + ((num - 1) * (num - 2) // 2)
    print(ans)

Submission status: Wrong Answer

Solution code:
def nc2(n):
    if n==0:
        return 0
    return n*(n-1)/2


n=int(input())
arr=[int(i) for i in input().strip().split(" ")]
ans=0
dic={}
for i in arr:
    dic[i]=dic.get(i,0)+1
for i in dic:
    if dic[i]==1 :
        continue
    ans+=nc2(dic[i])
    
print(dic)

for i in range(n):
    curr_nc2=nc2(dic[arr[i]])
    # print(curr_nc2)
    print(int(ans-curr_nc2+nc2(dic[arr[i]]-1)))

Submission status: Wrong Answer

Solution code:
import collections

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

c=collections.Counter(a)

print(c)

s=0

for i in c.values():
  s+=i*(i-1)//2 #ボールを抜かない場合に2つのボールを選ぶ方法の数

for j in a:
  f=c[j]
  print(s-(f-1)) #下記メモ参照

'''
複数個のボールから1個のボールが抜かれる場合、i*(i-1)//2が(i-1)*(i-2)//2となる。
i*(i-1)//2-(i-1)*(i-2)//2
=i-1
よって、2つのボールを選ぶ方法が(i-1)だけ減る。
'''

Submission status: Wrong Answer

Solution code:
from collections import Counter
from operator import mul
from functools import reduce
import sys
input = sys.stdin.readline

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

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

    ans = [0] * N
    cnt = Counter(A)
    s = 0
    for key, value in cnt.items():
        if value < 2:
            continue
        s += combinations_count(value, 2)
    
    for i in range(N):
        if cnt[A[i]]-1 < 1:
            ans[i] = 0
        elif cnt[A[i]]-1 < 2:
            ans[i] = s - combinations_count(cnt[A[i]], 2)
        else:
            ans[i] = s - combinations_count(cnt[A[i]], 2) + combinations_count(cnt[A[i]]-1, 2)
    
    print(*ans, sep="\n")

main()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
b = list(set(a))
ans = 0
for i in range(len(b)):
  k = a.count(b[i])
  ans += k*(k-1)/2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
b = list(set(a))
ans = 0
for i in range(len(b)):
  ans += a.count(b[i])*(a.count(b[i])-1)/2
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
an = tuple(map(str, input().split()))
print(an)

test_list = [[an[i] for i in range(n)] for i in range(n)]
for i in range(n):
    an2=list(an)
    Ans = 0
    an2[i]="0"
    c = collections.Counter(an2)
    c_list = list(c.values())
    
    for j in range(len(c_list)):
        Ans += (c_list[j]-1)*c_list[j]/2
    print(int(Ans))

Submission status: Wrong Answer

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

S={}
for i in range(n):
    a = A[i]
    if a in S :
        S[a]+=1
    else:
        S[a]=1

V=list(S.values())
c = sum([v*(v-1)//2 for v in V])

cdiff=0
K=[]
for i in range(n):
    a = A[i]
    s=S[a]
    if s>=2 :
        cdiff=(s*(s-1)-(s-1)*(s-2))//2
    print(c-cdiff)

Submission status: Wrong Answer

Solution code:

N = int(input())
A = list(map(int,input().split()))
# print('A:',A)
#まず、一気に数えてしまおう！
num = [0]*N
for i in range(N):
    num[A[i]-1]+=1
# print('num:',num)


#その数のペアはいくつ？
C = [0]*N
cnt=0 #１つも抜かさない時の選び出す場合の数

MAXN = 2*(10**5)+10
MOD = 10**9 + 7
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

for i in range(N):
    if num[i]!=0 and num[i]!=1:
        dammy = nCr(num[i],2,10**9+7)
        cnt+=dammy
        C[i] = dammy
# print('cnt,C:',cnt,C)


#実際に計算していく
for i in range(N):
    # print('A[i]',A[i])
    if num[A[i]-1] ==1 or num[A[i]-1] ==0 :
        print(cnt)

    elif num[A[i] -1]==2:
        print(cnt-C[A[i]-1])

    else:
        print(cnt - C[A[i]-1] + nCr(num[A[i]-1]-1,2))

Submission status: Wrong Answer

Solution code:
import math

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

dic = {}
for a in A:
    if not a in dic:
        dic[a] = 1
    else:
        dic[a] += 1

ans = 0
for a in dic:
    if dic[a] > 1:
         ans += dic[a] * (dic[a] - 1) // 2

ansdic = {}

for a in dic:
    ansdic[a] = 0
    if dic[a] > 1:
        ansdic[a] = ans - (dic[a] - 1)

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

Submission status: Wrong Answer

Solution code:
import math

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

nn = int(input())
aa = list(map(int,input().split()))

ne = [0]*200005
cn = [0]*200005
cnminus1 = [0]*200005
#print(nn,aa)
#print(len(ne))
for i in range(nn):
    ne[aa[i]] += 1

for i in range(nn):
 #   print(ne[i])
    if ne[i] == 0:
        cn[i] = 0
        cnminus1[i] = 0
    elif ne[i] == 1:
        cn[i] = 0
        cnminus1[i] = 0
    elif ne[i] == 2:
        cn[i] = 1
        cnminus1[i] = 0
    else:
        cn[i] = combinations_count(ne[i],2)
        cnminus1[i] = combinations_count(ne[i]-1,2)

sum_cn = sum(cn)

for i in range(nn):
    print(sum_cn - cn[aa[i]] + cnminus1[aa[i]])

Submission status: Wrong Answer

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
#import numpy as np
#import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
a = inpl()
kosuu = [0]*(200000+1)
cnt = [0]*(200000+1)
ans = [0]*(200000+1)

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

s = 0
for i in range(n):
  tmp = kosuu[i]
  s += tmp * (tmp - 1) // 2

for i in range(n):
  tmp = kosuu[a[i]]
  #print(s - cnt[a[i]] + max(0,((tmp - 1)*(tmp - 2)//2)))
  print(s - max(0,tmp-1))

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
#import numpy as np
#import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
a = inpl()
kosuu = [0]*(200000+1)
cnt = [0]*(200000+1)
ans = [0]*(200000+1)

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

for i in range(n):
  tmp = kosuu[i]
  cnt[i] = tmp * (tmp - 1) // 2

s = sum(cnt)
for i in range(n):
  tmp = kosuu[a[i]]
  #print(s - cnt[a[i]] + max(0,((tmp - 1)*(tmp - 2)//2)))
  print(s - max(0,tmp-1))

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
#import numpy as np
#import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
a = inpl()
kosuu = [0]*(200000+1)
cnt = [0]*(200000+1)
ans = [0]*(200000+1)

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

for i in range(n):
  tmp = kosuu[i]
  cnt[i] = tmp * (tmp - 1) // 2

s = sum(cnt)
for i in range(n):
  tmp = kosuu[a[i]]
  print(s - cnt[a[i]] + max(0,((tmp - 1)*(tmp - 2)//2)))

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
#import numpy as np
#import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
a = inpl()
kosuu = [0]*(n+1)
cnt = [0]*(n+1)
ans = [0]*(n+1)

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

for i in range(n):
  tmp = kosuu[i]
  cnt[i] = tmp * (tmp - 1) // 2

s = sum(cnt)
for i in range(n):
  tmp = kosuu[a[i]]
  print(s - cnt[a[i]] + max(0,((tmp - 1)*(tmp - 2)//2)))

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
#import numpy as np
#import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
a = inpl()
kosuu = [0]*(n+1)
cnt = [0]*(n+1)
ans = [0]*(n+1)

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

for i in range(n):
  tmp = kosuu[i]
  cnt[i] = tmp * (tmp - 1) // 2

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

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
#import numpy as np
#import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
a = inpl()
cnt = [0]*(n+1)
ans = [0]*(n+1)

for i in range(n):
  tmp = a.count(i)
  cnt[i] = tmp * (tmp - 1) // 2

s = sum(cnt)

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

Submission status: Wrong Answer

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

def choose2(n):
  if n <= 1:
    return 0
  return n*(n-1)//2

inp = [0]*(n+1)
for i in range(n):
  inp[a[i]] += 1

total = 0
for i in range(n):
  total += choose2(inp[i])

for i in range(n):
  count = total - choose2(inp[a[i]]) + choose2(inp[a[i]]-1)
  print(count)

Submission status: Wrong Answer

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

inp = [0]*(n+1)
for i in range(n):
  inp[a[i]] += 1

total = 0
for i in range(n):
  total += inp[i]*(inp[i]-1) // 2

for i in range(n):
  count = total - inp[a[i]]*(inp[a[i]]-1) // 2 + (inp[a[i]]-1)*(inp[a[i]]-2) // 2
  print(count)

Submission status: Wrong Answer

Solution code:

import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
v = c.values()
s = 0
for i in v:
    s += (i*(i-1))//2

for i in range(n):
    d = c[a[i]]
    x = (d*(d-1))//2 if d > 1 else 0
    y = (d-1*(d-2))//2 if d > 2 else 0
    print(s-x+y)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    ans = 0
    for v in c.values():
        ans += v*(v-1)//2

    for k in range(N):
        v = c[A[k]]
        diff = -v*(v-1)//2 + (v-1)*(v-2)//2
        print(ans + diff if v != 1 else 0)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

cA = Counter(A)

allS = 0
for key in cA:
    allS += cA[key] * (cA[key] - 1) / 2

for i in range(N):
    if i in cA.keys():
        print(int(allS - (cA[i] - 1)))
    else:
        print(int(allS))

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    n = int(input())
    balls = [int(i) for i in input().split()]

    # v - value written on ball
    # b - ball index in [0, n)
    # ct - number of times a value occurs

    # hist[v] = ct
    hist = Counter(balls)

    # counts[b] = ct 
    counts = [ hist[balls[b]] for b in range(n) ]

    diff_counts = set(hist.values())
    # combos[ct] = number of combos with ct - 1
    combos1 = { ct: 0 if ct == 1 else (ct-1) * (ct-2) // 2 for ct in
            diff_counts }
    combos = { ct: ct * (ct-1) // 2 for ct in diff_counts  }

    for k in range(n):
        ans = sum(combos.values()) - combos[counts[k]] + combos1[counts[k]]
        print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
A = list(map(int,input().split()))
ans = [0] * N
B = Counter(A)
for i in range(N):
    ans[i] = B[A[i]]-1

total=sum(ans)
C=[]
for i in range(N):
    c = (total-ans[i])//2
    C.append(c)

for num in C:
    print(num)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
A = list(map(int,input().split()))
ans = [0] * N
B = Counter(A)
for i in range(N):
    ans[i] = B[A[i]]-1
total=sum(A)
C=[]
for i in range(N):
    c = (total-ans[i])//2
    C.append(c)

for num in C:
    print(num)

Submission status: Wrong Answer

Solution code:
import collections

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

cA=collections.Counter(A)
sum=0
#print(len(cA))
#print(cA[3])
for i in range(1,N+1):
  if cA[i]>=2:
    #print(cA[i])
    sum+=int(cA[i]*(cA[i]-1)/2)
#print(sum)
#print(cA)
for i in range(N):
  ans=0
  #print(A[i])
  num=cA[A[i]]
  if num>=2:
    #print(num)
    ans=sum-int(num*(num-1)/2)
    #print(ans)
  num-=1
  if num>=2:
    #print(num)
    ans=ans+int(num*(num-1)/2)
    #print(ans)
  #print("------------------")
  print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def tri(num):
    if num < 0:
        return 0
    return int(num*(num+1)/2)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    c = Counter(a)
    for i in range(n):
        print(sum([tri(j-1) for j in c.values()]))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

a_2 = [0 for i in range(n)]
for i in range(n):
    a_2[a[i]-1] += 1

al = [0 for i in range(n)]
c = 0
for i in a_2:
    if i > 1:
        al[c] += i * (i-1) / 2
    c += 1

for i in range(n):
    f = a[i]
    t = a_2[f-1] - 1
    #print(int(sum(al)-(al[f-1]-t*(t-1)/2)))

Submission status: Wrong Answer

Solution code:
from collections import Counter
import math

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

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

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

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 += combs_1[a]
        print(ans_k)
    else:
        print(0)

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 = {}
combs_1 = {}
for k, v in dic.items():
    if v >= 2:
        combs[k] = combinations_count(v, 2)
        ans += combs[k]
    if v >= 3:
        combs_1[k] = combinations_count(v-1, 2)

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 += combs_1[a]
        print(ans_k)
    else:
        print(0)