Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())

if v == w:
  print('NO')
  exit()
elif (a > b) and (v >= m):
  print('NO')
  exit()
  
for i in range(1,t+1):
  oni = a+(v*i)
  child = c+(w*i)
  if oni >= child:
    print('YES')
    break
else:
  print('NO')

Fixed submission:
A, V = [int(n) for n in input().split()]
B, W = [int(n) for n in input().split()]
T = int(input())
 
if V <= W:
    print('NO')
    exit()
    
d = abs(A - B)

if V > W and d <= (V - W) * T:
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Runtime Error):
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())

oni = a + (v*t)
child = b + (w*t)

if oni = child:
  print('YES')
else:
  print('NO')

Fixed submission:
A, V = [int(n) for n in input().split()]
B, W = [int(n) for n in input().split()]
T = int(input())
 
if V <= W:
    print('NO')
    exit()
    
d = abs(A - B)

if V > W and d <= (V - W) * T:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
ans = 1

if 0 in A:
  print(1)
  exit
  
for i in range(N):
  ans *= A[i]
  if ans > 10**18:
    print(-1)
     exit()
    
print(ans)


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

if 0 in A:
  ans = 0
  N = 0
  
for i in range(N):
  ans *= A[i]
  if ans > 10**18:
    ans = -1
    break
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
ans = 1

for i in range(len(A)):
  ans *= A[i]
  
if ans > 10**18:
  ans = -1
  
print(ans)

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

if 0 in A:
  ans = 0
  N = 0
  
for i in range(N):
  ans *= A[i]
  if ans > 10**18:
    ans = -1
    break
    
print(ans)
Buggy python submission (verdict: Runtime Error):
import decimal
A,B = map(int,input().split())
A = decimal(A)
B = decimal(B)
print(int(A*B))

Fixed submission:
from decimal import Decimal
A,B = map(str,input().split())
A = Decimal(A)
B = Decimal(B)
print(int(A*B))

Buggy python submission (verdict: Runtime Error):
import math

A,B = map(int,input().split())
ans = A * B

print(math.floor(ans))

Fixed submission:
from decimal import Decimal
A,B = map(str,input().split())
A = Decimal(A)
B = Decimal(B)
print(int(A*B))
Buggy python submission (verdict: Runtime Error):
from decimal import Decimal
A,B = map(str,input().split())
A = Decimal(A)
B = Decimal(B)
print(int(A*B))

Fixed submission:
# ABC169 D Div Game

n = int(input())

def factorization(n):
    arr = []
    if n == 1:
        return arr
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

f_list = factorization(n)
cnt = 0
for i in range(len(f_list)):
    _tmp = f_list[i][1]
    j = 1
    while _tmp >= 0:
        _tmp -= j
        j += 1
        cnt += 1
    cnt -= 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
T = input()
PD = list(T)

for i in range(len(PD)):
  if PD[i] == '?':
    if i == 0 and P[1] in ('D','?'):
      PD[i] = 'P'
    elif i == len(PD):
      PD[i] = 'D'
    elif PD[i-1] == 'D' and PD[i+1] in ('D','?'):
      PD[i] = 'P'
    elif PD[i+1] == 'D':
      PD[i] = 'P'
    else:
      PD[i] = 'D'
      
print(''.join(PD))

Fixed submission:
T = input()
print(T.replace('?','D'))

Buggy python submission (verdict: Runtime Error):
T = input()
PD = list(T)

for i in range(len(PD)):
  if PD[i] == '?':
    if i == 0 and P[1] == 'D':
      PD[i] = 'P'
    elif i == len(PD):
      PD[i] = 'D'
    elif (PD[i-2] == 'P' and PD[i-1] == 'D') and (PD[i-1] == 'D' and PD[i+1] in ('D','?')):
      PD[i] = 'P'
    else:
      PD[i] = 'D'
      
print(''.join(PD))

Fixed submission:
T = input()
print(T.replace('?','D'))

Buggy python submission (verdict: Runtime Error):
T = input()
PD = list(T)

