Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
ans = 0
for i in reversed(range(int(math.sqrt(n)))):
    if n%i == 0:
        j = n // i
        ans = i+j-2
        break
print(ans)


Fixed submission:
import math
n = int(input())
ans = 0
for i in reversed(range(int(math.sqrt(n))+1)):
    if n%i == 0:
        j = n // i
        ans = i+j-2
        break
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
i = 0
ans = 10**13
for i in range(int(math.sqrt(n))):
    if n%i != 0:
        continue
    j = n // i
    ans = min(ans, i+j-2)
print(ans)


Fixed submission:
import math
n = int(input())
ans = 0
for i in reversed(range(int(math.sqrt(n))+1)):
    if n%i == 0:
        j = n // i
        ans = i+j-2
        break
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
i = 0
ans = 10**18
for i in range(int(math.sqrt(n))):
    if n%i != 0:
        continue
    j = n // i
    ans = min(ans, i+j-2)
print(ans)


Fixed submission:
import math
n = int(input())
ans = 0
for i in reversed(range(int(math.sqrt(n))+1)):
    if n%i == 0:
        j = n // i
        ans = i+j-2
        break
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
i = 0
for j in reversed(range(int(math.sqrt(n)))):
    if n % j == 0:
        i = j
        break
j = n // i
print(i + j - 2)


Fixed submission:
import math
n = int(input())
ans = 0
for i in reversed(range(int(math.sqrt(n))+1)):
    if n%i == 0:
        j = n // i
        ans = i+j-2
        break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0
for i in range(n):
    ans += i
print(ans)


Fixed submission:
n = int(input())
print((n*(n-1))//2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for _ in range(n)]
mx = []
for i in range(n):
    x = a.pop(i)
    mx.append(max(a))
    a.insert(i, x)
for i in range(n):
    print(mx[i])


Fixed submission:
import copy
n = int(input())
a = [int(input()) for _ in range(n)]
s = copy.copy(a)
s.sort(reverse=True)
first = s[0]
second = s[1]
mx = []
for i in range(n):
    if a[i] == first:
        mx.append(second)
    else:
        mx.append(first)
for i in range(n):
    print(mx[i])
Buggy python submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())
ans = b - (b//c)
ans -= b//d
ans += b//((c*d)//math.gcd(c, d))
x = (a-1)-((a-1)//c)
x -= (a-1)//d
x += (a-1)//((c*d)//math.gcd(c,d))
ans -= x
print(ans)


Fixed submission:
import fractions
a, b, c, d = map(int, input().split())
ans = b - (b//c)
ans -= b//d
ans += b//((c*d)//fractions.gcd(c, d))
x = (a-1)-((a-1)//c)
x -= (a-1)//d
x += (a-1)//((c*d)//fractions.gcd(c,d))
ans -= x
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(m)]
cnt = [0]*n
for i in range(m):
    for j in range(lr[i][0]-1, lr[i][1]):
        cnt[j] += 1
ans = sum(i==m for i in cnt)
print(ans)


Fixed submission:
n, m = map(int, input().split())
left = 0
right = n+1
for i in range(m):
    l, r = map(int, input().split())
    left = max(left, l)
    right = min(right, r)
ans = 0
for i in range(left-1, right):
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]
def search(i, p):
    if p > n:
        print(-1)
        exit()
    elif i == 2:
        print(p)
        exit()
    else:
        search(a[i-1], p+1)

search(1, 0)


Fixed submission:
import sys
sys.setrecursionlimit(500*500)
n = int(input())
a = [int(input()) for _ in range(n)]
def search(i, p):
    if p > n:
        print(-1)
        exit()
    elif i == 2:
        print(p)
        exit()
    else:
        search(a[i-1], p+1)

search(1, 0)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]
def search(i, p):
    if p > n:
        print(-1)
        exit()
    if i == 2:
        print(p)
        exit()
    else:
        search(a[i-1], p+1)

search(1, 0)


Fixed submission:
import sys
sys.setrecursionlimit(500*500)
n = int(input())
a = [int(input()) for _ in range(n)]
def search(i, p):
    if p > n:
        print(-1)
        exit()
    elif i == 2:
        print(p)
        exit()
    else:
        search(a[i-1], p+1)

search(1, 0)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]
def search(i, p):
    if i == 2:
        print(p)
        exit()
    elif p > n:
        print(-1)
        exit()
    else:
        search(a[i-1], p+1)

