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:
from scipy.misc 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に関して全探索
D = {}
C = {}
for row in A:
    ans = 0
    if row not in D:
        for i in K:
            tmp = 0
            if i == row:
                tmp = K[i]-1
            else:
                tmp = K[i]
            if tmp not in C:
                ans += comb(tmp, 2, exact=True)
            else:
                ans += C[tmp]
        D[row] = int(ans)
        print(D[row])
    else:
        print(D[row])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = input().split()
i = int(0)
j = int(0)
B = [-1] * N
C = [-1] * N
sum = int(0)

for i in range(N):
    if B[i] == -1:
        count = int(0)
        for j in range(N):
            if A[i] == A[j]:
                count = count + 1
                B[j] = i
        j = j + 1
        num = count -1
        sum = sum + int(count*(count-1)/2)
        C[i] = num
    else:
        C[i] = C[B[i]]

i = 0
for i in range(N):
    print(sum - C[i])
    i = i + 1

Submission status: Time Limit Exceeded

Solution code:
from scipy.misc 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に関して全探索
D = {}
for row in A:
    ans = 0
    if row not in D:
        for i in K:
            if i == row:
                ans += comb(K[i]-1, 2, exact=True)
            else:
                ans += comb(K[i], 2, exact=True)
        D[row] = int(ans)
        print(D[row])
    else:
        print(D[row])

Submission status: Time Limit Exceeded

Solution code:
from scipy.misc 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,exact=True)
        else:
            ans += comb(K[i],2,exact=True)
    print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import collections as cl
import math


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


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

cnt = cl.Counter(A)
ans = 0
mem = {}

for a in A:
    if a in mem:
        print(mem[a])
        continue
    ans = 0
    cnt[a] -= 1
    for v in cnt.values():
        if v < 2:
            continue
        ans += combinations_count(v, 2)
    cnt[a] += 1
    print(ans)
    mem[a] = ans

Submission status: Time Limit Exceeded

Solution code:
import collections as cl
import math


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


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

cnt = cl.Counter(A)
ans = 0
mem = {}

for a in A:
    if a in mem:
        print(mem[a])
        continue
    ans = 0
    cnt[a] -= 1
    for v in cnt.values():
        if v < 2:
            continue
        ans += combinations_count(v, 2)
    cnt[a] += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections as cl
import math


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


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

cnt = cl.Counter(A)
ans = 0

for a in A:
    ans = 0
    cnt[a] -= 1
    for v in cnt.values():
        if v < 2:
            continue
        ans += combinations_count(v, 2)
    cnt[a] += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
A_dic = defaultdict(int)
B_dic = defaultdict(int)
C_dic = defaultdict(int)

for i in A:
  A_dic[i] += 1
  B_dic[i] = 1

