Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
while True:
    x, y, z = map(int, raw_input().split())
    if x==0 and y==0 and z==0: break
    dp = [[0.0 for col in range(5101)] for row in range(61)]
    m = {}
    for i in range(y+10):
        m[i] = (0,0)
    v = []
    v = map(int, raw_input().split())
    for i in range(z):
        n, e, a = map(int, raw_input().split())
        m[n] = (e, a)
    dp[0][0] = 1.0
    for i in range(y):
        for j in range(5001):
            for k in range(x):
                nx = i + v[k]
                if m[nx][0] == 1:
                    dp[min(y,nx+m[nx][1])][j]+=dp[i][j]/x
                elif m[nx][0]==2:
                    dp[nx][j+m[nx][1]]+=dp[i][j]/x
                elif m[nx][0]==3:
                    dp[nx][max(0,j-m[nx][1])]+=dp[i][j]/x
                else:
                    dp[min(y,nx)][j] += dp[i][j]/x                       
    ans = 0.0
    for i in range(5001):   
        ans += dp[y][i]*i
    print int(ans) 

Fixed submission:
while True:
    x, y, z = map(int, raw_input().split())
    if x==0 and y==0 and z==0: break
    dp = [[0.0 for col in range(5101)] for row in range(61)]
    m = {}
    for i in range(y+10):
        m[i] = (0,0)
    v = []
    v = map(int, raw_input().split())
    for i in range(z):
        n, e, a = map(int, raw_input().split())
        m[n] = (e, a)
    dp[0][0] = 1.0
    for i in range(y):
        for j in range(y*100):
            if dp[i][j] == 0.0: continue
            for k in range(x):
                nx = i + v[k]
                if m[nx][0] == 1:
                    dp[min(y,nx+m[nx][1])][j]+=dp[i][j]/x
                elif m[nx][0]==2:
                    dp[nx][j+m[nx][1]]+=dp[i][j]/x
                elif m[nx][0]==3:
                    dp[nx][max(0,j-m[nx][1])]+=dp[i][j]/x
                else:
                    dp[min(y,nx)][j] += dp[i][j]/x                       
    ans = 0.0
    for i in range(5001):   
        ans += dp[y][i]*i
    print int(ans)
Buggy python submission (verdict: Runtime Error):
while True:
    n = input()
    if n == 0: break
    p = map(int, raw_input().strip().split(" "))
    j = map(int, raw_input().strip().split(" "))
    j.sort(); j.reverse();
    sum = 0; num = n;
    for m in p:
        sum += m
    for i in range(n):
        if (num-1)*(sum+j[i]) < num*sum: break
        num-=1; sum+=j[i]
    print num * sum

Fixed submission:
while True:
    n = input()
    if n == 0: break
    p = map(int, raw_input().strip().split(" "))
    j = map(int, raw_input().strip().split(" "))
    j.sort(); j.reverse();
    sum = 0; num = n;
    for m in p:
        sum += m
    for i in range(n-1):
        if (num-1)*(sum+j[i]) < num*sum: break
        num-=1; sum+=j[i]
    print num * sum
Buggy python submission (verdict: Runtime Error):
import sys
for s in sys.stdin:
 a,b=map(int,raw_input().split())
 print a-b

Fixed submission:
import sys
for s in sys.stdin:
 a,b=map(int,s.split())
 print a-b
Buggy python submission (verdict: Runtime Error):
l = [0 for i in range(20)]
pos = goal = 0
def solve(cur,sum):
    global pos, goal
    if cur == goal:
        print " ".join(map(str,l[:pos]))
        return
    for i in range(sum,0,-1):
        if cur + i <= goal:
            l[pos] = i
            pos += 1
            solve(cur+i,i)
            pos -= 1
while True:
    goal = int(raw_input())
    if goal==0: break
    solve(0,goal)

