Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,m = map(int, raw_input().split())
n_list = [] #row major format
m_list = []
for i in range(0, n):
	n_list.append(raw_input())

for x in range(0, m):
	m_list.append(raw_input())

def match_first_rows(n_start):
	result = (-1,-1)
	first_m = m_list[0] # first row
	for x in range(n_start, n):
		n_row = n_list[x]
		if first_m in n_row: # substring matching of first m_row
			j = n_row.index(first_m)
			return (x, j)
	return (-1,-1) #return -1,-1 if none found

# given the leftmost corner of matching in matrix n, start matching each row to see if there is a potential match
# only guranteed first row match
def begin_matching(i,j):
	nx_start = i
	ny_start = j
	for x in range(0,m):
		n_row_string = n_list[nx_start+x]
		n_string = n_row_string[j:j+m] # align window
		m_string = m_list[x]
		if n_string!=m_string:
			return False
	return True

def find_m():

	found_m = False
	counter = 0
	while(counter<=n-m and not(found_m)):

		i,j = match_first_rows(counter)
		if i==-1: 
			#goes through entirety, not returning things at all
			print("No")
			found_m = True
		# found a potential starting point
		else:
			result = begin_matching(i,j)
			if result:
				print("Yes")
				found_m = True
			else:
				#do it again, but one row lower
				counter +=1 

find_m()

Fixed submission:
a,b = map(int, raw_input().split())

if a==b:
	print "Draw"
else:
	if a!=1 and b!=1:
		if a<b:
			print "Bob"
		else:
			print "Alice"
	elif a==1 and b!=1:
		print "Alice"
	else:
		print "Bob"

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

if a==b:
	print("Draw")
else:
	if a!=1 and b!=1:
		if a<b:
			print("Bob")
		else:
			print("Alice")
	elif a==1 and b!=1:
		print("Alice")
	else:
		print("Bob")

Fixed submission:
a,b = map(int, raw_input().split())

if a==b:
	print "Draw"
else:
	if a!=1 and b!=1:
		if a<b:
			print "Bob"
		else:
			print "Alice"
	elif a==1 and b!=1:
		print "Alice"
	else:
		print "Bob"

Buggy python submission (verdict: Runtime Error):
def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    a, b = input()
    if a == 1:
        a = 14
    if b == 1:
        b = 14

    if a == b:
        print('Draw')
    elif a > b:
        print('Alice')
    else:
        print('Bob')
 
main()


Fixed submission:
def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    a, b = reads()
    if a == 1:
        a = 14
    if b == 1:
        b = 14

    if a == b:
        print('Draw')
    elif a > b:
        print('Alice')
    else:
        print('Bob')
 
main()
Buggy python submission (verdict: Runtime Error):
def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    n, m = reads();
    g = [set() for _ in range(m)]
    for _ in range(m):
        a, b = reads()
        g[a - 1].add(b - 1)
        g[b - 1].add(a - 1)
    
    count = 0
    q = [(0, [])]
    while q:
        i, p = q.pop(0)
        if len(p) == (n-1):
            count += 1
        for e in g[i]:
            if e in p:
                continue
            pp = p[:]
            pp.append(i)
            q.append((e, pp))
    print(count)
 
main()


Fixed submission:
def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    n, m = reads();
    g = [set() for _ in range(n+1)]
    for _ in range(m):
        a, b = reads()
        g[a - 1].add(b - 1)
        g[b - 1].add(a - 1)
    
    count = 0
    q = [(0, [])]
    while q:
        i, p = q.pop(0)
        if len(p) == (n-1):
            count += 1
        for e in g[i]:
            if e in p:
                continue
            pp = p[:]
            pp.append(i)
            q.append((e, pp))
    print(count)
 
main()
Buggy python submission (verdict: Time Limit Exceeded):
def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    x = input()
    while 'ST' in x:
        x = x.replace('ST', '')
    print(len(x))

main()


Fixed submission:
def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    x = input()
    s = []
    for c in x:
    	if len(s) == 0:
    		s.append(c)
    	elif c == 'T' and s[-1] == 'S':
    		s.pop()
    	else:
    		s.append(c)
    print(len(s))
 
