Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s=input()
ans=[0]*4
checK='NWSE'
for i in range(len(s)):
  for j in range(len(check)):
    if s[i]==check[j]:
      ans[j]+=1
if (ans[0]%2+ans[2]%2)%2==0 and (ans[1]%2+ans[3]%2)%2==0:
  print('Yes')
else:
  print('No')

Fixed submission:
s=input()
ans=[0]*4
check='NWSE'
for i in range(len(s)):
  for j in range(len(check)):
    if s[i]==check[j]:
      ans[j]+=1
if ans[0]!=0 and ans[2]!=0 and ans[1]!=0 and ans[3]!=0:
  print('Yes')
elif ans[0]!=0 and ans[2]!=0 and ans[1]==0 and ans[3]==0:
  print('Yes')
elif ans[0]==0 and ans[2]==0 and ans[1]!=0 and ans[3]!=0:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
s=input()
ans=[0]*4
checK='NWSE'
for i in range(len(s)):
  for j in range(len(check)):
    if s[i]==check[j]:
      ans[j]+=1
if (ans[0]+ans[2])%2==0 and (ans[1]+ans[3])%2==0:
  print('Yes')
else:
  print('No')

Fixed submission:
s=input()
ans=[0]*4
check='NWSE'
for i in range(len(s)):
  for j in range(len(check)):
    if s[i]==check[j]:
      ans[j]+=1
if ans[0]!=0 and ans[2]!=0 and ans[1]!=0 and ans[3]!=0:
  print('Yes')
elif ans[0]!=0 and ans[2]!=0 and ans[1]==0 and ans[3]==0:
  print('Yes')
elif ans[0]==0 and ans[2]==0 and ans[1]!=0 and ans[3]!=0:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
n=int(input().split())
arr=list(map(int,input().split()))
l=min(arr)
r=max(arr)
ans=10**10
for i in range(l,r+1):
  tmp=0
  for j in range(n):
    tmp+=(arr[j]-i)**2
  if tmp<ans:
    ans=tmp
print(ans)

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
l=min(arr)
r=max(arr)
ans=10**10
for i in range(l,r+1):
  tmp=0
  for j in range(n):
    tmp+=(arr[j]-i)**2
  if tmp<ans:
    ans=tmp
print(ans)
Buggy python submission (verdict: Runtime Error):
n,l=map(int,input().split())
arr=list(map(int,input().split()))
pos=0
tmp=0
for i in range(n-1):
  if (arr[i]+arr[i+1])>tmp:
    pos=i
    tmp=(arr[i]+arr[i+1])
if tmp<l:
  print('Impossible')
else:
  print('Possible')
  ans=[]
  for i in range(pos):
    ans.append(i+1)
  for i in range(n,pos+1):
    ans.append(i)
  ans.append(pos+1)
  for i in range(n-1):
    print(ans[i])

Fixed submission:
n,l=map(int,input().split())
arr=list(map(int,input().split()))
pos=0
tmp=0
for i in range(n-1):
  if (arr[i]+arr[i+1])>tmp:
    pos=i
    tmp=(arr[i]+arr[i+1])
if tmp<l:
  print('Impossible')
else:
  print('Possible')
  ans=[]
  for i in range(pos):
    ans.append(i+1)
  for i in range(n-1,pos+1,-1):
    ans.append(i)
  ans.append(pos+1)
  for i in range(n-1):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
import collections

n,k=map(int,input().split())
g=[[] for _ in range(n+1)]
e=[]
for _ in range(n-1):
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)
  e.append((a,b))
ans=0
if k%2==0:
  for i in range(1,n+1):
    tmp=0
    checked=[0]*(n+1)
    checked[i]=1
    q=collections.deque()
    q.append((i,0))
    while len(q)!=0:
      v,d=q.popleft()
      if d<=k//2:
        tmp+=1
      else:
        break
      for u in g[v]:
        if checked[u]==0:
          checked[u]=1
          q.append((u,d+1))
    ans=max(ans,tmp)
  print(n-ans)
if k%2==1:
  for v1,v2 in e:
    tmp=0
    checked=[0]*(n+1)
    checked[v1]=1
    checked[v2]=1
    q=collections.deque()
    q.append((v1,0))
    while len(q)!=0:
      v,d=q.popleft()
      if d<=k//2:
        tmp+=1
      else:
        break
      for u in g[v]:
        if checked[u]==0:
          checked[u]=1
          q.append((u,d+1))
    checked=[0]*(n+1)
    checked[v1]=1
    checked[v2]=1
    q=collections.deque()
    q.append((v2,0))
    while len(q)!=0:
      v,d=q.popleft()
      if d<=(k-1)//2:
        tmp+=1
      else:
        break
      for u in g[v]:
        if checked[u]==0:
          checked[u]=1
          q.append((u,d+1))
    ans=max(ans,tmp)
  print(n-ans)    