Fixed submission:
l = [0]*31
pos = goal = 0
def solve(sum,cur):
    global pos, goal
    if sum == goal:
        print " ".join(map(str,l[:pos]))
        return
    for i in range(cur,0,-1):
        if sum + i <= goal:
            l[pos] = i
            pos += 1
            solve(sum+i,i)
            pos -= 1
while True:
    goal = int(raw_input())
    if goal == 0: break
    solve(0,goal)
Buggy python submission (verdict: Runtime Error):
while True:
    l = map(int, raw_input().split())
    if l[0]==0 and l[1]==0 and l[2]==0: break
    n = l[0]+l[1]+l[2]
    s = [] #????¨????
    a = set(range(n)) #??????
    b = set() #?£????
    c = set() #??£???
    for i in range(input()):
        x, y, z, r = map(int, raw_input().split())
        x-=1;y-=1;z-=1;
        if r==0: s.append(set([x,y,z]))
        else:
            c.add(x);c.add(y);c.add(z);
    while True:
        f = True
        for lst in s:
            if len(lst & c) >=2:
                s.remove(lst)
                lst = lst - c
                b.add(lst.pop())
                f = False
        if f : break
    a = a - b; a = a - c;
    for i in range(n):
        if i in a: print 2
        elif i in b: print 0
        else: print 1

Fixed submission:
while True:
    i,j,k = map(int, raw_input().split())
    if i==0 and j==0 and k==0: break
    n = i+j+k
    s = []
    a = set(range(n))
    b = set()
    c = set()
    for i in range(input()):
        x, y, z, r = map(int, raw_input().split())
        x-=1;y-=1;z-=1;
        if r==0: s.append(set([x,y,z]))
        else:
            c.add(x);c.add(y);c.add(z);
    while True:
        f = True
        for lst in s:
            if len(lst & c) >=2:
                s.remove(lst)
                lst = lst - c
                if len(lst)>=1: b.add(lst.pop())
                f = False
        if f : break
    a = a - b; a = a - c;
    for i in range(n):
        if i in a: print 2
        elif i in b: print 0
        else: print 1

Buggy python submission (verdict: Runtime Error):
while True:
    l = map(int, raw_input().split())
    if l[0]==0 and l[1]==0 and l[2]==0: break
    n = l[0]+l[1]+l[2]
    s = [] #????¨????
    a = set(range(n)) #??????
    b = set() #?£????
    c = set() #??£???
    for i in range(input()):
        x, y, z, r = map(int, raw_input().split())
        x-=1;y-=1;z-=1;
        if r==0: s.append(set([x,y,z]))
        else:
            c.add(x);c.add(y);c.add(z);
    while True:
        f = True
        for lst in s:
            if len(lst & c) >=2:
                s.remove(lst)
                lst = lst - c
                if len(lst)>=1: b.add(lst.pop())
                f = False
        if f : break
    a = a - b; a = a - c;
    for i in range(n):
        if i in a: print 2
        elif i in b: print 0
        else: print 1

Fixed submission:
while True:
    i,j,k = map(int, raw_input().split())
    if i==0 and j==0 and k==0: break
    n = i+j+k
    s = []
    a = set(range(n))
    b = set()
    c = set()
    for i in range(input()):
        x, y, z, r = map(int, raw_input().split())
        x-=1;y-=1;z-=1;
        if r==0: s.append(set([x,y,z]))
        else:
            c.add(x);c.add(y);c.add(z);
    while True:
        f = True
        for lst in s:
            if len(lst & c) >=2:
                s.remove(lst)
                lst = lst - c
                if len(lst)>=1: b.add(lst.pop())
                f = False
        if f : break
    a = a - b; a = a - c;
    for i in range(n):
        if i in a: print 2
        elif i in b: print 0
        else: print 1
Buggy python submission (verdict: Time Limit Exceeded):
while 1:
    n = input()
    if n == 0: break
    p = [map(int, raw_input().split()) for i in range(n)]
    ans = 0
    for i in range(n):
        for j in range(i,n):
            x  = p[j][0]
            y  = p[j][1]
            mx = x - p[i][0]
            my = y - p[i][1]
            if [x+my, y-mx] in p:
                if [x+my-mx, y-mx-my] in p:        
                    ans = max(ans, mx**2 + my**2)
    print ans

