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: Runtime Error

Solution code:
import copy

def nC2(n):
    if n < 2:
        return 0
    else:
        return n*(n-1)//2

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

count = 0
B = copy.copy(A)
Num = list(set(B))
for num in Num:
    count += nC2(B.count(num))
#print(count)

for k in range(n):
    B = copy.copy(A)
    num = B.pop(k)
#    print()
#    print(k, num, B)
    print(countAll - B.count(num))

Submission status: Runtime Error

Solution code:
import copy
import math

def nC2(n):
    if n < 2:
        return 0
    else:
        return n*(n-1)//2

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

for k in range(n):
    B = copy.copy(A)
    B.pop(k)
#    print()
#    print(k, B)
    Num = list(set(B))
    
    count = 0
    for num in Num:
        count += combination(B.count(num), 2)
#        print(num, B.count(num))
    print(count)

Submission status: Runtime Error

Solution code:
import collections
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
sum=0
SUM=0
n= int(input())
a = [int(x) for x in input().split()]
F=a
sum=0
j=0
for k in range(n):
     t=a[k]
     del a[k]
     c = collections.Counter(a)
     u=list(c.values())
     for j in range(len(u)):
       if u[j]>=2:
           B= cmb(u[j], 2)
           sum=sum+B
           j=j+1
     B=0
     print(sum)
     sum=0
     a.insert(k, t)

Submission status: Runtime Error

Solution code:
import collections
collections.setrecursionlimit(500*500)
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
sum=0
SUM=0
n= int(input())
a = [int(x) for x in input().split()]
F=a
sum=0
j=0
for k in range(n):
     t=a[k]
     del a[k]
     c = collections.Counter(a)
     u=list(c.values())
     for j in range(len(u)):
       if u[j]>=2:
           B= cmb(u[j], 2)
           sum=sum+B
           j=j+1
     B=0
     print(sum)
     sum=0
     a.insert(k, t)

Submission status: Runtime Error

Solution code:
import collections
from scipy.special import comb
sum=0
SUM=0
n= int(input())
a = [int(x) for x in input().split()]
F=a
sum=0
j=0
for k in range(n):
     t=a[k]
     del a[k]
     c = collections.Counter(a)
     u=list(c.values())
     for j in range(len(u)):
       if u[j]>=2:
           B= comb(u[j], 2, exact=True)
           sum=sum+B
           j=j+1
     B=0
     print(sum)
     sum=0
     a.insert(k, t)

Submission status: Runtime Error

Solution code:

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

c = [0]*n

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

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

Submission status: Runtime Error

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

d = [[0]*n for _ in range(n)]

for i in range(n):
    b = list(a)
    b[i] = 0
    for j in range(n):        
        d[i][b[j]] = d[i][b[j]]+1
    
for i in range(n):
    c = 0
    for j in range(n):
        c = c + d[i][j]*(d[i][j]-1)//2
    print(c)

Submission status: Runtime Error

Solution code:
input = sys.stdin.readline

from collections import Counter

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

#
C=Counter()
for i in range(n):
    C[a[i]] += 1
xsum=0
for key, value in C.items():
    xsum += value*(value-1)//2

#
for k in range(n):
    print( xsum - (C[a[k]] - 1) )

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
cnt = {}
total = 0

for a in A:
    if a not in cnt:
        cnt[a] = 0
    cnt[a] += 1

for i in cnt.values():
    total += i * (i - 1) // 2

for i in range(N):
    print(total - (cnt[i] - 1))

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split())
from collections import Counter
L = list(Counter(A))
LV = L.values()

ans = 0
for x in LV:
    ans += x*(x-1)//2

for k in range(n):
    print(ans-(A[k]-1))

Submission status: Runtime Error

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] += 1

for i in range(N + 1):
    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] + 1] > 0:
        diff = box_2[A_list[i] + 1] - box_3[A_list[i] + 1]
        print(int(ans_base - diff))
    else:
        print(int(ans_base))

Submission status: Runtime Error

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] += 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: Runtime Error

Solution code:
from scipy.misc import comb
N=int(input())
A=list(map(int,input().split()))
nset=set([])
ndict={}
for a in A:
  if a in nset:
    ndict[a]+=1
  else:
    nset.add(a)
    ndict[a]=1
