Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)
B.append(0)
p = B[0]
y = dict()
u = 0
for k in range(N+1):
    q = B[k]
    if p != q:
        y[p] = u
        u = 0
    u += 1
    p = q
for j in range(N):
    g = 0
    x = A[j]
    y[x] -= 1
    for l in y.values():
        g += l*(l-1)//2
    print(g)
    y[x] += 1

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)
B.append(0)
p = B[0]
y = dict()
u = 0
for k in range(N+1):
    q = B[k]
    if p != q:
        y[p] = u
        u = 0
    u += 1
    p = q
All = 0
for l in y.values():
    All +=l*(l-1)//2
for j in range(N):
    x = A[j]
    print(All+(y[x]-1)*(y[x]-2)//2-y[x]*(y[x]-1)//2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)
B.append(0)
p = B[0]
y = dict()
u = 0
for k in range(N+1):
    q = B[k]
    if p != q:
        y[p] = u
        u=0
    u += 1
    p = q
for j in range(N):
    g = 0
    x = A[j]
    y[x] -= 1
    va = list(y.values())
    for l in va:
        g += l*(l-1)//2
    print(g)
    y[x] += 1

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)
B.append(0)
p = B[0]
y = dict()
u = 0
for k in range(N+1):
    q = B[k]
    if p != q:
        y[p] = u
        u = 0
    u += 1
    p = q
All = 0
for l in y.values():
    All +=l*(l-1)//2
for j in range(N):
    x = A[j]
    print(All+(y[x]-1)*(y[x]-2)//2-y[x]*(y[x]-1)//2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
d = dict()
for o in range(N):
    d[o] = A[o]
B = sorted(A)
B.append(0)
p = B[0]
y = dict()
u = 0
for k in range(N+1):
    q = B[k]
    if p != q:
        y[p] = u
        u=0
    u += 1
    p = q
for j in range(N):
    g = 0
    x = d[j]
    y[x] -= 1
    va = list(y.values())
    for l in va:
        g += l*(l-1)//2
    print(g)
    y[x] += 1

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)
B.append(0)
p = B[0]
y = dict()
u = 0
for k in range(N+1):
    q = B[k]
    if p != q:
        y[p] = u
        u = 0
    u += 1
    p = q
All = 0
for l in y.values():
    All +=l*(l-1)//2
for j in range(N):
    x = A[j]
    print(All+(y[x]-1)*(y[x]-2)//2-y[x]*(y[x]-1)//2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
C = [i for i in range(N)]
d = dict(zip(C, A))
B = sorted(A)
B.append(0)
p = B[0]
y = dict()
u = 0
for k in range(N+1):
    q = B[k]
    if p != q:
        y[p] = u
        u=0
    u += 1
    p = q
for j in range(N):
    g = 0
    x = d[j]
    y[x] -= 1
    va = list(y.values())
    for l in va:
        g += l*(l-1)//2
    print(g)
    y[x] += 1

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)
B.append(0)
p = B[0]
y = dict()
u = 0
for k in range(N+1):
    q = B[k]
    if p != q:
        y[p] = u
        u = 0
    u += 1
    p = q
All = 0
for l in y.values():
    All +=l*(l-1)//2
for j in range(N):
    x = A[j]
    print(All+(y[x]-1)*(y[x]-2)//2-y[x]*(y[x]-1)//2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
C = [i for i in range(N)]
d = dict(zip(C, A))
B = sorted(A)
B.append(0)
p = B[0]
nm = []
nn = []
u = 0
for k in range(N+1):
    q = B[k]
    if p != q:
        nm.append(p)
        nn.append(u)
        u=0
    u += 1
    p = q
y = dict(zip(nm, nn))
P = len(nm)
for j in range(N):
    g = 0
    x = d[j]
    y[x] -= 1
    va = list(y.values())
    for l in range(P):
        v = va[l]
        g += v*(v-1)//2
    print(g)
    y[x] += 1

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = sorted(A)
B.append(0)
p = B[0]
y = dict()
u = 0
for k in range(N+1):
    q = B[k]
    if p != q:
        y[p] = u
        u = 0
    u += 1
    p = q
All = 0
for l in y.values():
    All +=l*(l-1)//2
for j in range(N):
    x = A[j]
    print(All+(y[x]-1)*(y[x]-2)//2-y[x]*(y[x]-1)//2)