Fixed submission:
import collections

n,k=map(int,input().split())
g=[[] for _ in range(n+1)]
e=[]
for _ in range(n-1):
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)
  e.append((a,b))
ans=0
if k%2==0:
  for i in range(1,n+1):
    tmp=0
    checked=[0]*(n+1)
    checked[i]=1
    q=collections.deque()
    q.append((i,0))
    while len(q)!=0:
      v,d=q.popleft()
      if d<=k//2:
        tmp+=1
      else:
        break
      for u in g[v]:
        if checked[u]==0:
          checked[u]=1
          q.append((u,d+1))
    ans=max(ans,tmp)
  print(n-ans)
if k%2==1:
  for v1,v2 in e:
    tmp=0
    checked=[0]*(n+1)
    checked[v1]=1
    checked[v2]=1
    q=collections.deque()
    q.append((v1,0))
    while len(q)!=0:
      v,d=q.popleft()
      if d<=k//2:
        tmp+=1
      else:
        break
      for u in g[v]:
        if checked[u]==0:
          checked[u]=1
          q.append((u,d+1))
    checked=[0]*(n+1)
    checked[v1]=1
    checked[v2]=1
    q=collections.deque()
    q.append((v2,0))
    while len(q)!=0:
      v,d=q.popleft()
      if d<=(k-1)//2:
        tmp+=1
      else:
        break
      for u in g[v]:
        if checked[u]==0:
          checked[u]=1
          q.append((u,d+1))
    ans=max(ans,tmp)
  print(n-ans)
Buggy python submission (verdict: Runtime Error):
S = str(input())

if S == "RRR":
    print(3)
elif S == "RRS" or S == "SRR":
    print(2)
elif S == "SSS"
    print(0)
else:
    print(1)

Fixed submission:
S = str(input())

if S == "RRR":
    print(3)
elif S == "RRS" or S == "SRR":
    print(2)
elif S == "SSS":
    print(0)
else:
    print(1)
Buggy python submission (verdict: Runtime Error):
K = int(input())
remainder_set = set()
sequence = 7
i = 1
for i in range(10**7 + 9):
    if sequence%K == 0:
        print(i+1)
        break
    else:
        if sequence%K in emainder_set:
            print(-1)
            break
        else:
            i += 1
            sequence *= 10
            sequence += 7

Fixed submission:
K = int(input())
remainder_set = set()
sequence = 7
i = 1
for i in range(K):
    remainder = sequence%K
    #print(sequence,remainder)
    if remainder == 0:
        print(i+1)
        break
    else:
        if remainder in remainder_set:
            print(-1)
            break
        else:
            i += 1
            remainder_set.add(remainder)
            sequence = remainder*10 + 7

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

if K%2 == 0:
    print(-1)

suretu = 7
i = 1
for i in range(10**7 + 9):
    if suretu%K == 0:
        print(i+1)
        break
    else:
        i += 1
        suretu *= 10
        suretu += 7

Fixed submission:
K = int(input())
remainder_set = set()
sequence = 7
i = 1
for i in range(K):
    remainder = sequence%K
    #print(sequence,remainder)
    if remainder == 0:
        print(i+1)
        break
    else:
        if remainder in remainder_set:
            print(-1)
            break
        else:
            i += 1
            remainder_set.add(remainder)
            sequence = remainder*10 + 7

Buggy python submission (verdict: Runtime Error):
K = int(input())

if K%2 == 0:
    print(-1)

suretu = 7
i = 1
for i in range(10**7 + 9)
    if suretu%K == 0:
        print(i)
        break
    else:
        i += 1
        suretu *= 10
        suretu += 7

Fixed submission:
K = int(input())
remainder_set = set()
sequence = 7
i = 1
for i in range(K):
    remainder = sequence%K
    #print(sequence,remainder)
    if remainder == 0:
        print(i+1)
        break
    else:
        if remainder in remainder_set:
            print(-1)
            break
        else:
            i += 1
            remainder_set.add(remainder)
            sequence = remainder*10 + 7

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

if K%2 == 0:
    print(-1)