#print(nset,ndict)
all=0
for n in nset:
  tmp=ndict[n]
  if tmp>=2:
    all+=comb(tmp,2,exact=True)
all=int(all)
for a in A:
  tmp=ndict[a]
  if tmp==1:
    print(all)
  elif tmp==2:
    print(all-1)
  else:
    print( all-comb(tmp,2,exact=True)+comb(tmp-1,2,exact=True) )

Submission status: Runtime Error

Solution code:
from collections import Counter

cnt = Counter(a)
b = set(a)
c = 0
for i in b:
    c += cnt[i]*(cnt[i]-1)//2

for i in a:
    print(c-cnt[i]+1)

Submission status: Runtime Error

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

c = collections.Counter(A)
keys = c.keys()
ans_dict = {}
ans_dict2 = {}
for key in keys:
    ans_dict[key] = cmb(c[key]-1,2)
    ans_dict2[key] = cmb(c[key],2)

SUM  = sum(ans_dict2.values())

# print(ans_dict)
# print(ans_dict2)

for key in A:
    print(SUM-ans_dict2[key]+ans_dict[key])

Submission status: Runtime Error

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 = 
ans = 0
for k in dic:
  tmp  =dic[k]
  if tmp >= 2:
    memo[k] = C(tmp, 2)
    ans += memo[k]

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

Submission status: Runtime Error

Solution code:
n = int(input())
L = [int(i) for i in input().split()]
t = set(L)
dn = {}
dc = {}
All = 0
for i in L:
  dn[i] += 1
for i in t:
  dc[i] = int(dn[i]*(dn[i]-1)/2)
  All += dc[i]
for i in range(n):
  print(All-dc[L[i]] + int((dn[L[i]]-1)*(dn[L[i]]-2)/2))

Submission status: Runtime Error

Solution code:
n = int(input())
L = [int(i) for i in input().split()]
t = set(L)
dn = {}
dc = {}
All = 0
for i in t:
  dn[i] = L.count(i)
  dc[i] = int(dn[i]*(dn[i]-1)/2)
  All += dc[i]
for i in range(n):
  print(All-dc[L[i]] + int((dn[L[i]-1]-1)*(dn[L[i]-2])/2))

Submission status: Runtime Error

Solution code:
import copy
from scipy.special import comb
n = int(input())
#x, y, a, b, c = map(int, input().split())
#s= list(input())
a = list(map(int, input().split()))
an = [0] * n
for i in range(n):
    an[a[i]-1] += 1

ac2 = []
ac2_diff = []
for i in range(n):
    ac2.append(comb(an[i], 2, exact=True))
    ac2_diff.append(ac2[i]-comb(an[i]-1, 2, exact=True))
sum = sum(ac2)
for i in range(n):
    print(sum - ac2_diff[a[i]-1])

Submission status: Runtime Error

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

dict = {}

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
    dict[(index)] = [counter,comb(counter,2),comb(counter-1,2)]
    sum+=dict[(index)][1]




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

Submission status: Runtime Error

Solution code:
import sys

from scipy.special import comb #scipy.special

#import numpy as np

n = int(input())

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

dict = {}

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
    dict[(index)] = [counter,comb(counter,2),comb(counter-1,2)]
    sum+=dict[(index)][1]




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

Submission status: Runtime Error

Solution code:
N = int(input())

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

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

ans_all = 0
ans_list = {}
for k, v in d.items():
    if v == 1:
        continue
    if v == 2:
        ans_all += 1
        ans_list[k] = 1
        continue
    ans_all += v*(v-1)/2
    ans_list[k] = v*(v-1)/2 - (v-1)*(v-2)/2

for a in A:
    print(int(ans_all-ans_list[a]))

Submission status: Runtime Error

Solution code:
import sys

from scipy.special 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)

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: Runtime Error

Solution code:
import sys

from scipy.special 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: Runtime Error

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

data = [0]*n

for aa in a:
  data[aa] += 1

allans = 0
for d in data:
  if d >= 2:
    allans += (d*(d-1))//2
    