for i in range(N):
  if B_dic[A[i]] == 1:
    B_dic[A[i]] -= 1
    A_dic[A[i]] -= 1
    C_dic[A[i]] += sum([(i*(i-1))//2 for i in list(A_dic.values()) if i >= 2])
    print(C_dic[A[i]])
    A_dic[A[i]] += 1
  else:
    print(C_dic[A[i]])

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

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

for i in A:
  A_dic[i] += 1

for i in range(N):
  A_dic[A[i]] -= 1
  print(sum([(i*(i-1))//2 for i in list(A_dic.values()) if i >= 2]))
  A_dic[A[i]] += 1

Submission status: Time Limit Exceeded

Solution code:
def q4():
    import collections
    N = int(input())
    A = [int(i) for i in input().split()]

    def combinations_count(n, r):
        """ 組み合わせ総数を計算 """
        import math
        ret = 0 if n < r else math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
        return ret

    all_sum = 0  # 総数
    counter = collections.Counter(A)
    # all_sumを作成
    for v in counter.values():
        all_sum += combinations_count(v, 2)

    for i in range(N):
        cnt = counter[A[i]]  # i番目の値の出現回数を取得
        ans = all_sum - combinations_count(cnt, 2) + combinations_count(cnt - 1, 2)
        print(ans)

        
if __name__ == '__main__':
    q4()

Submission status: Time Limit Exceeded

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

    def combinations_count(n, r):
        """ 組み合わせ総数を計算 """
        import math
        ret = 0 if n < r else math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
        return ret

    unique_values = set(A)

    all_sum = 0  # 総数
    # all_sumを作成
    for u in unique_values:
        cnt = A.count(u)
        all_sum += combinations_count(cnt, 2)

    for i in range(N):
        cnt = A.count(A[i])
        ans = all_sum - combinations_count(cnt, 2) + combinations_count(cnt - 1, 2)
        print(ans)


if __name__ == '__main__':
    q4()

Submission status: Time Limit Exceeded

Solution code:
import math
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: Time Limit Exceeded

Solution code:
from math import factorial

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

An = list(set(A))

if A == An:
    for i in range(N):
        print(0)
else:
    anses = [0] * len(An)
    
    for idx, i in enumerate(An):
        for j in An:
            count = A.count(j)
            if i == j:
                count -= 1
    
            if count == 2:
                ans = 1
            elif count <= 1:
                ans = 0
            else:
                ans = factorial(count) // (factorial(count - 2) * factorial(2))
            anses[idx] += ans
    
    for a in A:
        print(anses[An.index(a)])

Submission status: Time Limit Exceeded

Solution code:
from math import factorial

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

An = list(set(A))
anses = [0] * len(An)

for idx, i in enumerate(An):
    for j in An:
        count = A.count(j)
        if i == j:
            count -= 1

        if count == 2:
            ans = 1
        elif count <= 1:
            ans = 0
        else:
            ans = factorial(count) // (factorial(count - 2) * factorial(2))
        anses[idx] += ans

for a in A:
    print(anses[An.index(a)])

Submission status: Time Limit Exceeded

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

num_list = [0]* (len(a)+1)

for i in range(len(a)+1):
    num_list[i] = a.count(i)

total = 0

for j in range(len(num_list)):
    total += (num_list[j]* (num_list[j]-1))/2

#print(total)

for k in range(len(a)):
#    print(num_list[a[k]]) 
    print(int(total-(num_list[a[k]])+1))
"""
import math

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

cnt = flaot(0.0)

for i in range(1, len(a)+1):
    b = a[0:i-1]+a[i:len(a)]
    
    cnt = 0.0
    for j in range (1, len(a)):
        cnt += b.count(j)*(b.count(j)-1)/2
    print(int(cnt))
"""

Submission status: Time Limit Exceeded

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

result = [n*(n-1)/2 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: Time Limit Exceeded

Solution code:
import math
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):
    array_k = [Balls[i] for i in range(N) if i!=k]
    sum_k=0
    c= Counter(array_k)
    for j in list(c.values()):
        sum_k += combinations_count(j,2)
    
    print(sum_k)

Submission status: Time Limit Exceeded

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

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

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

f2 = factorial(2)

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

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

Submission status: Time Limit Exceeded

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

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

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

f2 = factorial(2)

for k in range(N):
    tmp = ret.copy()
    tmp[A[k]-1] -= 1
    print(int(sum([factorial(n) / (f2 * factorial(n - 2)) for n in tmp if n > 1])))

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
import collections
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

Solution code:
from collections import Counter
import math

def ncr(n, r):
  if r > n:
    return 0
  return math.factorial(n) // math.factorial(n-r) // math.factorial(r)

input()
As = list(map(int, input().split()))
counter = Counter(As)
res = {}
for k, v in counter.items():
  res[k] = (ncr(v, 2), ncr(v-1, 2))
total = sum(v[0] for k,v in res.items())
for a in As:
  v1, v2 = res[a]
  print(total - v1 + v2)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import math

def ncr(n, r):
  if r > n:
    return 0
  return math.factorial(n) // math.factorial(n-r) // math.factorial(r)

input()
As = list(map(int, input().split()))
counter = Counter(As)
res = {}
for k, v in counter.items():
  res[k] = (ncr(v, 2), ncr(v-1, 2))

for a in As:
  print(sum(v[0] if k != a else v[1] for k,v in res.items()))

Submission status: Time Limit Exceeded

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

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

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):
    ans = 0
    AA = copy.copy(A)
    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: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
counter = Counter(A)
S = [x * (x - 1) // 2 for x in counter.values()]

# (n-1)(n-2)/2 - n(n-1)/2 = 1 - n
print('\n'.join(str(sum(S) + 1 - counter[x]) for x in A))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split( )))
calist = []
for i in range(n):
  ca = a[0:i] + a[i + 1:n]
  calist.append(ca)
salist = []
for j in calist:
  sca = sorted(j)
  setsca = set(sca)
  cacount = 0
  for k in setsca:
    p = j.count(k)
    pnum = p * (p - 1) / 2
    cacount += pnum
  salist.append(cacount)
for k in salist:
  print(int(k))

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
nans = 0
for i in range(n):
    cnt = a.count(i)
    if cnt >= 2:
        nans += math.factorial(cnt)//(math.factorial(cnt-2)*math.factorial(2))
for i in range(n):
    num = a[i]
    numcnt = a.count(num)
    print(nans-(numcnt-1))

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    acopy = a.copy()
    del acopy[i]
    l = len(acopy)
    acopy.sort()
    cnt = 1
    ans = 0
    for j in range(l-1):
        if acopy[j] == acopy[j+1]:
            cnt += 1
            continue
        else:
            if cnt != 1:
                if cnt == 2:
                    ans += 1
                    cnt = 1
                    continue
                else:
                    ans += math.factorial(cnt)//(math.factorial(cnt-2)*math.factorial(2))
                    cnt = 1
                    continue
    if cnt != 1:
        ans += math.factorial(cnt)//(math.factorial(cnt-2)*math.factorial(2))
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
import copy


def cAnswer(a):
    return (a * (a-1)) / (2)


N = int(input())

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

ans = []

for i in range(N):
    A = deque(A)
    k = A.popleft()
    numbers = list(A).copy
    numbers = list(set(A))
    x = 0
    for j in numbers:
        way = cAnswer(A.count(j))
        x = x + way
    
    ans.append(int(x))
    A.append(k)

for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
lst = [int(x) for x in input().split()]
counters = Counter(lst)
dic = {}
for k, v in dict(counters).items():
    if v > 1:
        dic[k] = v

m = {}
for x in lst:
    n = m.get(x)
    if n is None:
        n = 0
        for k, v in dic.items():
            if k == x:
                v -= 1
            n += v * (v - 1) // 2

    m[x] = n
    print(n)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
A = list(map(int , input().split()))
bb = dict(Counter(A))
for j in A:
    bb[j] -= 1
    pattern_ = []
    for i in bb.values():
        pattern_.append((i*(i-1))//2)
    print(sum(pattern_))
    bb[j] += 1

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
import collections
import math
def comb(n,r):
    if n >= r:
        return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
    else:
        return 0

for i in range(N):
    a = A[i]
    A[i] = 0
    c = collections.Counter(A)
    values,counts = zip(*c.most_common())
    counts1 = list(counts)
    d = 0
    for j in range(len(counts1)):
        b = comb(counts1[j],2)
        d += b
    print(d)
    A[i] = a

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from collections import Counter

n = int(input())
a = [int(x) for x in input().split()]
d = deque(a)
e = deque([])
# print(d)
for i in range(n):
    ans = 0
    a = d.popleft()
    c = Counter(d)
    # print(c)
    for j in c.values():
        # print(j)
        ans += (j-1)*j//2
    # print(ans, d)
    e.append(ans)
    d.append(a)
    
for k in e:
    print(k)

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:
N = int(input())
A = list(map(int, input().split()))
for k in range(N):
    L = [0 for i in range(N)]
    for i in range(N):
        if i!=k:
            L[A[i] - 1] += 1
    sum = 0
    for i in range(N):
        if L[i] > 1:
            sum += L[i] * (L[i] - 1) / 2
    print(int(sum))

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8

n = int(input())
a = input().split()

list_n = [0 for i in range(n)]
basic = 0

for i in a:
    aa = int(i)
    count = list_n[aa - 1]
    basic += count
    list_n[aa - 1] += 1

ans = 0
for i in range(n):
    ans = 0
    lislis = list_n.copy()
    a1 = int(a[i])
    ans = basic - lislis[a1 - 1] + 1
    print("{}".format(int(ans)))

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8

n = int(input())
a = input().split()

list_n = []

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

for i in a:
    aa = int(i)
    list_n[aa - 1] += 1

basic = 0
for i in list_n:
    basic += i * (i - 1) / 2

ans = 0
for i in range(n):
    ans = 0
    lislis = list_n.copy()
    a1 = int(a[i])
    ans = basic - lislis[a1 - 1] + 1
    print("{}".format(int(ans)))

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8

n = int(input())
a = input().split()

list_n = []
list_a = []

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

for i in a:
    aa = int(i)
    list_a.append(aa)
    list_n[aa - 1] += 1

ans = 0
for i in range(n):
    ans = 0
    lislis = list_n.copy()
    a1 = list_a[i]
    lislis[a1 - 1] -= 1
    for t in lislis:
        ans += t * (t - 1) / 2
    print("{}".format(int(ans)))

Submission status: Time Limit Exceeded

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

# n(n-1)/2 - (n-1)(n-2)/2 = n-1
dic = {}
su = 0
m = 0
for a in An:
  dic[a] = 0
for a in An:
  dic[a] += 1 
for a,n in enumerate(An):
  su = 0
  for d,i in enumerate(dic):
    m = dic[i]
    su += m * (m-1) / 2
    if i == n:
      su += -m+1
  print(int(su))

Submission status: Time Limit Exceeded

Solution code:
class Combination:
    def __init__(self,N):
        self.fact = [0 for _ in range(N+1)]
        self.N = N
        self.init_fact()
    
    def init_fact(self):
        self.fact[0] = 1
        self.fact[1] = 1
        for i in range(2,N + 1):
            self.fact[i] = self.fact[i-1] * i

    def calc(self,n,k):
        return self.fact[n] / (self.fact[k] * self.fact[n-k])

N = int(input())

A_num = [0 for _ in range(N + 1)]
A = []
comb = Combination(N)
ans = 0

for i in input().split(" "):
    A_num[int(i)] += 1
    A.append(int(i))

for i in A_num:
    if i < 2:
         continue
    else:
        ans += comb.calc(i,2)

for i in A:
    ans_tmp = ans - comb.calc(A_num[i],2)
    if (A_num[i] - 1) < 2:
        print(int(ans_tmp))
        continue
    else:
        ans_tmp += comb.calc(A_num[i] -1, 2)
        print(int(ans_tmp))
        continue

    print(int(ans))
    A_num[i] += 1

Submission status: Time Limit Exceeded

Solution code:
class Combination:
    def __init__(self,N):
        self.fact = [0 for _ in range(N+1)]
        self.N = N
        self.init_fact()
    
    def init_fact(self):
        self.fact[0] = 1
        self.fact[1] = 1
        for i in range(2,N + 1):
            self.fact[i] = self.fact[i-1] * i

    def calc(self,n,k):
        return self.fact[n] / (self.fact[k] * self.fact[n-k])

N = int(input())

A_num = [0 for _ in range(N + 1)]
A = []
conb = Combination(N)

for i in input().split(" "):
    A_num[int(i)] += 1
    A.append(int(i))

for i in A:
    A_num[i] -= 1
    ans = 0
    for a in A_num:
        if a < 2:
            continue
        else:
            ans += conb.calc(a,2)
    print(int(ans))
    A_num[i] += 1

Submission status: Time Limit Exceeded

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

for i in a:
    point = 0
    for j,k in dic.items():
        if j == i:
            point += (k-1)*(k-2)//2
        else:
            point += k*(k-1)//2
    print(point)

Submission status: Time Limit Exceeded

Solution code:
# %%time
# N = 20000
# A_list = list(range(N))
N = int(input())
A_list = list(map(int, input().split()))
total = 0
A_counts = []
for i in range(1, N+1):
    i_count = A_list.count(i)
    A_counts.append(i_count)
    total += i_count*(i_count-1)//2
for k in range(N):
    A_k_count = A_counts[A_list[k]-1]
    print(total-(A_k_count-1))

Submission status: Time Limit Exceeded

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 += int(i*(i-1)/2)
for k in range(N):
    print(S - A.count(A[k]) + 1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
CA = collections.Counter(A)
V,C = zip(*CA.most_common())
S = 0
for i in range(len(C)):
    L = C[i]
    if L == 1:
        break
    S += int(L*(L-1)/2)
for k in range(N):
    SS = S - A.count(A[k]) + 1
    print(SS)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
A = list(map(int,input().split()))
for i in range(N):
    x = A[i]
    A[i] = 0
    CA = collections.Counter(A)
    B = CA.most_common()
    S = 0
    for j in range(len(B)):
        L = B[j][1]
        if L == 1:
            break
        S += int(L*(L-1)/2)
    print(S)
    A[i] = x

Submission status: Time Limit Exceeded

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

for i in range(n):
    N = a[i]
    ans = 0
    for x,y in A.items():
        if x == N:
            y -= 1
        ans += y*(y-1)//2
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict, deque, Counter


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



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
c=Counter(a)
for i in range(n):
  t=0
  for k,v in c.items():
    if k==a[i]:
      v-=1
    t+=v*(v-1)//2
  print(t)

Submission status: Time Limit Exceeded

Solution code:
import copy
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
count=dict(Counter(a))
ans=0

for i in range(n):
    count1=copy.copy(count)
    num=a[i]
    count1[num]-=1
    for j,k in count1.items():
        ans+=k*(k-1)/2
    print(int(ans))
    ans=0

Submission status: Time Limit Exceeded

Solution code:
import math

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


for i in range(1, len(a)+1):
    b = a[0:i-1]+a[i:len(a)]
    
    cnt = 0.0
    for j in range (1, len(a)):
        cnt += b.count(j)*(b.count(j)-1)/2
    print(int(cnt))

Submission status: Time Limit Exceeded

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

for i in range(1, len(a)+1):
    b = a[0:i-1]+a[i:len(a)]
    
    cnt = 0
    for j in range (1, len(a)):
        cnt += b.count(j)*(b.count(j)-1)/2
    print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:
n,*a=map(int,open(0).read().split())
C=0
dp=[0]*n
for i in range(n-1):
  for j in range(i+1,n):
    if a[i]==a[j]:
      C+=1
      dp[i]+=1
      dp[j]+=1
      
for i in range(n):
  print(C-dp[i])

Submission status: Time Limit Exceeded

Solution code:
n,*a=map(int,open(0).read().split())
dp=[0]*n
for i in range(n):
  for j in range(n):
    if i==j:continue
    for k in range(j+1,n):
      if i==k:continue
      if a[j]==a[k]:
        dp[i]+=1
               
print(*dp)

Submission status: Time Limit Exceeded

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

for i in range(1, len(a)+1):
    b = a[0:i-1]+a[i:len(a)]
    cnt = 0
    for j in range (1, len(a)):
        cnt += b.count(j)*(b.count(j)-1)/2

    print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
nums = list(map(int,input().split()))
x = [0] * N
ans = 0
for i in range(N):
    x[nums[i] - 1] += 1
for u in  range(N):
    x[nums[u] - 1] -= 1
    for i in range(N):
        ans += (x[i]*(x[i]-1))/2
    print(int(ans))
    x[nums[u] - 1] += 1
    ans = 0

Submission status: Time Limit Exceeded

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))
list=[]
list1={}

for i in range(N):
    if A[i] not in list:
        list.append(A[i])
        x=A[i]
        A[i]=0
        c=collections.Counter(A)
        a=[j*(j-1)/2 for j in c.values() if j>1]
        print(int(sum(a)))
        A[i]=x
        list1[A[i]]=sum(a)
        
    else:
        print(int(list1[A[i]]))

Submission status: Time Limit Exceeded

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))
sum=0
list=[]
list1={}

for i in range(N):
    if A[i] not in list:
        list.append(A[i])
        x=A[i]
        A[i]=0
        c=collections.Counter(A)
        for j in c.values():
            sum+=j*(j-1)/2
        print(int(sum))
        A[i]=x
        list1[A[i]]=sum
        sum=0
    else:
        print(int(list1[A[i]]))

Submission status: Time Limit Exceeded

Solution code:
import collections

def main():
    N=int(input())
    A=list(map(int,input().split()))
    sum=0
    for i in range(N):
        x=A[i]
        A[i]=0
        c=collections.Counter(A)
        for j in c.values():
            sum+=j*(j-1)/2
        print(int(sum))
        sum=0
        A[i]=x


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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=0
  for j in e:
    h=int(j*(j-1)/2)
    g=g+h
  print(g)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import collections
N=int(input())
A=list(map(int,input().split()))
sum=0
for i in range(N):
    x=A.pop(i)
    c=collections.Counter(A)
    for j in c.values():
        sum+=j*(j-1)/2
    print(int(sum))
    sum=0
    A.insert(i,x)

Submission status: Time Limit Exceeded

Solution code:
import collections
import math
def cmb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
la = list(map(int,input().split()))
all = 0
for i in range(N+1):
    all += cmb(la.count(i),2)
for k in range(N):
    print(all-la.count(la[k])+1)

Submission status: Time Limit Exceeded

Solution code:
import collections
import math
def cmb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
la = list(map(int,input().split()))
c = collections.Counter(la)
#print(c)
ans = 0
for i in range(N):
    c[la[i]] -= 1
    #print(c)
    for a in c:
        #print(a)
        ans += cmb(c[a],2)
    print(ans)
    ans = 0
    c[la[i]]+=1

Submission status: Time Limit Exceeded

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