Buggy python submission (verdict: Time Limit Exceeded):
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# import numpy as np
def resolve():
    N = ir()
    # A = np.array(lr(), np.int32)
    A = lr()
    A = [[A[i], i] for i in range(N)]
    A.append([2*10**5+1, N+1])
    A = sorted(A, key=lambda x: x[0])
    c = []
    d = []
    e = []
    tmp = 1
    st = 0
    for i in range(N+1):
        if tmp == A[i][0]:
            st += 1
        else:
            if st > 1:
                c.append(tmp)
                d.append(st)
                e.append(st*(st-1)//2)
            else:
                c.append(tmp)
                d.append(st)
                e.append(0)
            tmp = A[i][0]
            st = 1
    ans = []
    tmp = 0
    # print(c, d, e)
    for i in range(N):
        if A[i][0] > c[tmp]:
            tmp += 1
        num = d[tmp]
        plu = 0
        if num > 2:
            plu = (num-1)*(num-2)//2
        ans.append([sum(e)-e[tmp]+plu, A[i][1]])
    # print(ans)
    # print(iA)
    ans = sorted(ans, key=lambda x: x[1])
    for i in range(N):
        print(ans[i][0])

resolve()

Fixed submission:
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# import numpy as np
def resolve():
    N = ir()
    # A = np.array(lr(), np.int32)
    A = lr()
    A = [[A[i], i] for i in range(N)]
    A.append([2*10**5+1, N+1])
    A = sorted(A, key=lambda x: x[0])
    c = []
    d = []
    e = []
    tmp = 1
    st = 0
    for i in range(N+1):
        if tmp == A[i][0]:
            st += 1
        else:
            if st > 1:
                c.append(tmp)
                d.append(st)
                e.append(st*(st-1)//2)
            else:
                c.append(tmp)
                d.append(st)
                e.append(0)
            tmp = A[i][0]
            st = 1
    ans = []
    tmp = 0
    # print(c, d, e)
    se = sum(e)
    for i in range(N):
        if A[i][0] > c[tmp]:
            tmp += 1
        num = d[tmp]
        plu = 0
        if num > 2:
            plu = (num-1)*(num-2)//2
        ans.append([se-e[tmp]+plu, A[i][1]])
    # print(ans)
    # print(iA)
    ans = sorted(ans, key=lambda x: x[1])
    for i in range(N):
        print(ans[i][0])

resolve()

Buggy python submission (verdict: Runtime Error):
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
import numpy as np
def resolve():
    N = ir()
    # A = np.array(lr(), np.int32)
    A = lr()
    A = [[A[i], i] for i in range(N)]
    A.append([2*10**5+1, N+1])
    A = sorted(A, key=lambda x: x[0])
    c = []
    d = []
    e = []
    tmp = 1
    st = 0
    for i in range(N+1):
        if tmp == A[i][0]:
            st += 1
        else:
            if st > 1:
                c.append(tmp)
                d.append(st)
                e.append(st*(st-1)//2)
            else:
                c.append(tmp)
                d.append(st)
                e.append(0)
            tmp = A[i][0]
            st = 1
    ans = []
    tmp = 0
    # print(c, d, e)
    for i in range(N):
        if A[i][0] > c[tmp]:
            tmp += 1
        num = d[tmp]
        plu = 0
        if num > 2:
            plu = (num-1)*(num-2)//2
        ans.append([sum(e)-e[tmp]+plu, A[i][1]])
    # print(ans)
    # print(iA)
    ans = sorted(ans, key=lambda x: x[1])
    for i in range(N):
        print(ans[i][0])

resolve()

Fixed submission:
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# import numpy as np
def resolve():
    N = ir()
    # A = np.array(lr(), np.int32)
    A = lr()
    A = [[A[i], i] for i in range(N)]
    A.append([2*10**5+1, N+1])
    A = sorted(A, key=lambda x: x[0])
    c = []
    d = []
    e = []
    tmp = 1
    st = 0
    for i in range(N+1):
        if tmp == A[i][0]:
            st += 1
        else:
            if st > 1:
                c.append(tmp)
                d.append(st)
                e.append(st*(st-1)//2)
            else:
                c.append(tmp)
                d.append(st)
                e.append(0)
            tmp = A[i][0]
            st = 1
    ans = []
    tmp = 0
    # print(c, d, e)
    se = sum(e)
    for i in range(N):
        if A[i][0] > c[tmp]:
            tmp += 1
        num = d[tmp]
        plu = 0
        if num > 2:
            plu = (num-1)*(num-2)//2
        ans.append([se-e[tmp]+plu, A[i][1]])
    # print(ans)
    # print(iA)
    ans = sorted(ans, key=lambda x: x[1])
    for i in range(N):
        print(ans[i][0])

resolve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
import numpy as np
def resolve():
    N = ir()
    A = np.array(lr(), np.int32)
    iA = np.argsort(A)
    B = A[iA]
    B = np.append(B, 2*10**5+1)
    c = []
    d = []
    e = []
    tmp = 1
    st = 0
    for i in range(N+1):
        if tmp == B[i]:
            st += 1
        else:
            if st > 1:
                c.append(tmp)
                d.append(st)
                e.append(st*(st-1)//2)
            else:
                c.append(tmp)
                d.append(st)
                e.append(0)
            tmp = B[i]
            st = 1
    ans = []
    tmp = 0
    # print(c, d, e)
    for i in range(N):
        if B[i] > c[tmp]:
            tmp += 1
        num = d[tmp]
        plu = 0
        if num > 2:
            plu = (num-1)*(num-2)//2
        ans.append(sum(e)-e[tmp]+plu)
    # print(ans)
    # print(iA)
    iiA = np.argsort(iA)
    for i in range(N):
        print(ans[iiA[i]])
            
resolve()

Fixed submission:
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# import numpy as np
def resolve():
    N = ir()
    # A = np.array(lr(), np.int32)
    A = lr()
    A = [[A[i], i] for i in range(N)]
    A.append([2*10**5+1, N+1])
    A = sorted(A, key=lambda x: x[0])
    c = []
    d = []
    e = []
    tmp = 1
    st = 0
    for i in range(N+1):
        if tmp == A[i][0]:
            st += 1
        else:
            if st > 1:
                c.append(tmp)
                d.append(st)
                e.append(st*(st-1)//2)
            else:
                c.append(tmp)
                d.append(st)
                e.append(0)
            tmp = A[i][0]
            st = 1
    ans = []
    tmp = 0
    # print(c, d, e)
    se = sum(e)
    for i in range(N):
        if A[i][0] > c[tmp]:
            tmp += 1
        num = d[tmp]
        plu = 0
        if num > 2:
            plu = (num-1)*(num-2)//2
        ans.append([se-e[tmp]+plu, A[i][1]])
    # print(ans)
    # print(iA)
    ans = sorted(ans, key=lambda x: x[1])
    for i in range(N):
        print(ans[i][0])

resolve()