suretu = 7
i = 1
while 1:
    if suretu%K == 0:
        print(i)
        break
    else:
        i += 1
        suretu *= 10
        suretu += 7

Fixed submission:
K = int(input())
remainder_set = set()
sequence = 7
i = 1
for i in range(K):
    remainder = sequence%K
    #print(sequence,remainder)
    if remainder == 0:
        print(i+1)
        break
    else:
        if remainder in remainder_set:
            print(-1)
            break
        else:
            i += 1
            remainder_set.add(remainder)
            sequence = remainder*10 + 7
Buggy python submission (verdict: Runtime Error):
L,R,d = map(int, input().split())

minumum = math.ceil(L/d)
maximum = R//d

if maximum - minumum >=0:
    print(maximum - minumum+1)
else:
    print(0)

Fixed submission:
import math
L,R,d = map(int, input().split())

minumum = math.ceil(L/d)
maximum = R//d

if maximum - minumum >=0:
    print(maximum - minumum+1)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())

#f(n) を以下の 2 つの条件の両方を満たすような 3 つの整数の組 (x,y,z)の個数とします。
# 1≤x,y,z
# x**2 + y**2 + z**2 + xy + yz + zx = n

# x,y,zの最大値を考える。
# x**2 + 1**2 + 1**2 + x + 1 + x = n
# x**2 + 2x = n - 3
# x**2 + 2x -n + 3 = 0
# x = {-2 ± sqrt(2**2 - 4*1*(-n+3))}/2*1
# x = {-2 ± sqrt(4 + 4n -12)}/2
# 1 ≤ xより
# x = {-2 + sqrt(4n - 8)}/2 = {-2 + 2 * sqrt(n - 2)}/2 = -1 + sqrt(n - 2)
# ∴ 1 ≤ x ≤ math.floor(-1 + sqrt(n - 2))
# y,zも同様。
# N <= 10**4 より、x,y,xで全探索しても(10**2)**3 = 10**6 で間に合う

ans_dict = {i:set() for i in range(1,N+1)}

for i in range(1,1 + math.floor(-1 + math.sqrt(N - 2))):
    for j in range(1,1 + math.floor(-1 + math.sqrt(N - 2))):
        for k in range(1,1 + math.floor(-1 + math.sqrt(N - 2))):
            n = i**2 + j**2 + k**2 + i*j + j*k + k*i
            if 1 <= n <= N:
                ans_dict[n].add((i,j,k))
            
for i in range(1,N+1):
    print(len(ans_dict[i]))

Fixed submission:
import math

N = int(input())

#f(n) を以下の 2 つの条件の両方を満たすような 3 つの整数の組 (x,y,z)の個数とします。
# 1≤x,y,z
# x**2 + y**2 + z**2 + xy + yz + zx = n

# x,y,zの最大値を考える。
# x**2 + 1**2 + 1**2 + x + 1 + x = n
# x**2 + 2x = n - 3
# x**2 + 2x -n + 3 = 0
# x = {-2 ± sqrt(2**2 - 4*1*(-n+3))}/2*1
# x = {-2 ± sqrt(4 + 4n -12)}/2
# 1 ≤ xより
# x = {-2 + sqrt(4n - 8)}/2 = {-2 + 2 * sqrt(n - 2)}/2 = -1 + sqrt(n - 2)
# ∴ 1 ≤ x ≤ math.floor(-1 + sqrt(n - 2))
# y,zも同様。
# N <= 10**4 より、x,y,xで全探索しても(10**2)**3 = 10**6 で間に合う

ans_dict = {i:set() for i in range(1,N+1)}

if N != 1:
    for i in range(1,1 + math.floor(-1 + math.sqrt(N - 2))):
        for j in range(1,1 + math.floor(-1 + math.sqrt(N - 2))):
            for k in range(1,1 + math.floor(-1 + math.sqrt(N - 2))):
                n = i**2 + j**2 + k**2 + i*j + j*k + k*i
                if 1 <= n <= N:
                    ans_dict[n].add((i,j,k))
                
    for i in range(1,N+1):
        print(len(ans_dict[i]))
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
from collections import deque

N = int(input())
A = [int(e) for e in input().split()]

A.sort(reverse=True)

if N == 2:
    print(A[1])
else:
    ans = A[0]
    friendly_deque = deque()
    friendly_deque.append(A[1])
    friendly_deque.append(A[1])
    
    #print(ans,friendly_deque)
    
    for i in range(2,N):
        add = friendly_deque.popleft()
        ans += add
        friendly_deque.append(A[i])
        friendly_deque.append(A[i])
        #print(ans,friendly_deque)
