Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03053 (python)

Fixed submission:
# coding: utf-8
#!/usr/bin/env python3

from collections import deque

# input
h, w = map(int, input().split())
a = [ list(input()) for _ in range(h) ]

# direction vector
dx, dy = [1, 0, -1, 0], [0, 1, 0, -1]

# 訪れたかどうかの情報を持つ bool 値
is_visited = [ [False for _ in range(w)] for __ in range(h) ]

q = deque()

for x in range(w):
    for y in range(h):
        if a[y][x] == "#":
            q.append( (x, y, 0) )
            is_visited[y][x] = True

while q:
    # queue の先頭を取り出す
    x, y, cnt = q.popleft()
    # 4方向にループ
    for i in range(4):
        nx, ny = x + dx[i], y + dy[i]

        if nx < 0 or w <= nx or ny < 0 or h <= ny or is_visited[ny][nx]:
            continue

        q.append( (nx, ny, cnt+1) )
        is_visited[ny][nx] = True

print(cnt)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())

dx = [ 0, -1, 0, 1 ]
dy = [ -1, 0, 1, 0 ]

a = [ list(input()) for _ in range(h) ]
ans = 0
while True:
    tmp = [ list("." *w) for _ in range(h) ]

    for y in range(h):
        for x in range(w):
            if a[x][y] == "#":
                tmp[x][y] = "#"
                for i in range(4):
                    nx = x+dx[i]
                    ny = y+dy[i]
                    if nx < 0 or ny < 0 or w <= nx or h <= ny:
                        continue
                    tmp[nx][ny] = "#"
    for y in range(h):
        for x in range(w):
            a[y][x] = tmp[y][x]

    ans += 1
    all_black = True
    for y in range(h):
        for x in range(w):
            if a[y][x] == ".":
                all_black = False
    if all_black:
        break

print(ans)
Problem p03054 (python)

Fixed submission:
h, w, n = map(int, input().split())
sr, sc = map(int, input().split())
s = input()
t = input()
sr -= 1; sc -= 1
 
L=0; R=w-1; U=0; D=h-1;
is_drop = False
for i in range(n)[::-1]:
    if t[i] == 'U': D = min(D+1, h-1)
    if t[i] == 'D': U = max(U-1, 0)
    if t[i] == 'L': R = min(R+1, w-1)
    if t[i] == 'R': L = max(L-1, 0)
    if s[i] == 'U': U += 1
    if s[i] == 'D': D -= 1
    if s[i] == 'L': L += 1
    if s[i] == 'R': R -= 1
    if R < L or D < U: is_drop = True
if (not L <= sc <= R) or (not U <= sr <= D):  is_drop = True

print( "NO" if is_drop else "YES" )

Buggy submission (verdict: Runtime Error):
h, w, n = map(int, input().split())
sr, sc = map(int, input().split())
s = input()
t = input()
sr -= 1; sc -= 1
 
L=0; R=w-1; U=0; D=h-1;
is_drop = False
for i in range(n)[::-1]:
    if t[i] == 'U': D = min(D+1, h-1)
    if t[i] == 'D': U = max(U-1, 0)
    if t[i] == 'L': R = min(R+1, w-1)
    if t[i] == 'R': L = max(L-1, 0)
    if s[i] == 'U': U++
    if s[i] == 'D': D--
    if s[i] == 'L': L++
    if s[i] == 'R': R--
    if R < L or D < U: is_drop = True
    if (not L <= sc <= R) or (not U <= sr <= D):  is_drop = True

print( "NO" if is_drop else "YES" )
Problem p03221 (python)

Fixed submission:
# coding: utf-8
# N : 県の数, M: 市の数
import bisect

N, M = map(int, input().split())
ps, ys = [], []

v = [ [] for _ in range(N+1) ]

for i in range(M):
    p, y = map(int, input().split())
    ps += [p]; ys += [y];
    v[p].append(y)

for i in range(N):
    v[i+1].sort()


for i in range(M):
    print("{:06d}".format(ps[i]), end="")
    print("{:06d}".format(bisect.bisect_left(v[ps[i]], ys[i])+1))