main()
Buggy python submission (verdict: Runtime Error):
, S = map(int, input().split())

all = []
for x in range(0,K+1):
	if S-x < 0:
		break
	for y in range(0, min(K,S-x)+1):
		z = S-x-y
		if z>-1:
			if z < K+1:
				all.append(str(x)+str(y)+str(z))
		else:
			break

print(len(all))

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

cnt = 0
for x in range(0,K+1):
	if S-x < 0:
		break
	for y in range(0, min(K,S-x)+1):
		z = S-x-y
		if z>-1:
			if z < K+1:
				cnt += 1
		else:
			break

print(cnt)

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

all = []
for x in range(0,K+1):
	if S-x < 0:
		break
	for y in range(0, min(K,S-x)+1):
		z = S-x-y
		if z>-1:
			if z < K+1:
				all.append(str(x)+str(y)+str(z))
		else:
			break

print(len(set(all)))

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

cnt = 0
for x in range(0,K+1):
	if S-x < 0:
		break
	for y in range(0, min(K,S-x)+1):
		z = S-x-y
		if z>-1:
			if z < K+1:
				cnt += 1
		else:
			break

print(cnt)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3

Alice, Bob = map(int, input())
if Alice == 1:
    Alice = 14
if Bob == 1:
    Bob = 14

if Alice > Bob:
    print('Alice')
elif Bob > Alice:
    print('Bob')
else:
    print('Draw')

Fixed submission:
#!/usr/bin/env python3

Alice, Bob = map(int, input().split())
if Alice == 1:
    Alice = 14
if Bob == 1:
    Bob = 14

if Alice > Bob:
    print('Alice')
elif Bob > Alice:
    print('Bob')
else:
    print('Draw')
Buggy python submission (verdict: Runtime Error):
x = input()
if x < 1200:
    print('ABC')
else:
    print('ARC')


Fixed submission:
x = int(input())
if x < 1200:
    print('ABC')
else:
    print('ARC')
Buggy python submission (verdict: Runtime Error):
s = raw_input()
words = []
for c in list(s):
    if c == 'B':
        words.pop()
    else:
        words.append(c)
print ''.join(words)

Fixed submission:
s = raw_input()
words = []
for c in list(s):
    if c == 'B':
        if len(words) > 0:
            words.pop()
    else:
        words.append(c)
print ''.join(words)
Buggy python submission (verdict: Runtime Error):
import sys
s = list(raw_input())
if len(s) == 2:
    if s[0] == s[1]:
        print 1, 2
    else
        print -1, -1
else:
    for n in [3]:
        for i in xrange(len(s) - n + 1):
            sub = s[i:i+n]
            for char in set(sub):
                if sub.count(char) >= n / 2 + n % 2:
                    print i + 1, i + n
                    sys.exit()
    print -1, -1


Fixed submission:
import sys
s = list(raw_input())
if len(s) == 2:
    if s[0] == s[1]:
        print 1, 2
    else:
        print -1, -1
else:
    for n in [3]:
        for i in xrange(len(s) - n + 1):
            sub = s[i:i+n]
            for char in set(sub):
                if sub.count(char) >= n / 2 + n % 2:
                    print i + 1, i + n
                    sys.exit()
    print -1, -1

Buggy python submission (verdict: Runtime Error):
import sys
s = list(raw_input())
if len(s) == 2:
    if s[0] == s[1]:
        print 1, 2
    else
        print -1, -1
else:
    for n in range(3, len(s)):
        for i in xrange(len(s) - n + 1):
            sub = s[i:i+n]
            for char in set(sub):
                if sub.count(char) >= n / 2 + n % 2:
                    print i + 1, i + n
                    sys.exit()
    print -1, -1


Fixed submission:
import sys
s = list(raw_input())
if len(s) == 2:
    if s[0] == s[1]:
        print 1, 2
    else:
        print -1, -1
else:
    for n in [3]:
        for i in xrange(len(s) - n + 1):
            sub = s[i:i+n]
            for char in set(sub):
                if sub.count(char) >= n / 2 + n % 2:
                    print i + 1, i + n
                    sys.exit()
    print -1, -1

