Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np

temp=input().split()
N=int(temp[0])
M=int(temp[1])

A=np.zeros((M, N))

for i in range(M):
  temp=list(map(int, input().split()))
  for j in range(1, temp[0]+1):
    A[i, temp[j]-1]=1
    
    
p=list(map(int, input().split()))

counter=0
for i in range(pow(2, N)):
  temp=format(i, '0'+str(N)+'b')
  s=[int(temp[j]) for j in range(N)]
  
  a=np.dot(A, s)%2
  
  if all(p==a):
    counter+=1
    
print(counter)

Fixed submission:
import numpy as np

N, M=map(int, input().split())
matrix=np.zeros((M, N))

for i in range(M):
  temp=np.array(list(map(int, input().split())))
  temp-=1
  matrix[i, temp[1:]]=1
  
p=np.array(list(map(int, input().split())))

counter=0
for i in range(pow(2, N)):
  s=np.array(list(map(int, list(format(i, '0'+str(N)+'b')))))
  if all(np.dot(matrix, s)%2==p)==True:
    counter+=1
    
print(counter)

Buggy python submission (verdict: Runtime Error):
import numpy as np

temp=input().split()
N=int(temp[0])
M=int(temp[1])

A=np.zeros((M, N))

for i in range(M):
  temp=list(map(int, input().split()))
  for j in range(1, temp[0]+1):
    A[i, temp[j]]=1
    
    
p=list(map(int, input().split()))

counter=0
for i in range(pow(2, N)):
  temp=format(i, '0'+str(N)+'b')
  s=[temp[j] for j in range(N)]
  
  a=np.dot(A, s)%2
  
  if p==a:
    counter+=1
    
print(counter)

Fixed submission:
import numpy as np

N, M=map(int, input().split())
matrix=np.zeros((M, N))

for i in range(M):
  temp=np.array(list(map(int, input().split())))
  temp-=1
  matrix[i, temp[1:]]=1
  
p=np.array(list(map(int, input().split())))

counter=0
for i in range(pow(2, N)):
  s=np.array(list(map(int, list(format(i, '0'+str(N)+'b')))))
  if all(np.dot(matrix, s)%2==p)==True:
    counter+=1
    
print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
MOD=10**9+7
UPPERLIMIT=3*10**5
MODMUL=[1, 1]+[0]*(UPPERLIMIT-1)
for i in range(2, UPPERLIMIT+1):
  MODMUL[i]=MODMUL[i-1]*i%MOD
MODDIV=[1]*UPPERLIMIT+[pow(MODMUL[-1], MOD-2, MOD)]
for i in range(UPPERLIMIT, 0, -1):
  MODDIV[i-1]=MODDIV[i]*i%MOD
def MODCOMB(n, r):
  if n<r or n<1:
    return 0
  else:
    return (((MODMUL[n]*MODDIV[r])%MOD)*MODDIV[n-r])%MOD

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

ans=0
k=MODCOMB(N*M-2, K-2)
for x1 in range(N-1):
  for x2 in range(x1+1, N):
    ans=(ans+abs(x1-x2)*M*M*k)%MOD
    
for y1 in range(M-1):
  for y2 in range(y1+1, M):
    ans=(ans+abs(y1-y2)*N*N*k)%MOD
    
print(ans)

Fixed submission:
MOD=10**9+7
UPPERLIMIT=3*10**5
MODMUL=[1, 1]+[0]*(UPPERLIMIT-1)
for i in range(2, UPPERLIMIT+1):
  MODMUL[i]=MODMUL[i-1]*i%MOD
MODDIV=[1]*UPPERLIMIT+[pow(MODMUL[-1], MOD-2, MOD)]
for i in range(UPPERLIMIT, 0, -1):
  MODDIV[i-1]=MODDIV[i]*i%MOD
def MODCOMB(n, r):
  if n<r or n<1:
    return 0
  else:
    return (((MODMUL[n]*MODDIV[r])%MOD)*MODDIV[n-r])%MOD

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