Buggy submission (verdict: Runtime Error):
def index_bin(l, x):
    n = len(l)
    b = 0
    e = n
    while(b != e):
        if x > l[(b+e)//2]:
            b = (b+e)//2 + 1
        else:
            e = (b+e)//2
    return b


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

P = []
Y = []
PY = [[] for _ in range(M)]


for i in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    PY[p-1].append(y)

for i in range(M):
    PY[i+1].sort()

for i in range(M):
    x = index_bin(PY[P[i]-1], Y[i]) + 1
    print("%06d%06d" % (P[i], x))
Problem p03774 (python)

Fixed submission:
import math

N, M = map(int, raw_input().split())

a, b, c, d = [], [], [], []

for i in xrange(N):
    s = map(int, raw_input().split())
    a.append(s[0])
    b.append(s[1])

for i in xrange(M):
    s = map(int, raw_input().split())
    c.append(s[0])
    d.append(s[1])


ans = 0
t = 0
for i in xrange(N):
    for j in xrange(M):
        if j == 0:
            t = abs(a[i]-c[j]) + abs(b[i]-d[j])
            ans = 1
        elif t > abs(a[i]-c[j]) + abs(b[i]-d[j]):
            t = abs(a[i]-c[j]) + abs(b[i]-d[j])
            ans = j+1
        #print "t = %d" % t
        #print "ans=%d" % ans
    print ans

Buggy submission (verdict: Runtime Error):
N, M = map(int, raw_input().split())

a, b = [map(int, raw_input().split()) for _ in xrange(N)]
c, d = [map(int, raw_input().split()) for _ in xrange(M)]

for i in xrange(N):
    for j in xrange(M):

        d = abs(a[i]-c[j]) + abs(b[i]-d[j])

        if j == 0:
            t = d
            ans = 1

        elif t > d:
            t = d
            ans = j+1

    print ans
Problem p03775 (python)

Fixed submission:
N = int(raw_input())
t = 1
for i in xrange(1, N):

    if i*i > N:
        break

    elif i*i == N:
        t = i
        break

    if N % i == 0:
        t = i

print max(len(str(t)), len(str(N/t)))

Buggy submission (verdict: Runtime Error):
N = int(raw_input())

for i in xrange(1, N):

    if i*i == N:
        t = i
        break

    elif i*i > N:
        break

    if N % i == 0:
        t = i

print len(str(N/t))

Buggy submission (verdict: Runtime Error):
N = int(raw_input())

for i in xrange(1, N):

    if i*i > N:
        break

    elif i*i == N:
        t = i
        break

    if N % i == 0:
        t = i

print len(str(N/t))

Buggy submission (verdict: Runtime Error):
N = int(raw_input())

for i in xrange(1, N):

    if i*i > N:
        break

    if N % i == 0:
        ans = len(str(N/i))

print ans

Buggy submission (verdict: Runtime Error):
N = int(raw_input())
t = 0
for i in xrange(1, N):

    if i*i > N:
        break

    elif i*i == N:
        t = i
        break

    if N % i == 0:
        t = i

print max(len(str(t)), len(str(N/t)))
Problem p03776 (python)

Fixed submission:
from math import factorial

def comb(n, k):
    f = factorial
    return f(n) / f(k) / f(n-k)

N, A, B = map(int, raw_input().split())
v = map(int, raw_input().split())

v.sort(reverse = True)

print float(sum(v[0:A]))/A

X, Y = 0, 0
ans = 0

for i in range(N):
    if (v[i] == v[A-1]):
        X += 1
    if (v[i] == v[A-1]) and (i < A):
        Y += 1

if (v[0] != v[A-1]):
    ans = comb(X, Y)

else:
    for i in range(A, B+1):
        if(i <= X):
            ans += comb(X, i)

print ans

Buggy submission (verdict: Runtime Error):
from math import factorial

N, A, B = map(int, raw_input().split())
v = map(int, raw_input().split())

C = [[0 for i in range(51)] for j in range(51)] #C[n][k] => nCk

for i in range(1, N+1):
    for j in rane(1, i+1):
        if (j == 0 or j == i):
            C[i][j] = 1
        else:
            C[i][j] = C[i-1][j-1] + C[i-1][j]

v.sort(reverse = True)

t = v[A-1]

ans = 0
X, Y = v.count(t), v[:A].count(t)

if (v[0] != v[A-1]):
    ans = C[X][Y]

else:
    for i in range(A, B+1):
        if(i <= X):
            ans += comb[X][i]

print float(sum(v[0:A]))/A
print ans
Problem p02835 (python)

Fixed submission:
a=list(map(int, input().split()))
if a[0]+a[1]+a[2]<=21:
  print('win')
elif a[0]+a[1]+a[2]>21:
  print('bust')

Buggy submission (verdict: Runtime Error):
a=input().split()
if a[0]+a[1]+a[2]<=21:
  print('win')
elif a[0]+a[1]+a[2]>21:
  print('bust')
Problem p02627 (python)

Fixed submission:
a = input()

if a.isupper():
    print('A')
else:
    print('a')

Buggy submission (verdict: Runtime Error):
a = input("insert a here")

if a.isupper():dfdf
    print('A')
else:
    print('a')
Problem p02546 (python)

Fixed submission:
import os,sys

s=input()
n=len(s)
if s[n-1]=='s':
    s=s+'es'
else:
    s=s+'s'

print(s)

Buggy submission (verdict: Runtime Error):
import os,sys
c=0

n=input()
for i in range(int(n)):
    m=input()
    one=m[0]
    two=m[2]
    if(one==two):
        c+=1
    
if(c>=3):
    print('Yes')
else:
    print('No')
Problem p02547 (python)

Fixed submission:
import os,sys
c=0
ok=False
n=input()
for i in range(int(n)):
    m=input()
    one=m[0]
    two=m[2]
    if one==two:
        c+=1
    else:
        c=0
    if c>=3:
        ok=True
    
if(ok):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import os,sys
c=0

n=input()
for i range(n):
    m=input()
    one=m[0]
    two=m[2]
    if(one==two):
        c+=1
    
if(c>=3):
    print('Yes')
else:
    print('No')
Problem p02819 (python)

Fixed submission:
x = int(input())
count=0
while count<1:
    ans=0
    for i in range(2,int(pow(x,0.5))):
        if x%i==0:
            ans+=1
            break
    if ans==0:
        count+=1
    else:
        x+=1
print(x)

Buggy submission (verdict: Runtime Error):
from sympy import nextprime
print(nextprime(int(input())))
Problem p02820 (python)

Fixed submission:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
ans =0
for i in range(n):
    if i<k:
        if t[i] =='r':
            ans+=p
        elif t[i] =='s':
            ans+=r
        else :
            ans+=s
    else:
        if t[i] =='r' and t[i-k]!='r':
            ans+=p
        elif t[i] =='s' and t[i-k]!='s':
            ans+=r
        elif t[i] =='p' and t[i-k]!='p':
            ans+=s
        else:
            t[i]='a'
            continue
print(ans)

Buggy submission (verdict: Runtime Error):
for i in range(n):
    if i<k:
        if t[i] =='r':
            ans+=p
        elif t[i] =='s':
            ans+=r
        else :
            ans+=s
    else:
        if t[i] =='r' and t[i-k]!='r':
            ans+=p
        elif t[i] =='s' and t[i-k]!='s':
            ans+=r
        elif t[i] =='p' and t[i-k]!='p':
            ans+=s
        else:
            t[i]='a'
            continue
print(ans)
Problem p02622 (python)

Fixed submission:
s = str(input())
t = str(input())
count = 0

for i in range(len(s)):
    if s[i] != t[i]:
        count += 1
        
print(count)

Buggy submission (verdict: Runtime Error):
def distance(x, y):
    return (x ** 2 + y ** 2) ** (1 / 2)


def main():
    n, d = map(int, input().split())
    xy_lst = [list(map(int, input().split())) for _ in range(n)]
    count = 0

    for i in range(n):
        x = xy_lst[i][0]
        y = xy_lst[i][1]
        if distance(x, y) <= d:
            count += 1

    print(count)


if __name__ == '__main__':
    main()
Problem p02629 (python)

Fixed submission:
def main():
    n = int(input())
    alp = 'abcdefghijklmnopqrstuvwxyz'
    answer = ''

    while n >= 1:
        n -= 1
        answer += alp[n % 26]
        n //= 26

    real_answer = ''
    for i in range(1, len(answer) + 1):
        real_answer += answer[-i]

    print(real_answer)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    abc = 'abcdefghijklmnopqrstuvwxyz'

    length = 1
    accumulation = 0
    while True:
        if n <= 26 ** length + accumulation:
            break
        else:
            accumulation += 26 ** length
            length += 1


    if length == 1:
        answer = abc[n - 1]

    else:
        lst = []
        for _ in range(length - 1):
             if n % 26 != 0:
                 tmp = n // (26 ** (length - 1))
             else:
                 tmp = (n - 1) // (26 ** (length - 1))

             lst.append(tmp)
             n -= (26 ** (length - 1) * tmp)
             length -= 1

        lst.append(n)

        answer = ''
        for i in range(len(lst)):
            number = lst[i]
            answer += abc[number - 1]


    print(answer)



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    abc = 'abcdefghijklmnopqrstuvwxyz'

    length = 1
    accumulation = 0
    while True:
        if n <= 26 ** length + accumulation:
            break
        else:
            accumulation += 26 ** length
            length += 1


    if length == 1:
        answer = abc[n - 1]

    else:
        lst = []
        for _ in range(length - 1):
             tmp = n // (26 ** (length - 1))
             lst.append(tmp)
             n -= (26 ** (length - 1) * tmp)
             length -= 1

        lst.append(n)

        answer = ''
        for i in range(len(lst)):
            number = lst[i]
            answer += abc[number - 1]


    print(answer)



if __name__ == '__main__':
    main()
Problem p02659 (python)

Fixed submission:
def main():
    a, b = input().split()
    a = int(a)
    b_1 = ''
    b_1 += b[0]
    b_1 += b[2:]
    b_1 = int(b_1)

    answer = (a * b_1) // 100
    print(answer)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    a, b = input().split()
    b = 100 * b

    answer = a * b // 100
    print(answer)


if __name__ == '__main__':
    main()
Problem p02779 (python)

Fixed submission:
n = int(input())
a_lst = list(map(int,input().split()))
new_lst = list(set(a_lst))

if len(a_lst)==len(new_lst):
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
ps_lst = [list(map(str,input().split())) for _ in range(m)]
ac_count = 0
wa_count = 0

ac_prolst = []
for i in range(len(ps_lst)):
    number = ps_lst[i][0]
    answer = ps_lst[i][1]
    if answer=='AC':
        ac_prolst.append(number)
ac_lst = list(set(ac_prolst))

ps_dic = {}
for i in range(m):
    number = ps_lst[i][0]
    if number in ac_lst:
        tmp_dic = {number: 'WA'}
        ps_dic.update(tmp_dic)

for i in range(m):
    number = ps_lst[i][0]
    answer = ps_lst[i][1]

    if number in ac_lst:
        if answer == 'AC' and ps_dic[number] == 'WA':
            ac_count += 1
            tmp_dic = {number: 'AC'}
            ps_dic.update(tmp_dic)
        elif answer == 'WA' and ps_dic[number] == 'WA':
            wa_count += 1

print('{} {}'.format(ac_count, wa_count))
Problem p02881 (python)

Fixed submission:
n = int(input())

need_lst = []
for i in range(1,int(n**(1/2)+1)):
    if n%i==0:
        need = i+n//i
        need_lst.append(need-2)

print(min(need_lst))

Buggy submission (verdict: Runtime Error):
n = int(input())

for i in range(2,int(n**(1/2)+1)):
    divisor_lst = []
    if n%i==0:
        j = n//i
        divisor_lst.append([i,j])

n_x = divisor_lst[-1][0]
n_y = divisor_lst[-1][1]

print(n_x+n_y-2)

Buggy submission (verdict: Runtime Error):
def prime_number(x):
    if x==2 or x==3:
        return True
    else:
        if x&2==0 or x%3==0:
            return False
        else:
            divisor_lst = [1,x]
            for i in range(1,x+1):
                if i%2!=0 and i%3!=0:
                    if i not in divisor_lst and x%i==0:
                        return False
                    break
            else:
                return True

n = int(input())

if prime_number(n):
    print(n-1)
else:
    i = 1
    j = n//i
    divisor_lst = []
    while i<=j:
        i += 1
        j = n//i
        if n%i==0:
            divisor_lst.append([i,j])

    n_x = divisor_lst[-1][0]
    n_y = divisor_lst[-1][1]
    print(n_x+n_y-2)

Buggy submission (verdict: Runtime Error):
def prime_number(x):
    if x==2 or x==3:
        return True
    else:
        if x&2==0 or x%3==0:
            return False
        else:
            divisor_lst = [1,x]
            for i in range(1,x+1):
                if i%2!=0 and i%3!=0:
                    if i not in divisor_lst and x%i==0:
                        return False
                        break
            else:
                return True

n = int(input())

if prime_number(n):
    print(n-1)
else:
    i = 1
    j = n//i
    divisor_lst = []
    while i<=j:
        i += 1
        j = n//i
        if n%i==0:
            divisor_lst.append([i,j])

    n_x = divisor_lst[-1][0]
    n_y = divisor_lst[-1][1]
    print(n_x+n_y-2)

Buggy submission (verdict: Runtime Error):
def prime_number(x):
    divisor_lst = [1,x]
    for i in range(1,x+1):
        if i not in divisor_lst and x%i==0:
            return False
        break
    else:
        return True

n = int(input())

if prime_number(n):
    print(n-1)
else:
    i = 1
    j = n//i
    divisor_lst = []
    while i<=j:
        i += 1
        j = n//i
        if n%i==0:
            divisor_lst.append([i,j])

    n_x = divisor_lst[-1][0]
    n_y = divisor_lst[-1][1]
    print(n_x+n_y-2)

Buggy submission (verdict: Runtime Error):
def prime_number(x):
    if x==2 or x==3:
        return True
    else:
        if x%2==0 or x%3==0:
            return False
        else:
            divisor_lst = [1,x]
            for i in range(1,x+1):
                if i not in divisor_lst and x%i==0:
                    return False
                    break
            else:
                return True

n = int(input())

if prime_number(n):
    print(n-1)
else:
    i = 1
    divisor_lst = []
    while i<=j:
        i += 1
        j = n//i
        if n%i==0:
            divisor_lst.append([i,j])

    n_x = divisor_lst[-1][0]
    n_y = divisor_lst[-1][1]
    print(n_x+n_y-2)
Problem p03137 (python)

Fixed submission:
n,m = map(int,input().split())
x_lst = list(map(int,input().split()))
x_lst.sort()

if n>=m:
    answer = 0
else:
    remainder_lst = []
    for i in range(m-1):
        x1 = x_lst[i]
        x2 = x_lst[i+1]

        remainder = x2 - x1
        remainder_lst.append(remainder)

    remainder1_lst = sorted(remainder_lst, reverse=True)
    delete = 0

    for i in range(n-1):
        remainder1 = remainder1_lst[i]
        delete += remainder1
    answer =  sum(remainder_lst) - delete

print(answer)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
x_lst = list(map(int,input().split()))
x_lst.sort()

if m==1:
    print(0)
else:
    remainder_lst = []
    for i in range(m-1):
        x1 = x_lst[i]
        x2 = x_lst[i+1]

        remainder = x2 - x1
        remainder_lst.append(remainder)

    remainder1_lst = sorted(remainder_lst, reverse=True)
    delete = 0

    if n==1:
        answer = sum(remainder_lst)
    else:
        for i in range(n-1):
            remainder1 = remainder1_lst[i]
            delete += remainder1
        answer = sum(remainder_lst) - delete

    print(answer)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
x_lst = list(map(int,input().split()))
x_lst.sort()

if m==1:
    print(0)
else:
    remainder_lst = []
    for i in range(m-1):
        x1 = x_lst[i]
        x2 = x_lst[i+1]

        remainder = x2 - x1
        remainder_lst.append(remainder)

    remainder1_lst = sorted(remainder_lst, reverse=True)
    delete = 0

    for i in range(n-1):
        remainder1 = remainder1_lst[i]
        delete += remainder1

    answer = sum(remainder_lst) - delete
    print(answer)
Problem p02546 (python)

Fixed submission:
s = input()
if s[-1] == 's':
  print(s+'es')
else:
  print(s+'s')

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
st = set([])
for i in range(k):
  x,y = map(int,input().split())
  for z in range(x,y+1):
    st.add(z)
ans = [1]
for i in range(1,n):
  s = 0
  for x in st:
    if i >= x:
      s = s + ans[i-x]
  ans.append(s % 998244353)   
  
print(ans[-1])
Problem p02570 (python)

Fixed submission:
d,t,s = map(int,input().split())
if d/s <= t:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
lst = list(map(int,input().split()))

l = lst[0]
g = lst[0]
pair_coprime = True
set_coprime = False
for i in range(1,n):
  if set_coprime == False:
    g = math.gcd(g,lst[i])
    if g == 1:
      set_coprime = True
      
  if pair_coprime == True:
    g_l = math.gcd(l,lst[i])
    if g_l == 1:
      l = l*lst[i]//g_l
    else:
      pair_coprime = False
    
if set_coprime == False:
  print('not coprime')
  
elif pair_coprime == False:
  print('setwize coprime')
else:
  print('pairwize coprime')
Problem p02597 (python)

Fixed submission:
n = int(input())
s = list(input())
num = 0
k = -1
for i in range(1,n):
  if i + k >= n-1:
    break
  if s[-i] == 'R':
    j = k+1
    while True:
      if j +i == n:
        k = j
        break
      if s[j] == 'W':
        s[j] = 'R'
        s[-i] = 'W'
        k = j
        num += 1
        break
      j += 1
      
print(num)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = list(input())
num = 0
k = -1
for i in range(1,n):
  if i + k >= n-1:
    break
  if s[-i] == 'R':
    j = k+1
    while True:
      if s[j] == 'W':
        s[j] = 'R'
        s[-i] = 'W'
        k = j
        num += 1
        break
      j += 1
    
print(num)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = list(input())
num = 0
k = -1
for i in range(1,n):
  if i + k == n:
    break
  if s[-i] == 'R':
    j = k+1
    while True:
      if s[j] == 'W':
        s[j] = 'R'
        s[-i] = 'W'
        k = j
        num += 1
        break
      j += 1
    
print(num)
Problem p02623 (python)

Fixed submission:
import sys
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b2 = []
t = k
start = 0
while True:
  if start == len(b):
    break
  else:
    if t - b[start] < 0:
      break
    else:  
      t -= b[start]
      b2.append(b[start])
      start += 1
num = start
lst = [start]
M = start

for i in range(len(a)):
  if a[i] > t and b2 == []:
    print(M)
    sys.exit()
  while a[i] > t and b2 != []:
    b_ = b2.pop()
    t = t+b_
    num -= 1
    
  if a[i] <= t:
    t -= a[i]
    num += 1
  
 
  if M < num:
    M = num
  lst.append(num)    
    
  
  
  
  
print(M)

Buggy submission (verdict: Runtime Error):
import sys
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
t = k
start = 0
while True:
  if start == len(b):
    break
  else:
    if t - b[start] < 0:
      break
    else:  
      t -= b[start]
      start += 1

num = start
lst = [0]
M = 0

for i in range(len(a)):
  while a[i] > t:
    b_ = b.pop()
    t = t+b_
    num -= 1
  t -= a[i]
  num += 1
  
 
  if lst[-1] < num:
    M = num
  lst.append(num)    
    
print(M)

Buggy submission (verdict: Runtime Error):
import sys
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
t = k
start = 0
while True:
  if start == len(b):
    break
  else:
    if t - b[start] < 0:
      break
    else:  
      t -= b[start]
      start += 1

num = start
lst = [0]
M = 0
print(start,t)
for i in range(len(a)):
  while a[i] > t:
    b_ = b.pop()
    t = t+b_
    num -= 1
  t -= a[i]
  num += 1
  print(num,t)
 
  if lst[-1] < num:
    M = num
  lst.append(num)    
    
print(M)
Problem p02695 (python)

Fixed submission:
import sys

n,m,q = map(int,input().split())
score = {}
for i in range(1,10):
  for j in range(2,11):
    score[(i,j)] = [0 for k in range(10)]
    
for i in range(q):
  a,b,c,d = map(int,input().split())
  score[(a,b)][c] = d


total = []
dic = {}
for i in range(m):
  dic[(i,)] = score[(1,2)][i]
total.append(dic)

if n == 2:
  print(max(score[(1,2)]))
  sys.exit()

M = []
for i in range(2,n):
  Max = 0
  d = {}
  for k in range(m):
    for tup in total[-1].keys():
      s = total[-1][tup]
      if tup[-1] <= k:
        for j in range(1,i):
          s += score[(j+1,i+1)][k-tup[j-1]] 
        s += score[(1,i+1)][k]  
        ky = tup + (k,)
        d[ky] = s
        if s > Max:
          Max = s
  total.append(d)
  M.append(Max)

print(M[-1])

Buggy submission (verdict: Runtime Error):
from collections import deque
n,m,q = map(int,input().split())
score = {}
for i in range(1,10):
  for j in range(2,11):
    score[(i,j)] = [0 for k in range(10)]
    
for i in range(q):
  a,b,c,d = map(int,input().split())
  score[(a,b)][c] = d


total = []
dic = {}
for i in range(m):
  dic[(i,)] = score[(1,2)][i]
total.append(dic)

M = []
for i in range(2,n):
  Max = 0
  d = {}
  for k in range(m):
    for tup in total[-1].keys():
      s = total[-1][tup]
      if tup[-1] <= k:
        for j in range(1,i):
          s += score[(j+1,i+1)][k-tup[j-1]] 
        s += score[(1,i+1)][k]  
        ky = tup + (k,)
        d[ky] = s
        if s > Max:
          Max = s
  total.append(d)
  M.append(Max)

print(M[-1])