Buggy python submission (verdict: Runtime Error):
import sys
s = list(raw_input())
if len(s) == 2:
    if s[0] == s[1]:
        print 1, 2
    else
        print -1, -1
else:
    for n in range(3, 100):
        for i in xrange(len(s) - n + 1):
            sub = s[i:i+n]
            for char in set(sub):
                if sub.count(char) >= n / 2 + n % 2:
                    print i + 1, i + n
                    sys.exit()
    print -1, -1


Fixed submission:
import sys
s = list(raw_input())
if len(s) == 2:
    if s[0] == s[1]:
        print 1, 2
    else:
        print -1, -1
else:
    for n in [3]:
        for i in xrange(len(s) - n + 1):
            sub = s[i:i+n]
            for char in set(sub):
                if sub.count(char) >= n / 2 + n % 2:
                    print i + 1, i + n
                    sys.exit()
    print -1, -1
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import argparse
import numpy as np

parser = argparse.ArgumentParser(description='Range Product')
parser.add_argument('a', type=int)
parser.add_argument('b', type=int)
args = parser.parse_args()

a = args.a
b = args.b

if a > 0 and b > 0:
    print 'Positive'
elif a < 0 and b < 0:
    if (b - a) % 2 == 0:
        print 'Negative'
    else:
        print 'Positive'
else:
    print 'Zero'

Fixed submission:
input = raw_input()
a, b = input.split()
a = int(a)
b = int(b)
if a > 0 and b > 0:
    print 'Positive'
elif a < 0 and b < 0:
    if (b - a) % 2 == 0:
        print 'Negative'
    else:
        print 'Positive'
else:
    print 'Zero'

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import argparse
import numpy as np

parser = argparse.ArgumentParser(description='Range Product')
parser.add_argument('a', type=int)
parser.add_argument('b', type=int)
args = parser.parse_args()

a = args.a
b = args.b

if a > 0 and b > 0:
    print 'Positive'
elif a < 0 and b < 0:
    if (b - a) % 2 == 0:
        print 'Negative'
    else:
        print 'Positive'
else:
    print 'Zero'

Fixed submission:
input = raw_input()
a, b = input.split()
a = int(a)
b = int(b)
if a > 0 and b > 0:
    print 'Positive'
elif a < 0 and b < 0:
    if (b - a) % 2 == 0:
        print 'Negative'
    else:
        print 'Positive'
else:
    print 'Zero'

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import argparse
import numpy as np

parser = argparse.ArgumentParser(description='Range Product')
parser.add_argument('a', type=int)
parser.add_argument('b', type=int)
args = parser.parse_args()

a = args.a
b = args.b

print a, b

if a > 0 and b > 0:
    print 'Positive'
elif a < 0 and b < 0:
    if (b - a) % 2 == 0:
        print 'Negative'
    else:
        print 'Positive'
else:
    print 'Zero'

Fixed submission:
input = raw_input()
a, b = input.split()
a = int(a)
b = int(b)
if a > 0 and b > 0:
    print 'Positive'
elif a < 0 and b < 0:
    if (b - a) % 2 == 0:
        print 'Negative'
    else:
        print 'Positive'
else:
    print 'Zero'
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())
ans = 0
for x in range(0,k+1):
  for y in range(0,k+1):
    for z in range(0,k+1):
      if x+y+z == s:
         ans+=1

print(ans)

Fixed submission:
k,s = map(int,input().split())
ans = 0
for x in range(0,k+1):
  for y in range(0,k+1):
    if s-x-y<=k and s-x-y>=0:
      ans+=1

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

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

dic = {}

for i in range(1, n + 1, 2):
    j = n - i
    dic[j] = 1 if j == 0 else 2

for i in a_lst:
    dic[i] -= 1

    if dic[i] < 0:
        print(0)
        sys.exit()

