Problem p02732 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

from collections import defaultdict
c = defaultdict(int)
cm = set()
c2 = list()
num = 0
for i in range(N):
  c[A[i]] += 1
  cm.add(A[i])
for i in list(cm):
  num += c[i]*(c[i]-1)//2
for i in range(N):
  ans = num - c[A[i]] + 1
  c2.append(ans)

for cs in c2:
  print(cs)

Buggy submission (verdict: Runtime Error):
N = int(input())
import numpy as np

A = list(map(int, input().split()))
dp = np.zeros((N,N), dtype=np.int32)
for i in range(N):
  tmp = [0]*(A[i]-1)+[1]+[0]*(N-A[i])
  tmp = np.array(tmp, dtype=np.int32)
  dp[i] = tmp+dp[i-1]

dp = np.array(dp)
ans = []
for i in range(N):
  if i > 0 and i < N-1:
    tmp = dp[N-1] - dp[i] + dp[i-1]
    tmp = tmp*(tmp-1)//2
    tmp = tmp[tmp>0]
    ans.append(tmp.sum(dtype=np.int32))
  if i == 0:
    tmp = dp[N-1] - dp[i]
    tmp = tmp*(tmp-1)/2
    tmp = tmp[tmp>0]
    ans.append(tmp.sum(dtype=np.int32))
  if i == N-1:
    tmp = dp[N-2]
    tmp = tmp*(tmp-1)/2
    tmp = tmp[tmp>0]
    ans.append(tmp.sum(dtype=np.int32))
for i in ans:
  print(i)

Buggy submission (verdict: Runtime Error):
 = int(input())
import numpy as np

A = list(map(int, input().split()))
dp = np.zeros((N,N), dtype=np.int32)
for i in range(N):
  tmp = [0]*(A[i]-1)+[1]+[0]*(N-A[i])
  tmp = np.array(tmp, dtype=np.int32)
  dp[i] = tmp+dp[i-1]

dp = np.array(dp)
ans = []
for i in range(N):
  if i > 0 and i < N-1:
    tmp = dp[N-1] - dp[i] + dp[i-1]
    tmp = tmp*(tmp-1)//2
    tmp = tmp[tmp>0]
    ans.append(tmp.sum(dtype=np.int32))
  if i == 0:
    tmp = dp[N-1] - dp[i]
    tmp = tmp*(tmp-1)//2
    tmp = tmp[tmp>0]
    ans.append(tmp.sum(dtype=np.int32))
  if i == N-1:
    tmp = dp[N-2]
    tmp = tmp*(tmp-1)//2
    tmp = tmp[tmp>0]
    ans.append(tmp.sum(dtype=np.int32))
for i in ans:
  print(i)

Buggy submission (verdict: Runtime Error):
N = int(input())
import numpy as np

A = list(map(int, input().split()))
dp = np.zeros((N,N))
for i in range(N):
  tmp = [0]*(A[i]-1)+[1]+[0]*(N-A[i])
  tmp = np.array(tmp)
  dp[i] = tmp+dp[i-1]

dp = np.array(dp)
ans = []
for i in range(N):
  if i > 0 and i < N-1:
    tmp = dp[N-1] - dp[i] + dp[i-1]
    tmp = tmp*(tmp-1)/2
    tmp = tmp[tmp>0]
    ans.append(tmp.sum())
  if i == 0:
    tmp = dp[N-1] - dp[i]
    tmp = tmp*(tmp-1)/2
    tmp = tmp[tmp>0]
    ans.append(tmp.sum())
  if i == N-1:
    tmp = dp[N-2]
    tmp = tmp*(tmp-1)/2
    tmp = tmp[tmp>0]
    ans.append(tmp.sum())
for i in ans:
  print(int(i))

Buggy submission (verdict: Runtime Error):
N = int(input())
import numpy as np

A = list(map(int, input().split()))
dp = np.zeros((N,9))
for i in range(N):
  tmp = [0]*(A[i]-1)+[1]+[0]*(9-A[i])
  tmp = np.array(tmp)
  dp[i] = tmp+dp[i-1]

dp = np.array(dp)
ans = []
for i in range(N):
  if i > 0 and i < N-1:
    tmp = dp[N-1] - dp[i] + dp[i-1]
    tmp = tmp*(tmp-1)/2
    tmp = tmp[tmp>0]
    ans.append(tmp.sum())
  if i == 0:
    tmp = dp[N-1] - dp[i]
    tmp = tmp*(tmp-1)/2
    tmp = tmp[tmp>0]
    ans.append(tmp.sum())
  if i == N-1:
    tmp = dp[N-2]
    tmp = tmp*(tmp-1)/2
    tmp = tmp[tmp>0]
    ans.append(tmp.sum())
for i in ans:
  print(int(i))

Buggy submission (verdict: Runtime Error):
N = int(input())
import numpy as np

A = list(map(int, input().split()))
dp = np.zeros((N,9))
for i in range(N):
  tmp = [0]*(A[i]-1)+[1]+[0]*(9-A[i])
  tmp = np.array(tmp)
  dp[i] = tmp+dp[i-1]

dp = np.array(dp)
ans = []
for i in range(N):
  if i > 0 and i < N-1:
    tmp = dp[N-1] - dp[i] + dp[i-1]
    tmp = tmp*(tmp-1)/2
    tmp = [t for t in tmp.tolist() if t > 0]
    tmp = np.array(tmp)
    ans.append(tmp.sum())
  if i == 0:
    tmp = dp[N-1] - dp[i]
    tmp = tmp*(tmp-1)/2
    tmp = np.array([t for t in tmp.tolist() if t>0])
    ans.append(tmp.sum())
  if i == N-1:
    tmp = dp[N-2]
    tmp = tmp*(tmp-1)/2
    tmp = np.array([t for t in tmp.tolist() if t>0])
    ans.append(tmp.sum())
for i in ans:
  print(int(i))