for aa in a:
  if data[aa] == 2:
    print(allans - (data[aa]*(data[aa]-1))//2)
  elif data[aa] > 2:
    print(allans - (data[aa]-1))
  else:
    print(allans)

Submission status: Runtime Error

Solution code:
n = int(input())
alist = list(map(int, input().split()))
from scipy.special import comb

# n = 5
# alist = [1, 1, 2, 1, 2]
ans = []

def alist_k (alist_def, k):
    alist_def2 = alist_def.copy()
    alist_def2.pop(k)
    return alist_def2

for k in range(n):
    alist2 = alist_k(alist, k)
    num_list = list(set(alist2))
    for i in num_list:
        ans.append(comb(alist2.count(i), 2, exact=True))
    print(sum(ans))
    ans = []

#print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
alist = map(int, input().split())
from scipy.special import comb

# n = 5
# alist = [1, 1, 2, 1, 2]
ans = []

def alist_k (alist_def, k):
    alist_def2 = alist_def.copy()
    alist_def2.pop(k)
    return alist_def2

for k in range(n):
    alist2 = alist_k(alist, k)
    num_list = list(set(alist2))
    for i in num_list:
        ans.append(comb(alist2.count(i), 2, exact=True))
    print(sum(ans))
    ans = []

#print(ans)

Submission status: Runtime Error

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
    
def combinations_count(n,r):
    return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))

for i in range(n):
    if l[i]>=2:
        l1[i]+=combinations_count(l[i],2)

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

Submission status: Runtime Error

Solution code:
import math

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

b = []
total = 0

for i in range(n):
    b.append(0)

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

for i in range(n):
    b[a[i]] -=1
    for j in range(n):
        if b[j] >= 2:
            total += b[j]*(b[j]-1)//2
    print(total)
    total = 0
    b[a[i]] += 1

#for i in range(n):
 #   print(b[i])

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
A = tuple(map(int, input().split()))
A_count = Counter(A)
ans = 0
for i, j in A_count:
    ans += j * (j - 1) // 2
for k in range(1, N+1):
    n = A_count[A[k-1]]
    ans_ = ans - (n - 1)
    print(ans_)

Submission status: Runtime Error

Solution code:
import copy

n = int(input())
list1 = list(map(int,input().split()))
list2 = copy.copy(list1) 　　#全体の組み合わせ計算
list3 = copy.copy(list1)    #K番目の数字との組み合わせ計算

kei1=0
kei2=0

for x in range(n):
    l = list2.pop(0)
    if l in list2:
        kei1 += list2.count(l)

    k = list3.pop(x)
    if k in list3:
        kei2 += list3.count(k)

    print(kei1-kei2)

Submission status: Runtime Error

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

Al = 0
cnt = 0
def solution(N,A,B,Al,cnt):
  for a in B:
      cnt = A.count(a)
      Al +=  cnt*(cnt-1)//2

  for k in range(N):
      cnt = A.count(A[k])
      print(Al - cnt +1)
solution(N,A,B,Al,cnt):

Submission status: Runtime Error

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

All = 0
cnt = 0
def solution(N,A,B,All,cnt):
  for a in B:
      cnt = A.count(a)
      All +=  cnt*(cnt-1)//2

  for k in range(N):
      cnt = A.count(A[k])
      print(All - cnt +1)
solution(N,A,B,All,cnt):

Submission status: Runtime Error

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

c=[0 for i in range(N+1)]
g=[0 for i in range(N+1)]

wa=0
for i in range(1,N+1):
    #b[a[i]-1]=b[a[i]-1]+1
    g[i]=str(a).count(str(i))
    #print(g[i])
    #print(str(a))
    #print(i)
    if(g[i]>1):
        c[i]=combinations_count(g[i],2)
        wa=c[i]+wa
    #    print(g)
    #    print(c[i])
    else:
        c[i]=0

        #print(c[i])


wawa=wa
#print(wa)
for i in range(1,N+1):
    d=i+1
    wa=wa-g[a[i]]+1
    #print(g[a[i]-1])
    print(wa)
    wa=wawa

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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

K = {}
for row in A:
    if row in K:
      K[row] += 1
    else:
      K[row] = 1

# 辞書Kに関して全探索
for row in A:
    ans = 0
    for i in K:
        if i == row:
            ans += comb(K[i]-1,2)
        else:
            ans += comb(K[i],2)
    print(int(ans))

Submission status: Runtime Error