Fixed submission:
while 1:
    n = input()
    if n == 0: break
    p = set([tuple(map(int, raw_input().split())) for i in range(n)])
    ans = 0
    for x1, y1 in p:
        for x2, y2 in p:
            mx = x2 - x1
            my = y2 - y1
            if mx==0 and my==0: continue
            if (x2+my, y2-mx) in p:
                if(x2+my-mx, y2-mx-my) in p:
                    ans = max(ans, mx**2 + my**2)
    print ans
Buggy python submission (verdict: Runtime Error):
while 1:
    n = 1000 - input()
    if n==0:break
    m = [500,100,50,10,5,1]
    for i in range(6):
        x = n / m[i]; n -= m[i] * x; m[i] = x;
    print reduce(lambda a, x: a+x, m)

Fixed submission:
while 1:
    n = 1000-input()
    if n==1000:break
    m = [500,100,50,10,5,1]
    for i in range(6):
        m[i],n = divmod(n,m[i])
    print reduce(lambda a, x: a+x, m)
Buggy python submission (verdict: Runtime Error):
import numpy as np
while 1:
    n = input()
    if n == 0: break
    p = np.array(sorted([map(int, raw_input().split()) for i in range(n)]))
    dist = [p[i] - p[0] for i in range(1,n)]
    m = input()
    q = np.array(sorted([map(int, raw_input().split()) for i in xrange(m)]))
    for p1 in q:
        for i in range(n-1):
            f = True
            for p2 in q:
                if np.all(p1 + dist[i] == p2):
                    f = False
                    break
            if f: break
        else:
            print p1[0] - p[0][0], p1[1] - p[0][1]

Fixed submission:
while 1:
    n = input()
    if n == 0: break
    p = set([tuple(map(int, raw_input().split())) for i in range(n)])
    m = input()
    q = set([tuple(map(int, raw_input().split())) for i in xrange(m)])
    ret = False
    for px, py in p:
        if ret: break
        for qx, qy in q:
            if ret: break
            dx = qx - px
            dy = qy - py
            for x, y in p:
                mx = x + dx
                my = y + dy
                if (mx, my) not in q:
                    break
            else:
                print dx, dy
                ret = True

Buggy python submission (verdict: Time Limit Exceeded):
while 1:
    n = input()
    if n == 0: break
    p = sorted([map(int, raw_input().split()) for i in range(n)])
    d = [[p[i][0] - p[0][0], p[i][1] - p[0][1]] for i in range(1,n)]
    m = input()
    q = sorted([map(int, raw_input().split()) for i in xrange(m)])
    for p1 in q:
        for i in range(n-1):
            f = True
            for p2 in q:
                if p1[0] + d[i][0] == p2[0] and p1[1] + d[i][1] == p2[1]:
                    f = False
                    break
            if f: break
        else:
            print p1[0] - p[0][0], p1[1] - p[0][1]

Fixed submission:
while 1:
    n = input()
    if n == 0: break
    p = set([tuple(map(int, raw_input().split())) for i in range(n)])
    m = input()
    q = set([tuple(map(int, raw_input().split())) for i in xrange(m)])
    ret = False
    for px, py in p:
        if ret: break
        for qx, qy in q:
            if ret: break
            dx = qx - px
            dy = qy - py
            for x, y in p:
                mx = x + dx
                my = y + dy
                if (mx, my) not in q:
                    break
            else:
                print dx, dy
                ret = True
