Buggy python submission (verdict: Time Limit Exceeded):
# bin/env/pypy3
import sys
import collections
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
c = collections.Counter(a)
#print(n,a,c)
memo_e = {}
for e in a:
    if not e in memo_e:
        c[e] -= 1
        memo_e[e] = sum(v*(v-1)//2 for v in c.values() if v > 1)
        c[e] += 1
    print(memo_e[e])


Fixed submission:
# bin/env/pypy3
import sys
import collections
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
c = collections.Counter(a)
#print(n,a,c)
memo_e = {}
s = sum(v*(v-1)//2 for v in c.values() if v > 1)
for e in a:
    if not e in memo_e:
        #c[e] -= 1
        if 1 < c[e]:
            memo_e[e] = s - (c[e]*(c[e]-1)//2 - (c[e]-1)*(c[e]-2)//2)
        else:
            memo_e[e] = s
    print(memo_e[e])

Buggy python submission (verdict: Time Limit Exceeded):
# bin/env/pypy3
import sys
import collections
import heapq
import math
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
c = collections.Counter(a)
#print(n,a,c)
memo_f = {}
memo_c = {}
def combinations_count(n, r):
    return n*(n-1)//2
    s = str([n,r])
    if s in memo_c:
        return memo_c[s]
    if not n in memo_f: memo_f[n] = math.factorial(n)
    b = max(n - r,0)
    if not b in memo_f: memo_f[b] = math.factorial(b)
    if not r in memo_f: memo_f[r] = math.factorial(r)
    memo_c[s] = memo_f[n] // (memo_f[b] * memo_f[r])
    return memo_c[s]
memo_e = {}
for e in a:
    if not e in memo_e:
        c[e] -= 1
        b = [combinations_count(v,2) for v in c.values() if v > 1]
        memo_e[e] = sum(b)
        c[e] += 1
    print(memo_e[e])

Fixed submission:
# bin/env/pypy3
import sys
import collections
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
c = collections.Counter(a)
#print(n,a,c)
memo_e = {}
s = sum(v*(v-1)//2 for v in c.values() if v > 1)
for e in a:
    if not e in memo_e:
        #c[e] -= 1
        if 1 < c[e]:
            memo_e[e] = s - (c[e]*(c[e]-1)//2 - (c[e]-1)*(c[e]-2)//2)
        else:
            memo_e[e] = s
    print(memo_e[e])

Buggy python submission (verdict: Time Limit Exceeded):
# bin/env/pypy3
import sys
import collections
import heapq
import math
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
c = collections.Counter(a)
#print(n,a,c)
memo_f = {}
memo_c = {}
def combinations_count(n, r):
    return n*(n-1)//2
    s = str([n,r])
    if s in memo_c:
        return memo_c[s]
    if not n in memo_f: memo_f[n] = math.factorial(n)
    b = max(n - r,0)
    if not b in memo_f: memo_f[b] = math.factorial(b)
    if not r in memo_f: memo_f[r] = math.factorial(r)
    memo_c[s] = memo_f[n] // (memo_f[b] * memo_f[r])
    return memo_c[s]
for e in a:
    c[e] -= 1
    b = [combinations_count(v,2) for v in c.values() if v > 1]
    print(sum(b))
    c[e] += 1


Fixed submission:
# bin/env/pypy3
import sys
import collections
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
c = collections.Counter(a)
#print(n,a,c)
memo_e = {}
s = sum(v*(v-1)//2 for v in c.values() if v > 1)
for e in a:
    if not e in memo_e:
        #c[e] -= 1
        if 1 < c[e]:
            memo_e[e] = s - (c[e]*(c[e]-1)//2 - (c[e]-1)*(c[e]-2)//2)
        else:
            memo_e[e] = s
    print(memo_e[e])

Buggy python submission (verdict: Time Limit Exceeded):
# bin/env/pypy3
import sys
import collections
import heapq
import math
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
c = collections.Counter(a)
#print(n,a,c)
memo_f = {}
memo_c = {}
def combinations_count(n, r):
    s = str([n,r])
    if s in memo_c:
        return memo_c[s]
    if not n in memo_f: memo_f[n] = math.factorial(n)
    b = max(n - r,0)
    if not b in memo_f: memo_f[b] = math.factorial(b)
    if not r in memo_f: memo_f[r] = math.factorial(r)
    memo_c[s] = memo_f[n] // (memo_f[b] * memo_f[r])
    return memo_c[s]
for e in a:
    c[e] -= 1
    b = [combinations_count(v,2) for v in c.values() if v > 1]
    print(sum(b))
    c[e] += 1


Fixed submission:
# bin/env/pypy3
import sys
import collections
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
c = collections.Counter(a)
#print(n,a,c)
memo_e = {}
s = sum(v*(v-1)//2 for v in c.values() if v > 1)
for e in a:
    if not e in memo_e:
        #c[e] -= 1
        if 1 < c[e]:
            memo_e[e] = s - (c[e]*(c[e]-1)//2 - (c[e]-1)*(c[e]-2)//2)
        else:
            memo_e[e] = s
    print(memo_e[e])

Buggy python submission (verdict: Time Limit Exceeded):
# bin/env/pypy3
import sys
import collections
import heapq
import math
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
c = collections.Counter(a)
#print(n,a,c)
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(max(n - r,0)) * math.factorial(r))
for e in a:
    c[e] -= 1
    b = [combinations_count(v,2) for v in c.values() if v > 1]
    print(sum(b))
    c[e] += 1

Fixed submission:
# bin/env/pypy3
import sys
import collections
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
c = collections.Counter(a)
#print(n,a,c)
memo_e = {}
s = sum(v*(v-1)//2 for v in c.values() if v > 1)
for e in a:
    if not e in memo_e:
        #c[e] -= 1
        if 1 < c[e]:
            memo_e[e] = s - (c[e]*(c[e]-1)//2 - (c[e]-1)*(c[e]-2)//2)
        else:
            memo_e[e] = s
    print(memo_e[e])