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:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
B = Counter(A)
C = {key:(B[key]*(B[key]-1)//2) for key in B}
ans = sum(B.values())
for i in A:
    if C[i] < 2:
        print(ans)
    else:
        ans = ans - C[i] +(B[key-1]*(B[key]-2)//2)
        print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = [a.count(i+1) for i in range(n)]
d = []
for j in b:
    if j >= 2:
        d.append(factorial(j)//factorial(2)//factorial(j-2))
    else:
        d.append(0)

for k in a:
    if b[k-1] >= 3:
        u = b[k-1] 
        p = factorial(u-1)//factorial(2)//factorial(u-3)
        print(sum(d)-d[k-1]+p)
    else:
        print(sum(d)-d[k-1])

Submission status: Runtime Error

Solution code:
import math

def ABC159D(a):
    if a<2:
        return 0
    else:
        return math.factorial(a)//math.factorial(a-2)//2


n=int(input())
a=list(map(int,input().split()))
d1=dict()
for i in a:
    if i not in d1:
        d1[i]=1
    else:
        d1[i] += 1
#print(d1)
d2={i:ABC159D(j) for i,j in d1.items()}
d3={i:ABC159D(j-1)-d2[i] for i,j in d1.items()}
#print(d2,d3)
p=sum(d2.values())
print(''.join([p+d3[i] for i in a]))

Submission status: Runtime Error

Solution code:
def com(n):
    return n*(n-1)//2
ans=0
n=int(input())
a=list(map(int,input().split()))
coun=[0]*(n+1)
for i in range(n):
    coun[a[i]]+=1
foi i in range(n+1):
    ans+=com(coun[i])
for i in range(n):
    m=com(coun[a[i]]-1)
    o=com(coun[a[i]])
    print(ans-o+m)

Submission status: Runtime Error

Solution code:
def com(n):
    return n*(n-1)//2
ans=0
n=int(input())
a=list(map(int,input().split()))
coun=[0]*n
for i in range(n):
    coun[a[i]]+=1
for i in range(n+1):
    ans+=com(coun[i])
for i in range(n):
    m=com(coun[a[i]]-1)
    o=com(coun[a[i]])
    print(ans-o+m)

Submission status: Runtime Error

Solution code:
def com(n):
    return n*(n-1)//2
ans=0
n=int(input())
a=list(map(int,input().split()))
coun=[0]*n
for i in range(n+1):
    coun[a[i]]+=1
for i in range(n+1):
    ans+=com(coun[i])
for i in range(n+1):
    m=com(coun[a[i]]-1)
    o=com(coun[a[i]])
    print(ans-o+m)

Submission status: Runtime Error

Solution code:
def com(n):
    return n*(n-1)//2
ans=0
n=int(input())
a=list(map(int,input().split()))
coun=[0]*n
for i in range(n):
    coun[a[i]]+=1
for i in range(n):
    ans+=com(coun[i])
for i in range(n):
    m=com(coun[a[i]]-1)
    o=com(coun[a[i]])
    print(ans-o+m)

Submission status: Runtime Error

Solution code:
def com(n):
    return n*(n-1)//2
ans=0
n=int(input())
a=list(map(int,input().split()))
coun=[0]*n
for i in range(n):
    coun[a[i]]+=1
foi i in range(n):
    ans+=com(coun[i])
for i in range(n):
    m=com(coun[a[i]]-1)
    o=com(coun[a[i]])
    print(ans-o+m)

Submission status: Runtime Error

Solution code:

from collections import Counter
from scipy.special import comb
import numpy as np
N = int(input())
A = list(map(int, input().split()))

total = 0
answers = np.array([0] * (N + 1))
for number, appearance in Counter(A).items():
    flat = comb(appearance, 2, exact=True)
    minus_one = comb(appearance - 1, 2, exact=True)
    total += flat
    answers[number] = minus_one - flat
answers += total

print(*answers[A], sep="\n")

Submission status: Runtime Error

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

for i in A:
    B[i] += 1
sum_original = sum(j*(j-1)//2 for j in B)
for k in range(N):
    print(sum_original - (B[A[k]]+1)

Submission status: Runtime Error

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

for k in range(N):
    del A[k]
    ans = 0
    
    for i in range(1,N+1):
        n = A.count(i)
        nc2 = n * (n-1) / 2
        ans += nc2
    print(ans)

Submission status: Runtime Error

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

for k in range(N):
    del A[k]
    ans = 0
    
    for i in range(1,N+1):
        n = sum(A[j] == i for j in range(N-1))
        nc2 = n * (n-1) / 2
        ans += nc2
    print(ans)

Submission status: Runtime Error

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

for k in range(N):
         del A[k]
         ans = 0
         for i in range(1,N+1):
         	n = sum(A[j] == i for j in range(1,N))
         	nc2 = n * (n-1) / 2
         	ans += nc2
         
         print(ans)

Submission status: Runtime Error

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

for k in range(1, N+1):
         A = A.remove(k)
         ans = 0
         for i in range(1,N+1):
         	n = sum(A[j] == i for j in range(1,N))
         	nc2 = n * (n-1) / 2
         	ans += nc2
         
         print(ans)

Submission status: Runtime Error

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

for k in range(1, N+1):
         A = A.remove(A[k])
         ans = 0
         for i in range(1,N+1):
         	n = sum(A[j] == i for j in range(1,N))
         	nc2 = n * (n-1) / 2
         	ans += nc2
         
         print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

counter = np.bincount(A)

diff = (counter * (counter-1)//2 - (counter-1) * (counter-2)//2)
ans = total - diff[A]

print(*ans, sep="\n")

Submission status: Runtime Error

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

counter = np.bincount(A)

ans = []
for i in range(len(A)):
    counter_i = counter.copy()
    counter_i[A[i]] -=1
    sum_i = sum(counter_i * (counter_i -1) //2)
    ans.append(sum_i)
    
for i in range(len(ans)):
    print(ans[i])

Submission status: Runtime Error

Solution code:
    n = int(input())
    a = list(map(int, input().split()))
    b = [0 for _ in range(max(a)+1)]
    for x in a:
        b[x] += 1
    c = sum([x*(x-1)//2 for x in b])
    for i in range(n):
        print(c-b[a[i]]+1)

Submission status: Runtime Error

Solution code:
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v):
    print(["Yes", "No"][not v])


if not __name__ == '__main__':
    def debug(*v):
        print(*v)


# エントリーポイント
def main():
    N = input(int)
    A = input([int, N])

    count = dd(int)
    for a in A:
        count[a] += 1
    debug(count)
    for a in A:
        ans = 0
        for k, v in count.items():
            temp = v if not k == a else v - 1
            ans += (temp * (temp - 1)) // 2
        print(ans)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Submission status: Runtime Error

Solution code:
import collections
import math

url = "https://atcoder.jp//contests/abc159/tasks/abc159_d"


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


def main():
    input()
    t = list(map(int, input().split()))
    col = collections.Counter(t)
    com = {}
    al = 0
    for key in col:
        com[key] = combinations_count(col[key], 2)
        al += com[key]
    for v in t:
        c = col[v] - 1
        if c <= 1:
            c = 0
        else:
            c = com[v] - c
        tmp = (al - com[v]) + c
        print(tmp)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import defaultdict

      
def r(i) :
  if i < 2:
    return 1
  else :
    return i*r(i-1)

a = int(input())
b = list(map(int,input().split()))
for i in range(a):
  total = 0
  c = defaultdict(int)
  for j in range(a):
    if j != i:
      c[b[j]] += 1
  for key in c.keys():
    if c[key] > 1:
  #    print(c[key],key)
  #    print("###")
      total += r(c[key]) / (r(2)*r(c[key]-2))
  print(int(total))

Submission status: Runtime Error

Solution code:
import collections
import math

url = "https://atcoder.jp//contests/abc159/tasks/abc159_d"


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


def main():
    input()
    t = list(map(int, input().split()))
    col = collections.Counter(t)
    com = {}
    al = 0
    for key in col:
        com[key] = combinations_count(col[key], 2)
        al += com[key]
    for v in t:
        c = col[v] - 1
        if c <= 1:
            c = 0
        else:
            c = combinations_count(c, 2)
        tmp = (al - com[v]) + c
        print(tmp)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    input()
    t = list(map(int, input().split()))
    col = collections.Counter(t)
    com = {}
    al = 0
    for key in col:
        com[key] = combinations_count(col[key], 2)
        al += com[key]
    for v in t:
        c = col[v] - 1
        if c <= 1:
            c = 0
        else:
            c = combinations_count(c, 2)
        tmp = (al - com[v]) + c
        print(tmp)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter

def Get_nC2(n):
    return int(n*(n-1) / 2)


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

c = Counter(A_i)
cnt_dict = {}

total = sum(list(map(Get_nC2, tmp.values())))

for a_i in A_i:
    result =  total - Get_nC2(c[a_i]) + Get_nC2(c[a_i-1])
    print(result)

Submission status: Runtime Error

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

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

for i in range(N):
    count[A_n[i]] -= 1
    ans =[count[i]*(count[i]-1)//2 for i in range(N)]
    print(sum(ans))
    count[A_n[i]] += 1

Submission status: Runtime Error

Solution code:
from scipy.special import comb
c=lambda n:comb(n,2,exact=True)
n=int(input())
a=list(map(int,input().split()))
b=[a.count(i+1)for i in range(n)]
s=0
for i in b:
    s+=c(i)
for k in range(n):
    print(s-b[a[k]-1]+1)

Submission status: Runtime Error

Solution code:

def Get_nC2(n):
    return int(n*(n-1) / 2);


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

cnt_dict = {}
for a_i in A_i:
    cnt = 0
    if a_i in cnt_dict:
        print(cnt_dict[a_i])
        continue
    else:
    for j in range(min(A_i), max(A_i)+1):
        j_cnt = A_i.count(j)
        if a_i == j:
            j_cnt -= 1

        cnt += Get_nC2(j_cnt)

        cnt_dict[a_i] = cnt

        print(cnt)

Submission status: Runtime Error

Solution code:
def fact(n):
    if n == 1 or n == 0:
        return 1
    elif n < 0:
        return 0
    else:
        return n * fact(n - 1)

def b(n, k):
    nk = fact(n-k)
    if nk == 0:
        return 0
    else:
        return fact(n) / (fact(k) * nk)
N = int(input())
A = [int(i) for i in input().split()] 

A_dict = [0 for i in range(N + 1)]
for a in A:
    A_dict[a] += 1
total = 0
for amount in A_dict:
    total += b(amount, 2)
for a in A:
    print(int(total - (A_dict[a] - 1)))

Submission status: Runtime Error

Solution code:
def fact(n):
    if n == 1 or n == 0:
        return 1
    elif n < 0:
        return 0
    else:
        return n * fact(n - 1)

def b(n, k):
    nk = fact(n-k)
    if nk == 0:
        return 0
    else:
        return fact(n) / (fact(k) * nk)
N = int(input())
A = [int(i) for i in input().split()] 

A_dict = {}
for a in A:
    if a not in A_dict:
        A_dict[a] = 0
    A_dict[a] += 1

total = 0
for key in A_dict:
    total += b(A_dict[key], 2)
    
for k in range(N):
    diff = b(A_dict[A[k]], 2) - b(A_dict[A[k]] - 1, 2)
    print(int(total - diff))

Submission status: Runtime Error

Solution code:
def fact(n):
    if n == 1 or n == 0:
        return 1
    elif n < 0:
        return 0
    else:
        return n * fact(n - 1)

def b(n, k):
    nk = fact(n-k)
    if nk == 0:
        return 0
    else:
        return fact(n) / (fact(k) * nk)
N = int(input())
A = [int(i) for i in input().split()] 

A_dict = {}
for a in A:
    if a not in A_dict:
        A_dict[a] = 0
    A_dict[a] += 1

for k in range(N):
    A_dict[A[k]] -= 1
    total = 0
    for key in A_dict:
        total += b(A_dict[key], 2)
    A_dict[A[k]] += 1
    print(int(total))

Submission status: Runtime Error

Solution code:
#coding:utf-8
from copy import copy

MOD = 1000000007

def add(a, b):
    return (a + b) % mod

def sub(a, b):
    return (a + mod - b) % mod

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, pow(b, mod-2, mod))

f = [1]
for i in range(10**5+5):
    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

def nCr(n, r):
    return f[n] // (f[r] * f[n-r])
  
def main():
    n = int(input())
    li = list(map(int, input().split()))
    nums = [0] * n
    for num in li:
        nums[num - 1] += 1
        
    sumv = 0
    for num in nums:
        if num == 0:
            continue
        sumv += nCr(num, 2)
    
    for num in li:
        cnt = nums[num - 1]
        if cnt == 1:
            print(sumv)
            continue
        v = sumv + nCr(cnt-1, 2) - nCr(cnt, 2)
        print(v)
        
  
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

setA = set(A)
an = 0
for num in B:
    d = A.count(num)
    an += d*(d-1)//2

for i in range(n):
    ans = an
    t = A[i]
    e = A.count(A[i])
    ans -= e*(e-1)//2
    ans += (e-1)*(e-2)//2
    print(ans)

Submission status: Runtime Error

Solution code:
import collections 
N=int(input())
A=list(map(int,input().split()))
s=0
cnt=collections.Counter(A)
for key in cnt.keys():
  s+=(cnt[key]*(cnt[key]-1))//2
for i in range(N):
  tmp=s
  tmp-=cnt(A[i])*(cnt(A[i])-1)//2
  tmp+=(cnt(A[i])-1)*(cnt(A[i])-2)//2
  print(tmp)

Submission status: Runtime Error

Solution code:
n = int(input())
lis = list(map(int,input().split()))
num = [0 for i in range(n)]
for nn in lis:
  num[nn-1] += 1
ans = 0
for nnn in num:
  ans += (nnn*(nnn-1))//2
for i in range(n):
  print(ans-(num[lis[i]]*(num[lis[i]]-1))//2+((num[lis[i]]-1)*(num[lis[i]]-2))//2)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
d = defaultdict(int)
for x in a:
  d[x] += 1
for x in a:
  c = d[x] - 1
  print(c * (c-1) // 2)a

Submission status: Runtime Error

Solution code:
# coding: utf-8
n = int(input())
A = list(map(int, input().split()))
X = [0]*n
for a in A:
    X[a] += 1
s = 0
for x in X:
    s += x*(x-1)//2
for a in A:
    print(s-X[a]+1)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
uA = list(set(A))
c = {u:A.count(u) for u in uA}
 
la = {}
lb = {}
 
for a in uA:
  la[a] = int(c[a]*(c[a]-1)/2)
  lb[a] = int((c[a]-1)*(c[a]-2)/2)
  
for a in A:
  ks = la.values()
  b = lb[a] + sum([v for k,v in la.items if k!=a])
  print(b)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
uA = list(set(A))
c = {u:A.count(u) for u in uA}
 
la = {}
lb = {}
 
for a in uA:
  la[a] = int(c[a]*(c[a]-1)/2)
  lb[a] = int((c[a]-1)*(c[a]-2)/2)
  
for a in A:
  ks = la.values(
  b = lb[a] + sum([v for k,v in la.items if k!=a])
  print(b)

Submission status: Runtime Error

Solution code:
def a(n):
    if n<2: return n
    return n+a(n-1)
N=int(input())
As=list(map(int,input().split()))
for i in range(len(As)):
    sum_=0
    l=As[:i]+As[i+1:]
    m=list(set(l))
    for f in m:
        c=l.count(f)
        sum_+=a(c-1)
    print(sum_)

Submission status: Runtime Error

Solution code:
from collections import Counter
import math

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

ca = Counter(a)
k = ca.keys()
d = {}

for i in k:
    d[i] = int(math.factorial(ca[i]) / 2) if ca[i] > 1 else 0


sumca = sum(d[i] for i in k)

for i in range(n):
    w = int(d[a[i]] / ca[a[i]]) if d[a[i]] > 1 else 0
    ans = sumca - d[a[i]] + w
    print(ans)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
N=int(input())
A=input().split(" ")
for i in range(N):
    A[i]=int(A[i])

NA=[]
for j in range(N):
    NA.clear()
    for i in range(N):
        NA.append(int(A[i]))
    NA.pop(j)
    count=[]
    pat=0
    for i in range(1,N):
        count.append(NA.count(i))
        com = comb(count[i-1], 2, exact=True)
        pat=pat+com
    print(pat)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
N=int(input())
A=input().split(" ")
for i in range(N):
    A[i]=int(A[i])

NA=[]
for j in range(N):
    NA.clear()
    for i in range(N):
        NA.append(int(A[i]))
    NA.pop(j)
    count=[]
    pat=0
    for i in range(1,N):
        count.append(NA.count(i))
        # print(count[i-1])
        com = comb(count[i-1], 2, exact=True)
        pat=pat+com
    print(pat)

Submission status: Runtime Error

Solution code:
n = input()
n = int(n)
lin = input().split()
# 要素の個数を求める
dic_s = {}
for c in lin:
  dic_s.setdefault(c, 0)
  dic_s[c] += 1
# 1つしかない要素は計算対象外
for key, value in dic_s.items():
  if value == 1:
    del dic_s[key]
dic_tot = {}
for c in lin:
  # 1度求めたら再計算しない
  # 同じ数字が多いと時間短縮
  if dic_tot.get(c):
    print(int(dic_tot[c]))
  else:
    # 指定数値を除いた2つを選ぶ
    tot = 0
    for key,value in dic_s.items():
      v = value
      if key == c:
        v -= 1
      if v > 1:
        tot += v * (v - 1) / 2
    dic_tot.setdefault(c,tot)
    print(int(tot))

Submission status: Runtime Error

Solution code:
def factrial(n):
    if n < 2:
        return 1
    return n * factrial(n - 1)

def combination(n, r):
    return int(factrial(n) / factrial(r) / factrial(n - r))

def combination2(n):
    return combination(n, 2)

def dictcomb(dic):
    ans = 0
    for key in dic:
        ans += combination2(dic[key])
    return ans

def solve(a, dic):
    for i in a:
        dic[i] -= 1
        print(dictcomb(dic))
        dic[i] += 1

def main():
    n = int(input())
    a = list(map(int,input().split()))
    dic = {}
    for i in a:
        if i in dic:
            dic[i] += 1
        else:
            dic[i] = 1
    solve(a, dic)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

import collections

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

c = collections.Counter(A)
values = c.keys()
counts = c.values()


ans = 0
for i in range(len(values)):
    tmp = counts[i]
    ans += (tmp * (tmp-1))//2

for i in range(N):
    num = A[i]
    index = values.index(num)
    print(ans - counts[index] + 1)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

import collections

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

c = collections.Counter(A)
values, counts = c.keys(), c.values()

ans = 0
for i in range(len(values)):
    tmp = counts[i]
    ans += (tmp * (tmp-1))//2

for i in range(N):
    num = A[i]
    index = values.index(num)
    print(ans - counts[index] + 1)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

import numpy as np

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

unique_array = np.unique(A, return_counts=True)

ans = 0
for i in range(len(unique_array[0])):
    tmp = unique_array[1][i]
    ans += (tmp * (tmp-1))//2


for i in range(N):
    num = A[i]
    index = np.where(unique_array[0] == num)[0]
    print(ans - unique_array[1][index][0] + 1)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
diff_dict = {}
total_sum = 0
for i in a:
    if i not in diff_dict:
        temp = (count_dict[i])*(count_dict[i]-1)//2
        diff_dict[i] = temp-(count_dict[i]-1)*(count_dict[i]-2)//2
        total_sum += temp
for i in a:
    print(total_sum - diff_dict[i])

Submission status: Runtime Error

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

from collections import Counter
from scipy.special import comb
c = Counter(a_li)
for x in a_li:
    ans = 0
    tmp = c.copy()
    tmp[x] -= 1
    for y in tmp.values():
        ans += comb(y,2)
    print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy as np
from sys import stdin
input = stdin.readline
N = int(input())
A = list(map(str, input().split()))
A = np.array(A)
number = np.zeros(N, dtype = int)
for i in range(N):
  number[i] = A.count(str(i + 1))
total = 0
for k in range(N):
  tmp = number[k]
  total += tmp * (tmp-1) // 2
for j in range(N):
  print(total - number[A[j]-1] + 1)

Submission status: Runtime Error

Solution code:
import numpy as np
from sys import stdin
input = stdin.readline
N = int(input())
A = list(map(str, input().split()))
A = np.array(A)
number = np.zeros(N, dtype = int)
for i in range(N):
  number[i] = A.count(str(i + 1)
total = 0
for k in range(N):
  tmp = number[k]
  total += tmp * (tmp-1) // 2
for j in range(N):
  print(total - number[A[j]-1] + 1)

Submission status: Runtime Error

Solution code:
import numpy as np
from sys import stdin
input = stdin.readline
N = int(input())
A = list(map(str, input().split()))
A = np.array(A)
number = np.zeros(N, dtype = int)
for i in range(N):
  number[i] = A.count('i + 1')
total = 0
for k in range(N):
  tmp = number[k]
  total += tmp * (tmp-1) // 2
for j in range(N):
  print(total - number[A[j]-1] + 1)

Submission status: Runtime Error

Solution code:
import numpy as np
from sys import stdin
input = stdin.readline
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
number = np.zeros(N, dtype = int)
for i in range(N):
  number[i] = A.count(i + 1)
total = 0
for k in range(N):
  tmp = number[k]
  total += tmp * (tmp-1) // 2
for j in range(N):
  print(total - number[A[j]-1] + 1)

Submission status: Runtime Error

Solution code:
impot numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
number = np.zeros(N, dtype = int)
for i in range(N):
  number[A[i]-1] += 1
total = 0
for k in range(N):
  total += number[k] * (number[k]-1) // 2
for j in range(N):
  print(total - number[A[j]-1] + 1)

Submission status: Runtime Error

Solution code:
n = int(input())
count = 0
a = 1
b = 1
c = 0
list_number = list(map(int, input().split()))
list_number.sort()
list_copy = list_number
ans = []
for i in list_number:
    del list_number[count]
    for p in list_number:
        for q in list_number:
            if p == list_number[a]:
                b += 1
                del list_number[a]
   		b = b*(b-1)//2
    	c = b
    ans.append(c)
	count += 1
	list_number = list_copy
print(ans)
for z in ans:
  print(z)

Submission status: Runtime Error

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

B=[]

for i in range (0,N+1):
    if len(A)==N-1:
        A.append(B[0])
        del B[0]
        
    
    if len(A)>N-1:
        B.append(A[i])
        del A[i]
        print({i})
        print(A)
        print(B)
        A.sort()
        count=0
        for j in range (0,N-2):
            
            if A[j]==A[j+1]:
                count=count+1

            
        print(count)

Submission status: Runtime Error

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

def B(j):
    #A=[1, 2, 2, 1, 1]
    for i in range (j,N-1):
        if len(A)!=4:
            del A[i]

    
            A.sort()
            count=0
            for i in range (0,N-3):
                
                if A[i]==A[i+1]:
                    
                    count+=1
                else:
                    count=0
        
        #print(count)
            return count

print(A)

#for i in range (i,N)


for k in range (0,N):
    print (B(k))

Submission status: Runtime Error

Solution code:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

def main()
    n=n0()
    a=n1()

    from math import factorial
    def comb(n):
        if n<=1:
            return 0
        if n==2:
            return 1
        return factorial(n)//(factorial(2)*factorial(n-2))

    c=[a.count(i) for i in range(1,n+1)]
    d=[comb(m) for m in c]
    s=sum(d)

    for i in range(n):
        print(s-d[a[i]-1]+comb(c[a[i]-1]-1))
if __name__ == '__main__':
	main()

Submission status: Runtime Error

Solution code:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

def main()
    n=n0()
    a=n1()

    from math import factorial
    def comb(n):
        if n<=1:
            return 0
        if n==2:
            return 1
        return factorial(n)//(factorial(2)*factorial(n-2))

    c=[a.count(i) for i in range(1,n+1)]
    d=[comb(m) for m in c]
    s=sum(d)

    for i in range(n):
        print(s-d[a[i]-1]+comb(c[a[i]-1]-1))
if __name__ == '__main__':
  	main()

Submission status: Runtime Error

Solution code:
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

def main()
    n=n0()
    a=n1()

    from math import factorial
    def comb(n):
        if n<=1:
            return 0
        if n==2:
            return 1
        return factorial(n)//(factorial(2)*factorial(n-2))

    c=[a.count(i) for i in range(1,n+1)]
    d=[comb(m) for m in c]
    s=sum(d)

    for i in range(n):
        print(s-d[a[i]-1]+comb(c[a[i]-1]-1))
if __name__ == '__main__':

Submission status: Runtime Error

Solution code:
L = int(input())
a = [int(i) for i in input().split()]
 
from functools import lru_cache
 
@lru_cache(maxsize=1000)
def h():
  for k in range(L):
    b = a
    b.remove(k)
    s = 0
    for c in list(set(b)):
      d = b.count(c)
      if d != 1:
        s += int(d*(d-1)/2)
    print(s)
h()

Submission status: Runtime Error

Solution code:
def choose2(number):
	if number>=2:
		return (number*(number-1))/2
	else:
		return 0
N = int(input())
k = list(map(int,input().split()))
valArr = list(set(k))
occurence = []
occurenceIndex = []
for i in range(N):
	occurence.append(0)
for j in range(N):
	occurence[k[j]]+=1
	
			
'''6*5/2
5*4/2
N*(N-1)/2
(N-2)*(N-1)/2
N*(N-1)/2*(N-2)/N
occurence = [1,2,3]
ans = 0+2*1/2+3*2/2
k val = 3
correct = 0+2*1/2+2*1/2

'''
ans = 0
for time in range(len(occurence)):
	ans+=choose2(occurence[time])
for ball in range(N):
	kans = ans-choose2(occurence[k[ball]])+choose2(occurence[k[ball]]-1)
	
	print(int(kans))

Submission status: Runtime Error

Solution code:
import math
inp = [input() for i in range(2)]
N = int(inp[0])
A = list(map(int, inp[1].split()))
# B = 0
d = {}
for k in A:
    # a = A.count(k)
    # B += (a - 1) / 2
    if k in d.keys():
        d[i] += 1

# for k in range(N):
#     c = A.count(A[k]) - 1
#     counter = B - c
#     print(int(counter))

p = {}
for k in d.keys():
    cnt = d[k]
    p[k] = cnt * (cnt-1) / 2

total = sum(p.values())

for item in A:
    print(int(total - d[item] + 1))

Submission status: Runtime Error

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

A_ = A.copy()

ANSWER = []
for i in range(N):
    del A_[i]
    unique_i = list(set(A_))

    answer_i = 0
    for j in unique_i:
        answer_i += (A_.count(j) * (A_.count(j)-1)/2)
    
    ANSWER.append(int(answer_i)
    
    A_ = A.copy()

Submission status: Runtime Error

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

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

cs = Counter(a)
s = 0

for v in cs.values():
    s += cmb(v)

for a in ls:
    print(s - cmb(cs[a]) + cmb(cs[a] - 1))

Submission status: Runtime Error

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

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

cs = Counter(a)
s = 0

for v in cs.values():
    s += cmb(v)

for a in ls:
    print(s - cmb(c[a]) + cmb(c[a] - 1))

Submission status: Runtime Error

Solution code:
from collections import Counter

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

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

cs = Counter(a)
s = 0

for v in cs.values():
    s += cmb(v)

for a in ls:
    print(s - cmb(c[a]) + cmb(c[a] - 1))

Submission status: Runtime Error

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

val = [0]*n
sumval = 0
for i in range(n):
    if(count[i] >= 2):
        val[i] = count[i]-1
        sumval = sumval + int(count[i]*(count[i]-1)/2)

for i in range(n):
    print(sumval - val[data[i]])

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N), count(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        count[A[i]]++;
    }
    long long answer = 0;
    for (int i = 0; i < N; i++) {
        answer += count[i] * (count[i] - 1) / 2;
    }
    for (int i = 0; i < N; i++) {
        cout << answer - count[A[i]] + 1 << endl;
    }
    return 0;
}

Submission status: Runtime Error

Solution code:
import sys
 
n = int(sys.stdin.readline())
 
li = list(map(int, sys.stdin.readline().split()))
 
ans = [0]*n
for i in range(n):
    li2 = li.copy()
    del li2[i]
    for j in range(n-1):
        for k in range(j+1, n-1):
            if li2[j] == li2[k]:
                ans[i] += 1
for l in range(len(ans)):

Submission status: Runtime Error

Solution code:
import numpy as np
from scipy.misc import comb
n = int(input())
a = list(map(int, input().split()))
a = np.array(a)

def count(a, k):
    mask = np.ones(n, dtype=bool)
    mask[k] = False
    elements, counts = np.unique(a[mask], return_counts=True)
    ans = 0
    for i in range(len(counts)):
        ans+=comb(counts[i], 2, exact=True)
    print(str(ans))
    
for k in range(n):
    count(a, k)