Problem p02732 (python)

Fixed submission:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

n = int(input())
a = list(map(int,input().split()))

#ひとつものぞかず、同じ数のボールをとるのは？
c = collections.Counter(a)
maxa = 0
item = [0 for i in range(max(a))]
for key,value in c.items():
    item[key-1] = value
    maxa += (value)*(value-1)//2
for i in range(len(a)):
    d = (item[a[i]-1])*(item[a[i]-1]-1)//2-(item[a[i]-1]-1)*(item[a[i]-1]-2)//2
    print(maxa-d)

Buggy submission (verdict: Runtime Error):
import collections
import bisect
n = int(input())
a = list(map(int,input().split()))
A = collections.Counter(a)
Key = []
Val = []
for key,val in A.items():
    Key.append(key)
    Val.append(val)
ans = 0
ans1 = 0
for i in range(len(Val)):
    ans+= ((Val[i])*(Val[i]-1))//2
for i in range(n):
    s = bisect.bisect_left(Key,a[i])
    d1 = (Val[s]*(Val[s]-1))//2
    Val[s]-=1
    d2 = (Val[s]*(Val[s]-1))//2
    ans1 = ans - (d1-d2)
    print(ans1)
    Val[s]+=1
print(ans1)

Buggy submission (verdict: Runtime Error):
import collections
import bisect
n = int(input())
a = list(map(int,input().split()))
A = collections.Counter(a)
Key = []
Val = []
for key,val in A.items():
    Key.append(key)
    Val.append(val)
ans = 0
for i in range(len(Val)):
    ans+= ((Val[i])*(Val[i]-1))//2
for i in range(n):
    s = bisect.bisect_left(Key,a[i])
    d1 = (Val[s]*(Val[s]-1))//2
    Val[s]-=1
    d2 = (Val[s]*(Val[s]-1))//2
    ans1 = ans - (d1-d2)
    print(ans1)
    Val[s]+=1

Buggy submission (verdict: Runtime Error):
import collections
import bisect
n = int(input())
a = list(map(int,input().split()))
A = collections.Counter(a)
Key = set(a)
Key = list(Key)
Val = []
for val in A.values():
    Val.append(val)
ans = 0
for i in range(len(Val)):
    ans+= ((Val[i])*(Val[i]-1))//2
for i in range(n):
    s = bisect.bisect_left(Key,a[i])
    d1 = (Val[s]*(Val[s]-1))//2
    Val[s]-=1
    d2 = (Val[s]*(Val[s]-1))//2
    ans1 = ans - (d1-d2)
    print(ans1)
    Val[s]+=1

Buggy submission (verdict: Runtime Error):
import collections
import sys
import numpy as np
import copy
import bisect
from operator import mul
from functools import reduce
import itertools
import math
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

sys.setrecursionlimit(1000000000)
n = int(input())
a = list(map(int,input().split()))
A = collections.Counter(a)
li = []
number = set(a)
number = list(number)
counter = []
for val in A.values():
    counter.append(val)
counter2 = []
for i in range(len(counter)):
    counter2.append((counter[i]*(counter[i]-1))//2)

for i in range(n):
    s = bisect.bisect_left(number,a[i])
    counter[s]-=1
    counter2[s] = counter2[s] - counter[s]
    ans = sum(counter2)
    counter2[s] = counter2[s] + counter[s]
    counter[s]+=1
    print(ans)
"""
temp = li[:]
for i in range(n):
    temp = li[:]
    ans = 0
    for j in range(len(temp)):
        if a[i] == temp[j][0]:
            temp[j][1] -= 1
            break
    for j in range(len(temp)):
        ans += ((temp[j][1])*(temp[j][1]-1))//2
    for j in range(len(temp)):
        if a[i] == temp[j][0]:
            temp[j][1] += 1
            break
    print(ans)
allans = 
"""