Buggy python submission (verdict: Time Limit Exceeded):
while 1:
    r, c = map(int, raw_input().split())
    if r == 0: break
    old = [None for i in range(r)]
    new = [[True]*c for i in range(r)]
    for i in range(r):
        old[i] = "".join(map(str, raw_input().split()))
    ans = 0
    n = 1<<r
    for i in range(n):
        for j in range(r):
            if i & (1<<j):
                for k in range(c):
                    new[j][k] = bool(int(old[j][k])) ^ True
            else:
                for k in range(c):
                    new[j][k] = bool(int(old[j][k]))
        ret = 0
        for j in range(c):
            cnt = 0
            for k in range(r):
                if not new[k][j]: cnt+=1
            ret += cnt if cnt > r/2 else r-cnt
        ans = max(ans, ret)
    print ans

Fixed submission:
while 1:
    r, c = map(int, raw_input().split())
    if r == 0: break
    old = [raw_input().split() for i in range(r)]
    old = map(list, zip(*old))
    new = [int("".join(lst),2) for lst in old]
    ans = 0
    for i in range(1<<r):
        ret = 0
        for j in new:
            cnt = bin(i^j).count('1')
            ret += cnt if cnt > r/2 else r-cnt
        ans = max(ans, ret)
    print ans
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import *
while 1:
    n, lmt = map(int, raw_input().split())
    if n == 0: break
    p = [input() for i in range(n)]
    p = sorted(set(i + j for i in p for j in p))
    s = bisect(p, lmt)
    ans = 0
    for i in p[:s]:
        t = bisect(p[:s], lmt - i)
        ans = max(ans, i + p[t-1])
    print ans

Fixed submission:
from bisect import *
while 1:
    n, lmt = map(int, raw_input().split())
    if n == 0: break
    p = [input() for i in range(n)] + [0]
    p = sorted(set(i + j for i in p for j in p))
    s = bisect(p, lmt)
    print max(i + p[bisect(p, lmt - i) - 1] for i in p[:s])

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import *
while 1:
    n, lmt = map(int, raw_input().split())
    if n == 0: break
    p = [input() for i in range(n)] + [0]
    p = sorted(set(i + j for i in p for j in p))
    s = bisect(p, lmt)
    ans = 0
    for i in p[:s]:
        t = bisect(p[:s], lmt - i)
        ans = max(ans, i + p[t-1])
    print ans

Fixed submission:
from bisect import *
while 1:
    n, lmt = map(int, raw_input().split())
    if n == 0: break
    p = [input() for i in range(n)] + [0]
    p = sorted(set(i + j for i in p for j in p))
    s = bisect(p, lmt)
    print max(i + p[bisect(p, lmt - i) - 1] for i in p[:s])

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import *
while 1:
    n, lmt = map(int, raw_input().split())
    if n == 0: break
    p = [input() for i in range(n)] + [0]
    p = sorted(set(i + j for i in p for j in p))
    s = bisect(p, lmt)
    print max(i + p[bisect(p[:s], lmt - i) - 1] for i in p[:s])

Fixed submission:
from bisect import *
while 1:
    n, lmt = map(int, raw_input().split())
    if n == 0: break
    p = [input() for i in range(n)] + [0]
    p = sorted(set(i + j for i in p for j in p))
    s = bisect(p, lmt)
    print max(i + p[bisect(p, lmt - i) - 1] for i in p[:s])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
while 1:
    c = input()
    r = input()
    if c == 0: break
    l = [map(int, raw_input().split()) for i in range(r)]
    ans = 0
    d = [(-1,0),(0,-1),(1,0),(0,1)]
    for i in range(c):
        for j in range(r):
            q = deque()
            a = [[0]*c for x in range(r)]
            if l[j][i] == 0: continue
            a[j][i] = 1
            q.append((j,i))
            while len(q) != 0:
                cy, cx = q.popleft()
                for x, y in d:
                    dx = x + cx; dy = y + cy;
                    if 0<=dx<c and 0<=dy<r and a[dy][dx] == 0 and l[dy][dx] == 1:
                        q.append((dy, dx))
                        a[dy][dx] = a[cy][cx] + 1
            for i in range(c):
                for j in range(r):
                    ans = max(ans, a[j][i])
    print ans