search(1, 0)


Fixed submission:
import sys
sys.setrecursionlimit(500*500)
n = int(input())
a = [int(input()) for _ in range(n)]
def search(i, p):
    if p > n:
        print(-1)
        exit()
    elif i == 2:
        print(p)
        exit()
    else:
        search(a[i-1], p+1)

search(1, 0)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 1
for i in range(1, n+1):
    ans *= i
ans = ans % (10**9 + 7)
print(ans)


Fixed submission:
n = int(input())
ans = 1
for i in range(1, n+1):
    ans *= i
    ans = ans % (10**9 + 7)
ans = ans % (10**9 + 7)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k, s = list(map(int, input().split()))
ans = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if (x + y + z) == s:
                ans += 1
print(ans)


Fixed submission:
k, s = list(map(int, input().split()))
ans = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if 0 <= z and z <= k:
            ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = (int(i) for i in input().split())
p = list(map(int, input().split()))

ans = 0
for i in range(n-k+1):
    tmp = 0
    for j in range(i, i+k):
        tmp += (p[j]+1)/2

    if(ans < tmp):
        ans = tmp

print(ans)


Fixed submission:
n, k = (int(i) for i in input().split())
p = list(map(int, input().split()))

ans = 0
tmp = 0
for i in range(k):
    tmp += (p[i]+1)/2
ans = tmp
for i in range(1, n-k+1):
    tmp += -(p[i-1]+1)/2 + (p[i+k-1]+1)/2
    if(ans < tmp):
        ans = tmp

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
robots = []
for i in range(n):
    x_tmp, l_tmp = (int(i) for i in input().split())
    robots.append({'x': x_tmp, 'l': l_tmp})

robots_sorted = sorted(robots, key=lambda x: x['x'])
ans = n
i = 0
while((robots_sorted[0]['x'] + robots_sorted[0]['l']) > (robots_sorted[1]['x'] - robots_sorted[1]['l'])):
    if(robots_sorted[0]['l'] > robots_sorted[1]['l'] * 2):
        robots_sorted.pop(0)
    else:
        robots_sorted.pop(1)

while(i < n-1):
    if((robots_sorted[i]['x'] + robots_sorted[i]['l']) > (robots_sorted[i+1]['x'] - robots_sorted[i+1]['l'])):
        if(i == n-2):
            if(robots_sorted[n-2]['l'] * 2 >= robots_sorted[n-1]['l']):
                robots_sorted.pop(i)
            else:
                robots_sorted.pop(i+1)
        elif(robots_sorted[i]['l'] > robots_sorted[i+1]['l']):
            robots_sorted.pop(i)
        else:
            robots_sorted.pop(i+1)
        i += -1
        n += -1
    i += 1

print(n)


Fixed submission:
n = int(input())
robots = []
for i in range(n):
    x_tmp, l_tmp = (int(i) for i in input().split())
    robots.append([x_tmp - l_tmp, x_tmp + l_tmp])

