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: Time Limit Exceeded

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

idx = 1
idx_count = 0
idx_set = []
for i in range(N):
  if idx != B[i]:
    tmp1 = int(idx_count*(idx_count-1)/2)		# 同一の整数を持つボールの組合せ数
    tmp2 = int((idx_count-1)*(idx_count-2)/2)	# 同一の整数を持つボールを1つ除いたときの組合せ数
    idx_set.append([idx, tmp1, tmp2])
    idx_count = 0
    idx = B[i]
  idx_count+=1
if idx_count != 0:
  tmp1 = int(idx_count*(idx_count-1)/2)		# 同一の整数を持つボールの組合せ数
  tmp2 = int((idx_count-1)*(idx_count-2)/2)	# 同一の整数を持つボールを1つ除いたときの組合せ数
  idx_set.append([idx, tmp1, tmp2])

idx_sum_set = []
for i in range(len(idx_set)):
  tmp = 0
  for j in range(len(idx_set)):
    if i == j:
      tmp += idx_set[j][2]
    else:
      tmp += idx_set[j][1]
  idx_sum_set.append([idx_set[i][0],tmp])
  
for i in range(N):
  for j in range(len(idx_sum_set)):
    if A[i] == idx_sum_set[j][0]:
      print(idx_sum_set[j][1])
"""
for i in range(N):
  tmp = 0
  for j in range(len(idx_set)):
    if A[i] == idx_set[j][0]:
      tmp += idx_set[j][2]
    else:
      tmp += idx_set[j][1]
  print(tmp)
"""

Submission status: Time Limit Exceeded

Solution code:
import collections
import math

# 組み合わせ算出
def combinations_count(n, r):
    if n == 1:
        return 0
    if n == 0:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if __name__ == '__main__':

    N= int(input())

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

    for i in range(N):
        total = 0

        b = a[:i] + a[i+1:]

        c = collections.Counter(b)

        for j in set(a):

            total = total + combinations_count(c[j], 2)

        print(total)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
a = input().split()
an = 0
ck = 0
beforeai = 0
beforei = 0