ans=0
k=MODCOMB(N*M-2, K-2)
for sa in range(1, N):
  ans=(ans+sa*(N-sa)*M*M*k)%MOD
    
for sa in range(1, M):
  ans=(ans+sa*(M-sa)*N*N*k)%MOD
    
print(ans)
Buggy python submission (verdict: Runtime Error):
temp=list(map(int, input().split()))
S=input()
K=int(temp[1]-1)

if S[K]=='A':
  S[K]='a'
elif S[K]=='B':
  S[K]='b'
else:
  S[K]='c'
  
print(S)

Fixed submission:
temp=list(map(int, input().split()))
S=list(input())
K=int(temp[1]-1)

if S[K]=='A':
  S[K]='a'
elif S[K]=='B':
  S[K]='b'
else:
  S[K]='c'
  
print("".join(S))

Buggy python submission (verdict: Runtime Error):
temp=list(map(int, input().split()))
S=input()
K=temp[1]

if S[K-1]=='A':
  S[K-1]='a'
elif S[K-1]=='B':
  S[K-1]='b'
else:
  S[K-1]='c'
  
print(S)

Fixed submission:
temp=list(map(int, input().split()))
S=list(input())
K=int(temp[1]-1)

if S[K]=='A':
  S[K]='a'
elif S[K]=='B':
  S[K]='b'
else:
  S[K]='c'
  
print("".join(S))
Buggy python submission (verdict: Runtime Error):
def f(j):
  nodes[j]=1
  for k in links[j]:
    if nodes[k]==0:
      f(k)

N, M=map(int, input().split())
XYZ=[list(map(int, input().split())) for _ in range(M)]
links=[[] for _ in range(N+1)]
for i in range(M):
  links[XYZ[i][0]].append(XYZ[i][1])
  links[XYZ[i][1]].append(XYZ[i][0])
  
nodes=[0]*(N+1)
ans=0
for i in range(1, N+1):
  if nodes[i]==0:
    ans+=1
    nodes[i]=1
    for j in links[i]:
      f(j)
      
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

def f(j):
  a[j]=1
  n=len(dic[j])
  for k in range(n):
    if a[dic[j][k]]==0:
      f(dic[j][k])

N, M=map(int, input().split())
dic={}
for i in range(1, N+1):
  dic[i]=[]

for i in range(M):
  x, y, z=map(int, input().split())
  dic[x].append(y)
  dic[y].append(x)
  
a=[0]*(N+1)
out=0
i=1
while i<N+1:
  if a[i]==0:
    a[i]=1
    out+=1
    n=len(dic[i])
    for j in range(n):
      if a[dic[i][j]]==0:
        f(dic[i][j])
  i+=1
print(out)

Buggy python submission (verdict: Runtime Error):
def f(j):
  a[j]=1
  n=len(dic[j])
  for k in range(n):
    if a[dic[j][k]]==0:
      f(dic[j][k])

N, M=map(int, input().split())
dic={}
for i in range(1, N+1):
  dic[i]=[]

for i in range(M):
  x, y, z=map(int, input().split())
  dic[x].append(y)
  dic[y].append(x)
  
a=[0]*(N+1)
out=0
i=1
while i<N+1:
  if a[i]==0:
    a[i]=1
    out+=1
    n=len(dic[i])
    for j in range(n):
      if a[dic[i][j]]==0:
        f(dic[i][j])
  i+=1
print(out)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

def f(j):
  a[j]=1
  n=len(dic[j])
  for k in range(n):
    if a[dic[j][k]]==0:
      f(dic[j][k])

N, M=map(int, input().split())
dic={}
for i in range(1, N+1):
  dic[i]=[]

for i in range(M):
  x, y, z=map(int, input().split())
  dic[x].append(y)
  dic[y].append(x)
  
a=[0]*(N+1)
out=0
i=1
while i<N+1:
  if a[i]==0:
    a[i]=1
    out+=1
    n=len(dic[i])
    for j in range(n):
      if a[dic[i][j]]==0:
        f(dic[i][j])
  i+=1
print(out)
Buggy python submission (verdict: Time Limit Exceeded):
H, W=map(int, input().split())