print(ans)

Fixed submission:
from collections import deque

N = int(input())
A = [int(e) for e in input().split()]


A.sort(reverse=True)

if N == 2:
    print(A[0])
else:
    ans = A[0]
    friendly_deque = deque()
    friendly_deque.append(A[1])
    friendly_deque.append(A[1])
    
    for i in range(2,N):
        add = friendly_deque.popleft()
        ans += add
        friendly_deque.append(A[i])
        friendly_deque.append(A[i])

    print(ans)
Buggy python submission (verdict: Runtime Error):
A,B = map(str, input().split())
A = int(A)
period_index = B.index(".")
B_after_the_decimal = int(B[period_index+1:])
B_before_the_decimal = int(B[0:period_index])

include_decimal = str(int(A*B_after_the_decimal))
include_decimal = include_decimal[:len(include_decimal)-(len(B) - period_index -1)]

if include_decimal != "":
    ans = include_decimal + A*B_before_the_decimal
else:
    ans = A*B_before_the_decimal
    
print(ans)

Fixed submission:
A,B = map(str, input().split())
A = int(A)
period_index = B.index(".")
B_after_the_decimal = int(B[period_index+1:])
B_before_the_decimal = int(B[0:period_index])

include_decimal = str(int(A*B_after_the_decimal))
include_decimal = include_decimal[:len(include_decimal)-(len(B) - period_index -1)]

if include_decimal != "":
    include_decimal = int(include_decimal)
    ans = include_decimal + A*B_before_the_decimal
else:
    ans = A*B_before_the_decimal
    
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())

room_and_connecting_room_dict = {i:set() for i in range(1,N+1)}

for i in range(M):
    A,B = map(int, input().split())
    room_and_connecting_room_dict[A].add(B)
    room_and_connecting_room_dict[B].add(A)

def get_child_ans(room_numbers_set): #room_number_list:前の部屋番の子ども全て
    
    next_room_numbers_set = set()
    
    for room_number in room_numbers_set:
        for child_room in room_and_connecting_room_dict[room_number]:
            if child_room not in calculated_room_numbers_set:
                ans_dict[child_room] = room_number #前の部屋番の子供は全て、前の部屋番に回答が確定する
                next_room_numbers_set.add(child_room)
                calculated_room_numbers_set.add(child_room)
 
    #終了判定
    if len(calculated_room_numbers_set) == N: #全部計算済み
        return 1
    elif len(next_room_numbers_set) == 0: #1から繋がる全てを計算したのに未計算がある
        return -1
    else: #孫がいるのでまだやる
        return get_child_ans(next_room_numbers_set)

ans_dict = dict()
ans_dict[1] = 0
calculated_room_numbers_set = set()
calculated_room_numbers_set.add(1)

is_there_ans = get_child_ans(set([1]))  

if is_there_ans == 1:
    print("Yes")
    for i in range(2,N+1):
        print(ans_dict[i])
else:
    print("No")

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

N,M = map(int, input().split())

room_and_connecting_room_dict = {i:set() for i in range(1,N+1)}

for i in range(M):
    A,B = map(int, input().split())
    room_and_connecting_room_dict[A].add(B)
    room_and_connecting_room_dict[B].add(A)

def get_child_ans(room_numbers_set): #room_number_list:前の部屋番の子ども全て
    
    next_room_numbers_set = set()
    
    for room_number in room_numbers_set:
        for child_room in room_and_connecting_room_dict[room_number]:
            if child_room not in calculated_room_numbers_set:
                ans_dict[child_room] = room_number #前の部屋番の子供は全て、前の部屋番に回答が確定する
                next_room_numbers_set.add(child_room)
                calculated_room_numbers_set.add(child_room)
 
    #終了判定
    if len(calculated_room_numbers_set) == N: #全部計算済み
        return 1
    elif len(next_room_numbers_set) == 0: #1から繋がる全てを計算したのに未計算がある
        return -1
    else: #孫がいるのでまだやる
        return get_child_ans(next_room_numbers_set)

ans_dict = dict()
ans_dict[1] = 0
calculated_room_numbers_set = set()
calculated_room_numbers_set.add(1)

is_there_ans = get_child_ans(set([1]))  

if is_there_ans == 1:
    print("Yes")
    for i in range(2,N+1):
        print(ans_dict[i])
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
A,B,C,K = map(int, input().split())
if K<=A:
    print(K)