for i in range(len(PD)):
  if PD[i] == '?':
    if i == 0 and P[1] == 'D':
      PD[i] = 'P'
    elif i == len(PD):
      PD[i] = 'D'
    elif PD[i-2] == 'P' and PD[i-1] == 'D':
      PD[i] = 'P'
    else:
      PD[i] = 'D'
      
print(''.join(PD))

Fixed submission:
T = input()
print(T.replace('?','D'))

Buggy python submission (verdict: Runtime Error):
T = input()
PD = list(T)

for i in range(len(PD)):
  if PD[i] == '?':
    if i == len(PD):
      PD[i] = 'D'
    elif PD[i-2] == 'P' and PD[i-1] == 'D':
      PD[i] = 'P'
    else:
      PD[i] = 'D'
      
print(''.join(PD))

Fixed submission:
T = input()
print(T.replace('?','D'))
Buggy python submission (verdict: Runtime Error):
a, b, c, k = map(int, input().split())
 
if (a >= k):
    print(k)
elif ((a + b) >= k):
    print(a)
else:
    max_num = a - c
    print(max_num

Fixed submission:
x = input()
y = input()
 
if x == y[:-1]:
	print('Yes')
else:
	print('No')

Buggy python submission (verdict: Runtime Error):
a, b, c, k = map(int, input().split())

if (a >= k):
    print(k)
elif ((a + b) >= k):
    print(a)
else:
    max_num = a - (k - a - b)
    print(max_num)

Fixed submission:
x = input()
y = input()
 
if x == y[:-1]:
	print('Yes')
else:
	print('No')
Buggy python submission (verdict: Runtime Error):
A,B,C,D = map(int,input().split())
 
Takahashi = A
Aoki = C
 
while Takahashi >= 0 or Aoki >=0:
  Aoki -= B
  if Aoki <= 0:
    print('Yes')
    break
  Takahashi -= D
  if Takahashi <= 0:
    print('No')
    break

Fixed submission:
S,W = map(int,input().split())
 
if S <= W:
  print('unsafe')
else:
  print('safe')

Buggy python submission (verdict: Runtime Error):
A,B,C,D = map(int,input().split())

Takahashi = A
Aoki = B

while Takahashi <= 0 or Aoki <=0:
  Aoki -= B
  if Aoki <= 0:
    print('Yes')
    break
  Takahashi -= D
  if Takahashi <= 0:
    print('No')
    break

Fixed submission:
S,W = map(int,input().split())
 
if S <= W:
  print('unsafe')
else:
  print('safe')

Buggy python submission (verdict: Runtime Error):
S,W = map(int,input().split())

if s <= w:
  print('unsafe')
else:
  print('safe')

Fixed submission:
S,W = map(int,input().split())
 
if S <= W:
  print('unsafe')
else:
  print('safe')
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
a, b, c, d = (int(i) for i in input().split())

Fixed submission:
import sys
input = sys.stdin.readline
a, b, c = (int(i) for i in input().split())
print(min(a+b,b+c,c+a))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,m=(int(i) for i in input().split())
a = [int(input()) for i in range(m)]
#print(n,m,a)

d=[0 for i in range(100000+10)]
p=1000000007
#n=100
#a=[1, 23, 45, 67, 89]
aa=[0 for i in range(100000+10)]

for i in range(10**5+10):
    if i in a:
        aa[i]=1
#print(aa)

d[0]=1
if aa[1] == 0:
    d[1]=1
else:
    d[1]=0
    
if aa[2] == 0:
    d[2]=d[1]+d[0]
else:
    d[2]=0
    
for i in range(2,n+1):
    if aa[i] == 0:
        d[i]=d[i-1]+d[i-2]
        d[i]=d[i]%p
    else:
        d[i]=0
#print(d)

print(d[n]%p)



Fixed submission:
import sys
input = sys.stdin.readline
n,m=(int(i) for i in input().split())
a = [int(input()) for i in range(m)]
#print(n,m,a)

d=[0 for i in range(100000+10)]
p=1000000007
#n=100
#a=[1, 23, 45, 67, 89]
aa=[0 for i in range(100000+10)]

for i in a:
    aa[i]=1
#print(aa)

d[0]=1
if aa[1] == 0:
    d[1]=1
else:
    d[1]=0
    
if aa[2] == 0:
    d[2]=d[1]+d[0]
else:
    d[2]=0
    
for i in range(2,n+1):
    if aa[i] == 0:
        d[i]=d[i-1]+d[i-2]
        d[i]=d[i]%p
    else:
        d[i]=0
#print(d)

print(d[n]%p)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,m=(int(i) for i in input().split())
a = [int(input()) for i in range(m)]
#print(n,m,a)

d=[0 for i in range(100000+10)]
p=1000000007
#n=100
#a=[1, 23, 45, 67, 89]

d[0]=1
if a.count(1) == 0:
    d[1]=1
else:
    d[1]=0
    
if a.count(2) == 0:
    d[2]=d[1]+d[0]
else:
    d[2]=0
    
for i in range(2,n+1):
    if a.count(i) == 0:
        d[i]=d[i-1]+d[i-2]
        d[i]=d[i]%p
    else:
        d[i]=0
#print(d)

print(d[n]%p)

Fixed submission:
import sys
input = sys.stdin.readline
n,m=(int(i) for i in input().split())
a = [int(input()) for i in range(m)]
#print(n,m,a)

d=[0 for i in range(100000+10)]
p=1000000007
#n=100
#a=[1, 23, 45, 67, 89]
aa=[0 for i in range(100000+10)]

for i in a:
    aa[i]=1
#print(aa)

d[0]=1
if aa[1] == 0:
    d[1]=1
else:
    d[1]=0
    
if aa[2] == 0:
    d[2]=d[1]+d[0]
else:
    d[2]=0
    
for i in range(2,n+1):
    if aa[i] == 0:
        d[i]=d[i-1]+d[i-2]
        d[i]=d[i]%p
    else:
        d[i]=0
#print(d)

print(d[n]%p)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=(int(i) for i in input().split())
mylist=[0 for i in range(100010)]

for i in range(m):
    a,b=(int(i) for i in input().split())
    for j in range(a,b+1):
      mylist[j]+=1

print(mylist.count(m))

Fixed submission:
n,m=(int(i) for i in input().split())
list_a=[]
list_b=[]
for i in range(m):
  a,b=(int(i) for i in input().split())
  list_a.append(a)
  list_b.append(b)
  
max_a=max(list_a)
min_b=min(list_b)

if min_b-max_a+1>=0:
  print(min_b-max_a+1)
else:
  print(0)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=(int(i) for i in input().split())
a,b=(int(i) for i in input().split())
myset=set()
for i in range(a,b+1):
    myset.add(i)
if m==1:
  ans=myset
else:
  ans=myset
  for i in range(1,m):
    a,b=(int(i) for i in input().split())
    myset=set()
    for i in range(a,b+1):
      myset.add(i)
    ans=ans&myset

print(len(ans))

Fixed submission:
n,m=(int(i) for i in input().split())
list_a=[]
list_b=[]
for i in range(m):
  a,b=(int(i) for i in input().split())
  list_a.append(a)
  list_b.append(b)
  
max_a=max(list_a)
min_b=min(list_b)

if min_b-max_a+1>=0:
  print(min_b-max_a+1)
else:
  print(0)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=(int(i) for i in input().split())

ans=set(int(i) for i in range(100000+10))

for i in range(m):
  a,b=(int(i) for i in input().split())
  myset=set()
  for i in range(a,b+1):
    myset.add(i)
  ans=ans&myset

print(len(ans))

Fixed submission:
n,m=(int(i) for i in input().split())
list_a=[]
list_b=[]
for i in range(m):
  a,b=(int(i) for i in input().split())
  list_a.append(a)
  list_b.append(b)
  
max_a=max(list_a)
min_b=min(list_b)

if min_b-max_a+1>=0:
  print(min_b-max_a+1)
else:
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
def merge_dict_add_values(d1, d2):
    return dict(Counter(d1) + Counter(d2))
  
n,m=(int(i) for i in input().split())
a=[int(i) for i in input().split()]

mydict={}
mydict[a[0]]=1
for i in range(1,len(a)):
    d2={}
    d2[a[i]]=1
    mydict=merge_dict_add_values(mydict, d2)
#print(mydict)

#list_bc=[]
b,c=(int(i) for i in input().split())
mydict[c]=b
for i in range(1,m):
    b,c=(int(i) for i in input().split())
    d2={}
    d2[c]=b
    mydict=merge_dict_add_values(mydict, d2)
#print(n,m,a,mydict_bc)

mylist = sorted(mydict.items(), key=lambda x: -x[0])

#print(mylist)
cnt=0
cnt0=0
i=0
while cnt <= n:
    cnt0+=mylist[i][0]*mylist[i][1]
    v=mylist[i][0]
    cnt+=mylist[i][1]
    i+=1

#print(cnt0,v,cnt)
print(cnt0-v*(cnt-n))


Fixed submission:
import heapq
h = []

n,m=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
for i in a:
    heapq.heappush(h, [(-1)*i,1])

for i in range(m):
    b,c=(int(i) for i in input().split())
    heapq.heappush(h, [(-1)*c,b])

num=0
data=0
while num <= n:
    v=heapq.heappop(h)
    data+=v[0]*v[1]
    num+=v[1]

print((-1)*(data-v[0]*(num-n)))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
def merge_dict_add_values(d1, d2):
    return dict(Counter(d1) + Counter(d2))
  
n,m=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
#list_bc=[]
mydict_bc={}
b,c=(int(i) for i in input().split())
mydict_bc[c]=b
for i in range(1,m):
    b,c=(int(i) for i in input().split())
    d2={}
    d2[c]=b
    mydict_bc=merge_dict_add_values(mydict_bc, d2)
#print(n,m,a,mydict_bc)

  
mydict={}

mydict[a[0]]=1
for i in range(1,len(a)):
    d2={}
    d2[a[i]]=1
    mydict=merge_dict_add_values(mydict, d2)
#print(mydict)
    
mydict_r1=merge_dict_add_values(mydict, mydict_bc)
mylist = sorted(mydict_r1.items(), key=lambda x: -x[0])

#print(mylist)
cnt=0
cnt0=0
i=0
while cnt <= n:
    cnt0+=mylist[i][0]*mylist[i][1]
    v=mylist[i][0]
    cnt+=mylist[i][1]
    i+=1

#print(cnt0,v,cnt)
print(cnt0-v*(cnt-n))


Fixed submission:
import heapq
h = []

n,m=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
for i in a:
    heapq.heappush(h, [(-1)*i,1])

for i in range(m):
    b,c=(int(i) for i in input().split())
    heapq.heappush(h, [(-1)*c,b])

num=0
data=0
while num <= n:
    v=heapq.heappop(h)
    data+=v[0]*v[1]
    num+=v[1]

print((-1)*(data-v[0]*(num-n)))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

R, G, B, N = (int(i) for i in input().split())
#print(R, G, B, N)

cnt=0
for i in range(N//R+1):
  for j in range(N//G+1):
    k=N-R*i-G*j
    if k >=0 and k%B==0:
      cnt+=1
      
print(cnt)

Fixed submission:
import sys
input = sys.stdin.readline

R, G, B, N = (int(i) for i in input().split())
#print(R, G, B, N)

cnt=0
for i in range(N//R+1):
  for j in range(N//G+1):
    k=N-R*i-G*j
    if k >=0 and k%B==0:
      cnt+=1
      
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h,w=(int(i) for i in input().split())
#print(h,w)

a=[[i for i in input()] for j in range(h)]
#print(a)

start=deque([])
goal=deque([])
for i in range(h):
    for j in range(w):
        if a[i][j]=='.':
            goal.append((i,j))
        else:
            start.append((i,j))
#print(goal)
#print(start)

cnt=0
for i in range(len(goal)):
    cnt1=2010    
    for j in range(len(start)):
        length=abs(goal[i][0]-start[j][0])+abs(goal[i][1]-start[j][1])
        if length < cnt1:
            cnt1= length
    if cnt < cnt1:
        cnt = cnt1
print(cnt)




Fixed submission:
from collections import deque
h,w=(int(i) for i in input().split())
#print(h,w)

a=[[i for i in input()] for j in range(h)]
#print(a)

cnt=0
ans=0
black=deque([])
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            cnt+=1
            black.append((i,j))
dy=deque([1,0,-1,0])
dx=deque([0,1,0,-1])
#print(black)
#print(cnt)

while cnt<h*w:
    for i in range(len(black)):
        data=black.popleft()
        for j in range(4):
            if 0<=data[0]+dy[j]<h and 0<=data[1]+dx[j]<w:
                if a[data[0]+dy[j]][data[1]+dx[j]]=='.':
                    a[data[0]+dy[j]][data[1]+dx[j]]='#'
                    cnt+=1
                    black.append((data[0]+dy[j],data[1]+dx[j]))
    ans+=1
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
cnt=float('inf')
wnum=0
bnum=0
for i in range(n+1):
  s1=s[:i]
  s2=s[i:]
#  print(s1,s2)
  wnum=s1.count('#')
  bnum=s2.count('.')
  cnt=min(cnt,wnum+bnum)

if s.count('#')==n or s.count('.')==n:
  cnt=0
  
print(cnt)
  


Fixed submission:
n=int(input())
s=input()

wlist=[0 for i in range(n)]
blist=[0 for i in range(n)]

wnum=0
bnum=0

for i in range(n):
  if s[i]=='.':
    wnum+=1
  else:
    bnum+=1
  wlist[i]=wnum
  blist[i]=bnum
#print(wlist,blist)

ans=float('inf')  
for i in range(n):
  ans=min(ans,wlist[-1]-wlist[i]+blist[i])
  
ans=min(ans,wlist[-1],blist[-1])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
cnt=float('inf')
wnum=0
bnum=0
for i in range(n+1):
  s1=s[:i]
  s2=s[i:]
#  print(s1,s2)
  wnum=s1.count('#')
  bnum=s2.count('.')
  cnt=min(cnt,wnum+bnum)

if s.count('#')==n or s.count('.')==n:
  cnt=0
  
print(cnt)
  

Fixed submission:
n=int(input())
s=input()

wlist=[0 for i in range(n)]
blist=[0 for i in range(n)]

wnum=0
bnum=0

for i in range(n):
  if s[i]=='.':
    wnum+=1
  else:
    bnum+=1
  wlist[i]=wnum
  blist[i]=bnum
#print(wlist,blist)

ans=float('inf')  
for i in range(n):
  ans=min(ans,wlist[-1]-wlist[i]+blist[i])
  
ans=min(ans,wlist[-1],blist[-1])

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import deque

n=int(input())
b=[int(i) for i in input().split()]

#print(n,b)

ans=deque([])

for j in range(n):
    tmp=110
    for i in range(len(b)-1,-1,-1):
        if len(b)==1:
            break
        else:
            if i+1==b[i]:
                val=b.pop(b[i])
                ans.append(val)
                
ans.append(b[0])

if ans.count(110) > 0:
    print(-1)
else:
    for i in range(n):
        print(ans[i])

Fixed submission:
import sys
input = sys.stdin.readline

n=int(input())
b=[int(i) for i in input().split()]

anslist=[]
while len(b) > 0:
    val=110
    for i in range(len(b)-1,-1,-1):
        if i+1==b[i]:
            val=i+1
            break
    anslist.append(val)
    b.pop(i)

if anslist.count(110)>0:
    print(-1)
else:
    for i in (reversed(anslist)):
        print(i)
Buggy python submission (verdict: Runtime Error):
n,m = [int(i) for i in input().split()]
e = [[int(i) for i in input().split()] for i in range(n)]
e.sort()
#print(n,m,e)
#e=dict(e)
#print(n,m,e,e[0][0]*m)

total=0
if m <= e[0][1]:
  total=e[0][0]*m
else:
  tmp=e[0][0]*e[0][1]
  m-=e[0][1]


#print(m)  
flag=0
for i in range(1,n):
  if 0 <= m <e[i][1] and flag==0:
    flag=1
    total=tmp+e[i][0]*m
  tmp+=e[i][0]*e[i][1]
  m-=e[i][1]

print(total)

Fixed submission:
n,m = [int(i) for i in input().split()]
e = [[int(i) for i in input().split()] for i in range(n)]
e.sort()
#print(n,m,e)

total=0
for i in range(n):
    if m > 0:
      total+=e[i][0]*min(e[i][1],m)
    m-=e[i][1]
    
print(total)

Buggy python submission (verdict: Runtime Error):
n,m = [int(i) for i in input().split()]
e = [[int(i) for i in input().split()] for i in range(n)]
e.sort()
#print(n,m,e)
#e=dict(e)
#print(n,m,e,e[0][0]*m)

total=0
if m < e[0][1]:
  total=e[0][0]*m
else:
  tmp=e[0][0]*e[0][1]
  m-=e[0][1]


#print(m)  
flag=0
for i in range(1,n):
  if 0 <= m <e[i][1] and flag==0:
    flag=1
    total=tmp+e[i][0]*m
  tmp+=e[i][0]*e[i][1]
  m-=e[i][1]

if n==1:
  total=e[0][0]*e[0][1]


print(total)

Fixed submission:
n,m = [int(i) for i in input().split()]
e = [[int(i) for i in input().split()] for i in range(n)]
e.sort()
#print(n,m,e)

total=0
for i in range(n):
    if m > 0:
      total+=e[i][0]*min(e[i][1],m)
    m-=e[i][1]
    
print(total)
Buggy python submission (verdict: Runtime Error):
a,b,q=(input().split())
a,b,q=int(a),int(b),int(q)
s=[int(input()) for i in range(a)]
t=[int(input()) for i in range(b)]
x=[int(input()) for i in range(q)]
dist=['' for i in range(8)]
dist1=['' for i in range(2)]
dist2=['' for i in range(4)]
sp1=['' for i in range(2)]
tp1=['' for i in range(4)]

import bisect
for k in range(q):

    p1=bisect.bisect_left(s,x[k])

    if 0 < p1 < a:
        dist1[0]=x[k]-s[p1-1]
        dist1[1]=s[p1]-x[k]
        sp1[0]=s[p1-1]
        sp1[1]=s[p1]
    elif p1==0:
        dist1[0]=s[0]-x[k]
        dist1[1]=s[0]-x[k]
        sp1[0]=s[0]
        sp1[1]=s[0]        
    elif p1==a:
        dist1[0]=x[k]-s[a-1]
        dist1[1]=x[k]-s[a-1]
        sp1[0]=s[a-1]
        sp1[1]=s[a-1]
        
    for i in range(2):     
        p11=bisect.bisect_left(t,sp1[i])

        if 0 < p11 < b:
            dist2[0+2*i]=sp1[i]-t[p11-1]
            dist2[1+2*i]=t[p11]-sp1[i]
        if p11==0:
            dist2[0+2*i]=t[0]-sp1[i]
            dist2[1+2*i]=t[0]-sp1[i]
        elif p11==b:
            dist2[0+2*i]=sp1[i]-t[b-1]
            dist2[1+2*i]=sp1[i]-t[b-1]
        
    dist[0]=dist1[0]+dist2[0]
    dist[1]=dist1[0]+dist2[1]
    dist[2]=dist1[1]+dist2[2]
    dist[3]=dist1[1]+dist2[3]
                
    p1=bisect.bisect_left(t,x[k])

    if 0 < p1 < b:
        sp1[0]=t[p1-1]
        sp1[1]=t[p1]
        dist1[0]=x[k]-t[p1-1]
        dist1[1]=t[p1]-x[k]
    elif p1==0:
        sp1[0]=t[0]
        sp1[1]=t[0]
        dist1[0]=t[0]-x[k]
        dist1[1]=t[0]-x[k]
    elif p1==b:
        sp1[0]=t[b-1]
        sp1[1]=t[b-1]
        dist1[0]=x[k]-t[b-1]
        dist1[1]=x[k]-t[b-1]
        
    for i in range(2):    
        p11=bisect.bisect_left(s,sp1[i])

        if 0 < p11 < a:
            dist2[0+2*i]=sp1[i]-s[p11-1]
            dist2[1+2*i]=s[p11]-sp1[i]
        elif p11==0:
            dist2[0+2*i]=s[0]-sp1[i]
            dist2[1+2*i]=s[0]-sp1[i]
        elif p11==a:
            dist2[0+2*i]=sp1[i]-s[a-1]
            dist2[1+2*i]=sp1[i]-s[a-1]

    dist[4]=dist1[0]+dist2[0]
    dist[5]=dist1[0]+dist2[1]
    dist[6]=dist1[1]+dist2[2]
    dist[7]=dist1[1]+dist2[3]
    
    ans=min(dist[0],dist[1],dist[2],dist[3],dist[4],dist[5],dist[6],dist[7])

    print(ans)



Fixed submission:
import itertools

n,a,b,c=(input().split())
n,a,b,c=int(n),int(a),int(b),int(c)
l=[int(input()) for i in range(n)]
#print(n,a,b,c,l)

ansans=float('inf')
ans=float('inf')

mylist=list(itertools.product(range(4),repeat=n))
#print(len(mylist))
#mylist=[1,2,2,2,3]
for j in range(len(mylist)):
    x,y,z=0,0,0
    for i in range(n):
        if mylist[j][i]==1:
            x+=l[i]
        elif mylist[j][i]==2:
            y+=l[i]
        elif mylist[j][i]==3:
            z+=l[i]
        
    if mylist[j].count(1)>0 and mylist[j].count(2)>0 and mylist[j].count(3) > 0:
        ans=0
        ans+=abs(a-x)+abs(b-y)+abs(c-z)
        compo=0
        for i in range(1,4):
            compo+=mylist[j].count(i)-1
        ans+=10*compo

    if ans < ansans:
        ansans = ans

print(ansans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=(int(i) for i in input().split())

e = [[int(i) for i in input().split()] for j in range(n)]
#print(e)

dp=[[0 for i in range(k+1)] for j in range(n)]

for j in range(k+1):
    if j >= e[0][0]:
      dp[0][j]=e[0][1]

for i in range(1,n):
  for j in range(k+1):
    if j < e[i][0]:
      dp[i][j]=dp[i-1][j]
    else:
      dp[i][j]=max(dp[i-1][j],dp[i-1][j-e[i][0]]+e[i][1])

print(max(dp[n-1]))


Fixed submission:
n,k=(int(i) for i in input().split())
e = [[int(i) for i in input().split()] for j in range(n)]
#print(n,k,e)
maxv=0
for i in range(n):
    maxv+=e[i][1]
#print(maxv)

dp = [[0 for i in range(maxv+1)] for j in range(n+1)]
#print(dp)

for i in range(1, maxv+1):
    dp[0][i] = float('inf')
#print(dp)

for j in range(n):
    for i in range(1, maxv+1):
        if i < e[j][1] :
            dp[j + 1][i] = dp[j][i]
        else:
            dp[j + 1][i] = min(dp[j][i], dp[j][i - e[j][1]] +e[j][0])
#print(dp)
ans = 0
for i in range(maxv+1):
    if dp[n][i] <= k and ans < i:
        ans = i
        
print(ans)
Buggy python submission (verdict: Runtime Error):
n, p= [int(i) for i in input().split()]
#print(n,p)
ans=0
pp=int(p**(1/n))+1
for i in range(1,pp):
  b=i**n
  c=p/b
  if c.is_integer()==True:
    ans=i
    
print(ans)

Fixed submission:
n=input()
ans=0
ans=n.count('2')
print(ans)