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

def comb2(n):
    return int(n * (n - 1) / 2)

def dictcomb(dic, dp):
    ans = 0
    for key in dic:
        ans += dp[dic[key]]
    return ans

def solve(a, dic, dp):
    for i in a:
        dic[i] -= 1
        print(dictcomb(dic, dp))
        dic[i] += 1

def main():
    dp = [comb2(n) for n in range(2 * (10 ** 5) + 1)]
    n = int(input())
    a = list(map(int,input().split()))
    d = collections.Counter(a)
    solve(a, d, dp)

if __name__ == '__main__':
    main()

Fixed submission:
import collections

def comb2(n):
    return int(n * (n - 1) / 2)

def combdict(dic, dp):
    ans = 0
    for v in dic.values():
        ans += dp[v]
    return ans

def solve(a, dic, dp):
    allsum = combdict(dic,dp)
    for i in a:
        print(allsum - dp[dic[i]] + dp[dic[i]-1])

def main():
    dp = [comb2(i) for i in range(2 * ( 10 ** 5) + 1)]
    n = int(input())
    a = list(map(int,input().split()))
    d = collections.Counter(a)
    solve(a, d, dp)

if __name__ == '__main__':
    main()

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

def comb2(n):
    return int(n * (n - 1) / 2)

def dictcomb(dic):
    ans = 0
    for key in dic:
        ans += comb2(dic[key])
    return ans

def solve(a, dic):
    for i in a:
        dic[i] -= 1
        print(dictcomb(dic))
        dic[i] += 1

def main():
    n = int(input())
    a = list(map(int,input().split()))
    d = collections.Counter(a)
    solve(a, d)

if __name__ == '__main__':
    main()

Fixed submission:
import collections

def comb2(n):
    return int(n * (n - 1) / 2)

def combdict(dic, dp):
    ans = 0
    for v in dic.values():
        ans += dp[v]
    return ans

def solve(a, dic, dp):
    allsum = combdict(dic,dp)
    for i in a:
        print(allsum - dp[dic[i]] + dp[dic[i]-1])

def main():
    dp = [comb2(i) for i in range(2 * ( 10 ** 5) + 1)]
    n = int(input())
    a = list(map(int,input().split()))
    d = collections.Counter(a)
    solve(a, d, dp)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def factrial(n):
    if n < 2:
        return 1
    return n * factrial(n - 1)

def combination(n, r):
    return int(factrial(n) / factrial(r) / factrial(n - r))

def combination2(n):
    return combination(n, 2)

def dictcomb(dic):
    ans = 0
    for key in dic:
        ans += combination2(dic[key])
    return ans

def solve(a, dic):
    for i in a:
        dic[i] -= 1
        print(dictcomb(dic))
        dic[i] += 1

def main():
    n = int(input())
    a = list(map(int,input().split()))
    dic = {}
    for i in a:
        if i in dic:
            dic[i] += 1
        else:
            dic[i] = 1
    solve(a, dic)

if __name__ == '__main__':
    main()

Fixed submission:
import collections

def comb2(n):
    return int(n * (n - 1) / 2)

def combdict(dic, dp):
    ans = 0
    for v in dic.values():
        ans += dp[v]
    return ans

def solve(a, dic, dp):
    allsum = combdict(dic,dp)
    for i in a:
        print(allsum - dp[dic[i]] + dp[dic[i]-1])

def main():
    dp = [comb2(i) for i in range(2 * ( 10 ** 5) + 1)]
    n = int(input())
    a = list(map(int,input().split()))
    d = collections.Counter(a)
    solve(a, d, dp)

if __name__ == '__main__':
    main()