Fixed submission:
while 1:
    c = input()
    r = input()
    if c == 0: break        
    l = [map(int, raw_input().split()) for i in range(r)]
    ans = 0
    d = [(-1,0),(0,-1),(1,0),(0,1)]
    def dfs(j, i, cnt):
        global ans
        ans = max(ans, cnt)
        for x, y in d:
            dx = x + i; dy = y + j
            if 0<=dx<c and 0<=dy<r and l[dy][dx]:
                l[dy][dx] = False
                dfs(dy, dx, cnt+1)
                l[dy][dx] = True
    for i in range(c):
        for j in range(r):
            if l[j][i]:
                l[j][i] = False
                dfs(j,i,1)
                l[j][i] = True
    print ans
Buggy python submission (verdict: Time Limit Exceeded):
from string import find
while 1:
    n = input()
    if n == 0: break
    m = input()
    s = raw_input()
    t = "IOI"
    for i in range(n-1):
        t += "OI"
    i = ans = 0
    while 1:
        tmp = find(s[i:-1], t)
        if tmp < 0: break
        i += tmp + 1
        ans += 1
    print ans

Fixed submission:
while 1:
    n = input()
    if n == 0: break
    m = input()
    s = raw_input()
    t = "IOI" + "OI"*(n-1)
    t_len = 3 + 2 *(n-1)
    ans = 0
    for i in range(m - t_len + 1):
        if s[i:i+t_len] == t: ans += 1
    print ans
Buggy python submission (verdict: Runtime Error):
DIV = 100000
n, m = map(int, raw_input().split())
l = [input() for _ in range(n-1)]
ans = [0]*(n-1)
pos = 0
for _ in range(m):
    k = input()
    if k > 0:
        for i in range(k): ans[pos+i] += 1
    else:
        for i in range(-1, k-1, -1):       
            ans[pos+i] += 1
    pos += k
print sum((ans[i] * l[i]) % DIV for i in range(n-1)) % DIV

Fixed submission:
DIV = 100000
n, m = map(int, raw_input().split())
l = [0]*n
for i in range(n-1):
    k = input()
    l[i+1] = l[i] + k
ans = pos = 0
for _ in xrange(m):
    k = input()
    ans = (ans + abs(l[pos + k] - l[pos])) % DIV
    pos += k
print ans

Buggy python submission (verdict: Runtime Error):
DIV = 100000
n, m = map(int, raw_input().split())
l = [input() for _ in range(n-1)]
ans = [0]*(n-1)
pos = 0
for _ in xrange(m):
    k = input()
    if k > 0:
        for i in xrange(k): ans[pos+i] += 1
    else:
        for i in xrange(-1, k-1, -1):       
            ans[pos+i] += 1
    pos += k
print sum((ans[i] * l[i]) % DIV for i in xrange(n-1)) % DIV

Fixed submission:
DIV = 100000
n, m = map(int, raw_input().split())
l = [0]*n
for i in range(n-1):
    k = input()
    l[i+1] = l[i] + k
ans = pos = 0
for _ in xrange(m):
    k = input()
    ans = (ans + abs(l[pos + k] - l[pos])) % DIV
    pos += k
print ans
Buggy python submission (verdict: Runtime Error):
n = input()
l = [input() for i in range(n-1)]
dp = [[n*n]*2 for i in range(n+1)]
dp[1][0] = 0
for i in range(1,n):
    for j in range(i+1,0,-1):
        dp[j][1] = min(dp[j][1], dp[j][0]+l[i-1])
        dp[j][0] = min(dp[j-1][0], dp[j-1][1]+l[i-1])
print min(dp[n/2])

Fixed submission:
INF = 1<<31
n = input()
dp = [[[INF]*2 for _ in xrange(n/2+2)] for _ in range(2)]
dp[1][1][0] = dp[1][0][1] = 0
for i in range(2,n+1):
    x = i % 2
    s = input()
    t = min(i,n/2)
    for j in range(1,t+1):
        dp[x][j][0] = min(dp[1-x][j-1][0], dp[1-x][j-1][1] + s)
        dp[x][j][1] = min(dp[1-x][j][0] + s, dp[1-x][j][1])