for i in range(n):
    beforeai = a[i]
    beforei = i
    a[i] = ' '#配列nを''に変更 
    tmp2 = Counter(a)
    an = 0
    for key in tmp2.keys():#keyごとの足し算ができた
        ck = tmp2[key]
        if ck == 1:
            an = an + 0
        else:
            an = an + (ck*(ck-1)//2)
    print(an)
    a[beforei] = beforeai

Submission status: Time Limit Exceeded

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

ad = dict((i, a.count(i)) for i in set(a))

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

for i in range(n):
    v = ad[a[i]]
    print(ans-v*(v-1)//2+(v-1)*(v-2)//2)

Submission status: Time Limit Exceeded

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

ad = dict((i, a.count(i)) for i in set(a))
ans = sum(map(lambda x: x*(x-1)//2,ad.values()))

for i in range(n):
    v = ad[a[i]]
    print(ans-v*(v-1)//2+(v-1)*(v-2)//2)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
d = {}
for i in range(N):
    if A[i] in d.keys():
        d[A[i]] += 1
    else:
        d[A[i]] = 1

sum = 0

for i in A:
    d[i] -= 1
    sum = 0
    for key in d.keys():
        sum += d[key]*(d[key] - 1) // 2
    print(sum)
    d[i] += 1

Submission status: Time Limit Exceeded

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

for e in A:
    d = dict((i, A.count(i)) for i in set(A))
    d[e]-=1
    
    ans = 0
    for i in list(d):
        if d[i] < 2:
            continue
        ans += d[i]*(d[i]-1)/2
    print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split(' ')))
c = [0] * (n + 1)
d = [0] * (n + 1)
for i in a:
    c[i] += 1
    d[i] = c[i] * (c[i] - 1) // 2
for i in a:
    if c[i] > 2:
        r = (((c[i] - 1) * (c[i] - 2)) // 2)
    else:
        r = 0
    print(sum(d) - d[i] + r)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
b =[0 for i in range(n-1)]
def count(lis):
    num = 0
    for i in range(len(lis)-1):
        for j in range(i+1, len(lis)):
            if lis[i] == lis[j]:
                num += 1
    return num

for k in range(n):
    i = -1
    j = -1
    while j <= n-1:
        i += 1
        j += 1
        if j == k:
            j += 1
        try:
            b[i] = a[j]
        except:
            continue
    print(count(b))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
ind2clus = {}
clus2ind = {}
for i in range(N):
    if A[i] not in clus2ind:
        clus2ind[A[i]]=[]
    clus2ind[A[i]].append(i)
    ind2clus[i] = A[i]
for i in range(N):
    ans = 0
    for one in clus2ind:
        if one!=ind2clus[i]:
            num = len(clus2ind[one])
        else:
            num = len(clus2ind[one])-1
        ans+=num*(num-1)//2
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import copy

def count(dic, key):
    ans = 0
    for i in key:
        d = dic[i]
        ans += d * (d - 1) // 2
    return(ans)

N = int(input())
A = list(map(int, input().split()))
a = dict(Counter(A))
k = list(a.keys())
for i in range(N):
    a2 = copy.copy(a)
    a2[A[i]] -= 1
    print(count(a2, k))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = list(map(int, input().split(' ')))
count_dict = {}
for A in A_list:
  strA = str(A)
  if strA in count_dict.keys():
    pass
  else:
    count_dict[strA] = A_list.count(A)
#print(count_dict)

sum_ = 0
for count in count_dict.values():
  sum_ += (count**2 - count) // 2

for A in A_list:
  print(sum_ - count_dict[str(A)] + 1)

Submission status: Time Limit Exceeded

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

for i in range(N):
    C=0
    for j in range(N):
        for k in range(N):
            if j==i or k==i or j==k:
                continue
            elif A[j]==A[k]:
                C+=1
    print(int(C/2))

Submission status: Time Limit Exceeded

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

def count(lis):
    num = 0
    for i in range(len(lis)-1):
        for j in range(i+1, len(lis)):
            if lis[i] == lis[j]:
                num += 1
    return num

for k in range(n):
    p = a.pop(k)
    print(count(a))
    a.insert(k, p)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = list(map(int, input().split(' ')))
count_dict = {}
for A in A_list:
  strA = str(A)
  if strA in count_dict.keys():
    count_dict[strA] += 1
  else:
    count_dict[strA] = 1
#print(count_dict)

sum_ = 0
for count in count_dict.values():
  sum_ += (count**2 - count) // 2

for A in A_list:
  num = count_dict[str(A)]
  ans = sum_ - (num**2-num)//2 + (num**2-3*num+2)//2
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = list(map(int, input().split(' ')))
count_list = [A_list.count(i) for i in range(N+1)]

sum_ = 0
for count in count_list:
  sum_ += (count**2 - count) // 2

for i in range(N):
  num = count_list[A_list[i]]
  ans = sum_ - (num**2-num)//2 + (num**2-3*num+2)//2
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = list(map(int, input().split(' ')))
count_list = [A_list.count(i) for i in range(N+1)]

sum_ = 0
for count in count_list:
  sum_ += (count**2 - count) // 2

for i in range(N):
  num = A_list.count(A_list[i])
  ans = sum_ - (num**2-num)//2 + (num**2-3*num+2)//2
  print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A_list = list(map(int, input().split(' ')))
count_list = [A_list.count(i) for i in range(N+1)]
table = [(count**2-count)//2 for count in count_list]
sum_table = sum(table)

for i in range(N):
  print(sum_table - table[A_list[i]] + (count_list[A_list[i]]-1)*(count_list[A_list[i]]-2)//2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
distinct = list(set(a))
l = [0] * len(distinct)
dic = dict(zip(distinct, l))
for i in distinct:
    c = a.count(i)
    dic[i] = c*(c-1)//2

for i in a:
    temp = dic[i]
    c = a.count(i) - 1
    dic[i] = c*(c-1)//2
    print(sum(dic.values()))
    dic[i] = temp

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
C = []
for i in range(N):
  a = A[i]
  A[i] = 0
  B = Counter(A)
  for v in B.values():
    if v != 1:
      C.append(v*(v-1)//2)
  print(sum(C))
  C.clear()
  A[i] = a

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ball = list(map(int,input().split()))
for i in range(N):
  x = 0
  for j in range(N):
    for k in range(N):
      if j!=i and i!= k and k!= j and ball[j] == ball[k]:
        x += 1
  print(x//2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(input().split(" "))
b = [0 for i in range(n+1)]
for i in range(n):
    b[int(a[i])] += 1
for i in range(n):
    b[int(a[i])] -= 1
    sum = 0
    for j in range(n+1):
        sum += b[j]*(b[j]-1)/2
    print(int(sum))
    b[int(a[i])] += 1

Submission status: Time Limit Exceeded

Solution code:
import copy

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

c=0

a_uniq=[0]*(n+1)

for i in a:
  a_uniq[i]+=1

for i in a_uniq:
  c+=sum(range(1,i))
#a_uniq=list(set(a))
#for i in a_uniq:
#  c+=sum(range(1, a.count(i)))

for i in range(0,n):
  print('{:.0f}'.format(c-a.count(a[i])+1))

Submission status: Time Limit Exceeded

Solution code:
import collections
import copy

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

for i in range(n):
    tmp_l = copy.copy(a)
    tmp_l.pop(i)
    c = collections.Counter(tmp_l)
    tmp_ans = 0
    for v in c.values():
        tmp_ans += ((v*(v-1))//2)
#     ans.append(tmp_ans)
    print(tmp_ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
 
num_cnt = {}
sum_cnt = 0
 
for x in a:
    if x not in num_cnt:
        cnt = a.count(x)
        num_cnt[x] = cnt
        sum_cnt += cnt*(cnt-1)//2

res = []
for x in a:
    cnt = num_cnt[x]
    res.append(str( sum_cnt - (cnt-1) ))

print('\n'.join(res))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
 
num_cnt = [0]*n
sum_cnt = 0
 
for num in range(n):
    cnt = a.count(num+1)
    if cnt > 0:
        num_cnt[num] = cnt
        sum_cnt += cnt*(cnt-1)//2

res = []
for x in a:
    cnt = num_cnt[x-1]
    res.append(str( sum_cnt - (cnt-1) ))

print('\n'.join(res))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
 
num_cnt = [0]*n
sum_cnt = 0
 
for num in range(n):
    cnt = a.count(num+1)
    if cnt > 0:
        num_cnt[num] = cnt
        sum_cnt += cnt*(cnt-1)//2
res = [0]*n
 
for num in range(n):
    cnt = num_cnt[num]
    res[num] = (sum_cnt - (cnt-1)) if cnt != 0 else 0
 
for a_k in a:
    print(res[a_k-1])

Submission status: Time Limit Exceeded

Solution code:
N_ = int(input())

A_ = input().split()
#print(A_)

U_ = set(A_)
#print(U_)


def xC(num):
    return (num * (num - 1)) //2

num = 0
dict = {}
judge = {}

for u in U_:
    num += xC(A_.count(u))

for u in U_:
    dict[u] = num - xC(A_.count(u)) + xC(A_.count(u) - 1)


for a in A_:
    print(dict[a])

Submission status: Time Limit Exceeded

Solution code:
import collections

N = int(input())

A = [x for x in input().split()]

c = collections.Counter(A)

for i in range(N):
  z = c[A[i]] - 1
  ans = 0
  for k,v in c.items():
    if v > 1:
      ans += (v*(v-1))//2
      
  print(ans-z, sep="\n")

Submission status: Time Limit Exceeded

Solution code:
import collections

N = int(input())

A = [x for x in input().split()]

c = collections.Counter(A)

ans = 0
for i in range(N):
  for k,v in c.items():      
    if v > 1 and k != A[i]:
      ans += (v*(v-1))//2
    elif v > 1 and k == A[i]:
      ans += ((v-1)*(v-2))//2
    else:
      continue
  print(ans, sep="\n");ans=0

Submission status: Time Limit Exceeded

Solution code:
import math
num = int(input())
n_list = list(map(int, input().split()))
tmp_list = []
reply = 0

for i in n_list:
    if not i in tmp_list:
        tmp_list.append(i)
        n = n_list.count(i)
        reply += math.floor(n * (n - 1) / 2)

text = ""
for i in n_list:
    n = n_list.count(i) - 1
    text += str(reply - n) + "\n"

print(text)

Submission status: Time Limit Exceeded

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

idx = 1
idx_count = 0
idx_set = []
for i in range(N):
  if idx != B[i]:
    tmp1 = int(idx_count*(idx_count-1)/2)		# あるボールの等価な組み合わせ数
    tmp2 = int((idx_count-1)*(idx_count-2)/2)	# あるボールを1つ除いたときの等価な組み合わせ数
    idx_set.append([idx, tmp1, tmp2])
    idx_count = 0
    idx = B[i]
  idx_count+=1
if idx_count != 0:
  tmp1 = int(idx_count*(idx_count-1)/2)		# あるボールの等価な組み合わせ数
  tmp2 = int((idx_count-1)*(idx_count-2)/2)	# あるボールを1つ除いたときの等価な組み合わせ数
  idx_set.append([idx, tmp1, tmp2])
#print(idx_set)

for i in range(N):
  tmp = 0
  for j in range(len(idx_set)):
    if A[i] == idx_set[j][0]:
      tmp += idx_set[j][2]
    else:
      tmp += idx_set[j][1]
  print(tmp)

Submission status: Time Limit Exceeded

Solution code:
import math
num = int(input())
n_list = list(map(int, input().split()))
tmp_list = []
reply = 0

for i in n_list:
    if not i in tmp_list:
        tmp_list.append(i)
        n = n_list.count(i)
        reply += math.floor(n * (n - 1) / 2)

text_list = []
for i in n_list:
    n = n_list.count(i) - 1
    text_list.append(str(reply - n) + "\n")

print("".join(map(str, text_list)))

Submission status: Time Limit Exceeded

Solution code:
import math
num = int(input())
n_list = list(map(int, input().split()))
tmp_list = []
reply = 0

# for i in range(num):
#     n = n_list.count(1 + i)
#     reply += math.floor(n * (n - 1) / 2)
for i in n_list:
    if not i in tmp_list:
        tmp_list.append(i)
        n = n_list.count(i)
        reply += math.floor(n * (n - 1) / 2)

for i in n_list:
    n = n_list.count(i) - 1
    print(reply - n)

Submission status: Time Limit Exceeded

Solution code:
import math
num = int(input())
n_list = list(map(int, input().split()))
reply = 0

for i in range(num):
    n = n_list.count(1 + i)
    reply += math.floor(n * (n - 1) / 2)

for i in n_list:
    n = n_list.count(i) - 1
    print(reply - n)

Submission status: Time Limit Exceeded

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

L=0
C=[]
for i in range(N):
    C.append(A.count(i+1))
    L+=int(C[i]*(C[i]-1)/2)
    
for i in A:
    print(L-C[i-1]+1)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
 
N = int(input())
As = [int(n) for n in input().split()]
 
C = Counter(As)
 
L = [(v * (v - 1) // 2, (v - 1) * (v - 2) // 2, k) for k, v in C.items()]
 
for i in range(N):
    print(sum([y if z == As[i] else x for x, y, z in L]))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=list(map(int,input().split()))
from collections import Counter
C=Counter(A)
Q=C.values()
def qq(F):
    n=len(F)
    ans=0
    for i in range(n):
        ans+= F[i]*(F[i]-1)//2
    return ans
    
for i in range(n):
    j=A[i]
    C[j]-=1
    print(qq(list(C.values())))
    C[j]+=1

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
num = [0 for i in range(N)]
zu = []
ans = []
for i in A:
    num[i-1]+=1
for i in range(N):
    temp = 1/2*num[i]*(num[i]-1)
    zu.append(int(temp))
for i in A:
    num[i-1]-=1
    temp = zu[i-1]
    zu[i-1] = 1/2*num[i-1]*(num[i-1]-1)
    print(int(sum(zu)))
    zu[i-1] = temp
    num[i-1]+=1

Submission status: Time Limit Exceeded

Solution code:
# 入力
N = int(input())
An = [int(x) for x in input().split()]
 
# 各数字の個数を求める
Cn = [An.count(i) for i in range(1,N+1)]
 
# 全部の組み合わせ
s = 0
for i in range(1,N+1):
    s += Cn[i-1]*(Cn[i-1]-1) // 2

for i in range(1,N+1):
    print(s - (Cn[An[i-1]-1] - 1))

Submission status: Time Limit Exceeded

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

L=0
C=[]
for i in range(N):
    C.append(A.count(i+1))
    L+=int(C[i]*(C[i]-1)/2)
    
for i in range(N):
    print(L-C[A[i]-1]+1)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
num = [0 for i in range(N)]
zu = []
ans = []
for i in A:
    num[i-1]+=1
sums = 0
for i in range(N):
    temp = 1/2*num[i]*(num[i]-1)
    zu.append(int(temp))
for i in A:
    num[i-1]-=1
    temp = zu[i-1]
    zu[i-1] = 1/2*num[i-1]*(num[i-1]-1)
    ans.append(int(sum(zu)))
    zu[i-1] = temp
    num[i-1]+=1

for i in range(N):
    print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
# 入力
N = int(input())
An = [int(x) for x in input().split()]
 
# 組み合わせ
L = [0]
for i in range(0,N+1):
    L.append(i*(i+1)//2)

# 各数字の個数を求める
Cn = [An.count(i) for i in range(1,N+1)]
 
# 全部の組み合わせ
Dn = [L[Cn[i-1]] for i in range(1,N+1)]
s = sum(Dn)
 
for i in range(1,N+1):
    print(s - (Cn[An[i-1]-1] - 1))

Submission status: Time Limit Exceeded

Solution code:
# 入力
N = int(input())
An = [int(x) for x in input().split()]
 
# 組み合わせ
L = [0]
for i in range(0,N+1):
    L.append(int(i*(i+1)/2))

# 各数字の個数を求める
Cn = [An.count(i) for i in range(1,N+1)]
 
# 全部の組み合わせ
Dn = [L[Cn[i-1]] for i in range(1,N+1)]
s = sum(Dn)

for i in range(1,N+1):
    print(s - (Cn[An[i-1]-1] - 1))

Submission status: Time Limit Exceeded

Solution code:
import math
import collections


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


def C(n, r):
    if n < 2:
        return 0
    else:
        return P(n, r)//math.factorial(r)


N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
dic = {}
total = 0
for key, value in c.items():
    C_val = C(value, 2)
    dic[key] = C_val
    total += C_val
for i in range(N):
    print(total - dic.get(A[i]) + C(c[A[i]]-1, 2))

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

n = int(input())

an = list(map(int, input().split()))
an_np = np.array(an)
an_uni = np.unique(an)

an_cnt = np.empty(len(an_uni))
for i, uni in enumerate(an_uni):
    an_cnt[i] = len(np.where(an_np == uni)[0])

an_cnt[an_cnt == 1] = 0
l_cnt = sum((an_cnt * (an_cnt - 1)) /2)
line_np = np.zeros(n)

for i, num in enumerate(an_np):
    idx = np.where(an_uni == num)
    cnt = an_cnt[idx]
#     l_cnt = sum(an_cnt * (an_cnt - 1) / 2)
    if l_cnt > 0:
        line_np[i] = l_cnt - (cnt - 1)
    else:
        line_np[i] = l_cnt
line_str = str(line_np)
print(line_str.strip("[]").replace(". ", "\n").strip("."))

Submission status: Time Limit Exceeded

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

import collections

dct=collections.Counter(lst)


for i in range(N):
    Sum=0
    for v in dct.values():
        Sum+=v*(v-1)//2


for i in range(N):
    print(Sum-dct[lst[i]]+1)

Submission status: Time Limit Exceeded

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

A0=sorted(A)
i=0
L=0
while i<N:
    C=A0.count(A0[i])
    L+=int(C*(C-1)/2)
    i+=C

for i in range(N):
    L0=A.count(A[i])
    print(L-L0+1)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
listA = list(map(int,input().split()))
listA_hozon = listA

S = Counter(listA)
#print(S)

##key##
key = S.keys()
#for i in key:
#  print(i)

for i in listA:
  out = 0
  listA = listA_hozon
  for a in key:
    if a == i:
      num = S[a]-1
      add = (S[a]-1) * (S[a]-2) /2
      out = out + add
    else:
      num = S[a]
      add = S[a] * (S[a]-1) /2
      out = out +add
  print(int(out))

Submission status: Time Limit Exceeded

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

import collections

dct=collections.Counter(lst)


for i in range(N):
    total={}
    for k, v in dct.items():
        total[k]=v*(v-1)//2
Sum=sum(total.values())


for i in range(N):
    print(Sum-dct[lst[i]]+1)

Submission status: Time Limit Exceeded

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

for i in range(N):
    answer=0
    removed=[lst[j] for j in range(N) if j!=i]
    for el in set(removed):
        el_num=removed.count(el)
        answer+=el_num*(el_num-1)//2
    print(answer)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

num = input()
num = int(num)

str = input()
list_in = list(map(int, str.split()))

count_arr = np.zeros((num+1), dtype=np.int32)

for item in list_in:
    count_arr[item] += 1

sum = 0
for i in range(num+1):
    tmp = count_arr[i]
    tmp = (tmp * (tmp -1))//2
    sum += tmp

for item in list_in:
    tmp = count_arr[item]
    result = sum - (tmp - 1)
    print(result)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

num = input()
num = int(num)

str = input()
list_in = str.split()
list_in = [int(x) for x in list_in]

count_arr = np.zeros((num+1), dtype=np.int32)

for item in list_in:
    count_arr[int(item)] += 1

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

for item in list_in:
    tmp = count_arr[item] - 1
    result = (sum - tmp)
    print(result)

Submission status: Time Limit Exceeded

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

A_keys = collections.Counter(A)
keys_list= A_keys.keys()
for k in range(N):
    Ak = A[k]
    result = 0
    for i in keys_list:
        cnt = A_keys[i]
        if i == A[k] and cnt >= 2:
            result += (cnt-1)*(cnt-2)/2
        elif i != A[k] and cnt >= 2:
            result += cnt*(cnt-1)/2
    print(int(result))

Submission status: Time Limit Exceeded

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

for k in range(N):
    Ak = A[k]
    A_keys = collections.Counter(A)
    keys_list= A_keys.keys()
    result = 0
    for i in keys_list:
        cnt = A_keys[i]
        if i == A[k] and cnt >= 2:
            result += (cnt-1)*(cnt-2)/2
        elif i != A[k] and cnt >= 2:
            result += cnt*(cnt-1)/2
    print(int(result))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
a=list(map(int,input().split()))
for i in range(N):
  b=a.copy()
  b.pop(i)
  res=0
  for j in range(N-1):
    for k in range(j+1,N-1):
      if b[j]==b[k]:
        res+=1
  print(res)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
C = []
for i in A:
    count = A.count(i) - 1
    C.append(count)

#print(C)
pre_ans = sum(C)//2
for i in range(N):
    print(pre_ans - C[i])

Submission status: Time Limit Exceeded

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

set_A = set(A)
count = 0
pre_ans = 0

for i in set_A:
    count = A.count(i)
    pre_ans += count*(count - 1) // 2

for i in A:
    count = A.count(i)
    ans = pre_ans - (count-1)
    print(ans)

Submission status: Time Limit Exceeded

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

for i in range(N):
    NA = A[:i] + A[i+1:]
    set_NA = set(NA)
    #print('NA=', NA)
    #print('set_NA=', set_NA)
    ans = 0
    for j in set_NA:
        count = NA.count(j)
        ans += count*(count - 1) // 2
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=input().split()
for k in range(N):
    a=[i for i in A]
    a[k]="x"
    n=0
    for i in range(N):
        for j in range(i+1,N):
            if a[i]==a[j]:
                n+=1
    print(n)

Submission status: Time Limit Exceeded

Solution code:
import sys
def combinations_count_bin(n):
    if n < 2:
        return 0
    return n*(n-1) // 2

input()
s = list(map(int, input().split(' ')))
set_s = set(s)
full_s = sum([combinations_count_bin(s.count(i)) for i in set_s])

sys.stdout.write("\n".join(map(lambda x: str(full_s - (s.count(x) - 1)), s)))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=input().split()
for k in range(N):
    a=[i for i in A]
    a[k]="x"
    n=0
    for i in range(N):
        for j in range(N):
            if i!=j and a[i]==a[j]:
                n+=1
    print(int(n/2))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
list_num = list(map(int, input().split()))
nums = list(set(list_num))
count = 0

for i in range(len(nums)):
    a = list_num.count(nums[i])
    count += a * (a - 1) / 2

for i in range(len(list_num)):
    list_c = list_num.copy()
    c = list_c.pop(i)
    b = list_c.count(c)
    print(int(count - b))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().rstrip().split()]
S = 0
C = {}
for s in list(set(A)):
    c = A.count(s)
    la = c*(c-1)//2
    S += la
    C[s] = c - 1

for a in A:
    print(S - C[a])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().rstrip().split()]
S = 0
C = {}
for s in list(set(A)):
    c = A.count(s)
    sm = (c-1)*(c-2)//2
    la = c*(c-1)//2
    S += la
    C[s] = la - sm

for a in A:
    print(S - C[a])

Submission status: Time Limit Exceeded

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

for i in range(n):
    k = list_num.copy()
    k.pop(i)
    x = []
    count = 0
    for j in range(len(k)):
        if not k[j] in x:
            num = k.count(k[j])
            count += num * (num-1) / 2
            x.append(k[j])
    
    print(int(count))

Submission status: Time Limit Exceeded

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

L = {}
C = {}
for s in list(set(A)):
    L[s] = A.count(s)
    C[s] = (L[s]**2-L[s])//2
S = sum(C.values())
for a in A:
    r = S - C[a] + (L[a] - 1)*(L[a] - 2)//2
    print(r)

Submission status: Time Limit Exceeded

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

input()
s = list(map(int, input().split(' ')))
set_s = set(s)
full_s = sum([combinations_count_bin(s.count(i)) for i in set_s])

for i in s:
	print(full_s - (s.count(i) - 1))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
a=list(np.fromstring(input(),int,sep=' '))
a_=list(set(a))
dic={}
ans=0
for i in a_:
    dic[i]=a.count(i)
for i in dic.values():
    ans+=i*(i-1)//2
    
for i in range(n):
    print(ans-(dic[a[i]]-1))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
d = {}
for i in A:
    if i in d.keys():
        d[i] += 1
    else:
        d[i] = 1
whole_ans = sum(map(lambda x: x*(x-1)//2, d.values()))
for i in A:
    d_ = d.copy()
    d_[i] -= 1
    dif = (d_[i]*(d_[i]-1) - d[i]*(d[i]-1)) // 2
    part_ans = whole_ans + dif
    print(part_ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
d = {}
# まず全体における答えを求める
for i in A:
    if i in d.keys():
        d[i] += 1
    else:
        d[i] = 1
whole_ans = sum(map(lambda x: x*(x-1)//2, d.values()))
# 差分更新
for i in A:
    d_ = d.copy()
    d_[i] -= 1
    dif = (d_[i]*(d_[i]-1) - d[i]*(d[i]-1)) // 2
    part_ans = whole_ans + dif
    print(part_ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
A = np.array(list(map(int,input().split())))
maxim = max(A)
select_num = 0
count_num = np.array([0]*(maxim+1))
for i in A:
  count_num[i] += 1
for i in range(1,maxim+1):
  select_num += (count_num[i])*(count_num[i] - 1)//2
for i in A:
  print(select_num -count_num[i] + 1)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
A = np.array(list(map(int,input().split())))
maxim = max(A)
select_num = 0
count_num = np.array([0]*(maxim+1))
for i in range(1,maxim+1):
  temp = np.count_nonzero(A == i)
  count_num[i] = temp
  select_num += (temp)*(temp - 1)//2
for i in A:
  print(select_num -count_num[i] + 1)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys

input = sys.stdin.readline

N = int(input())
A = np.array(list(map(int,input().split())))
maxim = max(A)
select_num = np.array([0]*(maxim+1))
select_num2 = np.array([0]*(maxim+1))
count_num = np.array([0]*(maxim+1))


for i in range(1,maxim+1):
  temp = np.count_nonzero(A == i)
  count_num[i] = temp
  if(temp > 1):
    select_num[i] = (temp)*(temp - 1)//2
    select_num2[i] = temp - 1
sumS = np.sum(select_num)
ans1,ans2 = sumS,select_num2
for i in A:
  print(ans1 -ans2[i])

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=list(map(int,input().split()))
all=0
for i in set(A):
    n=A.count(i)
    all+=int(n*(n-1)/2)
for j in range(N):
    tmp=A[j]
    num=A.count(tmp)
    print(all+1-num)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
li = list(map(int, input().split()))
for i in range(len(li)):
    goukei = 0
    x = li[i]
    del li[i]
#    print(li)
    for j in range(N):
        goukei += li.count(j) * (li.count(j)-1) / 2
    print(int(goukei))
    li.insert(i, x)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
for i in range(N):
    counter = 0
    p = A.pop(i)
    for j in list(set(A)):
        n = A.count(j)
        counter += int(n*(n-1)/2)
    A.insert(i,p)
    print(counter)

Submission status: Time Limit Exceeded

Solution code:
import copy
import collections

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

for i in range(n):
  c = 0
  b = list(a)
  b.pop(i)
  d = collections.Counter(b)
  for j in d.values(): 
    c += int(j*(j-1)/2)
  print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

input_1 = input()
input_2 = input_1.split()

for k in range(N):
    A = map(int, input_2)

    def equal(num):
        return num / 1
    A = [equal(x) for x in A]

    ans = 0

    A.remove(A[k])

    for l in range(N - 1):
        for m in range(N - 1):
            if A[l] == A[m]:
                ans += 1
        
        ans -= 1

    ans = ans / 2

    print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
input = sys.stdin.readline

N = int(input())
A = np.array(list(map(int,input().split())))
maxim = max(A)
#select_num = np.array([0 for _ in range(0,maxim+1)])
select_num = np.array([0]*(maxim+1))
select_num2 = np.array([0]*(maxim+1))
count_num = np.array([0]*(maxim+1))
for i in range(1,maxim+1):
  temp = np.count_nonzero(A == i)
  count_num[i] = temp
  if(temp > 1):
    select_num[i] = (temp)*(temp - 1)//2
    select_num2[i] = temp - 1
sumS = np.sum(select_num)
for i in range(N):
  print(sumS -select_num2[A[i]])