Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
base = []

seen = [0]*n

for i in range(n):
  seen[a[i]-1] =  seen[a[i]-1] + 1

for i in range(n):
   if (seen[i] == 0) or (seen[i] == 1):
      continue
   
   base.append((i+1)+seen[i]*n)

for i in range(n):
  count = 0
  for temp in base:
    now = temp//n
    if temp%n == a[i]:
      now = now - 1
      
    count = count + now*(now-1)//2
    
  print(int(count))


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

seen = [0]*n
count = 0
for i in range(n):
  seen[a[i]-1] =  seen[a[i]-1] + 1

for i in range(n):
   if (seen[i] == 0) or (seen[i] == 1):
      continue
   count = count +seen[i]*(seen[i]-1)//2

for i in a:
  ans = count - (seen[i-1]*(seen[i-1]-1))//2 + ((seen[i-1]-2)*(seen[i-1]-1))//2
    
  print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
base = []

seen = [0]*n

for i in range(n):
  seen[a[i]-1] =  seen[a[i]-1] + 1

for i in range(n):
   if not ((seen[i] == 0) or (seen[i] == 1)):
      base.append((i+1)+seen[i]*n)

for i in range(n):
  count = 0
  for temp in base:
    now = temp//n
    if temp%n == a[i]:
      now = now - 1
      
    count = count + now*(now-1)//2
    
  print(int(count))


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

seen = [0]*n
count = 0
for i in range(n):
  seen[a[i]-1] =  seen[a[i]-1] + 1

for i in range(n):
   if (seen[i] == 0) or (seen[i] == 1):
      continue
   count = count +seen[i]*(seen[i]-1)//2

for i in a:
  ans = count - (seen[i-1]*(seen[i-1]-1))//2 + ((seen[i-1]-2)*(seen[i-1]-1))//2
    
  print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
base = []

seen = [0]*n

for i in range(n):
  seen[a[i]-1] =  seen[a[i]-1] + 1

for i in range(n):
   if not ((seen[i] == 0) or (seen[i] == 1)):
      base.append([i+1,seen[i]])

for i in range(n):
  count = 0
  for temp in base:
    now = temp[1]
    if temp[0] == a[i]:
      now = now - 1
      
    count = count + now*(now-1)//2
    
  print(int(count))


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

seen = [0]*n
count = 0
for i in range(n):
  seen[a[i]-1] =  seen[a[i]-1] + 1

for i in range(n):
   if (seen[i] == 0) or (seen[i] == 1):
      continue
   count = count +seen[i]*(seen[i]-1)//2

for i in a:
  ans = count - (seen[i-1]*(seen[i-1]-1))//2 + ((seen[i-1]-2)*(seen[i-1]-1))//2
    
  print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))

seen = [0]*n

for i in range(n):
  seen[a[i]-1] =  seen[a[i]-1] + 1
  
for i in range(n):
  count = 0
  seen[a[i]-1] = seen[a[i]-1] - 1
  for j in range(n):
    if (seen[j] == 0) or (seen[j] == 1):
      continue
    count = count + (seen[j]*(seen[j]-1))//2
    
  print(int(count))
  seen[a[i]-1] = seen[a[i]-1] + 1


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

seen = [0]*n
count = 0
for i in range(n):
  seen[a[i]-1] =  seen[a[i]-1] + 1

for i in range(n):
   if (seen[i] == 0) or (seen[i] == 1):
      continue
   count = count +seen[i]*(seen[i]-1)//2

for i in a:
  ans = count - (seen[i-1]*(seen[i-1]-1))//2 + ((seen[i-1]-2)*(seen[i-1]-1))//2
    
  print(int(ans))