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

for i in range(N):
    k=i+1
    B = A[:]
    B.pop(i)
    C = [0]*(N+1)
    for l in range(N-1):
        C[B[l]] += 1
    temp = 0
    for m in range(N-1):
        temp += int(C[m]*(C[m]-1)/2)
    print(temp)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
str1 = str(input())
s1 = str1.split(" ")
l = [int(x) for x in s1]
d={}
for i in l:
    if i not in d:
        d[i]=1 
    else:
        d[i]+=1 
        
d2={}
for i in d.keys():
    if i not in d2:
        d[i]-=1 
        d2[i] = sum((x*(x-1)//2) for x in d.values())
        d[i]+=1 

for i in l:
    print(d2[i])

Submission status: Time Limit Exceeded

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

# 各数字の個数を格納
dict = {}
for a in A:
    if a in dict:
        dict[a] += 1
    else:
        dict[a] = 1

# k番目の値を除いたlistで同じ数字を引く回数を出力
memo = {}
for k in range(N):
    ans = 0
    m = A[k]
    if m in memo.keys():
        ans = memo[m]
    else:
        dict_work = dict.copy()
        dict_work[m] -= 1
        for d in dict_work.values():
            if d > 1:
                ans += (d * (d - 1)) // 2
        memo[m] = ans
    print(ans)

Submission status: Time Limit Exceeded

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

# 各数字の個数を格納
dict = {}
for a in A:
    if a in dict:
        dict[a] += 1
    else:
        dict[a] = 1

# k番目の値を除いたlistで同じ数字を引く回数を出力
memo = {}
for k in range(N):
    ans = 0
    m = A[k]
    if m in memo.keys():
        ans = memo[m]
    else:
        dict_work = dict.copy()
        dict_work[A[k]] -= 1
        for d in dict_work.values():
            if d > 1:
                ans += (d * (d - 1)) // 2
        memo[m] = ans
    print(ans)

Submission status: Time Limit Exceeded

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

# 各数字の個数を格納
dict = {}
for a in A:
    if a in dict:
        dict[a] += 1
    else:
        dict[a] = 1

# k番目の値を除いたlistで同じ数字を引く回数を出力
for k in range(N):
    dict_work = dict.copy()
    ans = 0
    dict_work[A[k]] -= 1
    for d in dict_work.values():
        if d > 1:
            ans += (d * (d - 1)) // 2
    print(ans)

Submission status: Time Limit Exceeded

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

# 各数字の個数を格納
dict = {}
for a in A_set:
    dict[a] = A.count(a) 

# k番目の値を除いたlistで同じ数字を引く回数を出力
for k in range(N):
    dict_work = dict.copy()
    ans = 0
    dict_work[A[k]] -= 1
    for d in dict_work.values():
        if d > 1:
            ans += (d * (d - 1)) // 2
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
kosuu = [0]*(N+1)
num = []
for i in range(N):
    kosuu[A[i]] += 1
for i in range(N):
    if kosuu[A[i]] >= 2:
        num.append(i)

base = 0
for i in kosuu:
    base += i*(i-1)//2
for i in range(N):
    if i not in num:
        print(base)
    else:
        print(base - (kosuu[A[i]]-1))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A_cnt = []
A_cal = []
A_cal_dec = []
A_max = max(A)
for i in range(A_max+1):
  tmp = A.count(i)
  #print(tmp)
  A_cnt.append(tmp)
  tmp2 = tmp*(tmp-1)/2
  tmp3 = (tmp-1)*(tmp-2)/2
  A_cal.append(tmp2)
  A_cal_dec.append(tmp3)

A_sum = sum(A_cal)
res = [int(A_sum-A_cal[num]+A_cal_dec[num]) for num in range(A_max+1)]
for i in A:
  print(res[i])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A_cnt = []
A_cal = []
A_cal_dec = []
A_max = max(A)
for i in range(A_max+1):
  tmp = A.count(i)
  #print(tmp)
  A_cnt.append(tmp)
  tmp2 = tmp*(tmp-1)/2
  tmp3 = (tmp-1)*(tmp-2)/2
  A_cal.append(tmp2)
  A_cal_dec.append(tmp3)
res = [int(sum(A_cal)-A_cal[num]+A_cal_dec[num]) for num in A]
for i in range(len(res)):
  print(res[i])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A_cnt = []
A_max = max(A)
for i in range(A_max+1):
  tmp = A.count(i)
  #print(tmp)
  A_cnt.append(tmp)
A_cal = [i*(i-1)/2 for i in A_cnt]
A_cal_dec = [(i-1)*(i-2)/2 for i in A_cnt]
res = []
for i in range(len(A)):
  num = A[i]
  tmp = sum(A_cal)-A_cal[num]+A_cal_dec[num]
  res.append(int(tmp))
for i in range(len(res)):
  print(res[i])

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
a =[int(i) for i in input().split()]
for i in range(n):
    ans = 0
    list_a = a.copy()
    list_a.pop(i)
    list_count = collections.Counter(list_a)
    for j in list_count.values():
        ans += int((j*(j-1)/2))
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

def choose(c):
  return c * (c - 1) // 2

n = int(input())
a = [int(e) for e in input().split()]
cnt = collections.Counter(a)

for i in a:
  temp = cnt.copy()
  temp[i] -= 1
  print(sum([choose(c) for c in temp.values()]))

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
a = [int(e) for e in input().split()]
cnt = collections.Counter(a)

for i in a:
  temp = [v if k != i else v - 1 for k, v in cnt.items()]
  print(sum([ c * (c-1) for c in temp])//2)

Submission status: Time Limit Exceeded

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

for i in range(n):
  temp = [a[k] for k in range(n) if k != i]
  cnt = [temp.count(k) for k in list(set(temp))]
  print(sum([ c * (c-1) for c in cnt]) // 2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
d = [0]*(n+1)
count = 0
for el in set(a):
    temp = d[el] = a.count(el)
    count += temp*(temp-1)
count //= 2
for el in a:
    print(count - d[el] + 1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
work = set(a)
d = [0]*(n+1)
count = 0
for el in work:
    temp = d[el] = a.count(el)
    count += temp*(temp-1)
count //= 2
for el in a:
    print(count - d[el] + 1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
d = [0]*(n+1)
count = 0
for el in a:
    temp = d[el]
    if temp == 0:
        temp = a.count(el)
        d[el] = temp
        count += temp*(temp-1)
count //= 2
for el in a:
    print(count - d[el] + 1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
d = []
count = 0
for el in a:
    temp = a.count(el)
    count += temp-1
    d.append(temp)
count //= 2
for el in d:
    print(count - el + 1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
d = dict()
count = 0
for el in a:
    temp = a.count(el)
    count += temp-1
    d[str(el)] = temp
count //= 2
for el in a:
    print(count - d[str(el)]+1)

Submission status: Time Limit Exceeded

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

def count_suru( list_desu ):
  points = [0] * ( n + 1 )
  for a in list_desu:
    points[a] += 1
  ret = 0
  for p in points:
    ret += ( p * ( p - 1 ) ) // 2
  return ret

for i in range( n ):
  print( count_suru( a_s[:i] + a_s[i+1:]  ) )

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
array = list(map(int, input().split()))
sameNum = [0]*(N)

for i in range(N):
    sameNum[array[i]-1] += 1

for k in range(1, N+1):
    answer = 0
    sameNumT = sameNum[:]
    sameNumT[array[k-1]-1] -= 1
    for l in range(N):
        answer += sameNumT[l]*(sameNumT[l]-1)//2
    print(answer)

Submission status: Time Limit Exceeded

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

for k in range(n):
    ans = 0
    modls= ls.copy()    
    modls.pop(k)
    
    indexset= set(modls)
    index= list(indexset)
    for j in index:
        con= modls.count(j) * (modls.count(j)-1) /2
        ans = ans + con
    print(int(ans))

Submission status: Time Limit Exceeded

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

def matrix(X,y):
    j = int(0)
    k = int(0)
    xnum = len(X)
    Z = [0] * xnum
    for j in range(xnum):
        if j == y:
            k = 1
        else:
            Z[j-k] = X[j]
        j = j + 1
    return Z

def count(X):
    j = int(0)
    xnum = len(X)
    count = int(0)
    for j in range(xnum):
        k = int(0)
        for k in range(j):
            if X[j] == X[k]:
                count = count + 1
            k = k + 1
        j = j + 1
    print(count)

for i in range(N):
    count(matrix(A,i))
    i = i + 1

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
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()))
li = Counter(A)
S = 0
for i,j in enumerate(li):
    if li[j]>=2:
        S += comb(li[j],2)

for i in A:
    ans = S
    tmp = li[i]
    if tmp>2:
        ans -= comb(tmp,2)-comb(tmp-1,2)
    elif tmp==2:
        ans -= 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import math
    import collections
    N = int(input())
    A = list(map(int, input().split()))
    tt = 0
    #ans = list()
    ann = 0

    def comb(m, n):
        return math.factorial(m) // (math.factorial(n) * math.factorial(m - n))
    '''
    def A_count(n):
        if n in memo:
            return memo[n]
        h = A.count(i)
        memo[n] = A.count(i)
        return h
    '''

    C = collections.Counter(A)
    for i in C.values():
        if i>=2:
            tt = tt + comb(i, 2)

    for i in A:
        f = C[i] #A_count(A[i])
        if f>=3:
            ann = (tt - comb(f, 2) + comb(f-1, 2))
        elif f==2:
            ann = tt - comb(f, 2)
        else:
            ann = tt
        print(ann)

    #for i in ans:
    #    print(i)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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

for k in range(N):
    list = []
    list = check[:]
    list[A[k]-1] -= 1
    ans = 0
    for l in list:
        if l>=2:
            ans += l*(l-1)//2
    print(ans)

Submission status: Time Limit Exceeded

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

def matrix(X,y):
    j = int(0)
    k = int(0)
    xnum = len(X)
    Z = [0] * xnum
    for j in range(xnum):
        if j == y:
            k = 1
        else:
            Z[j-k] = X[j]
        j = j + 1
    return Z

def count(X):
    j = int(0)
    xnum = len(X)
    count = int(0)
    for j in range(xnum):
        k = int(0)
        for k in range(j):
            if X[j] == X[k]:
                count = count + 1
            k = k + 1
        j = j + 1
    print(count)

for i in range(N):
    B = matrix(A,i)
    count(B)
    i = i + 1

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ar = list(map(int,input().split(" ")))
for i,r in enumerate(ar):
    count = 0
    ar.remove(r)
    for j in range(1,n+1):
        if ar.count(j) >= 2:
            for k in range(1,ar.count(j)):
                count += k
    print(count)
    ar.insert(i,r)

Submission status: Time Limit Exceeded

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

def matrix(X,y):
    j = int(0)
    k = int(0)
    Z = [0] * (N -1)
    xnum = len(X)
    while j < xnum:
        if j == y-1:
            k = 1
        else:
            Z[j-k] = X[j]
        j = j + 1
    return Z

def count(X):
    j = int(0)
    xnum = len(X)
    count = int(0)
    while j < xnum:
        k = int(0)
        while k < j:
            if X[j] == X[k]:
                count = count + 1
            k = k + 1
        j = j + 1
    print(count)

while i < N+1:
    B = matrix(A,i)
    count(B)
    i = i + 1

Submission status: Time Limit Exceeded

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

def matrix(X,y):
    j = int(0)
    k = int(0)
    Z = [0] * (N -1)
    xnum = len(X)
    while j < xnum:
        if j == y-1:
            k = 1
#            print(j,y,k)
        else:
            Z[j-k] = X[j]
#            print(j,y,k)
        j = j + 1
#    print(Z)
    return Z

def count(X):
    j = int(0)
    xnum = len(X)
    count = int(0)
    while j < xnum:
        k = int(0)
        while k < j:
            if X[j] == X[k]:
                count = count + 1
            k = k + 1
        j = j + 1
    print(count)



while i < N+1:
    B = matrix(A,i)
    count(B)
    i = i + 1

Submission status: Time Limit Exceeded

Solution code:
def main():
    import math
    from functools import lru_cache
    N = int(input())
    A = list(map(int, input().split()))
    tt = 0
    #ans = list()
    ann = 0
    memo = dict()

    def comb(m, n):
        return math.factorial(m) // (math.factorial(n) * math.factorial(m - n))
    '''
    def A_count(n):
        if n in memo:
            return memo[n]
        h = A.count(i)
        memo[n] = A.count(i)
        return h
    '''
    @lru_cache(maxsize = 1024)
    def annss(f):
        if f>=3:
            return (tt - comb(f, 2) + comb(f-1, 2))
        elif f==2:
            return tt - comb(f, 2)
        else:
            return tt
    

    B = set(A)
    for i in B:
        f = A.count(i)
        memo[i] = f
        if f>=2:
            tt = tt + comb(f, 2)

    for i in A:
        f = memo[i] #A_count(A[i])
        ann = annss(f)
        print(ann)

    #for i in ans:
    #    print(i)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
d = dict()
count = 0
for el in a:
    temp = a.count(el)
    count += temp-1
    d[str(el)] = temp
count //= 2
for el in a:
    print(count - d[str(el)]+1)

Submission status: Time Limit Exceeded

Solution code:
def main():
    import math
    N = int(input())
    A = list(map(int, input().split()))
    tt = 0
    #ans = list()
    ann = 0
    memo = dict()

    def comb(m, n):
        return math.factorial(m) // (math.factorial(n) * math.factorial(m - n))
    '''
    def A_count(n):
        if n in memo:
            return memo[n]
        h = A.count(i)
        memo[n] = A.count(i)
        return h
    '''
    B = set(A)
    for i in B:
        f = A.count(i)
        memo[i] = f
        if f>=2:
            tt = tt + comb(f, 2)

    for i in A:
        f = memo[i] #A_count(A[i])
        if f>=3:
            ann = (tt - comb(f, 2) + comb(f-1, 2))
        elif f==2:
            ann = tt - comb(f, 2)
        else:
            ann = tt
        print(ann)

    #for i in ans:
    #    print(i)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
count = 0
for el in a:
    count += a.count(el)-1
count //= 2
for el in a:
    print(count - a.count(el)+1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
count = 0
L = len(a)
for el in a:
    count += a.count(el)-1
count //= 2
for el in a:
    print(count - a.count(el)+1)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
array = list(map(int, input().split()))
sameNum = [0]*(N)

for i in range(N):
    sameNum[array[i]-1] += 1

for k in range(1, N+1):
    answer = 0
    sameNumT = sameNum.copy()
    sameNumT[array[k-1]-1] -= 1
    for l in range(N):
        answer += sameNumT[l]*(sameNumT[l]-1)//2
    print(answer)

Submission status: Time Limit Exceeded

Solution code:
mod = 7+10**9
def ncr(n,c,mod):
  x = 1
  y = 1
  for i in range(n-c+1,n+1):
    x = x*i%mod
  for j in range(1,c+1):
    y = y*j%mod
  return (x * pow(y, mod-2, mod)) % mod

a = int(input())
A = list(map(int, input().split()))  
d = {}
for k in A:
  if k in d:
    d[k] += 1
  else:
    d[k] = 1
 
res = 0
for k in d.values():
    if k >= 2:
      res += ncr(k, 2, mod)

for k in A:
  temp = res
  m = d[k]
  if m >= 2:
    temp -= ncr(m, 2, mod)

  d[k] -= 1
  if d[k] >= 2:
    temp += ncr(d[k], 2, mod)
  print(temp)
  d[k] += 1

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
A = list(map(int, input().split()))
tt = 0
#ans = list()
ann = 0
memo = dict()

def comb(m, n):
    return math.factorial(m) // (math.factorial(n) * math.factorial(m - n))
def A_count(n):
    if n in memo:
        return memo[n]
    h = A.count(i)
    memo[n] = A.count(i)
    return h

B = set(A)
for i in B:
    f = A_count(i)
    if f>=2:
        tt = tt + comb(f, 2)

for i in range(N):
    f = A_count(A[i])
    if f>=3:
        ann = (tt - comb(f, 2) + comb(f-1, 2))
    elif f==2:
        ann = tt - comb(f, 2)
    else:
        ann = tt
    print(ann)

#for i in ans:
#    print(i)

Submission status: Time Limit Exceeded

Solution code:
import math

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

def comb(m, n):
    return math.factorial(m) // (math.factorial(n) * math.factorial(m - n))


B = set(A)
for i in B:
    f = A.count(i)
    if f>=2:
        tt = tt + comb(f, 2)

for i in range(N):
    f = A.count(A[i])
    if f>=3:
        ans.append(tt - comb(f, 2) + comb(f-1, 2))
    elif f==2:
        ans.append(tt - comb(f, 2))
    else:
        ans.append(tt)

for i in ans:
    print(i)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
a = [int(i) for i in input().split()]
for i in range(N):
  ans = 0
  tmp = []
  tmp = a.copy()

  count = {}
  tmp.pop(i)
  for j in tmp:
    if ((j in [k for k in count.keys()]) == False):
      count[j] = 1
    else:
      count[j] += 1

  for k in count.keys():
    # aCb
    l = count[k]
    r = 2
    ans += (l * (l - 1)) / 2
  print(math.floor(ans))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

# import collections

n = int(input())
balls = list(map(int, input().split(' ')))

for k in range(n):
    # print(balls[ : k])
    # print(balls[ k + 1: ])
    arr = balls[ : k] + balls[ k + 1 : ]

    total = 0
    # dic = collections.Counter(arr)
    # for v in dic.values():
    #     total += int(v * (v - 1) / 2)

    # print(arr, list(set(arr)))
    for num in list(set(arr)):
        v = arr.count(num)
        total += int(v * (v - 1) / 2)
    print(total)

Submission status: Time Limit Exceeded

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

for i in A:
    temp = c.copy()
    temp[i] = temp[i]-1
    counter = 0
    for j in c.keys():
        n = temp[j]
        if n >= 2:
            counter += n*(n-1)/2
    print(int(counter))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import collections

n = int(input())
balls = list(map(int, input().split(' ')))

for k in range(n):
    # print(balls[ : k])
    # print(balls[ k + 1: ])
    arr = balls[ : k] + balls[ k + 1 : ]

    dic = collections.Counter(arr)
    total = 0
    for v in dic.values():
        total += int(v * (v - 1) / 2)
    print(total)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
nums = list(map(int, input().split()))
nums_count_dict = {number: nums.count(number) for number in set(nums)}
nums_count_combi = {number: nums_count_dict[number]*(nums_count_dict[number]-1)/2 for number in set(nums)}
total = sum(nums_count_combi.values())
for number in nums:
    print(int(total-nums.count(number)+1))

Submission status: Time Limit Exceeded

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

a=list(set(A))

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

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

Submission status: Time Limit Exceeded

Solution code:
#D
N = int(input())
Aslist = input().split(' ')

for k in range (N):
    ans = 0
    tuika = Aslist[k]
    Aslist.pop(k)
    Aslistsub = Aslist.copy()
    Aslistsubyouso = set(Aslistsub)
    for s in Aslistsubyouso:

        impo = Aslistsub.count(s)
        ans = ans + (impo * (impo-1) / 2)
    print(int(ans))
    
    Aslist.insert(k,tuika)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
array=list(map(int,input().split()))
tot=0
x=0
for c in range(n):
  if x<array[c]:
    x=array[c]
    t=array.count(array[c])
    tot+=int(t*(t-1)/2)
for i in range(n):
  ans=tot
  l=array.count(array[i])
  ans-=int(l*(l-1)/2)
  ans+=int((l-1)*(l-2)/2)
  print(ans)

Submission status: Time Limit Exceeded

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

for c in range(n):
  a=array.copy()
  count=0
  del a[c]
  for i in range(n-2):
    for j in range(n-2-i):
      if a[i]==a[i+1+j]:
        count+=1
  print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
from collections import Counter
a = Counter(A)

for i in A:
    t = 0
    for k in a.keys():
        c = a[k]
        if k == i:
            c -= 1
        t += (c * (c-1)) // 2
    print(t)

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
a = [int(s) for s in input().split()]
countMap = collections.Counter(a)

for k in range(n):
    answer = 0
    for key in countMap:
        kCount = 1 if key == a[k] else 0
        count = countMap[key] - kCount
        answer += int(count * (count - 1 ) / 2)
    print(answer)

Submission status: Time Limit Exceeded

Solution code:
import collections

def countPattern(a):
    countMap = collections.Counter(a)
    answer = 0
    for count in countMap.values():
        answer += int(count * (count - 1 ) / 2)
    return answer

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

for k in range(n):
    print(countPattern(a[i] for i in range(n) if i != k))

Submission status: Time Limit Exceeded

Solution code:
def pairs(lst):
  sets = list(set(lst))
  set_list = [lst.count(a) for a in sets]
  return sum([int(n * (n-1) / 2) for n in set_list])


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

for i in range(N):
  lst = num_list[:]
  del lst[i]
  print(pairs(lst))

Submission status: Time Limit Exceeded

Solution code:
"""
"""
from math import factorial
from collections import defaultdict


def int_as_array(num): return list(map(int, [y for y in str(num)]))


def array_as_int(arr): return int(''.join(map(str, arr)))


def read_int(): return int(input())


def read_array(): return list(map(int, input().split(' ')))


def array_to_string(arr, sep=' '): return sep.join(map(str, arr))


def matrix_to_string(arr, sep=' '): return '[\n' + '\n'.join(
    [sep.join(map(str, row)) for row in arr]) + '\n]'


cache = {}


def fac(x):
    return factorial(x)


def choose_combination(n, r):
    if r > n:
        return 0
    return int((fac(n) / fac((n - r))) * (1 / fac(r)))


def solve(n, array):
    counts = defaultdict(int)
    for x in array:
        counts[x] += 1
    total_ways = 0
    for x, count in counts.items():
        total_ways += choose_combination(counts[x], 2)
    for k in array:
        ways = choose_combination(counts[k] - 1, 2)
        print(total_ways + ways - choose_combination(counts[k], 2))


N = read_int()
array = read_array()
solve(N, array)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
N = int(input())
line = input()
l = []
counts = {}
for n in line.split(' '):
  n = int(n)
  if n not in counts:
    counts[n] = 0
  counts[n] += 1
  l.append(n)

results = {}

for n in counts:
  results[n] = 0
  for m in counts:
    count = counts[m]
    if m == n:
      count -= 1
    if count > 1:
      results[n] += int(factorial(count)) // 2 // int(factorial(count - 2))

for n in l:
  print(results[n])

Submission status: Time Limit Exceeded

Solution code:
"""
"""
from math import factorial
from collections import defaultdict


def int_as_array(num): return list(map(int, [y for y in str(num)]))


def array_as_int(arr): return int(''.join(map(str, arr)))


def read_int(): return int(input())


def read_array(): return list(map(int, input().split(' ')))


def array_to_string(arr, sep=' '): return sep.join(map(str, arr))


def matrix_to_string(arr, sep=' '): return '[\n' + '\n'.join(
    [sep.join(map(str, row)) for row in arr]) + '\n]'


cache = {}


def fac(x):
    if cache.get(x) is not None:
        return cache[x]
    ans = factorial(x)
    cache[x] = ans
    return ans


def choose_combination(n, r):
    if cache.get((n, r)) is None:
        if r > n:
            return 0
        cache[(n, r)] = int((fac(n) / fac((n - r))) * (1 / fac(r)))
    return cache.get((n, r))


def solve(n, array):
    counts = defaultdict(int)
    for x in array:
        counts[x] += 1
    ways_cache = {}
    for k in array:
        if ways_cache.get(k) is not None:
            print(ways_cache[k])
            continue
        ways = 0
        for x, count in counts.items():
            adjusted_count = counts[x]
            if x == k:
                adjusted_count -= 1
            ways += choose_combination(adjusted_count, 2)
        ways_cache[k] = ways
        print(ways)


N = read_int()
array = read_array()
solve(N, array)

Submission status: Time Limit Exceeded

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

cnt = [0] * n

for i in range(0, n-1):
    for j in range(i+1, n):
        if a[i] == a[j]:
            cnt[i] += 1
            cnt[j] += 1


for i in range(n):
    print((sum(cnt)//2-cnt[i]))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

N = int(input())

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

memo = [0]*N
ans=[None]*N

for a in A:
    memo[a-1] += 1

for a in A:
    if ans[a-1]:
        print(ans[a-1])
    else:
        memo[a-1] -= 1
        cnt = 0
        for m in memo:
            cnt += m*(m-1)//2
        ans[a-1] = cnt
        memo[a-1] += 1
        print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import functools
from collections import Counter
from math import factorial


@functools.lru_cache(maxsize=None)
def c(n):
    if n < 2:
        return 0
    return factorial(n) // (factorial(2) * factorial(n-2))


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

C = dict(Counter(A))
for a in A:
    n = 0
    for k, N_k in C.items():
        n += c(N_k - (k == a))
    print(n)

Submission status: Time Limit Exceeded

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

num_list = [0 for i in range(N)]


for n in A :
  num_list[n-1] += 1

for k in range(N) :
  ans = 0
  num_list[A[k]-1] -= 1
  for nums in num_list :
    if(nums != 0) :
      ans += int(nums*(nums-1)/2)
  print(ans)
  num_list[A[k]-1] += 1

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(input())
if N < 3 or 2 * (10**5) < N:
	print("error\nボールは3個以上200000以下")
	sys.exit()

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

set_lst = [x for x in set(A)]
nums_mutch = [0] * len(set_lst)
i = 0
while not i == len(set_lst):
	if set_lst[i] == 0:
		i += 1
		continue
	else:
		nums_mutch[i] =  A.count(set_lst[i])
		i += 1

all_flag = [int((x * (x - 1)) / 2) for x  in nums_mutch]
k = 0
while not k == N:
	klist = all_flag.copy()
	index_k = set_lst.index(A[k])
	kflag = nums_mutch[index_k] - 1
	klist[index_k] = int((kflag * (kflag - 1)) / 2)
	print(sum(klist))
	k += 1

Submission status: Time Limit Exceeded

Solution code:
n =int(input());l = list(map(int, input().split()))
for i in l:
  a=l.copy()
  a.remove(i)
  print(sum([a.count(j) * (a.count(j) - 1) // 2 for j in set(a) if a.count(j)>1]))

Submission status: Time Limit Exceeded

Solution code:
import math
f = math.factorial
def ncr(n):
  return f(n) // f(2) // f(n-2)
n =int(input())
l = list(map(int, input().split()))
for i in l:
  a=l.copy()
  a.remove(i)
  print(sum([ncr(a.count(j))for j in set(a) if a.count(j)>1]))

Submission status: Time Limit Exceeded

Solution code:
import operator as op
from functools import reduce
def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom
n =int(input())
l = list(map(int, input().split()))
for i in l:
  a=l.copy()
  a.remove(i)
  s = 0
  for j in set(a):
    k = a.count(j)
    if k>1:
      s+=ncr(k,2)
  print(s)

Submission status: Time Limit Exceeded

Solution code:
import math
f = math.factorial
n =int(input())
l = list(map(int, input().split()))

for i in l:
  a=l.copy()
  a.remove(i)
  s = 0
  for j in set(a):
    k = a.count(j)
    if k>1:
      s+=f(k) // f(2) // f(k-2)
  print(s)

Submission status: Time Limit Exceeded

Solution code:
import math
f = math.factorial
n =int(input())
l = list(map(int, input().split()))

for i in range(len(l)):
  a=l.copy()
  a.pop(i)
  s = 0
  for j in set(a):
    k = a.count(j)
    if k>1:
      s+=f(k) // f(2) // f(k-2)
  print(s)

Submission status: Time Limit Exceeded

Solution code:
import math
f = math.factorial
n =int(input())
l = list(map(int, input().split()))

for i in range(len(l)):
  a=l.copy()
  b=a.pop(i)
  s = 0
  for j in set(a):
    if a.count(j)>1:
      k= a.count(j)
      s+=f(k) // f(2) // f(k-2)
  print(s)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools
N = int(input())
A = np.array([int(x) for x in input().split(" ")])

for k, v in enumerate(A):
    print(sum([1 if c[0] == c[1] else 0 for c in [v for v in itertools.combinations(np.concatenate([A[:k],  A[k + 1:]]), 2)]]))

Submission status: Time Limit Exceeded

Solution code:
#200322D
N = int(input())
A = list(map(int,input().split()))
count = []

AllCount = 0
for i in range(N):
    icount = 0   
    for j in range(N):
        if A[i] == A[j]:
            icount += 1
            AllCount += 1
    count.append(icount)
            
for i in range(N):            
    print(int((AllCount-N)/2-count[i] + 1))