elif A<=K<=A+B:
    print(A)
else:
    print(A-(K-A-B))
    
    
    
    
N,M,X = map(int, input().split())
CA_array = list()
for i in range(N):
    CA_list = [int(e) for e in input().split()]
    CA_array.append(CA_list)
    
ans = 13*(10**5)
    
#N<=12なので全探索しても4096.全探索する。
for i in range(2**(N)): #4096
    bit_array = str(bin(i)[2:]).zfill((N))
    #print(bit_array)

    CA_on_bit_array = [0 for _ in range(M+1)]
    
    for j in range(len(bit_array)): #12

        if bit_array[j]=="0":
            #OFF時の処理
            pass
        elif bit_array[j]=="1":
            #ON時の処理
            for k in range(M+1): #13
                CA_on_bit_array[k] += CA_array[j][k]

    #ON・OFFの状態設定後の処理
    for k in range(1,M+1):
        if CA_on_bit_array[k] < X:
            break
    else:
        if CA_on_bit_array[0] < ans:
            ans = CA_on_bit_array[0]

if ans != 13*(10**5):
    print(ans)
else:
    print(-1)

Fixed submission:
N,M,X = map(int, input().split())
CA_array = list()
for i in range(N):
    CA_list = [int(e) for e in input().split()]
    CA_array.append(CA_list)
    
ans = 13*(10**5)
    
#N<=12なので全探索しても4096.全探索する。
for i in range(2**(N)): #4096
    bit_array = str(bin(i)[2:]).zfill((N))
    #print(bit_array)

    CA_on_bit_array = [0 for _ in range(M+1)]
    
    for j in range(len(bit_array)): #12

        if bit_array[j]=="0":
            #OFF時の処理
            pass
        elif bit_array[j]=="1":
            #ON時の処理
            for k in range(M+1): #13
                CA_on_bit_array[k] += CA_array[j][k]

    #ON・OFFの状態設定後の処理
    for k in range(1,M+1):
        if CA_on_bit_array[k] < X:
            break
    else:
        if CA_on_bit_array[0] < ans:
            ans = CA_on_bit_array[0]

if ans != 13*(10**5):
    print(ans)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
N,K = map(int, input().split())

x = abs(N - K*(int(N/K)-1))

for i in range(0,5):
    x = abs(x-K)
    ans = min(ans,x)

print(ans)

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

x = abs(N - K*(int(N/K)-1))
ans = N

for i in range(0,100000):
    x = abs(x-K)
    ans = min(ans,x)

print(ans)
Buggy python submission (verdict: Runtime Error):
K = int(input())

def get_next_lun(before_number,keta):  

  if keta == 1: #終了条件を忘れない
      if before_number == 9:
        return [8,9]
      if before_number == 0:
        return [1,2]
      else:
        return [before_number-1,before_number,before_number+1]
  else:
      if before_number == 9:
        for i in get_next_lun(before_number,keta-1):
        return []
      if before_number == 0:
        return []
      else:
        return [before_number-1,before_number,before_number+1]
      
      return 


Fixed submission:
#161d
import math
import copy

K = int(input())

keta = 1
lunlun_numbers_list = [1,2,3,4,5,6,7,8,9]
lunlun_numbers_numer = 9

if K <=9:
    print(lunlun_numbers_list[K-1])