robots.sort()
ans = n
right = robots[0][1]
for i in range(n-1):
    if(robots[i+1][0] < right):
        ans -= 1
        right = min(right, robots[i+1][1])
    else:
        right = robots[i+1][1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
robots = []
for i in range(n):
    x_tmp, l_tmp = (int(i) for i in input().split())
    robots.append({'x': x_tmp, 'l': l_tmp})

robots_sorted = sorted(robots, key=lambda x: x['x'])
ans = n
i = 0
while(i < n-1):
    if((robots_sorted[i]['x'] + robots_sorted[i]['l']) > (robots_sorted[i+1]['x'] - robots_sorted[i+1]['l'])):
        if(i == 0):
            if(robots_sorted[0]['l'] > robots_sorted[1]['l'] * 2):
                robots_sorted.pop(i)
            else:
                robots_sorted.pop(i+1)
        elif(i == n-2):
            if(robots_sorted[n-2]['l'] * 2 >= robots_sorted[n-1]['l']):
                robots_sorted.pop(i)
            else:
                robots_sorted.pop(i+1)
        elif(robots_sorted[i]['l'] > robots_sorted[i+1]['l']):
            robots_sorted.pop(i)
        else:
            robots_sorted.pop(i+1)
        i += -1
        n += -1
    i += 1

print(n)


Fixed submission:
n = int(input())
robots = []
for i in range(n):
    x_tmp, l_tmp = (int(i) for i in input().split())
    robots.append([x_tmp - l_tmp, x_tmp + l_tmp])

robots.sort()
ans = n
right = robots[0][1]
for i in range(n-1):
    if(robots[i+1][0] < right):
        ans -= 1
        right = min(right, robots[i+1][1])
    else:
        right = robots[i+1][1]
print(ans)
Buggy python submission (verdict: Runtime Error):
C = input()
print(chr(ord(C)+1)

Fixed submission:
C = input()
print(chr(ord(C)+1))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
a.extend(a)
for i in range(n):
    ans = 0
    k = 0
    for j in range(i,n+i):
        ans += a[j]*(-1)**k
        k += 1
    print(ans,end=" ")

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
a.extend(a)
ans = 0
k = 0
for i in range(n):
    ans += a[i]*(-1)**k
    k += 1
print(ans,end=" ")
for i in range(n-1):
    ans = 2*a[i]-ans 
    print(ans,end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
a.extend(a)
for i in range(n):
    ans = 0
    k = 0
    for j in range(i,n+i):
        ans += a[j]*(-1)**k
        k += 1
    print(ans,end=" ")

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
a.extend(a)
ans = 0
k = 0
for i in range(n):
    ans += a[i]*(-1)**k
    k += 1
print(ans,end=" ")
for i in range(n-1):
    ans = 2*a[i]-ans 
    print(ans,end=" ")
Buggy python submission (verdict: Runtime Error):
Import numpy as np

N,A,B=[int(i) for i in input().split()]
x=min(A,B)
if((A+B)>N):
    z=N
    y=abs(A+B-z)
else:
    y=0
print("{} {}".format(x,y))


Fixed submission:
import numpy as np

N,A,B=[int(i) for i in input().split()]
x=min(A,B)
if((A+B)>N):
    z=N
    y=abs(A+B-z)
else:
    y=0
print("{} {}".format(x,y))
Buggy python submission (verdict: Runtime Error):
x,y,z=[int(i) for i in range(input)]
print(x*y/2)

Fixed submission:
x,y,z=[int(i) for i in input().split()]
print(int(x*y/2))
Buggy python submission (verdict: Runtime Error):
a,b,c=[int(i) for i in input().split()]
if(a>b &&a>c):
  print(10*a+b+c)
elif(b>a &&  b>c):
  print(10*b+c+a)
else:
  print(a+b+10+c)

Fixed submission:
a=list(map(int,input().split()))
a.sort()
print(10*a[-1]+a[0]+a[1])
Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

N,X=[int(i) for i in input().split()]
a=input().split()
x=[]
for i in range(N):
    x.append(int(a[i]))
if(N==1):
    print(abs(x[0]-X))
    exit()
x=list(map(lambda y:abs(y-X) , x))
ans=gcd(x[0],x[1])
for i in range(2:N):
    ans=gcd(x[i],ans)
    
print(ans)


Fixed submission:
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

N,X=[int(i) for i in input().split()]
a=input().split()
x=[]
for i in range(N):
    x.append(int(a[i]))
if(N==1):
    print(abs(x[0]-X))
    exit()
x=list(map(lambda y:abs(y-X) , x))
ans=gcd(x[0],x[1])
for i in range(2,N):
    ans=gcd(x[i],ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

N,X=[int(i) for i in input().split()]
a=input().split()
x=[]
for i in range(N):
    x.append(int(a[i]))
if(N==1):
    print(abs(x[0]-X))
    exit()
x=list(map(lambda y:abs(y-X) , x))
x.sort()
print(math.gcd(x[0],x[1]))


Fixed submission:
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

N,X=[int(i) for i in input().split()]
a=input().split()
x=[]
for i in range(N):
    x.append(int(a[i]))
if(N==1):
    print(abs(x[0]-X))
    exit()
x=list(map(lambda y:abs(y-X) , x))
ans=gcd(x[0],x[1])
for i in range(2,N):
    ans=gcd(x[i],ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
N,X=[int(i) for i in input().split()]
a=input().split()
x=[]
for i in range(N):
    x.append(int(a[i]))
if(len(x)==1):
    print(abs(x[0]-X))
    exit()
xx=list(map(lambda y:abs(y-X) , x))
xx.sort()
print(math.gcd(xx[0],xx[1]))


Fixed submission:
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

N,X=[int(i) for i in input().split()]
a=input().split()
x=[]
for i in range(N):
    x.append(int(a[i]))
if(N==1):
    print(abs(x[0]-X))
    exit()
x=list(map(lambda y:abs(y-X) , x))
ans=gcd(x[0],x[1])
for i in range(2,N):
    ans=gcd(x[i],ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
N,X=[int(i) for i in input().split()]
a=input().split()
x=[]
for i in range(N):
    x.append(int(a[i]))
if(len(x)==1):
    print(abs(x[0]-X))
    exit()
x=list(map(lambda y:abs(y-X) , x))
x.sort()
print(math.gcd(x[0],x[1]))


Fixed submission:
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

N,X=[int(i) for i in input().split()]
a=input().split()
x=[]
for i in range(N):
    x.append(int(a[i]))
if(N==1):
    print(abs(x[0]-X))
    exit()
x=list(map(lambda y:abs(y-X) , x))
ans=gcd(x[0],x[1])
for i in range(2,N):
    ans=gcd(x[i],ans)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

n = list(map(int,input().split()))
r = list(map(int,input().split()))
t = int(input())

A = n[0]
V = n[1]

B = r[0]
W = r[1]

T = t

after_a = A + V * T
after_b = B + W * T

after_a_min = A - V * T
after_a_min = B - V * T
print(after_a)
print(after_b)

if after_a == after_b:
    print('YES')
    sys.exit()

if A < B and after_a > after_b:
    print('YES')
    sys.exit()

if A < B and after_a <= after_b:
    print('NO')
    sys.exit()


if A > B and after_a_min < after_b_min:
    print('YES')
    sys.exit()

if A > B and after_a_min >= after_b_min:
    print('NO')
    sys.exit()

Fixed submission:
import sys

n = list(map(int,input().split()))
r = list(map(int,input().split()))
t = int(input())

A = n[0]
V = n[1]

B = r[0]
W = r[1]

T = t

after_a = A + V * T
after_b = B + W * T

after_a_min = A - V * T
after_b_min = B - W * T

if (after_a == after_b) or (after_a_min == after_b_min):
    print('YES')
    sys.exit()

if A < B and after_a > after_b:
    print('YES')
    sys.exit()

if A < B and after_a < after_b:
    print('NO')
    sys.exit()


if A > B and after_a_min < after_b_min:
    print('YES')
    sys.exit()

if A > B and after_a_min > after_b_min:
    print('NO')
    sys.exit()

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

n = list(map(int,input().split()))
r = list(map(int,input().split()))
t = int(input())

A = n[0]
V = n[1]

B = r[0]
W = r[1]

T = t

after_a = A + V * T
after_b = B + W * T

if after_a == after_b:
    print('YES')
    sys.exit()

elif A < B and after_a > after_b:
    target = ['YES' if (A + V * i) - (B + W * i) == 0  else 'NO' for i in range(T)]
    pritn(target)

elif A > B and after_a < after_b:
    target = ['YES' if (A + V * i) - (B + W * i) == 0  else 'NO' for i in range(T)]

else:
    print('NO')
    sys.exit()

Fixed submission:
import sys

n = list(map(int,input().split()))
r = list(map(int,input().split()))
t = int(input())

A = n[0]
V = n[1]

B = r[0]
W = r[1]

T = t

after_a = A + V * T
after_b = B + W * T

after_a_min = A - V * T
after_b_min = B - W * T

if (after_a == after_b) or (after_a_min == after_b_min):
    print('YES')
    sys.exit()

if A < B and after_a > after_b:
    print('YES')
    sys.exit()

if A < B and after_a < after_b:
    print('NO')
    sys.exit()


if A > B and after_a_min < after_b_min:
    print('YES')
    sys.exit()

if A > B and after_a_min > after_b_min:
    print('NO')
    sys.exit()
Buggy python submission (verdict: Runtime Error):
n = int(input())
r = list(map(int,input().split()))

for i in range(n):
    if i == 0:
        x = r[i]
    else:
        x = x * r[i]
    
    if x >= 10**19:
        x = -1
        break

if x > 10**18:
        x = -1
print(int(x))

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

y = int(a[0]) * int(a[1])
print(y)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n = int(input())
r = list(map(int,input().split()))

lim = math.pow(10,18)

for i in range(n):
    if i == 0:
        x = r[i]
    else:
        x = x * r[i]

if x > lim:
    x = -1

print(int(x))

Fixed submission:
import math
n = int(input())
r = list(map(int,input().split()))

lim = math.pow(10,18)

for i in range(n):
    if i == 0:
        x = r[i]
    else:
        x = x * r[i]

    if x > 1000000000000000000:
        break

if x > 1000000000000000000:
    x = -1

if 0 in r:
    x = 0

print(math.floor(x))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
r = list(map(int,input().split()))
 
for i in range(n):
    if i == 0:
        x = r[i]
    else:
        x = x * r[i]
    
if x > 10**18:
    x = -1
 
print(int(x))

Fixed submission:
import math
n = int(input())
r = list(map(int,input().split()))

lim = math.pow(10,18)

for i in range(n):
    if i == 0:
        x = r[i]
    else:
        x = x * r[i]

    if x > 1000000000000000000:
        break

if x > 1000000000000000000:
    x = -1

if 0 in r:
    x = 0

print(math.floor(x))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
r = list(map(int,input().split()))

for i in range(n):
    if i == 0:
        x = r[i]
    else:
        x = x * r[i]
    
if x > 10**18:
    x = -1

print(int(x))

Fixed submission:
import math
n = int(input())
r = list(map(int,input().split()))

lim = math.pow(10,18)

for i in range(n):
    if i == 0:
        x = r[i]
    else:
        x = x * r[i]

    if x > 1000000000000000000:
        break

if x > 1000000000000000000:
    x = -1

if 0 in r:
    x = 0

print(math.floor(x))
Buggy python submission (verdict: Runtime Error):
import math
import decimal

r = list(map(float,input().split()))

x = decimal.Decimal(str(r[1])).quantize(Decimal('0'),rounding=ROUND_HALF_UP)
y = decimal.Decimal(str(r[1])).quantize(Decimal('0.01'),rounding=ROUND_HALF_UP)

z = x * y

z = math.floor(z)

print(z)

Fixed submission:
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

r = list(map(float,input().split()))

x = Decimal(str(r[0])).quantize(Decimal('0'),rounding=ROUND_HALF_UP)
y = Decimal(str(r[1])).quantize(Decimal('0.01'),rounding=ROUND_HALF_UP)

z = x * y

z = math.floor(z)

print(z)

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

r = list(map(float,input().split()))

x = decimal.Decimal(str(r[1])).quantize(Decimal('0'),rounding=ROUND_HALF_UP)
y = decimal.Decimal(str(r[1])).quantize(Decimal('0.01'),rounding=ROUND_HALF_UP)

z = x * y

z = math.floor(z)
if r[0] == 0 or r[1] == 0:
    z = int(0)

print(z)

Fixed submission:
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

r = list(map(float,input().split()))

x = Decimal(str(r[0])).quantize(Decimal('0'),rounding=ROUND_HALF_UP)
y = Decimal(str(r[1])).quantize(Decimal('0.01'),rounding=ROUND_HALF_UP)

z = x * y

z = math.floor(z)

print(z)

Buggy python submission (verdict: Runtime Error):
n = int(input())
r = list(map(int,input().split()))

lim = 10^18

for i in range(n):
    if i == 0:
        x = r[i]
    else:
        x = x * r[i]
    
    if x >= lim:
        x = -1
        break

if x > lim:
        x = -1
print(int(x))

Fixed submission:
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

r = list(map(float,input().split()))

x = Decimal(str(r[0])).quantize(Decimal('0'),rounding=ROUND_HALF_UP)
y = Decimal(str(r[1])).quantize(Decimal('0.01'),rounding=ROUND_HALF_UP)

z = x * y

z = math.floor(z)

print(z)
Buggy python submission (verdict: Runtime Error):
N = int(input())
As = [int(c) for c in input().split()]
counter = 0
w = 0


while w == 0:
    for i in range(N):
        if As[i] % 2 != 0:
            w = 1
        As[i] = int(As[i] / 2)
    counter += 1

print(counter)

Fixed submission:
s = input()
a = [int(c) for c in s]
print(sum(a))
Buggy python submission (verdict: Runtime Error):
S = input()
U = ['dreamer', 'dream', 'eraser', 'erase']

answer = 'NO'


def possible(current):
    possible = []
    for string in U:
        if S.startswith(current + string):
            possible.append(string)
    return possible


def judge(current):
    if current == S:
        global answer
        answer = 'YES'
        return
    if answer == 'YES':
        return
    else:
        if possible(current) == []:
            return
        else:
            for candidate in possible(current):
                new = current + candidate
                if len(S) >= len(new):
                    judge(current + candidate)


judge('')

print(answer)

Fixed submission:
S = input()
T = ''
U = ['dreamer', 'dream', 'eraser', 'erase']
answer = 'NO'
list = [T]
done = 0

while done == 0:
    for l in list:
        list.remove(l)
        for u in U:
            if S.startswith(l + u):
                if S == l + u:
                    answer = 'YES'
                    done = 1
                list.append(l + u)
    if list == []:
        done = 1
print(answer)

Buggy python submission (verdict: Runtime Error):
S = input()
T = ''
U = ['dreamer', 'dream', 'eraser', 'erase']

answer = 'NO'


def possible(current):
    possible = []
    for string in U:
        if S.startswith(current + string):
            possible.append(string)
    return possible


def judge(current):
    if current == S:
        global answer
        answer = 'YES'
        return
    if answer == 'YES' or len(S) < len(current):
        return
    else:
        if possible(current) == []:
            return
        else:
            for candidate in possible(current):
                new = current + candidate
                if len(S) >= len(new):
                    judge(current + candidate)


for string in U:
    judge(string)

print(answer)


Fixed submission:
S = input()
T = ''
U = ['dreamer', 'dream', 'eraser', 'erase']
answer = 'NO'
list = [T]
done = 0

while done == 0:
    for l in list:
        list.remove(l)
        for u in U:
            if S.startswith(l + u):
                if S == l + u:
                    answer = 'YES'
                    done = 1
                list.append(l + u)
    if list == []:
        done = 1
print(answer)
Buggy python submission (verdict: Runtime Error):
N,M = list(map(int,input().split()))
L = list(map(int,input().split()))#len(L) == N

p = sum(L)/(4*M)

cnt = 0
for i in range(N):
    if L[i] >= p:
        cnt += 1
if cnt >= M:
    print('Yes')
else:
    print('No')

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

l_1 = []
l_1.append(l_0[1])
l_1.append(l_0[0])
l_1.append(l_0[2])

l_2 = []
l_2.append(l_1[2])
l_2.append(l_1[1])
l_2.append(l_1[0])

print('{} {} {}'.format(l_2[0],l_2[1],l_2[2]))
Buggy python submission (verdict: Runtime Error):
import math
N,M = list(map(int,input().split()))

def combination(n,r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

ans = combination(N,2) + combination(M,2)

print(ans)

Fixed submission:
N,M = list(map(int,input().split()))
ans = (N*(N-1)//2) + (M*(M-1)//2)
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
N,M = list(map(int,input().split()))

def combination(n,r):
    return math.factorial(n)/(math.factorial(n-r)*math.factorial(r))

ans = combination(N,2) + combination(M,2)

print(ans)

Fixed submission:
N,M = list(map(int,input().split()))
ans = (N*(N-1)//2) + (M*(M-1)//2)
print(ans)
Buggy python submission (verdict: Runtime Error):
a = int(input()
print(a + a**2 + a**3)

Fixed submission:
a = int(input())
print(a + a**2 + a**3)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a_lst = list(map(int, input().split()))
a_lst.sort()
if n > k or k == 3:
    print(a_lst[0]+a_lst[1]+a_lst[2])
elif k == 2:
    print(a_lst[0]+a_lst[1])
else:
    print(a_lst[0])

Fixed submission:
n, k = map(int, input().split())
a_lst = list(map(int, input().split()))
a_lst.sort()

ans = 0

for i in range(k):
    ans += a_lst[i]
print(ans)