print(pow(2, n // 2) % (pow(10, 9) + 7))

Fixed submission:
import sys

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

dic = {}

for i in range(1, n + 1, 2):
    j = n - i
    dic[j] = 1 if j == 0 else 2

for i in a_lst:
    if i not in dic:
        print(0)
        sys.exit()

    dic[i] -= 1

    if dic[i] < 0:
        print(0)
        sys.exit()

print(pow(2, n // 2) % (pow(10, 9) + 7))
Buggy python submission (verdict: Time Limit Exceeded):
a, b, x = tuple(int(x) for x in input().split())

y = -1
for i in range(a, b + 1):
    if i % x == 0:
        y = i
        break

if y == -1:
    ans = 0
else:
    ans = (b - y) // x + 1

print(ans)


Fixed submission:
a, b, x = tuple(int(x) for x in input().split())

if a == 0:
    y = 0
else:
    y = x * ((a - 1) // x + 1)


if y == -1:
    ans = 0
else:
    ans = (b - y) // x + 1

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

k = 0
for item in arg_list:
    if item % 2 == 1 :
        k +=1
if k == 1:
    print('YES')
else:
    print('NO')
        

Fixed submission:
n = int(input())
a = map(int, input().split())
count = 0
for i in a:
    if i % 2 == 1:
        count += 1
print("YES" if count % 2 == 0 else "NO")
Buggy python submission (verdict: Runtime Error):
import math
from sympy import divisor_count
N = int(input())
N = math.factorial(N)
mod = 10**9+7

print(divisor_count(N) % mod)


Fixed submission:
inp = input()
a, b, c, d = inp.split(' ')

if int(a) * int(b) > int(c) * int(d):
    print(int(a) * int(b))
else:
    print(int(c) * int(d))
Buggy python submission (verdict: Runtime Error):
n = int(raw_input().split())

a = list(map(int, raw_input().split()))

p = map(lambda x : x % 2, a)
if p.count(1)%2 == 0 :
    print "YES"
else :
    print "NO"

Fixed submission:
n = int(raw_input())
 
a = list(map(int, raw_input().split()))
 
p = map(lambda x : x % 2, a)
if p.count(1)%2 == 0 :
    print "YES"
else :
    print "NO"

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

n = list(map(int, next(sys.stdin).split()))

if len(ns) == 1:
    print('YES')
    exit()

if sum(1 for n in ns if n % 2 == 1) % 2 == 0:
    print('YES')
else:
    print('NO')


Fixed submission:
import sys

next(sys.stdin)
ns = list(map(int, next(sys.stdin).split()))

if len(ns) == 1:
    print('YES')
    exit()

if sum(1 for n in ns if n % 2 == 1) % 2 == 0:
    print('YES')
else:
    print('NO')

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

if sum(for n in map(int, next(sys.stdin).split()) if n % 2 == 1) % 2 == 0:
    print('YES')
else:
    print('NO')


Fixed submission:
import sys

next(sys.stdin)
ns = list(map(int, next(sys.stdin).split()))

if len(ns) == 1:
    print('YES')
    exit()

if sum(1 for n in ns if n % 2 == 1) % 2 == 0:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys

next(sys.stdin)
n = np.array(list(map(int, next(sys.stdin).split())))
j = np.arange(len(n)) + 1

while True:
    if np.all(n == 0):
        print('YES')
        break

    k = n.argmin()
    n = np.hstack((n[k:], n[:k]))

    d = ((n[1:] - n[0]) // (j[1:] - j[0])).min()
    p = (n // j).min()
    t = min(d + 1, p)

    if t > 0:
        n -= j * t
    else:
        print('NO')
        break


Fixed submission:
import numpy as np
import sys

n = int(next(sys.stdin))
a = np.array(list(map(int, next(sys.stdin).split())))
j = np.arange(n) + 1

if np.any(a.sum() % j.sum() > 0):
    print('NO')
    exit()

s = a.sum() // j.sum()
k = s - (a[1:] - a[:-1])
if np.all(k >= 0) and np.all(k % n == 0):
    print('YES')
else:
    print('NO')

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys

next(sys.stdin)
n = np.array(list(map(int, next(sys.stdin).split())))
j = np.arange(len(n)) + 1

while True:
    k = n.argmin()
    n = np.hstack((n[k:], n[:k]))

    if np.all(n >= j):
        n -= j
    elif np.all(n == 0):
        print('YES')
        break
    else:
        print('NO')
        break


Fixed submission:
import numpy as np
import sys

n = int(next(sys.stdin))
a = np.array(list(map(int, next(sys.stdin).split())))
j = np.arange(n) + 1

if np.any(a.sum() % j.sum() > 0):
    print('NO')
    exit()

s = a.sum() // j.sum()
k = s - (a[1:] - a[:-1])
if np.all(k >= 0) and np.all(k % n == 0):
    print('YES')
else:
    print('NO')

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

next(sys.stdin)
n = list(map(int, next(sys.stdin).split()))

while True:
    k = min(range(len(n)), key=lambda k: n[k])
    n = n[k:] + n[:k]
    for k in range(1, len(n) + 1):
        if k <= n[k - 1]:
            n[k - 1] -= k
        else:
            print('NO')
            exit()
    if sum(n) == 0:
        print('YES')
        exit()


Fixed submission:
import numpy as np
import sys

n = int(next(sys.stdin))
a = np.array(list(map(int, next(sys.stdin).split())))
j = np.arange(n) + 1

if np.any(a.sum() % j.sum() > 0):
    print('NO')
    exit()

s = a.sum() // j.sum()
k = s - (a[1:] - a[:-1])
if np.all(k >= 0) and np.all(k % n == 0):
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import sys

people = defaultdict(set)

n, _ = map(int, next(sys.stdin).strip().split())

for i, line in enumerate(sys.stdin):
    _, *langs = line.strip().split()
    new = {i}
    for lang in langs:
        old = people[lang]
        new.update(old)
        for l in people.keys():
            if people[l] is old:
                people[l] = new

if len(next(people.values())) == n:
    print('YES')
else:
    print('NO')

Fixed submission:
import sys

next(sys.stdin)

_, *langs = map(int, next(sys.stdin).strip().split())
common_langs = set(langs)

unreachable = list()
for line in sys.stdin:
    _, *langs = map(int, line.strip().split())
    unreachable.append(set(langs))

change = True
while change:
    change = False
    for langs in unreachable:
        if len(common_langs & langs) > 0:
            s = len(common_langs)
            common_langs.update(langs)
            change |= not s == len(common_langs)
            langs.clear()
    unreachable = list(langs for langs in unreachable if len(langs) > 0)

if len(unreachable) == 0:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
w,h,n=map(int,raw_input().split())
x1=0,x2=w,y1=0,y2=h
for i in range(n):
    x,y,a=map(int,raw_input().split())
    if a==1: x1=max(x1,x)
    if a==2: x2=min(x2,x)
    if a==3: y1=max(y1,y)
    if a==4: y2=min(y2,y)
print max(0,x2-x1)*max(0,y2-y1)

Fixed submission:
w,h,n=map(int,raw_input().split())
x1,x2,y1,y2=0,w,0,h
for i in range(n):
    x,y,a=map(int,raw_input().split())
    if a==1: x1=max(x1,x)
    if a==2: x2=min(x2,x)
    if a==3: y1=max(y1,y)
    if a==4: y2=min(y2,y)
print max(0,x2-x1)*max(0,y2-y1)
Buggy python submission (verdict: Runtime Error):
import sys
s=raw_input()
flag=False
for j in range(s):
    if s[j]=='C':
        flag=True
    if s[j]=='F' and flag:
        print "Yes"
        sys.exit()
print "No"

Fixed submission:
import sys
s=raw_input()
flag=False
for j in range(len(s)):
    if s[j]=='C':
        flag=True
    if s[j]=='F' and flag:
        print "Yes"
        sys.exit()
print "No"
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n=int(raw_input())
a=map(int,raw_input().split())
b=sorted([(a[i],i+1) for i in range(n)])
s=[0,n+1]
ans=0
for c,j in b:
    k=bisect.bisect(s,j)
    ans+=c*(s[k]-j)*(j-s[k-1])
    s.insert(k,j)
print ans


Fixed submission:
n=int(raw_input())
a=map(int,raw_input().split())
def f():
    s=[(0,-1)]
    x=[0]*(n+1)
    for i,j in enumerate(a):
        while s[-1][0]>j:s.pop()
        x[j]=i-s[-1][1]
        s.append((j,i))
    return x
l=f()
a.reverse()
r=f()
print sum([i*l[i]*r[i] for i in a])

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n=int(raw_input())
a=map(int,raw_input().split())
b=sorted([(a[i],i+1) for i in range(n)])
s=[0,n+1]
ans=0
for c,j in b:
    k=bisect.bisect(s,j)
    ans+=c*(s[k]-j)*(j-s[k-1])
    bisect.insort(s,j)
print ans


Fixed submission:
n=int(raw_input())
a=map(int,raw_input().split())
def f():
    s=[(0,-1)]
    x=[0]*(n+1)
    for i,j in enumerate(a):
        while s[-1][0]>j:s.pop()
        x[j]=i-s[-1][1]
        s.append((j,i))
    return x
l=f()
a.reverse()
r=f()
print sum([i*l[i]*r[i] for i in a])
Buggy python submission (verdict: Runtime Error):
ii=lambda:map(int,raw_input().split())
n,k=ii()
T,F=True,False
e=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=ii()
    e[a-1]+=[b-1];e[b-1]+=[a-1]
cost=[0]*n
ans=10**5
def dfs(x,f):
    if f>=0:vis[f]=T
    q=[(x,0)]
    while len(q):
        v,c=q.pop(0)
        if c>k/2:break
        cost[v]=c;vis[v]=T
        for w in e[v]:
            if not vis[w]:q+=[(w,c+1)]
    return n-vis.count(T)
if k%2:
    for i in range(n):
        for j in e[i]:
            if i<j:vis=[F]*n;dfs(i,j);ans=min(ans,dfs(j,i))
else:
    for i in range(n):vis=[F]*n;ans=min(ans,dfs(i,-1))
print ans


Fixed submission:
n=int(raw_input())
a=map(int,raw_input().split())
a.sort()
print sum([a[2*i] for i in range(n)])
Buggy python submission (verdict: Runtime Error):
l = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    dx = a * (l[i+1] - l[i])
    if b < dx:
        ans += b
    else:
        ans += dx
print(ans)

Fixed submission:
n, a, b= map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    dx = a * (l[i+1] - l[i])
    if b < dx:
        ans += b
    else:
        ans += dx
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, x = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for i in range(n-1):
    while a[i] + a[i+1] > x:
        a[i+1] -= 1
        count += 1
print(count)

Fixed submission:
n, x = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for i in range(n-1):
    if a[i] + a[i+1] > x:
        y = a[i] + a[i+1] - x
        count += y
        a[i+1] = max(0, a[i+1]-y)
print(count)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
A, B = 0, 0
for i in range(n):
    x, y = int(input.split())
    dx, dy = 1, 1
    if A > x:
        dx = A // x
        if A % x != 0:
            dx += 1
    
    if B > y:
        dy = B // y
        if B % y != 0:
            dy += 1

    a = max(dx, dy)
    A, B = a * x, a * y
print(A + B)

Fixed submission:
n = int(input())
A, B = 0, 0
for i in range(n):
    x, y = map(int,input().split())
    dx, dy = 1, 1
    if A > x:
        dx = A // x
        if A % x != 0:
            dx += 1
    
    if B > y:
        dy = B // y
        if B % y != 0:
            dy += 1

    a = max(dx, dy)
    A, B = a * x, a * y
print(A + B)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = [input().split() for _ in range(n)]
ans = [0,0]
for i in range(n):
    ref_1 = int(l[i][0])
    ref_2 = int(l[i][1])
    for j in range(2,10**18-1):
        if (ans[0]>ref_1) or (ans[1]>ref_2):
            ref_1 = int(l[i][0])
            ref_2 = int(l[i][1])
            ref_1 *= j
            ref_2 *= j
        else:
            break

    ans[0], ans[1] = ref_1, ref_2
print(sum(ans))

Fixed submission:
n = int(input())
A, B = 0, 0
for i in range(n):
    x, y = map(int,input().split())
    dx, dy = 1, 1
    if A > x:
        dx = A // x
        if A % x != 0:
            dx += 1
    
    if B > y:
        dy = B // y
        if B % y != 0:
            dy += 1

    a = max(dx, dy)
    A, B = a * x, a * y
print(A + B)