Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    itr = map(int, input().split())
    dic = {}
    ls = []
    for num in itr:
        z = dic.setdefault(num, 0)
        dic[num] = z + 1
        ls.append(num)

    for i in range(n):
        # ls[i]を除く
        a = ls[i]
        dic[a] -= 1
        res = 0
        for k, v in dic.items():
            if v < 2:
                continue
            elif v == 2:
                res += 1
            else:
                res += int(v*(v-1)/2)
        print(res)
        dic[a] += 1


main()


Fixed submission:
def z(z_dic, v: int):
    if v in z_dic:
        return z_dic[v]
    z = 0
    if v == 2:
        z = 1
    elif v > 2:
        z = int(v*(v-1)/2)
    z_dic.setdefault(v, z)
    return z


def main():
    n = int(input())

    ar = [0] * (n+1)
    ls = []

    for x in map(int, input().split()):
        ls.append(x)
        ar[x] += 1

    zls = []
    zls2 = []

    z_dic = {}

    for i in range(1, n+1):
        v = ar[i]
        zls.append(z(z_dic, v))
        zls2.append(z(z_dic, v-1))
    ss = sum(zls)

    for i in range(1, n+1):
        aa = ls[i-1]
        print(ss - zls[aa-1] + zls2[aa-1])
    #
    # itr = map(int, input().split())
    # dic = {}
    # for num in itr:
    #     dic.setdefault(num, 0)
    #     dic[num] += 1
    #     ls.append(num)
    #
    # for i in range(n):
    #     # ls[i]を除く
    #     a = ls[i]
    #     dic[a] -= 1
    #     res = 0
    #     for k, v in dic.items():
    #         if v < 2:
    #             continue
    #         elif v == 2:
    #             res += 1
    #         else:
    #             res += int(v*(v-1)/2)
    #     print(res)
    #     dic[a] += 1


main()

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

sys.setrecursionlimit(100000000)


def main():
    n = int(input())
    ls = list(map(int, input().split()))
    dic = {}
    for x in ls:
        z = dic.setdefault(x, 0)
        dic[x] = z + 1

    for i in range(n):
        # ls[i]を除く
        a = ls[i]
        dic[a] -= 1
        res = 0
        for k, v in dic.items():
            if v < 2:
                continue
            elif v == 2:
                res += 1
            else:
                res += int(v*(v-1)/2)
        print(res)
        dic[a] += 1


main()


Fixed submission:
def z(z_dic, v: int):
    if v in z_dic:
        return z_dic[v]
    z = 0
    if v == 2:
        z = 1
    elif v > 2:
        z = int(v*(v-1)/2)
    z_dic.setdefault(v, z)
    return z


def main():
    n = int(input())

    ar = [0] * (n+1)
    ls = []

    for x in map(int, input().split()):
        ls.append(x)
        ar[x] += 1

    zls = []
    zls2 = []

    z_dic = {}

    for i in range(1, n+1):
        v = ar[i]
        zls.append(z(z_dic, v))
        zls2.append(z(z_dic, v-1))
    ss = sum(zls)

    for i in range(1, n+1):
        aa = ls[i-1]
        print(ss - zls[aa-1] + zls2[aa-1])
    #
    # itr = map(int, input().split())
    # dic = {}
    # for num in itr:
    #     dic.setdefault(num, 0)
    #     dic[num] += 1
    #     ls.append(num)
    #
    # for i in range(n):
    #     # ls[i]を除く
    #     a = ls[i]
    #     dic[a] -= 1
    #     res = 0
    #     for k, v in dic.items():
    #         if v < 2:
    #             continue
    #         elif v == 2:
    #             res += 1
    #         else:
    #             res += int(v*(v-1)/2)
    #     print(res)
    #     dic[a] += 1


main()