Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

N = stdin.readline().rstrip().split()
N = int(N[0])

int_list = list(map(int, stdin.readline().rstrip().split()))
cnt_list = [int_list.count(i) for i in range(1, N+1)]

ret_list = [0] * N

# これはO(N)でいける

tmp_ans = 0
for i in range(N):
    if cnt_list[i] > 1:
        tmp_ans += cnt_list[i]*(cnt_list[i]-1) // 2

# tmp_ans = sum([cnt_list[i]*(cnt_list[i]-1) // 2 for i in range(N) if cnt_list[i] > 1])

for i in range(N):
    if cnt_list[i] < 1:
        tmp_ret = 0
    else:
        tmp_ret = tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2
    ret_list[i] = tmp_ret

for i in int_list:
    print(ret_list[i-1])

# ret_list = [0 if cnt_list[i] < 1 else tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2 for i in range(N)]

# [print(ret_list[i-1]) for i in int_list]

Fixed submission:
from sys import stdin

N = stdin.readline().rstrip().split()
N = int(N[0])

int_list = list(map(int, stdin.readline().rstrip().split()))
cnt_list = [0] * N

for i in int_list:
    cnt_list[i-1] += 1

ret_list = [0] * N

# これはO(N)でいける

tmp_ans = 0
for i in range(N):
    if cnt_list[i] > 1:
        tmp_ans += cnt_list[i]*(cnt_list[i]-1) // 2


for i in range(N):
    if cnt_list[i] < 1:
        tmp_ret = 0
    else:
        tmp_ret = tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2
    ret_list[i] = tmp_ret