m=[[-1 for i in range(W+2)]]
mm=[[-1]+[0 for i in range(W)]+[-1] for j in range(H)]
m=m+mm+m

nexts=[]
for i in range(1, H+1):
  c=input()
  for j in range(1, W+1):
    if c[j-1]=='#':
      nexts.append([i, j])
      m[i][j]=1
      
def f(math, in_nexts):
  n=len(in_nexts)
  out_nexts=[]
  for i in range(n):
    x=in_nexts[i][0]
    y=in_nexts[i][1]
    if math[x-1][y]==0:
      math[x-1][y]=math[x][y]+1
      out_nexts.append([x-1, y])
    if math[x+1][y]==0:
      math[x+1][y]=math[x][y]+1
      out_nexts.append([x+1, y])
    if math[x][y-1]==0:
      math[x][y-1]=math[x][y]+1
      out_nexts.append([x, y-1])
    if math[x][y+1]==0:
      math[x][y+1]=math[x][y]+1
      out_nexts.append([x, y+1])
      
  return math, out_nexts

counter=0
while len(nexts)>0:
  m, nexts=f(m, nexts)
  counter+=1
  
print(counter-1)

Fixed submission:
H, W=map(int, input().split())

m=[[-1 for i in range(W+2)]]
mm=[[-1]+[0 for i in range(W)]+[-1] for j in range(H)]
m=m+mm+m

nexts=[]
for i in range(1, H+1):
  c=input()
  for j in range(1, W+1):
    if c[j-1]=='#':
      nexts.append([i, j])
      m[i][j]=1
      
def f(math, in_nexts):
  n=len(in_nexts)
  out_nexts=[]
  for i in range(n):
    x=in_nexts[i][0]
    y=in_nexts[i][1]
    if math[x-1][y]==0:
      math[x-1][y]=math[x][y]+1
      out_nexts.append([x-1, y])
    if math[x+1][y]==0:
      math[x+1][y]=math[x][y]+1
      out_nexts.append([x+1, y])
    if math[x][y-1]==0:
      math[x][y-1]=math[x][y]+1
      out_nexts.append([x, y-1])
    if math[x][y+1]==0:
      math[x][y+1]=math[x][y]+1
      out_nexts.append([x, y+1])
      
  return math, out_nexts

counter=0
while len(nexts)>0:
  m, nexts=f(m, nexts)
  counter+=1
  
print(counter-1)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions

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

X=[A[0]]
for i in range(1, N-1):
  X.append(fractions.gcd(X[-1], A[i]))

Y=[A[-1]]
for i in range(N-2, 0, -1):
  Y=[fractions.gcd(Y[0], A[i])]+Y
  
X=[Y[0]]+X
Y=Y+[X[-1]]

X=tuple(X)
Y=tuple(Y)

Z=[fractions.gcd(X[i], Y[i]) for i in range(N)]
    
print(max(Z))

Fixed submission:
import fractions

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

X=[0]*N
X[1]=A[0]
for i in range(2, N):
  X[i]=fractions.gcd(X[i-1], A[i-1])

Y=[0]*N
Y[-2]=A[-1]
for i in range(N-3, -1, -1):
  Y[i]=fractions.gcd(Y[i+1], A[i+1])
  
X[0]=Y[0]
Y[-1]=X[-1]

Z=[fractions.gcd(X[i], Y[i]) for i in range(N)]
    
print(max(Z))

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

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

X=[A[0]]
for i in range(1, N-1):
  X.append(fractions.gcd(X[-1], A[i]))
  
Y=[A[-1]]
for i in range(N-2, 0, -1):
  Y=[fractions.gcd(Y[0], A[i])]+Y
  
X=[Y[0]]+X
Y=Y+[X[-1]]
Z=[fractions.gcd(X[i], Y[i]) for i in range(N)]
    
print(max(Z))

Fixed submission:
import fractions

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

X=[0]*N
X[1]=A[0]
for i in range(2, N):
  X[i]=fractions.gcd(X[i-1], A[i-1])