Solution code:
from collections import Counter

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

def combinations_count(n, r):
    if n==1:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for k in range(N):
    tmp=Balls[k]
    del Balls[k]

    array_k = Balls
    sum_k=0
    c= Counter(array_k)
    for j in list(c.values()):
        sum_k += combinations_count(j,2)
    
    Balls.insert(k,tmp)
    print(sum_k)

Submission status: Runtime Error

Solution code:
N=int(input())
m=list(map(ine,input().split()))
t=[]
for i in range(N):
  t.append(0)
for i in range(N):
  t[m[i]-1]+=1
total=0
for i in range(N):
  total+=(t[i]*(t[i]-1))//2
for i in range(N):
  if t[m[i]-1]<2:
    print(total)
  else:
    print(total-(t[m[i]-1]-1))

Submission status: Runtime Error

Solution code:
import numpy as np
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-1)/f2 if n > 1 else 0 for n in ret]
E = np.ones(N)
for k in range(N):
    i = A[k]
    E[A[k]-1] = (ret[i-1]-2) / ret[i-1]
    print(int(np.dot(result, E)))
    E[A[k]-1] = 1

Submission status: Runtime Error

Solution code:
from collections import deque
import collections
from scipy.special import comb

N = int(input())
A = list(map(int, input().split()))
d2 = deque()
d = deque(A)
ans = 0

for i in range(N):
    d2.append(d.popleft())
    if i > 0:
        d.append(d2.popleft())
    c = collections.Counter(d)
    for i in c.keys():
        if c[i] >= 2:
            ans += comb(c[i], 2)
    print(int(ans))
    ans =0

Submission status: Runtime Error

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

for i in range(N):
    ans = 0
    AA = A.copy()
    AA.pop(i)
    AAA = collections.Counter(AA)
    for j in AAA.values():
        if j>=2:
            ans += int(j*(j-1)/2)
    print(ans)

Submission status: Runtime Error

Solution code:
import math
def comb(a,b):
    if a<b:
        return 0
    else:
        return math.factorial(a)/math.factorial(b)/math.factorial(a-b)
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
sum=0
for value in dic.values():
    sum+=comb(value,2)
for k in range(1,n+1):
    print(int(sum-comb(dic[A[k-1]],2)+comb(dic[A[k-1]]-1,2)))

Submission status: Runtime Error

Solution code:
from scipy.special import comb
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
sum=0
for value in dic.values():
    sum+=comb(value,2)
for k in range(1,n+1):
    print(int(sum-comb(dic[A[k-1]],2)+comb(dic[A[k-1]]-1,2)))

Submission status: Runtime Error

Solution code:
N=int(input())
li = list(map(int,input().split()))
num=[None]*N
num_ans=[None]*N

for i in range(min(li),max(li)+1):
  num_ans[i]=(li.count(i)*(li.count(i)-1))/2
ans=sum(num_ans)

for k in range(N):
  before=li.count(li[k])*(li.count(li[k])-1)/2
  after=(li.count(li[k])-2)*(li.count(li[k])-1)/2
  print(int(ans-before+after))

Submission status: Runtime Error

Solution code:
N=int(input())
li = list(map(int,input().split()))
num=[0]*N
num_ans=[0]*N

for i in range(max(li)+1):
  num[i]=li.count(i)
  num_ans[i]=(num[i]*(num[i]-1))/2
ans=sum(num_ans)

for k in range(N):
  num_k = li.count(li[k])
  before=num_k*(num_k-1)/2
  after=(num_k-2)*(num_k-1)/2
  print(int(ans-before+after))

Submission status: Runtime Error

Solution code:
N=int(input())
li = list(map(int,input().split()))
num=[0]*N
num_ans=[0]*N

for i in range(max(li)+1):
  num[i]=li.count(i)
  num_ans[i]=(num[i]*(num[i]-1))/2
ans=sum(num_ans)

for k in range(N):
  li2=(li[:k]+li[k+1:])
  num_k = li.count(li[k])
  before=num_k*(num_k-1)/2
  after=(num_k-2)*(num_k-1)/2
  print(int(ans-before+after))

Submission status: Runtime Error