print min(dp[0][n/2])

Buggy python submission (verdict: Runtime Error):
INF = 1<<31
n = input()
l = [input() for i in range(n-1)]
dp = [[INF]*2 for i in range(n+1)]
dp[1][0] = 0
for i in range(1,n):
    for j in range(i+1,0,-1):
        dp[j][1] = min(dp[j][1], dp[j][0]+l[i-1])
        dp[j][0] = min(dp[j-1][0], dp[j-1][1]+l[i-1])
print min(dp[n/2])

Fixed submission:
INF = 1<<31
n = input()
dp = [[[INF]*2 for _ in xrange(n/2+2)] for _ in range(2)]
dp[1][1][0] = dp[1][0][1] = 0
for i in range(2,n+1):
    x = i % 2
    s = input()
    t = min(i,n/2)
    for j in range(1,t+1):
        dp[x][j][0] = min(dp[1-x][j-1][0], dp[1-x][j-1][1] + s)
        dp[x][j][1] = min(dp[1-x][j][0] + s, dp[1-x][j][1])
print min(dp[0][n/2])

Buggy python submission (verdict: Runtime Error):
INF = 1<<31
n = input()
l = [input() for i in xrange(n-1)]
dp = [[INF]*2 for i in xrange(n+1)]
dp[1][0] = 0
for i in xrange(1,n):
    for j in xrange(i+1,0,-1):
        dp[j][1] = min(dp[j][1], dp[j][0]+l[i-1])
        dp[j][0] = min(dp[j-1][0], dp[j-1][1]+l[i-1])
print min(dp[n/2])

Fixed submission:
INF = 1<<31
n = input()
dp = [[[INF]*2 for _ in xrange(n/2+2)] for _ in range(2)]
dp[1][1][0] = dp[1][0][1] = 0
for i in range(2,n+1):
    x = i % 2
    s = input()
    t = min(i,n/2)
    for j in range(1,t+1):
        dp[x][j][0] = min(dp[1-x][j-1][0], dp[1-x][j-1][1] + s)
        dp[x][j][1] = min(dp[1-x][j][0] + s, dp[1-x][j][1])
print min(dp[0][n/2])

Buggy python submission (verdict: Runtime Error):
INF = 1<<31
n = input()
l = [0]*(n+1)
for i in xrange(1,n):
    l[i] = input()
dp = [[INF]*2 for i in xrange(n+1)]
dp[1][0] = 0
for i in xrange(1,n):
    for j in xrange(i+1,0,-1):
        dp[j][1] = min(dp[j][1], dp[j][0]+l[i])
        dp[j][0] = min(dp[j-1][0], dp[j-1][1]+l[i])
print min(dp[n/2])

Fixed submission:
INF = 1<<31
n = input()
dp = [[[INF]*2 for _ in xrange(n/2+2)] for _ in range(2)]
dp[1][1][0] = dp[1][0][1] = 0
for i in range(2,n+1):
    x = i % 2
    s = input()
    t = min(i,n/2)
    for j in range(1,t+1):
        dp[x][j][0] = min(dp[1-x][j-1][0], dp[1-x][j-1][1] + s)
        dp[x][j][1] = min(dp[1-x][j][0] + s, dp[1-x][j][1])
print min(dp[0][n/2])
Buggy python submission (verdict: Runtime Error):
n, k = map(int, raw_input().split())
d = {}
for i in range(k):
    a, b = map(int, raw_input().split())
    d[a] = b
dp =[[[[0]*(n+1) for i in range(4)] for j in range(4)] for k in range(4)]
def solve(a, b, c, i):
    if a == b == c: return 0
    if i in d and d[i] != c: return 0
    if i == n: return 1
    dp[a][b][c][i] = (solve(b,c,1,i+1) + solve(b,c,2,i+1) + solve(b,c,3,i+1)) % 10000
    return dp[a][b][c][i]