for i in int_list:
    print(ret_list[i-1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

N = stdin.readline().rstrip().split()
N = int(N[0])

int_list = list(map(int, stdin.readline().rstrip().split()))

cnt_list = [int_list.count(i) for i in range(1, N+1)]
ret_list = []

# これはO(N)でいける

# tmp_ans = 0
# for i in range(N):
#     if cnt_list[i] > 1:
#         tmp_ans += cnt_list[i]*(cnt_list[i]-1) // 2

tmp_ans = sum([cnt_list[i]*(cnt_list[i]-1) // 2 for i in range(N) if cnt_list[i] > 1])

# for i in range(N):
#     if cnt_list[i] < 1:
#         tmp_ret = 0
#     else:
#         tmp_ret = tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2
#     ret_list.append(tmp_ret)

# for i in int_list:
#     print(ret_list[i-1])

ret_list = [0 if cnt_list[i] < 1 else tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2 for i in range(N)]

[print(ret_list[i-1]) for i in int_list]

Fixed submission:
from sys import stdin

N = stdin.readline().rstrip().split()
N = int(N[0])

int_list = list(map(int, stdin.readline().rstrip().split()))
cnt_list = [0] * N

for i in int_list:
    cnt_list[i-1] += 1

ret_list = [0] * N

# これはO(N)でいける

tmp_ans = 0
for i in range(N):
    if cnt_list[i] > 1:
        tmp_ans += cnt_list[i]*(cnt_list[i]-1) // 2


for i in range(N):
    if cnt_list[i] < 1:
        tmp_ret = 0
    else:
        tmp_ret = tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2
    ret_list[i] = tmp_ret

for i in int_list:
    print(ret_list[i-1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

N = stdin.readline().rstrip().split()
N = int(N[0])

int_list = list(map(int, stdin.readline().rstrip().split()))

cnt_list = [int_list.count(i) for i in range(1, N+1)]
ret_list = []

# これはO(N)でいける

tmp_ans = 0
for i in range(N):
    if cnt_list[i] < 2:
        continue
    else:
        tmp_ans += cnt_list[i]*(cnt_list[i]-1) // 2

# for i in range(N):
#     if cnt_list[i] < 1:
#         tmp_ret = 0
#     else:
#         tmp_ret = tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2
#     ret_list.append(tmp_ret)

# for i in int_list:
#     print(ret_list[i-1])

ret_list = [0 if cnt_list[i] < 1 else tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2 for i in range(N)]

[print(ret_list[i-1]) for i in int_list]

Fixed submission:
from sys import stdin

N = stdin.readline().rstrip().split()
N = int(N[0])

int_list = list(map(int, stdin.readline().rstrip().split()))
cnt_list = [0] * N

for i in int_list:
    cnt_list[i-1] += 1

ret_list = [0] * N

# これはO(N)でいける

tmp_ans = 0
for i in range(N):
    if cnt_list[i] > 1:
        tmp_ans += cnt_list[i]*(cnt_list[i]-1) // 2


for i in range(N):
    if cnt_list[i] < 1:
        tmp_ret = 0
    else:
        tmp_ret = tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2
    ret_list[i] = tmp_ret

for i in int_list:
    print(ret_list[i-1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

N = stdin.readline().rstrip().split()
N = int(N[0])

int_list = list(map(int, stdin.readline().rstrip().split()))

cnt_list = [int_list.count(i) for i in range(1, N+1)]
ret_list = []

# これはO(N)でいける

tmp_ans = 0
for i in range(N):
    if cnt_list[i] < 2:
        continue
    else:
        tmp_ans += cnt_list[i]*(cnt_list[i]-1) // 2

# for i in range(N):
#     if cnt_list[i] < 1:
#         tmp_ret = 0
#     else:
#         tmp_ret = tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2
#     ret_list.append(tmp_ret)

ret_list = [0 if cnt_list[i] < 1 else tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2 for i in range(N)]

for i in int_list:
    print(ret_list[i-1])

Fixed submission:
from sys import stdin

N = stdin.readline().rstrip().split()
N = int(N[0])

int_list = list(map(int, stdin.readline().rstrip().split()))
cnt_list = [0] * N

for i in int_list:
    cnt_list[i-1] += 1

ret_list = [0] * N

# これはO(N)でいける

tmp_ans = 0
for i in range(N):
    if cnt_list[i] > 1:
        tmp_ans += cnt_list[i]*(cnt_list[i]-1) // 2


for i in range(N):
    if cnt_list[i] < 1:
        tmp_ret = 0
    else:
        tmp_ret = tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2
    ret_list[i] = tmp_ret

for i in int_list:
    print(ret_list[i-1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

N = stdin.readline().rstrip().split()
N = int(N[0])

int_list = list(map(int, stdin.readline().rstrip().split()))

cnt_list = [int_list.count(i) for i in range(1, N+1)]
ret_list = []

# これはO(N)でいける

tmp_ans = 0
for i in range(N):
    if cnt_list[i] < 2:
        continue
    else:
        tmp_ans += cnt_list[i]*(cnt_list[i]-1) // 2

for i in range(N):
    if cnt_list[i] < 1:
        tmp_ret = 0
    else:
        tmp_ret = tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2
    ret_list.append(tmp_ret)

for i in int_list:
    print(ret_list[i-1])

Fixed submission:
from sys import stdin

N = stdin.readline().rstrip().split()
N = int(N[0])

int_list = list(map(int, stdin.readline().rstrip().split()))
cnt_list = [0] * N

for i in int_list:
    cnt_list[i-1] += 1

ret_list = [0] * N

# これはO(N)でいける

tmp_ans = 0
for i in range(N):
    if cnt_list[i] > 1:
        tmp_ans += cnt_list[i]*(cnt_list[i]-1) // 2


for i in range(N):
    if cnt_list[i] < 1:
        tmp_ret = 0
    else:
        tmp_ret = tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2
    ret_list[i] = tmp_ret

for i in int_list:
    print(ret_list[i-1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

N = stdin.readline().rstrip().split()
N = int(N[0])

str_list = stdin.readline().rstrip().split()
int_list = int_data = [int(i) for i in str_list]

cnt_list = [int_list.count(i) for i in range(1, N+1)]
ret_list = []

# これはO(N)でいける

tmp_ans = 0
for i in range(N):
    if cnt_list[i] < 2:
        continue
    else:
        tmp_ans += cnt_list[i]*(cnt_list[i]-1) // 2

for i in range(N):
    if cnt_list[i] < 1:
        tmp_ret = 0
    else:
        tmp_ret = tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2
    ret_list.append(tmp_ret)

for i in int_list:
    print(ret_list[i-1])

Fixed submission:
from sys import stdin

N = stdin.readline().rstrip().split()
N = int(N[0])

int_list = list(map(int, stdin.readline().rstrip().split()))
cnt_list = [0] * N

for i in int_list:
    cnt_list[i-1] += 1

ret_list = [0] * N

# これはO(N)でいける

tmp_ans = 0
for i in range(N):
    if cnt_list[i] > 1:
        tmp_ans += cnt_list[i]*(cnt_list[i]-1) // 2


for i in range(N):
    if cnt_list[i] < 1:
        tmp_ret = 0
    else:
        tmp_ret = tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2
    ret_list[i] = tmp_ret

for i in int_list:
    print(ret_list[i-1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

N = stdin.readline().rstrip().split()
N = int(N[0])

str_list = stdin.readline().rstrip().split()
int_list = int_data = [int(i) for i in str_list]

cnt_list = []
ret_list = []

for i in range(1, N+1):
    tmp_cnt = int_list.count(i)
    cnt_list.append(tmp_cnt)
    
tmp_ans = 0
for i in range(N):
    if cnt_list[i] < 2:
        continue
    else:
        tmp_ans += cnt_list[i]*(cnt_list[i]-1) // 2

for i in range(N):
    if cnt_list[i] < 1:
        tmp_ret = 0
    else:
        tmp_ret = tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2
    ret_list.append(tmp_ret)

for i in int_list:
    print(ret_list[i-1])

Fixed submission:
from sys import stdin

N = stdin.readline().rstrip().split()
N = int(N[0])

int_list = list(map(int, stdin.readline().rstrip().split()))
cnt_list = [0] * N

for i in int_list:
    cnt_list[i-1] += 1

ret_list = [0] * N

# これはO(N)でいける

tmp_ans = 0
for i in range(N):
    if cnt_list[i] > 1:
        tmp_ans += cnt_list[i]*(cnt_list[i]-1) // 2


for i in range(N):
    if cnt_list[i] < 1:
        tmp_ret = 0
    else:
        tmp_ret = tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2
    ret_list[i] = tmp_ret

for i in int_list:
    print(ret_list[i-1])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

N = stdin.readline().rstrip().split()
N = int(N[0])

str_list = stdin.readline().rstrip().split()
int_list = int_data = [int(i) for i in str_list]

cnt_list = []
ret_list = []

for i in range(1, N+1):
    tmp_cnt = int_list.count(i)
    cnt_list.append(tmp_cnt)

for i in range(N):
    tmp_ret = 0
    for j in range(N):
        if i == j:
            if cnt_list[j] < 3:
                continue
            else:
                tmp_ret += (cnt_list[j]-1)*(cnt_list[j]-2) // 2
        else:
            if cnt_list[j] < 2:
                continue
            else:
                tmp_ret += cnt_list[j]*(cnt_list[j]-1) // 2
    
    ret_list.append(tmp_ret)

for i in int_list:
    print(ret_list[i-1])

Fixed submission:
from sys import stdin

N = stdin.readline().rstrip().split()
N = int(N[0])

int_list = list(map(int, stdin.readline().rstrip().split()))
cnt_list = [0] * N

for i in int_list:
    cnt_list[i-1] += 1

ret_list = [0] * N

# これはO(N)でいける

tmp_ans = 0
for i in range(N):
    if cnt_list[i] > 1:
        tmp_ans += cnt_list[i]*(cnt_list[i]-1) // 2


for i in range(N):
    if cnt_list[i] < 1:
        tmp_ret = 0
    else:
        tmp_ret = tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2
    ret_list[i] = tmp_ret

for i in int_list:
    print(ret_list[i-1])