Solution code:
N = int(input())
A = input()
c = [0 for _ in range(N)]
a = [0 for _ in range(N)]
for i in range(0,len(A),2):
    c[int(A[i]) - 1] += 1
    a[i // 2] = int(A[i])

allsum = 0

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

for i in range(N):
    print(allsum - (c[a[i] - 1] - 1))

Submission status: Runtime Error

Solution code:
from math import factorial

def convination(n, r):
    a = factorial(n) / factorial(r) / factorial(n - r)
    return int(a)

num = int(input())
list=input().split()
listnum = [int(i) for i in list]

for i in range(num):
  lista= listnum[:i]+listnum[i+1:]
  ans = 0
  for j in set(lista):
      a = lista.count(j)
      if a >= 2:
          ans += convination(a, 2)
  print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial

def convination(n, r):
    a = factorial(n) / factorial(r) / factorial(n - r)
    return int(a)

num = int(input())
list=input().split()
listnum = [int(i) for i in list]

for i in range(num):
  lista= listnum[:i]+listnum[i+1:]
  ans = 0
  for j in set(lista):
      a = lista.count(j)
      if a >= 2:
        ans += convination(lista.count(j), 2)
  print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial
import copy

def convination(n, r):
    a = factorial(n) / factorial(r) / factorial(n - r)
    return int(a)

num = int(input())
list=input().split()
listnum = [int(i) for i in list]

for i in range(num):
  lista = copy.copy(listnum)
  lista.pop(i)
  ans = 0
  for j in set(lista):
      a = lista.count(j)
      if a >= 2:
        ans += convination(lista.count(j), 2)
  print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    B = (A[:i]+A[i+1:]).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: Runtime Error

Solution code:
N = int(input())
A = input().split()
for i in range(N):
    A[i] = int(A[i])
for i in range(N):
    B = A.copy()
    B = B[:i]+B[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: Runtime Error

Solution code:
import math
import collections

n = int(input())
a = list(map(int, input().split()))
num_list = []
ans_total = 0

c = collections.Counter(a)

for d in c:
    ans_total += int(math.factorial(c[d])/(2*math.factorial(c[d]-2)))

for i in range(n):
    print(ans_total-c[a[i]]+1)

Submission status: Runtime Error

Solution code:
import collections

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)
    C = collections.Counter(B)
    #print(C)
    D = list(C.values())
    #print(D)
    E=0
    for j in range(len(D)):
        E+=int(D[j]*(D[j]-1)/2)
    print(E)

Submission status: Runtime Error

Solution code:
N = int(input())
A = input()
Asum = [0] + [0 for _ in range(N)]
Al = [0 for _ in range(N)]
for i in range(0,N*2,2):
    Asum[int(A[i])] += 1
    Al[i // 2] = int(A[i])

for i in range(0,N):
    isum = 0
    for k in range(1, N+1):
        if not Asum[k] == 0:
            isum += (Asum[k] -(Al[i] == k))*(Asum[k] - (Al[i] == k) - 1) // 2
    print(isum)

Submission status: Runtime Error

Solution code:
N = int(input())
A = input()
Asum = [0] + [0 for _ in range(N)]
Al = [0 for _ in range(N)]
for i in range(0,N*2,2):
    Asum[int(A[i])] += 1
    Al[i // 2] = int(A[i])

for i in range(0,N):
    isum = 0
    for k in range(1, N+1):
        isum += (Asum[k] -(Al[i] == k))*(Asum[k] - (Al[i] == k) - 1) // 2
    print(isum)

Submission status: Runtime Error

Solution code:
# %%time
import numpy as np
# N = 200000
# A_npa = np.arange(N, dtype=np.int32)
N = int(input())
A_npa = np.array(list(map(int, input().split())))
total = 0
A_unique, inverse, counts = np.unique(
    A_npa, return_inverse=True, return_counts=True)
counts = np.sum(counts*(counts-1)//2)-(counts-1)
for i in inverse:
    print(counts[i])

Submission status: Runtime Error

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 x in A:
    print(S - count[x] + 1)

Submission status: Runtime Error

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 x in range(A):
    print(S - count[x] + 1)

Submission status: Runtime Error

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 x in range(A):
    print(S - A.count(x) + 1)

Submission status: Runtime Error

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 x in range(A):
    print(S - A.count(x) + 1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
s = 0
for i in set(a):
    s += c[i] * (c[i] - 1)
dp = [-1] * n
for i in a:
    if dp[i] == -1:
        dp[i] = (s - c[i] * (c[i] - 1) + (c[i] - 1) * (c[i] - 2)) // 2
        print(dp[i])
    else:
        print(dp[i])

Submission status: Runtime Error

Solution code:
a=int(input())
b=list(map(int,input().split()))
c=b
c=sorted(b)
d=0
e=[]
g=list(set(b))
while d<a-1:
  f=c.count(c[d])
  e.append(f)
  d=d+f

l=e
import numpy as np
for i in b:  
  h=g.index(i)
  l[h]=l[h]-1
  m=np.array(l)
  m=int(sum(m*(m-1)/2))
  print(m)
  l[h]=l[h]+1

Submission status: Runtime Error

Solution code:
import numpy as np

a=int(input())
b=list(map(int,input().split()))
c=b
c.sort()
d=0
e=[]
g=list(set(b))
while d<a-1:
  f=c.count(c[d])
  e.append(f)
  d=d+f

l=e

for i in b:  
  h=g.index(i)
  l[h]=l[h]-1
  m=np.array(l)
  m=int(sum(m*(m-1)/2))
  print(m)
  l[h]=l[h]+1

Submission status: Runtime Error

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

for i in range(a):
  c=b[:i]+b[i+1:]
  c.sort()
  d=0
  e=[]

  while d<a-1:
    f=c.count(c[d])
    e.append(f)
    d=d+f

  g=np.array(e)
  print(int(sum((g-1)*g/2)))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

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

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = np.array(input().split(),dtype=int)
sum = 0

kn = [0 for i in range(n)]
for i in range(n):
    kn[a[i]] += 1
for i in range(n):
    sum += kn[i]*(kn[i]-1)//2

for i in range(n):
    x = kn[a[i]]
    print(sum-x+1)

Submission status: Runtime Error

Solution code:
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
dif = [0] * n
sum_c = 0
c = Counter(a)
for i, v in c.items():
    if v < 2:
        continue
    val = v * (v - 1) / 2
    dif[i] = v - 1
    sum_c += val
print('\n'.join([int(sum_c - data[i]) for i in a])

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
dif = [0] * n
sum_c = 0
c = collections.Counter(a)
for i, v in c.items():
    if v < 2:
        continue
    val = v * (v - 1) // 2
    dif[i] = 2 * (v - 1) // 2
    sum_c += val
print('\n'.join([int(sum_c - data[i]) for i in a])

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
dif = [0] * n
sum_c = 0
for i, v in collections.Counter(a).items():
    if v < 2:
        continue
    val = v * (v - 1) // 2
    dif[i] = 2 * (v - 1) // 2
    sum_c += val
print('\n'.join([int(sum_c - data[i]) for i in a])

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
dif = [0] * n
sum = 0
for i, v in collections.Counter(a).items():
    if v < 2:
        continue
    val = v * (v - 1) // 2
    dif[i] = 2 * (v - 1) // 2
    sum += val
print('\n'.join([int(sum - data[i]) for i in a])

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
a = list(map(int, input().split()))
dif = [0] * n
sum = 0
for i, v in collections.Counter(a).items():
    if v < 2:
        continue
    val = v * (v - 1) // 2
    dif[i] = 2 * (v - 1) // 2
    sum += val
print('\n'.join([int(sum_count - data[i]) for i in a])

Submission status: Runtime Error

Solution code:
import math
import numpy as np

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

n = int(input())
a = np.array(list(map(int, input().split())))
num, count = np.unique(a, return_counts=True)

for k in a:
    combi_sum = 0
    for i in num:
        inv_n = count[num==i].sum()
        if i == k:
            inv_n -= 1
        combi_sum += combi(inv_n, 2)
    print(combi_sum)

Submission status: Runtime Error

Solution code:
import math
import numpy as np

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

n = int(input())
a = np.array(list(map(int, input().split())))
num, count = np.unique(a, return_counts=True)

for k in a:
    combi_sum = 0
    for i in num:
        inv_n = count[num==i].sum()
        if i == k:
            inv_n -= 1
        combi_sum += combi(inv_n, 2)
    print(combi_sum)