else:
    while 1:
        new_lunlun_numbers_list = list()
        for lower_keta in lunlun_numbers_list:
            ketasu = int(math.log10(lower_keta)//1 + 1)

            if lower_keta>=10:
                last_keta = lower_keta - ((lower_keta//10) * 10)
            else:
                last_keta = lower_keta

            #print(lower_keta,ketasu,last_keta)

            if last_keta !=0: 
                new_lunlun_numbers_list.append(lower_keta*10 + last_keta - 1)
            
            new_lunlun_numbers_list.append(lower_keta*10 + last_keta)

            if last_keta !=9:
                new_lunlun_numbers_list.append(lower_keta*10 + last_keta + 1)

        if len(new_lunlun_numbers_list)+lunlun_numbers_numer >= K:
            new_lunlun_numbers_list.sort(reverse=False)
            print(new_lunlun_numbers_list[K-lunlun_numbers_numer-1])
            #print(new_lunlun_numbers_list)
            break
        else:
            lunlun_numbers_numer+=len(new_lunlun_numbers_list)

        lunlun_numbers_list = copy.copy(new_lunlun_numbers_list)
Buggy python submission (verdict: Time Limit Exceeded):
N,X,Y = map(int, input().split())

#N <=2*10**3
#総当たりはN*(N-1) = 4*10**6　間に合う

ans_dict = {i:0 for i in range(1,N+1)}

for i in range(1,N+1):
    for j in range(i+1,N+1):
        #print(i,j)
        #ストレートで行くパターン
        straight = j-i
        #XYを経由するパターン
        throught_XY = min(abs(X-i),abs(Y-i))+min(abs(X-j),abs(Y-j))+1
        
        distance = min(straight,throught_XY)
        
        ans_dict[distance] += 1
        
for i in range(1,N):
    print(ans_dict[i])

Fixed submission:
N,X,Y = map(int, input().split())

#N <=2*10**3
#総当たりはN*(N-1) = 4*10**6　間に合う

ans_dict = {i:0 for i in range(1,N+1)}

for i in range(1,N+1):
    for j in range(i+1,N+1):
        #print(i,j)
        #ストレートで行くパターン
        straight = j-i
        #XYを経由するパターン
        throught_XY = min(abs(X-i),abs(Y-i))+min(abs(X-j),abs(Y-j))+1
        
        distance = min(straight,throught_XY)
        
        ans_dict[distance] += 1
        
for i in range(1,N):
    print(ans_dict[i])
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000000000000)

from operator import mul
from functools import reduce
from functools import lru_cache

N = int(input())
A_list = [int(e) for e in input().split()]

#ある番号のボールが何個あるかをまとめる
number_dict = dict()

for i in range(N):
    ball_number = A_list[i]
    if ball_number not in number_dict:
        number_dict[ball_number] = 0
        
    number_dict[ball_number] += 1

#それぞれの番号のボールから2個選ぶ組み合わせをカウントする。
comb_dict = dict()

@lru_cache(maxsize=10000000000000)
def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
    
@lru_cache(maxsize=10000000000000)
def two_choice(N):
    if N == 2:
        return 1
    elif N <= 1:
        return 0
    elif N == 3:
        return 3
    else:
        return combinations_count(N,2)*combinations_count(N-2,2)

all = 0

for in_dict in number_dict.items():
    ball_number = in_dict[0]
    balls = in_dict[1]
    comb_dict[ball_number] = two_choice(balls)
    all += comb_dict[ball_number]

#回答作成
for i in range(1,N+1):
    ball_number = A_list[i-1]
    now_balls = number_dict[ball_number] - 1
    print(int(all-comb_dict[ball_number]+two_choice(now_balls)))

Fixed submission:
import sys
sys.setrecursionlimit(1000000000)

from operator import mul
from functools import reduce
from functools import lru_cache

N = int(input())
A_list = [int(e) for e in input().split()]

#ある番号のボールが何個あるかをまとめる
number_dict = dict()

for i in range(N):
    ball_number = A_list[i]
    if ball_number not in number_dict:
        number_dict[ball_number] = 0
        
    number_dict[ball_number] += 1

#それぞれの番号のボールから2個選ぶ組み合わせをカウントする。
comb_dict = dict()

@lru_cache(maxsize=10000000000000)
def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
    
@lru_cache(maxsize=10000000000000)
def two_choice(N):
    if N == 2:
        return 1
    elif N <= 1:
        return 0
    elif N == 3:
        return 3
    else:
        return combinations_count(N,2)

all = 0

for in_dict in number_dict.items():
    ball_number = in_dict[0]
    balls = in_dict[1]
    comb_dict[ball_number] = two_choice(balls)
    all += comb_dict[ball_number]

#回答作成
for i in range(1,N+1):
    ball_number = A_list[i-1]
    now_balls = number_dict[ball_number] - 1
    print(int(all-comb_dict[ball_number]+two_choice(now_balls)))
Buggy python submission (verdict: Runtime Error):
a_list =[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(a_list[K+1])

Fixed submission:
a_list =[1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51]
K = int(input())
print(a_list[K-1])
Buggy python submission (verdict: Runtime Error):
S = list(input())

if len(S)%2 != 0:
  print("No")
else:
  for i in range(len(S)):
    if (i%2 == 0 & S[i] != "h") or (i%2 == 1 & S[i] != "i"):
        print("No")
        break
  else:
   	print("Yes")

Fixed submission:
S = list(input())

if len(S)%2 != 0:
  print("No")
else:
  for i in range(len(S)):
    if (i%2 == 0 and S[i] != "h") or (i%2 == 1 and S[i] != "i"):
        print("No")
        break
  else:
   	print("Yes")