Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c, k = map(int, input().split())

ans = 0
for i in range(k):
    if a != 0:
        ans += 1
        a += -1
        continue
    if b != 0:
        ans += 0
        b += -1
        continue
    if c != 0:
        ans += -1
        c += -1
        continue
print(ans)


Fixed submission:
a, b, c, k = map(int, input().split())

ans = 0

if a > k:
    ans += 1*k
    k = 0
else:
    ans += 1*a
    k -= a

if b > k:
    ans += 0*k
    k = 0
else:
    ans += 0*b
    k -= b

if c > k:
    ans += -1*k
    k = 0
else:
    ans += -1*c
    k -= c


print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a, b, c, k = map(int, input().split())

ans = 0
for i in range(k):
    if a != 0:
        ans += 1
        a += -1
        continue
    if b != 0:
        ans += 0
        b += -1
        continue
    if c != 0:
        ans += -1
        c += -1
        continue
print(ans)


Fixed submission:
a, b, c, k = map(int, input().split())

ans = 0

if a > k:
    ans += 1*k
    k = 0
else:
    ans += 1*a
    k -= a

if b > k:
    ans += 0*k
    k = 0
else:
    ans += 0*b
    k -= b

if c > k:
    ans += -1*k
    k = 0
else:
    ans += -1*c
    k -= c


print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,Y=map(int,input().split())

def main():
    for i in range(N+1):
        for j in range(N+1):
            for k in range(N+1):
                if i*10000+j*5000+k*1000==Y:
                    if i+j+k==N:
                        return i,j,k
    return -1,-1,-1
ans=main()
print(ans[0],ans[1],ans[2])

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

for i in range(N+1):
    for j in range(N-i+1):
        k=N-i-j
        if i*10000+j*5000+k*1000==Y:
            print(i,j,k)
            exit()