ans = (solve(0,0,1,1) + solve(0,0,2,1) + solve(0,0,3,1)) % 10000
print ans

Fixed submission:
n, k = map(int, raw_input().split())
d = {}
for i in range(k):
    a, b = map(int, raw_input().split())
    d[a] = b
dp =[[[[0]*(n+1) for i in range(4)] for j in range(4)] for k in range(4)]
def solve(a, b, c, i):
    if dp[a][b][c][i]: return dp[a][b][c][i]
    if a == b == c: return 0
    if i in d and d[i] != c: return 0
    if i == n: return 1
    dp[a][b][c][i] = (solve(b,c,1,i+1) + solve(b,c,2,i+1) + solve(b,c,3,i+1)) % 10000
    return dp[a][b][c][i]
ans = (solve(0,0,1,1) + solve(0,0,2,1) + solve(0,0,3,1)) % 10000
print ans
Buggy python submission (verdict: Runtime Error):
a, b = map(int, raw_input().split())
p = map(int, raw_input().split())
q = map(int, raw_input().split())
ans = 0
for i in range(a):
    if b - i <= ans: break
    j = 0; k = i
    cnt = 0
    while 1:
        if p[j] == q[k]:
            cnt += 1; j += 1; k += 1
        else: j += 1
        if j == a: break
    ans = max(ans, cnt)
print ans

Fixed submission:
l = map(int, raw_input().split())
if len(l) == 2:
    a = l[0]; b = l[1]
else:
    a = l[0]; b = input()
p = map(int, raw_input().split())
q = map(int, raw_input().split())
ans = 0
for i in range(a):
    if b - i <= ans or a - i <= ans: break
    j = 0; k = i
    cnt = 0
    while 1:
        if p[j] == q[k]:
            cnt += 1; j += 1; k += 1
        else: j += 1
        if j == a: break
    ans = max(ans, cnt)
print ans

Buggy python submission (verdict: Runtime Error):
l = map(int, raw_input().split())
if len(l) == 2:
    a = l[0]; b = l[1]
else:
    a = l[0]; b = input()
p = map(int, raw_input().split())
q = map(int, raw_input().split())
ans = 0
#?°??????????
for i in range(a):
    if b - i <= ans or a - i <= ans: break
    j = 0; k = i
    cnt = 0
    while 1:
        if p[j] == q[k]:
            cnt += 1; j += 1; k += 1
        else: j += 1
        if j == a: break
    ans = max(ans, cnt)
print ans

Fixed submission:
l = map(int, raw_input().split())
if len(l) == 2:
    a = l[0]; b = l[1]
else:
    a = l[0]; b = input()
p = map(int, raw_input().split())
q = map(int, raw_input().split())
ans = 0
for i in range(a):
    if b - i <= ans or a - i <= ans: break
    j = 0; k = i
    cnt = 0
    while 1:
        if p[j] == q[k]:
            cnt += 1; j += 1; k += 1
        else: j += 1
        if j == a: break
    ans = max(ans, cnt)
print ans
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, raw_input().split())
l = map(int, raw_input().split())
dp = [False for i in range(n + 1)]
for i in range(m):
    if l[i] <= n: dp[l[i]] = True
cnt = 1
while 1:
    if dp[n]: break
    ndp = [False for i in range(n + 1)]
    for i in range(n+1):
        if dp[i]:
            ndp[i] = True
            for j in range(m):
                if i + l[j] <= n: ndp[i+l[j]] = True
    cnt += 1
    dp = ndp
print cnt

Fixed submission:
n, m = map(int, raw_input().split())
l = map(int, raw_input().split())
INF = 1<<31
dp = [INF]*(n+1)
dp[0] = 0
for c in l:
    for i in range(n-c+1):
        if dp[i] != INF:
            dp[i + c] = min(dp[i] + 1, dp[i + c])
print dp[n]