When I used the count method of python normally, I did TLE, so when I tried using Counter, I was able to AC.

Below is the answer using Counter.
code.py
import sys
from collections import Counter
N=int(sys.stdin.readline())
L=list(map(int,sys.stdin.readline().split()))
C=Counter(L)           #Included in L{letter:Number of appearances}I will come back with the dictionary type of
x=0
for a in C.values():   #Extract only the value (number of occurrences)
  x += int(a*(a-1)/2)  
for K in range(N):
  print(x-C[L[K]]+1)   #Subtract the combination containing K from all the same number of combinations
Below is the TLE answer. Will it be faster with a little tinkering?
code.py
import sys
N=int(sys.stdin.readline())
L=list(map(int,sys.stdin.readline().split()))
C=list(set(L))
x=0
for i in range(len(C)):
  a = L.count(C[i])
  x += int(a*(a-1)/2)  
for K in range(N):
  print(x-L.count(L[K])+1)
        Recommended Posts