print(-1,-1,-1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = map(int, input().split(' '))

ans = 0
for i in range(0, n, 2):
  if l[i] % 2 == 1:
    ans += 1
print(ans)

Fixed submission:
n = int(input())
l = list(map(int, input().split(' ')))
 
ans = 0
for i in range(0, n, 2):
  if l[i] % 2 == 1:
    ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
input()
l = sorted(map(int, input().split(' ')))

answer = 0
spots = [l.pop()]

while l:
	n = l.pop()
	answer += spots[0]
	spots = spots[1:] + [n] * 2

print(answer)


Fixed submission:
input()
l = sorted(map(int, input().split(' ')))

answer = 0
spots = [l.pop()]
x = len(l)

for i in range(x):
	n = l.pop()
	answer += spots[i]
	spots.append(n)
	spots.append(n)

print(answer)
Buggy python submission (verdict: Runtime Error):
s = 0
q = int(n ** .5)
for i in range(1, int(n ** .5) + 1):
	x = n // i
	s += i * (x * (x+1)) / 2
	if x**2 != n:
		y = max(n // (i+1), q)
		s += (i * (i+1) // 2) * ((x * (x+1) // 2) - (y * (y+1) // 2))

print(int(s))

Fixed submission:
n = int(input())
s = 0
for i in range(1, n+1):
	x = n // i
	s += i * (x * (x+1)) / 2 
print(int(s))
Buggy python submission (verdict: Time Limit Exceeded):
X, N = map(int, input().split())
if N == 0:
  print(X)
  exit()
P = list(map(int, input().split()))
 
i = 0
while 1:
  for d in [-1, +1]:
    if not X+i*d in P:
      print(X+i*d)
      break
  i += 1

Fixed submission:
X, N = map(int, input().split())
if N == 0:
  print(X)
  exit()
P = list(map(int, input().split()))

i = 0
while 1:
  if not X-i in P:
    print(X-i)
    break
  if not X+i in P:
    print(X+i)
    break
  i += 1
Buggy python submission (verdict: Time Limit Exceeded):
from math import *

def gcd(x, y):
    while y != 0:
        (x, y) = (y, x % y)
    return x

n = int(input())
a = [int(x) for x in input().split()]

s = 1

for i in range(n):
    x = a[i]
    for z in range(2,int(sqrt(a[i])+1)):
        t = 1
        while(x%z==0):
            t *= z
            x /= z
        while(s%t != 0):
            s *= z
    if(x > 1 and s%x!=0):
        s *= x

k = 0
for i in a:
    k += s//i
    k %= (1000000000+7)

print(k%(1000000000+7))


Fixed submission:
from math import *

def gcd(x, y):
    while y != 0:
        (x, y) = (y, x % y)
    return x

def lcm(x,y):
    return x*y//gcd(x,y)
n = int(input())
a = [int(x) for x in input().split()]

mod = 1000000000+7

k = 1
for x in a:
    k = lcm(k,x)

ans = 0

for x in a:
    ans += k//x

print(ans%mod)
Buggy python submission (verdict: Runtime Error):
from math import gcd

a, b, c, d = map(int, input().split())

def not_devision(a, x, y):
    return (a - int(a/x)) + (a - int(a/y)) - (a - int(a/int((x*y)/gcd(x, y))))

print(not_devision(b, c, d) - not_devision(a-1, c, d))

Fixed submission:
a, b, c, d = map(int, input().split())

def gcd(a, b):
    while b != 0:
        a, b = b, a%b
    
    return a

def lcm(a, b):
    return a*b//gcd(a, b)

x = (b - (b//c)) + (b - (b//d)) - (b - (b//lcm(c, d)))
y = (a-1 - ((a-1)//c)) + (a-1 - ((a-1)//d)) - (a-1 - ((a-1)//lcm(c, d)))

print(x-y)

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

a, b, c, d = map(int, input().split())

def not_devision(a, x, y):
    return (a - (a//x)) + (a - (a//y)) - (a - (a//((x*y)//gcd(x, y))))

print(not_devision(b, c, d) - not_devision(a-1, c, d))

Fixed submission:
a, b, c, d = map(int, input().split())

def gcd(a, b):
    while b != 0:
        a, b = b, a%b
    
    return a

def lcm(a, b):
    return a*b//gcd(a, b)

x = (b - (b//c)) + (b - (b//d)) - (b - (b//lcm(c, d)))
y = (a-1 - ((a-1)//c)) + (a-1 - ((a-1)//d)) - (a-1 - ((a-1)//lcm(c, d)))

print(x-y)

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

a, b, c, d = map(int, input().split())

def not_devision(a, x, y):
    return (a - (a//x)) + (a - (a//y)) - (a - (a//((x*y)//gcd(x, y))))

print(not_devision(b, c, d) - not_devision(a-1, c, d))

Fixed submission:
a, b, c, d = map(int, input().split())

def gcd(a, b):
    while b != 0:
        a, b = b, a%b
    
    return a

def lcm(a, b):
    return a*b//gcd(a, b)

x = (b - (b//c)) + (b - (b//d)) - (b - (b//lcm(c, d)))
y = (a-1 - ((a-1)//c)) + (a-1 - ((a-1)//d)) - (a-1 - ((a-1)//lcm(c, d)))

print(x-y)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()
print(S[:K-1] + S[K-1].lower + S[K:])

Fixed submission:
N, K = map(int, input().split())
S = input()
print(S[:K-1] + S[K-1].lower() + S[K:])
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y)

def o3gcd(array):
    x = array[0]
    for y in array:
        x = gcd(x, y)

    return x

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

result = 0

for i in range(N):
    array = A[:i]
    array.extend(A[i+1:])
    x = o3gcd(array)

    result = max(result, x)

print(result)

Fixed submission:
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y)

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

L = [0]
for i in A:
    L.append(gcd(L[-1], i))

R = [0]
for i in range(N-1, -1, -1):
    R.append(gcd(R[-1], A[i]))
R.reverse()
M = []
for i in range(N):
    M.append(gcd(L[i], R[i+1]))

print(max(M))
Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())

result = A
for i in range(A+1, B+1):
    result ^= i

print(result)


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

array = []
bin_B = bin(B)[2:]
digit_B = len(bin_B)

if (A-1) % 4 == 1 or (A-1) % 4 == 2:
    if B % 4 == 1 or B % 4 == 2:
        array.append('0')
    else:
        array.append('1')
else:
    if B % 4 == 1 or B % 4 == 2:
        array.append('1')
    else:
        array.append('0')

for i in range(2, digit_B+1):
    num = 2 ** i
    if (A-1) % num < (num // 2) or ((A-1) % num) % 2 == 1:
        if B % num < (num // 2) or (B % num) % 2 == 1:
            array.append('0')
        else:
            array.append('1')
    else:
        if B % num < (num // 2) or (B % num) % 2 == 1:
            array.append('1')
        else:
            array.append('0')

array.reverse()
result = ''
for i in array:
    result += i

print(int(result, 2))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
 
result = 0
while True:
    if '01' in S:
        index = S.find('01')
        S = S[:index] + S[index+2:]
        result += 2
    elif '10' in S:
        index = S.find('10')
        S = S[:index] + S[index+2:]
        result += 2
 
    else:
        break
 
print(result)

Fixed submission:
S = input()
 
num_0 = S.count('0')
num_1 = S.count('1')

print(min(num_0, num_1) * 2)

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

result = 0
while True:
    if '01' in S:
        index = S.find('01')
        S = S[:index] + S[index+2:]
        result += 2
    elif '10' in S:
        index = S.find('10')
        S = S[:index] + S[index+2:]
        result += 2

    else:
        break

print(result)


Fixed submission:
S = input()
 
num_0 = S.count('0')
num_1 = S.count('1')

print(min(num_0, num_1) * 2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(max(int, input().split()))

def gcd(x, y):
  if x % y == 0:
    return y
  else:
    gcd(y, x % y)

num = A[0]
for i in range(1, N):
  num = gcd(max(num, A[i]), min(num, A[i]))

print(num)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
def gcd(x, y):
  if x % y == 0:
    return y
  else:
    return gcd(y, x % y)
 
num = A[0]
for i in range(1, N):
  num = gcd(max(num, A[i]), min(num, A[i]))
 
print(num)
Buggy python submission (verdict: Runtime Error):
N = int(input())
xyh = [list(map(int, input().split())) for _ in range(N)]

if N == 1:
    Cx, Cy, H = xyh[0][0], xyh[0][1], xyh[0][2]

elif N == 2:
    if xyh[0][2] > xyh[1][2]:
        Cx, Cy, H = xyh[0][0], xyh[0][1], xyh[0][2]
    else:
        Cx, Cy, H = xyh[1][0], xyh[1][1], xyh[1][2]

else:
    flag = False
    for i in range(101):
        for j in range(101):
            sampleH = xyh[0][2] + abs(i-xyh[0][0]) + abs(j-xyh[0][1])
            for k in range(1, N):
                flag = True
                if xyh[k][2] + abs(i-xyh[k][0]) + abs(j-xyh[k][1]) != sampleH:
                    flag = False
                    break
            if flag:
                Cx, Cy, H = i, j, sampleH
                break
        if flag:
            break

print(Cx, Cy, H)


Fixed submission:
N = int(input())
xyh = []
for _ in range(N):
    x, y, h = map(int, input().split())
    if h != 0:
        xyh.append([x, y, h])

if len(xyh) == 1:
    Cx, Cy, H = xyh[0][0], xyh[0][1], xyh[0][2]

elif len(xyh) == 2:
    if xyh[0][2] > xyh[1][2]:
        Cx, Cy, H = xyh[0][0], xyh[0][1], xyh[0][2]
    else:
        Cx, Cy, H = xyh[1][0], xyh[1][1], xyh[1][2]

else:
    flag = False
    for i in range(101):
        for j in range(101):
            sampleH = xyh[0][2] + abs(i-xyh[0][0]) + abs(j-xyh[0][1])
            for k in range(1, len(xyh)):
                flag = True
                if xyh[k][2] + abs(i-xyh[k][0]) + abs(j-xyh[k][1]) != sampleH:
                    flag = False
                    break
            if flag:
                Cx, Cy, H = i, j, sampleH
                break
        if flag:
            break

print(Cx, Cy, H)
Buggy python submission (verdict: Runtime Error):
from math import gcd
from functools import reduce

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
array = []
for i in range(N-1):
    array.append(x[i+1]-x[i])

if len(array) > 1:
    result = reduce(gcd, array)
else:
    result = array[0]
print(result)


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

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
array = []
for i in range(N):
    array.append(x[i+1]-x[i])

if len(array) > 1:
    result = gcd(array[0], array[1])
    for i in range(2, len(array)):
        result = gcd(result, array[i])
else:
    result = array[0]
    
print(result)

Buggy python submission (verdict: Runtime Error):
from fraction import gcd
from functools import reduce

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
array = []
for i in range(N-1):
    array.append(x[i+1]-x[i])

if len(array) > 1:
    result = reduce(gcd, array)
else:
    result = array[0]
print(result)


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

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.append(X)
x.sort()
array = []
for i in range(N):
    array.append(x[i+1]-x[i])

if len(array) > 1:
    result = gcd(array[0], array[1])
    for i in range(2, len(array)):
        result = gcd(result, array[i])
else:
    result = array[0]
    
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
counter = 0

for i in range(1, N+1):
    j = K - i
    while j <= 0:
        j += K
    while j <= N:
        k = K - i
        while k <= 0:
            k += K
        while k <= N:
            if (j+k) % K == 0 and (j+k) != 0:
                counter += 1
            k += K
        j += K

print(counter)


Fixed submission:
N, K = map(int, input().split())
result = (N//K)**3
if K % 2 == 0:
    if N-K*(N//K) < K/2:
        result += (N//K)**3
    else:
        result += ((N//K)+1)**3

print(result)
Buggy python submission (verdict: Runtime Error):
S = input()
K = int(input())
flag = True

for i in range(K):
    if S[i] != 1:
        print(S[i])
        flag = False

if flag:
    print(1)


Fixed submission:
S = input()
K = int(input())
flag = True

for i in range(K):
    if S[i] != '1':
        print(S[i])
        flag = False
        break

if flag:
    print(1)
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
s = [input() for _ in range(H)]
case = [[1, 0], [-1, 0], [0, 1], [0, -1]]
flag = True

for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            flag = False
            for k in range(4):
                x, y = i+case[k][0], j+case[k][1]
                if x < 0 or x >= H or y < 0 or y >= H:
                    continue
                if s[x][y] == '#':
                    flag = True
                    break
            if not flag:
                break
    if not flag:
        break

print('Yes' if flag else 'No')


Fixed submission:
H, W = map(int, input().split())
s = [input() for _ in range(H)]
case = [[1, 0], [-1, 0], [0, 1], [0, -1]]
flag = True

for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            flag = False
            for k in range(4):
                x, y = i+case[k][0], j+case[k][1]
                if x < 0 or x >= H or y < 0 or y >= W:
                    continue
                if s[x][y] == '#':
                    flag = True
                    break
            if not flag:
                break
    if not flag:
        break

print('Yes' if flag else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N-1)]

for i in range(N-1):
    result = 0
    for j in range(i, N-1):
        if result <= CSF[j][1]:
            result = CSF[j][0] + CSF[j][1]
        else:
            flag = True
            num = CSF[j][1] + CSF[j][2]
            while flag:
                if num >= result:
                    result = num + CSF[j][0]
                    flag = False
                num += CSF[j][2]

    print(result)

print(0)


Fixed submission:
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N-1)]

for i in range(N-1):
    result = 0
    for j in range(i, N-1):
        if result <= CSF[j][1]:
            result = CSF[j][0] + CSF[j][1]
        else:
            result = CSF[j][0] + CSF[j][1] + ((-((-(result-CSF[j][1]))//CSF[j][2])) * CSF[j][2])

    print(result)

print(0)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
T = [int(input()) for i in range(N)]
T.sort()
T.reverse()
result = T[0]

for i in range(1, N):
    a = 1
    while True:
        if (result * a) % T[i] == 0:
            result *= a
            break
        a += 1

print(result)


Fixed submission:
N = int(input())
T = [int(input()) for i in range(N)]
result = T[0]

for i in range(1, N):
    n = T[i]
    m = result
    while n % m != 0:
        m, n = n%m, m
    result = (result * T[i]) // m

print(result)
Buggy python submission (verdict: Runtime Error):
N = int(input())
s = [int(input()) for _ in range(N)]

result = sum(s)

if result % 10 == 0:
    while True:
        min_s = min(s)
        if min_s % 10 == 0:
            s.remove(min_s)
        else:
            result -= min_s
            break

print(result)


Fixed submission:
N = int(input())
s = [int(input()) for _ in range(N)]

result = sum(s)

if result % 10 == 0:
    for _ in range(N):
        min_s = min(s)
        if min_s % 10 == 0:
            s.remove(min_s)
        else:
            result -= min_s
            break

    if result % 10 == 0:
        result = 0

print(result)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
d = {}
array = []
for _ in range(N):
    a, b = map(int, input().split())
    if a in array:
        d[a] += b
    else:
        d[a] = b
        array.append(a)

array.sort()
counter = 0
for i in array:
    counter += d[i]
    if counter >= K:
        print(i)
        break

Fixed submission:
N, K = map(int, input().split())
array = [0 for _ in range(10**5)]
for _ in range(N):
    a, b = map(int, input().split())
    array[a-1] += b

num = 0
for i in range(len(array)):
    num += array[i]
    if num >= K:
        print(i+1)
        break
Buggy python submission (verdict: Runtime Error):
N = int(input())

array = []
r = 2
result = 11

while True:
    while True:
        if N % r == 0:
            array.append(r)
            N //= r
        else:
            break
    if N == 1:
        break

    r += 1

for i in range(2 ** len(array)):
    bin_i = bin(i)[2:]
    bin_i = '0' * (len(array) - len(bin_i)) + bin_i
    A = 1
    B = 1
    for j in range(len(bin_i)):
        if bin_i[j] == '1':
            A *= array[j]
        else:
            B *= array[j]

    result = min(result, max(len(str(A)), len(str(B))))

print(result)


Fixed submission:
N = int(input())
array = []

for i in range(1, int(N**0.5)+1):
    if N % i == 0:
        array.append(len(str(N//i)))

print(min(array))
Buggy python submission (verdict: Runtime Error):
x = int(input())

result = x // 11 * 2

if result % 11 == 0:
    print(result)

elif result % 11 < 6:
    print(result + 1)

else:
    print(reault + 2)


Fixed submission:
X=int(input())
d=X//11*2
m=X%11
if m>0:d+=1
if m>6:d+=1
print(d)
Buggy python submission (verdict: Runtime Error):
import sys
N = int(sys.stdin.readline())
a_list = list(map(int, sys.stdin.readline().split()))

result = 0
for index in range(N):
    if (index + 1) % 2 == 1:
        if a_list[index] % 2 == 1:
            result += 1
        
print(result)
        



Fixed submission:
import sys
L,R,d = map(int, sys.stdin.readline().split())
# L=5
# R=10
# d=2
result = 0
for index in range(L,R+1):
    if index % d == 0:
        result += 1
        
print(result)

Buggy python submission (verdict: Runtime Error):
import sys
L,R,d = int(sys.stdin.readline())
# L=5
# R=10
# d=2
result = 0
for index in range(L,R+1):
    if index % d == 0:
        result += 1
        
print(result)
        



Fixed submission:
import sys
L,R,d = map(int, sys.stdin.readline().split())
# L=5
# R=10
# d=2
result = 0
for index in range(L,R+1):
    if index % d == 0:
        result += 1
        
print(result)

Buggy python submission (verdict: Runtime Error):
N = int(input())
X = str(input())

def popcount(X):
  counter = 0
  for i in range(N):
    if X[i] == "1":
      counter += 1
  return counter

    
def converter(N,X):
  conv_counter = 0
  for i in range(N):
    conv_counter += int(X[i])*(2**((N-1)-i))
  return conv_counter

def decorder(N,X):
  #10進数のXをＮ桁の2進数に直す
  reslist = []
  for i in range(N):
    p = int(X) // 2**((N-1)-i)
    reslist.append(str(p))
    X = str(int(X) - p*(2**((N-1)-i)))
  #print("reslist",reslist)
  res = "".join(reslist)
  return res

def bit_change(X,P):
  LISTX = list(X)
  change_num = abs(int(X[P])-1)
  LISTX[P] = str(change_num)
  X = "".join(LISTX)
  return X


def main(N,X):
  for i in range(N):
    result = 0
    #二進数のBIT変換
    target = bit_change(X,i)
    #print("target",target)
    
    if converter(N,target) == 0:
      flag = 0
    else:
      flag = 1
    #print("flag:",flag)
    
    while flag == 1:
      result += 1
      pop_count = popcount(target)
      conv = converter(N,target)
      target_10 = conv % pop_count
      
      if target_10 == 0:
        flag = 0
        
      else:
        target = decorder(N,target_10)
	  
    print(result)
    
main(N,X)
    
#print(decorder(N,X))
    
  


Fixed submission:
S = input().split()

counter = 0
for _ in range (int(S[0]),int(S[1])+1):
  if _ % int(S[2]) == 0:
    counter += 1
  
print(counter)

Buggy python submission (verdict: Runtime Error):
S = int(input().split())
counter = 0
for _ in range (S[0],S[1]):
  if _ % S[2] == 0:
    counter += 1
  
print(counter)
    

Fixed submission:
S = input().split()

counter = 0
for _ in range (int(S[0]),int(S[1])+1):
  if _ % int(S[2]) == 0:
    counter += 1
  
print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
N = list(input())

N_rev = N[::-1]
#print(N_rev[1:5])

while len(N_rev) > 0:
  if N_rev[0] == "m" and N_rev[1] == "a" and N_rev[2] == "e" and N_rev[3] == "r" and N_rev[4] == "d":
      N_rev = N_rev[5:]
      #print("subscript[dream]",N_rev)
  elif N_rev[0] == "r" and N_rev[1] == "e" and N_rev[2] == "m" and N_rev[3] == "a" and N_rev[4] == "e" and N_rev[5] == "r" and N_rev[6] == "d":
      N_rev = N_rev[7:]
      #print("subscript[dreamer]",N_rev)
  elif N_rev[0] == "r" and N_rev[1] == "e" and N_rev[2] == "s" and N_rev[3] == "a" and N_rev[4] == "r" and N_rev[5] == "e":
      N_rev = N_rev[6:]
      #print("subscript[eraser]",N_rev)
      
  elif N_rev[0] == "e" and N_rev[1] == "s" and N_rev[2] == "a" and N_rev[3] == "r" and N_rev[4] == "e":
      N_rev = N_rev[5:]

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

if len(N_rev) == 0:
  print("YES")

Fixed submission:
import re
S = input()
'''
メタ文字：
^ = 文字列の先頭、
| = OR
+ = 直前のパターンを1回以上繰り返し、
$ = 文字列の末尾
'''
if re.match("^(dream|dreamer|erase|eraser)+$", S):
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N = list(input())


N_rev = N[::-1]
#print(N_rev)

while len(N_rev) > 0:
  if N_rev[0] == "m":
    if N_rev[1] == "a" and N_rev[2] == "e" and N_rev[3] == "r" and N_rev[4] == "d":
      N_rev = N_rev[5:]
      #print("subscript[dream]",N_rev)
    else:
      print("NO")
      sys.exit()
  elif N_rev[0] == "r":
    if N_rev[1] == "e" and N_rev[2] == "m" and N_rev[3] == "a" and N_rev[4] == "e" and N_rev[5] == "r" and N_rev[6] == "d":
      N_rev = N_rev[7:]
      #print("subscript[dreamer]",N_rev)
    elif N_rev[1] == "e" and N_rev[2] == "s" and N_rev[3] == "a" and N_rev[4] == "r" and N_rev[5] == "e":
      N_rev = N_rev[6:]
      #print("subscript[eraser]",N_rev)
    else:
      print("NO")
      sys.exit()
  elif N_rev[0] == "e":
    if N_rev[1] == "s" and N_rev[2] == "a" and N_rev[3] == "r" and N_rev[4] == "e":
      N_rev = N_rev[5:]
      #print("subscript[erase]",N_rev)
    else:
      print("NO")
      sys.exit()
  else:
    print("NO")
    sys.exit()

if len(N_rev) == 0:
  print("YES")


Fixed submission:
import re
S = input()
'''
メタ文字：
^ = 文字列の先頭、
| = OR
+ = 直前のパターンを1回以上繰り返し、
$ = 文字列の末尾
'''
if re.match("^(dream|dreamer|erase|eraser)+$", S):
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
from math import gcd
g=gcd(A,B)
print((A*B)//g)

Fixed submission:
A,B=map(int,input().split())
ans=1
for g in range(1,100000):
  if A%g==0 and B%g==0:
    ans=g
print((A*B)//ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=[]
pos={}
for i in range(ord('A'),ord('Z')+1):
  l.append(chr(i))
  pos[chr(i)]=len(l)-1
for i in input():
  print(l[(pos(i)+n)%26],end="")

Fixed submission:
n=int(input())
l=[]
pos={}
for i in range(ord('A'),ord('Z')+1):
  l.append(chr(i))
  pos[chr(i)]=len(l)-1
for i in input():
  print(l[(pos[i]+n)%26],end="")