Y=[0]*N
Y[-2]=A[-1]
for i in range(N-3, -1, -1):
  Y[i]=fractions.gcd(Y[i+1], A[i+1])
  
X[0]=Y[0]
Y[-1]=X[-1]

Z=[fractions.gcd(X[i], Y[i]) for i in range(N)]
    
print(max(Z))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

N, Q=map(int, input().split())
S=input()
indexs=[]
for i in range(N-1):
  if S[i:i+2]=='AC':
    indexs.append(i+1)
    
indexs=np.array(indexs)
    
for i in range(Q):
  l, r=map(int, input().split())
  r-=1
  
  print(np.sum((indexs-l)*(indexs-r)<=0))
  

Fixed submission:
N, Q=map(int, input().split())
S=input()
counter=[0]*N
for i in range(N-1):
  if S[i:i+2]=='AC':
    counter[i]+=1
    
  counter[i+1]=counter[i]

counter=[0]+counter
for i in range(Q):
  l, r=map(int, input().split())
  print(counter[r-1]-counter[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q=map(int, input().split())
S=input()

num=[0]*N

for i in range(N-1):
  if S[i:i+2]=='AC':
    num[i]=1
    
num=[0]+num+[0]
    
for i in range(Q):
  l, r=map(int, input().split())
  print(sum(num[l:r]))

Fixed submission:
N, Q=map(int, input().split())
S=input()
counter=[0]*N
for i in range(N-1):
  if S[i:i+2]=='AC':
    counter[i]+=1
    
  counter[i+1]=counter[i]

counter=[0]+counter
for i in range(Q):
  l, r=map(int, input().split())
  print(counter[r-1]-counter[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q=map(int, input().split())
S=input()
num=[0]*N

for i in range(N-1):
  if S[i:i+2]=='AC':
    num[i]=1
    
num=[0]+num+[0]
    
for i in range(Q):
  l, r=map(int, input().split())
  print(sum(num[l:r]))

Fixed submission:
N, Q=map(int, input().split())
S=input()
counter=[0]*N
for i in range(N-1):
  if S[i:i+2]=='AC':
    counter[i]+=1
    
  counter[i+1]=counter[i]

counter=[0]+counter
for i in range(Q):
  l, r=map(int, input().split())
  print(counter[r-1]-counter[l-1])
Buggy python submission (verdict: Runtime Error):
H, W=map(int, input().split())
a=[list(map(int, input().split())) for i in range(H)]
out=[]
n=0
for i in range(H):
  for j in range(W-1):
    if a[i][j]%2==1:
      n+=1
      a[i][j]-=1
      a[i][j+1]+=1
      out.append([i+1, j+1, i+1, j+2])
      
      
for i in range(H):
  if a[i][-1]%2==1:
    n+=1
    a[i][-1]-=1
    a[i+1][-1]+=1
    out.append([i+1, W, i+2, W])
    
print(n)
for i in range(n):
  print(' '.join(map(str, out[i])))

Fixed submission:
H, W=map(int, input().split())
a=[list(map(int, input().split())) for i in range(H)]
out=[]
n=0
for i in range(H):
  for j in range(W-1):
    if a[i][j]%2==1:
      n+=1
      a[i][j]-=1
      a[i][j+1]+=1
      out.append([i+1, j+1, i+1, j+2])
      
      
for i in range(H-1):
  if a[i][-1]%2==1:
    n+=1
    a[i][-1]-=1
    a[i+1][-1]+=1
    out.append([i+1, W, i+2, W])
    
print(n)
for i in range(n):
  print(' '.join(map(str, out[i])))
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=list(map(int, input().split()))
X=set()
for s in S:
  X.add(s)
  
if len(X)==3:
  print('Three')
else:
  print('Four')

Fixed submission:
N=int(input())
S=list(input().split())
X=set()
for s in S:
  X.add(s)
  
if len(X)==3:
  print('Three')
else:
  print('Four')
Buggy python submission (verdict: Runtime Error):
H, W=map(int, input().split())
m=[[-1 for i in range(W+2)]]
mm=[[-1]+[0 for j in range(W)]+[-1] for i in range(H)]
m=m+mm+m
m[1][1]=1

counter0=0
for i in range(1, H+1):
  c=input()
  for j in range(1, W+1):
    if c[j-1]=='#':
      mm[i][j]=-1
    else:
      counter0+=1
      
def f(math, kazu, h, w):
  cha=0
  for i in range(1, h+1):
    for j in range(1, w+1):
      if math[i][j]==kazu:
        if math[i-1][j]==0:
          math[i-1][j]=kazu+1
          cha=1
        if math[i+1][j]==0:
          math[i+1][j]=kazu+1
          cha=1
        if math[i][j-1]==0:
          math[i][j-1]=kazu+1
          cha=1
        if math[i][j+1]==0:
          math[i][j+1]=kazu+1
          cha=1
  return math, cha

cha=1
i=1
while cha==1:
  m, cha=f(m, i, H, W)
  i+=1
  
if m[H][W]==0:
  out=-1
else:
  out=counter0-m[H][W]
  
print(out)

Fixed submission:
H, W=map(int, input().split())
m=[[-1 for i in range(W+2)]]
mm=[[-1]+[0 for j in range(W)]+[-1] for i in range(H)]
m=m+mm+m
m[1][1]=1

counter0=0
for i in range(1, H+1):
  c=input()
  for j in range(1, W+1):
    if c[j-1]=='#':
      m[i][j]=-1
    else:
      counter0+=1
      
def f(math, kazu, h, w):
  cha=0
  for i in range(1, h+1):
    for j in range(1, w+1):
      if math[i][j]==kazu:
        if math[i-1][j]==0:
          math[i-1][j]=kazu+1
          cha=1
        if math[i+1][j]==0:
          math[i+1][j]=kazu+1
          cha=1
        if math[i][j-1]==0:
          math[i][j-1]=kazu+1
          cha=1
        if math[i][j+1]==0:
          math[i][j+1]=kazu+1
          cha=1
  return math, cha

cha=1
i=1
while cha==1:
  m, cha=f(m, i, H, W)
  i+=1
  
if m[H][W]==0:
  out=-1
else:
  out=counter0-m[H][W]
  
print(out)
Buggy python submission (verdict: Runtime Error):
def f(hito, zahyo, mae=0):
  x[hito]=zahyo
  for tsugi in links[hito]:
    if tsugi[0]==mae:
      continue
      
    if x[tsugi[0]]==None:
      f(tsugi[0], zahyo+tsugi[1], hito)
    else:
      if x[tsugi[0]]==zahyo+tsugi[1]:
        pass
      else:
        print('No')
        exit()

N, M=map(int, input().split())
links=[[] for _ in range(N+1)]
for _ in range(M):
  l, r, d=map(int, input().split())
  links[l].append([r, d])
  links[r].append([l, -d])
  
x=[None]*(N+1)
for i in range(1, N+1):
  if x[i]==None:
    f(i, 0)
    
print('Yes')

Fixed submission:
import sys
sys.setrecursionlimit(10**5)

def f(hito, zahyo):
  x[hito]=zahyo
  for tsugi in links[hito]:
    if x[tsugi[0]]==None:
      f(tsugi[0], zahyo+tsugi[1])
    else:
      if x[tsugi[0]]!=zahyo+tsugi[1]:
        print('No')
        exit()

N, M=map(int, input().split())
links=[[] for _ in range(N+1)]
for _ in range(M):
  l, r, d=map(int, input().split())
  links[l].append([r, d])
  links[r].append([l, -d])
  
x=[None]*(N+1)
for i in range(1, N+1):
  if x[i]==None:
    f(i, 0)
    
print('Yes')
Buggy python submission (verdict: Runtime Error):
N, A, B=map(int, input().split())
print(min(A*T, B))

Fixed submission:
N, A, B=map(int, input().split())
print(min(A*N, B))
Buggy python submission (verdict: Runtime Error):
x, y=map(int, input().split())
alp='ABCDEF'
if x==y:
  print('=')
elif alp.index(x)<alp.index(y):
  print('<')
else:
  print('>')

Fixed submission:
x, y=input().split()
alp='ABCDEF'
if x==y:
  print('=')
elif alp.index(x)<alp.index(y):
  print('<')
else:
  print('>')
Buggy python submission (verdict: Runtime Error):
a, b, c, d, e, f=map(int, input().split())
def g(x, y):
  if y==0:
    return 0
  else:
    return x/y
  
maxnodo=g(e, 100+e)
a*=100
b*=100

candnodo=0

q_max=f//b
for q in range(q_max, -1, -1):
  p_max=(f-b*q)//a
  for p in range(p_max, -1, -1):
    s_max=(f-(a*p+b*q))//d
    while s_max>0 and g(d*s_max, a*p+b*q+d*s_max)>maxnodo:
      s_max-=1
      
    for s in range(s_max, -1, -1):
      r=(f-(a*p+b*q+d*s))//c
      while r>0 and g(c*r+d*s, a*p+b*q+c*r+d*s)>maxnodo:
        r-=1
        
      if g(c*r+d*s, a*p+b*q+c*r+d*s)>candnodo:
        candnodo=g(c*r+d*s, a*p+b*q+c*r+d*s)
        out=[a*p+b*q+c*r+d*s, c*r+d*s]
        temp=[p, q, r, s]
print(*out)

Fixed submission:
a, b, c, d, e, f=map(int, input().split())
def g(x, y):
  if y==0:
    return 0
  else:
    return x/y
  
maxnodo=g(e, 100+e)
a*=100
b*=100

candnodo=0
out=[a, 0]
q_max=f//b
for q in range(q_max, -1, -1):
  p_max=(f-b*q)//a
  for p in range(p_max, -1, -1):
    s_max=(f-(a*p+b*q))//d
    while s_max>0 and g(d*s_max, a*p+b*q+d*s_max)>maxnodo:
      s_max-=1
      
    for s in range(s_max, -1, -1):
      r=(f-(a*p+b*q+d*s))//c
      while r>0 and g(c*r+d*s, a*p+b*q+c*r+d*s)>maxnodo:
        r-=1
        
      if g(c*r+d*s, a*p+b*q+c*r+d*s)>candnodo:
        candnodo=g(c*r+d*s, a*p+b*q+c*r+d*s)
        out=[a*p+b*q+c*r+d*s, c*r+d*s]
        temp=[p, q, r, s]
print(*out)
Buggy python submission (verdict: Runtime Error):
N=int(input())
P=list(map(int, input().split()))
X=[0]+list(map(int, input().split()))
ko=[[] for _ in range(N+1)]
for i, p in enumerate(P, 2):
  ko[p].append(i)
  
def f(p):
  n=len(ko[p])
  if n==0:
    return X[p], 0
  
  dp=[[float('inf')]*(X[p]+1) for _ in range(n+1)]
  dp[0][0]=0
  for i, c in enumerate(ko[p], 1):
    a, b=f(c)
    for j in range(a, 5001):
      dp[i][j]=min(dp[i][j], dp[i-1][j-a]+b)
    for j in range(b, 5001):
      dp[i][j]=min(dp[i][j], dp[i-1][j-b]+a)
      
  out=min(dp[-1])
  if out==float('inf'):
    print('IMPOSSIBLE')
    exit()
  elif out>X[p]:
    return out, X[p]
  else:
    return X[p], out
  
print('POSSIBLE') if min(f(1))<=X[1] else print('IMPOSSIBLE')

Fixed submission:
N=int(input())
P=list(map(int, input().split()))
X=[0]+list(map(int, input().split()))
ko=[[] for _ in range(N+1)]
for i, p in enumerate(P, 2):
  ko[p].append(i)
  
def f(p):
  n=len(ko[p])
  if n==0:
    return X[p], 0
  
  dp=[[float('inf')]*5001 for _ in range(n+1)]
  dp[0][0]=0
  for i, c in enumerate(ko[p], 1):
    a, b=f(c)
    for j in range(a, 5001):
      dp[i][j]=min(dp[i][j], dp[i-1][j-a]+b)
    for j in range(b, 5001):
      dp[i][j]=min(dp[i][j], dp[i-1][j-b]+a)
      
  out=min(dp[-1][:X[p]+1])
  if out==float('inf'):
    print('IMPOSSIBLE')
    exit()
  elif out>X[p]:
    return out, X[p]
  else:
    return X[p], out
  
print('POSSIBLE') if min(f(1))<=X[1] else print('IMPOSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
P=list(map(int, input().split()))
X=[0]+list(map(int, input().split()))
ko=[[] for _ in range(N+1)]
for i, p in enumerate(P, 2):
  ko[p].append(i)
  
def f(p):
  n=len(ko[p])
  if n==0:
    return X[p], 0
  
  dp=[[float('inf')]*5001 for _ in range(n+1)]
  dp[0][0]=0
  for i, c in enumerate(ko[p], 1):
    a, b=f(c)
    for j in range(a, 5001):
      dp[i][j]=min(dp[i][j], dp[i-1][j-a]+b)
    for j in range(b, 5001):
      dp[i][j]=min(dp[i][j], dp[i-1][j-b]+a)
      
  out=min(dp[-1][:X[p]+1])
  if out==float('inf'):
    print('IMPOSSIBLE')
    exit()
  elif out>X[p]:
    return out, X[p]
  else:
    return X[p], out
  
print('POSSIBLE') if min(f(1))<=X[1] else print('IMPOSSIBLE')

Fixed submission:
N=int(input())
P=list(map(int, input().split()))
X=[0]+list(map(int, input().split()))
ko=[[] for _ in range(N+1)]
for i, p in enumerate(P, 2):
  ko[p].append(i)
  
def f(p):
  n=len(ko[p])
  if n==0:
    return X[p], 0
  
  dp=[[float('inf')]*5001 for _ in range(n+1)]
  dp[0][0]=0
  for i, c in enumerate(ko[p], 1):
    a, b=f(c)
    for j in range(a, 5001):
      dp[i][j]=min(dp[i][j], dp[i-1][j-a]+b)
    for j in range(b, 5001):
      dp[i][j]=min(dp[i][j], dp[i-1][j-b]+a)
      
  out=min(dp[-1][:X[p]+1])
  if out==float('inf'):
    print('IMPOSSIBLE')
    exit()
  elif out>X[p]:
    return out, X[p]
  else:
    return X[p], out
  
print('POSSIBLE') if min(f(1))<=X[1] else print('IMPOSSIBLE')
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
paper=[]
for i in range(N):
  a=int(input())
  try:
    del paper[paper.index(a)]
  except:
    paper.append(a)
print(len(paper))

Fixed submission:
N=int(input())
paper={}
for i in range(N):
  a=input()
  if a in paper:
    paper[a]+=1
  else:
    paper[a]=1
counter=0
for key in paper.keys():
  if int(paper[key])%2==1:
    counter+=1
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
paper=[]
for i in range(N):
  a=int(input())
  try:
    del paper[paper.index(a)]
  except:
    paper.append(a)
print(len(paper))

Fixed submission:
N=int(input())
paper={}
for i in range(N):
  a=input()
  if a in paper:
    paper[a]+=1
  else:
    paper[a]=1
counter=0
for key in paper.keys():
  if int(paper[key])%2==1:
    counter+=1
print(counter)
Buggy python submission (verdict: Runtime Error):
A, B, C, D=map(int, input().split())
X=set([for i in range(A, B+1)])
print(sum([1 for i in range(C, D+1) if i in X]))

Fixed submission:
A, B, C, D=map(int, input().split())
X=set([i for i in range(A, B)])
print(sum([1 for i in range(C, D) if i in X]))
Buggy python submission (verdict: Runtime Error):
N, M=map(int, input().split())
x=[]
y=[]
for i in range(M):
  a, b=map(int, input().split())
  if a==1:
    x.append(b)
  if b==1:
    x.append(a)
  if a==N:
    y.append(b)
  if b==N:
    y.append(a)
    
x.sort()
y.sort()
i=0
j=0
out='IMPOSSIBLE'
nx=len(x)
ny=len(y)
while i+j<nx+ny-1:
  if x[i]==y[j]:
    out='POSSIBLE'
    break
  elif x[i]>y[j]:
    j+=1
  else:
    i+=1
    
print(out)

Fixed submission:
N, M=map(int, input().split())
x=[]
y=[]
for i in range(M):
  a, b=map(int, input().split())
  if a==1:
    x.append(b)
  if b==N:
    y.append(a)
    
nx=len(x)
ny=len(y)

if nx==0 or ny==0:
  print('IMPOSSIBLE')
  exit()

x.sort()
y.sort()
i=0
j=0
out='IMPOSSIBLE'

while i+j<nx+ny-1:
  if x[i]==y[j]:
    out='POSSIBLE'
    break
  elif x[i]>y[j]:
    j+=1
  else:
    i+=1
    
print(out)
Buggy python submission (verdict: Runtime Error):
N=int(input())
a=list(map(int, input().split()))
c=[0]*9
for i in range(N):
  c[a[i]//400]+=1
  
temp=[1 for i in range(8) if c[i]>0]
x=len(temp)
y=min(8, x+c[8])

print(x, y)

Fixed submission:
N=int(input())
a=list(map(int, input().split()))
c=[0]*9
for i in range(N):
  c[min(a[i]//400, 8)]+=1
  
temp=[1 for i in range(8) if c[i]>0]
x=len(temp)
y=x+c[8]
 
print(max(x, 1), y)

Buggy python submission (verdict: Runtime Error):
N=int(input())
a=list(map(int, input().split()))
c=[0]*9
for i in range(N):
  c[a[i]//400]+=1
  
x=sum([1 for i in range(8) if c[i]>0])
y=min(8, x+c[8])

print(x, y)

Fixed submission:
N=int(input())
a=list(map(int, input().split()))
c=[0]*9
for i in range(N):
  c[min(a[i]//400, 8)]+=1
  
temp=[1 for i in range(8) if c[i]>0]
x=len(temp)
y=x+c[8]
 
print(max(x, 1), y)
Buggy python submission (verdict: Time Limit Exceeded):
N, A=map(int, input().split())
x=list(map(int, input().split()))

dp=[[[0]*2501 for j in range(N+1)] for i in range(N)]

dp[0][0][0]=1
dp[0][1][x[0]]=1
for i in range(1, N):
  dp[i][0][0]=1
  for j in range(1, i+2):
    for k in range(2501):
      if k-x[i]>=0:
        dp[i][j][k]=dp[i-1][j-1][k-x[i]]+dp[i-1][j][k]
      else:
        dp[i][j][k]=dp[i-1][j][k]
        
print(sum([dp[-1][j][A*j] for j in range(1, N+1)]))

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

dp=[[[0]*2501 for j in range(N+1)] for i in range(N)]

dp[0][0][0]=1
dp[0][1][x[0]]=1
for i in range(1, N):
  dp[i][0][0]=1
  for j in range(1, i+2):
    for k in range(2501):
      if k-x[i]>=0:
        dp[i][j][k]=dp[i-1][j-1][k-x[i]]+dp[i-1][j][k]
      else:
        dp[i][j][k]=dp[i-1][j][k]
        
print(sum([dp[-1][j][A*j] for j in range(1, N+1)]))
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()

l = []
for i in range(len(S) - len(T)):
  cnt = 0
  for j in range(len(T)):
    if T[j] != S[i+j]:
      cnt += 1
  l.append(cnt)
print(min(l))

Fixed submission:
S = input()
T = input()

l = []
if len(S) != len(T):
  for i in range(len(S) - len(T)):
    cnt = 0
    for j in range(len(T)):
      if T[j] != S[i+j]:
        cnt += 1
    l.append(cnt)
  print(min(l))
else:
  cnt = 0
  for i in range(len(S)):
    if T[i] != S[i]:
      cnt += 1
  print(cnt)