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

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

N = int(input()) 
time = [int(input()) for i in range(N)]

if N==1:
  print(time[0])
else:
  tmp = time[0]*time[1]//gcd(time[0],time[1])
  for i in time:
    if tmp%i!=0:
      tmp = tmp*i//gcd(tmp,i)

  print(tmp)

Buggy submission (verdict: Runtime Error):
def gcd(x, y):
  if y == 0:
    return x
  else:
    return gcd(y, x % y)

N = int(input()) 
time = [int(input()) for i in range(N)]

tmp = time[0]*time[1]//gcd(time[0],time[1])
for i in time:
  if tmp%i!=0:
    tmp = tmp*i//gcd(tmp,i)
    
print(tmp)
Problem p03637 (python)

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

cnt_t = 0
cnt_f = 0

for i in l:
  if i%4==0:
    cnt_f += 1
  elif i%2==0:
    cnt_t += 1

num = N-cnt_t-cnt_f

if cnt_t == 0:
  cnt_f += 1
if num <= cnt_f:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
l = [int(input()) for i in range(N)]

cnt_t = 0
cnt_f = 0

for i in l:
  if i%4=0:
    cnt_f += 1
  else:
    cnt_t += 1

num = N-cnt_t-cnt_f

if num <= cnt_f+1:
  print("Yes")
else:
  print("No")
Problem p03645 (python)

Fixed submission:
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,M = IL()

data = [0]*N
for i in range(M):
  a,b = IL()
  if a == 1:
    if data[b]==1:
      print("POSSIBLE")
      break
    else:
      data[b]=1
  if b == N:
    if data[a]==1:
      print("POSSIBLE")
      break
    else:
      data[a]=1
else:
  print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,M = IL()

data = []
for i in range(M):
  a,b = IL()
  if a == 1:
    if b in data:
      print("POSSIBLE")
      break
    else:
      data.append(b)
  if b == N:
    if a in data:
      print("POSSIBLE")
      break
    else:
      data.append(a)
else:
  print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
N,M = list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(M)]

ab.sort()
data = []
for a,b in ab:
  if a == 1:
    data.append(b)
  else:
    break

for i in range(M,-1,-1):
  a = ab[i][0]
  if a in data and ab[i][1] == N:
    print("POSSIBLE")
    break
  elif a==1:
    print("IMPOSSIBLE")
    break
Problem p03651 (python)

Fixed submission:
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

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

N,K = IL()

if N == 1:
    if K == I():
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
else:
    l = IL()
    l.sort(reverse=True)

    if K <= l[0]:
        num = gcd(l[0],l[1])
        for i in l:
            if i%num == 0:
                continue
            else:
                num = gcd(num,i)
        if K%num == 0:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")
    else:
        print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

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

N,K = IL()
l = IL()

if K <= max(l):
    num = gcd(l[0],l[1])
    for i in l:
        if i%num == 0:
            continue
        else:
            num = gcd(num,i)
    if K%num == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
else:
    print("IMPOSSIBLE")
Problem p03682 (python)

Fixed submission:
import sys
from operator import itemgetter
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def init(n):
  for i in range(N):
    par[i]=i
    rnk[i]=0
def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
def unite(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return
  if (rnk[x]<rnk[y]):
    par[x]=y
  else:
    par[y]=x
    if(rnk[x]==rnk[y]):
      rnk[x]+=1
def same(x,y):
    return find(x)==find(y)

N = I()
xlist = []
ylist = []

par=[0 for i in range(N)]
rnk=[0 for i in range(N)]
init(N)

for i in range(N):
  x, y = IL()
  xlist.append([x, i])
  ylist.append([y, i])
xlist.sort(key=itemgetter(0))
ylist.sort(key=itemgetter(0))

node = []
for i in range(N-1):
  x, xID = xlist[i]
  nextx, nextxID = xlist[i + 1]
  y, yID = ylist[i]
  nexty, nextyID = ylist[i + 1]
  
  node.append([nextx - x, xID, nextxID])
  node.append([nexty - y, yID, nextyID])
node.sort(key=itemgetter(0), reverse=True)

ans = 0
while node:
  val, i, j = node.pop()
  if same(i, j):
    continue
  else:
    unite(i, j)
    ans += val
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import heapq
import bisect
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

import itertools
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


def init(n):
  for i in range(N):
    par[i]=i
    rnk[i]=0
def find(x):
  if par[x]==x:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
def unite(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return
  if (rnk[x]<rnk[y]):
    par[x]=y
  else:
    par[y]=x
    if(rnk[x]==rnk[y]):
      rnk[x]+=1
def same(x,y):
    return find(x)==find(y)

N = I()
xlist = []
ylist = []

par=[0 for i in range(N)]
rnk=[0 for i in range(N)]
init(N)

for i in range(N):
  x, y = IL()
  xlist.append([x, i])
  ylist.append([y, i])
xlist.sort()
ylist.sort()


hpop = heapq.heappop
hpush = heapq.heappush

node = []
for i in range(N-1):
  x, xID = xlist[i]
  nextx, nextxID = xlist[i + 1]
  y, yID = ylist[i]
  nexty, nextyID = ylist[i + 1]
  
  hpush(node, [nextx - x, xID, nextxID])
  hpush(node, [nexty - y, yID, nextyID])

ans = 0
while node:
  val, i, j = hpop(node)
  if same(i, j):
    continue
  else:
    unite(i, j)
    ans += val
print(ans)
Problem p03826 (python)

Fixed submission:
import sys
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

A,B,C,D = IL()
print(max(A*B, C*D))

Buggy submission (verdict: Runtime Error):
import sys
import math
import numpy as np
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

A,B,C,D = IL()
print(max(A*B, C*D))
Problem p03853 (python)

Fixed submission:
H,W = list(map(int,input().split()))
picture = [input() for i in range(H)]

for i in range(2*H):
  print(picture[i//2])

Buggy submission (verdict: Runtime Error):
H,W = list(map(int,input89.split()))
picture = [input() for i in range(H)]

for i in range(2*H):
  print(picture[i//2])
Problem p02818 (python)

Fixed submission:
list=input().split()
A=int(list[0])
B=int(list[1])
K=int(list[2])

if A >= K:
    print(str((A-K)) + " " + str(B))
else:
    print("0 "+ str(max(B-(K-A),0)) )

Buggy submission (verdict: Runtime Error):
list=input().split()
A=int(list[0])
B=int(list[1])
K=int(list[2])

if A >= K:
    print((A-K) + " " + B)
else:
    print("0 "+ str(max(B-(K-A),0)) )
Problem p02614 (python)

Fixed submission:
H, W, K = list(map(int, input().split()))

c = [None] * H

for i in range(H):
  c[i] = list(input())

res = 0

for h in range(2 ** H):
  for w in range(2 ** W):
    cnt = 0
    for i in range(H):
      for j in range(W):
        if ((h >> i) & 1) == 0 and ((w >> j) & 1) == 0 and c[i][j] == '#':
          cnt += 1
    #print(cnt)
    if cnt == K:
      res += 1

print(res)

Buggy submission (verdict: Runtime Error):
H, W, K = list(map(int, input().split()))

mat = [None] * H

m = {
  '.': 0,
  '#': 1
}

for i in range(H):
  mat[i] = list(map(lambda x: m[x], list(input())))

res = 0
pattern = set()

def total(mat):
  return sum([sum(r) for r in mat])

def fillH(mat, i):
  res = mat[i]
  mat[i] = [0] * W
  return res

def restoreH(mat, i, v):
  mat[i] = v

def fillV(mat, j):
  res = [None] * W
  for i in range(H):
    res[i] = mat[i][j]
    mat[i][j] = 0
  return res

def restoreV(mat, j, v):
  for i in range(H):
    mat[i][j] = v[i]

def DFS(mat, path):
  global pattern
  global res
  #print(mat, path)
  if total(mat) > K:
    for i in range(H):
      if not i in path[0]:
        v = fillH(mat, i)
        path[0] |= {i}
        DFS(mat, path)
        restoreH(mat, i, v)
        path[0].remove(i)
    for j in range(W):
      if not j in path[1]:
        v = fillV(mat, j)
        path[1] |= {j}
        DFS(mat, path)
        restoreV(mat, j, v)
        path[1].remove(j)
  elif total(mat) < K:
    return
  else:
    if not tuple(map(frozenset, path)) in pattern:
      pattern |= {tuple(map(frozenset, path))}
      res += 1

DFS(mat, [set(), set()])

print(res)
Problem p02727 (python)

Fixed submission:
import heapq
from collections import deque

X, Y, A, B, C = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

r.sort()

if A < X:
  p += r[-(X - A):]
  r = r[:-(X - A)]
  A = X

if B < Y:
  q += r[-(Y - B):]
  r = r[:-(Y - B)]
  B = Y

p.sort()
q.sort()

pq = deque(heapq.merge(p[A - X:], q[B - Y:]))

while r and pq[0] < r[-1]:
  pq.popleft()
  pq.append(r.pop())

print(sum(pq))

Buggy submission (verdict: Runtime Error):
import heapq
from collections import deque

X, Y, A, B, C = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

r.sort()

if A < X:
  p += r[-(X - A):]
  r = r[:-(X - A)]
  A = X

if B < Y:
  q += r[-(Y - B):]
  r = r[:-(Y - B)]
  B = Y

p.sort()
q.sort()

pq = deque((heapq.merge(p[A - X:], q[B - Y:])))

while pq[0] < r[-1]:
  pq.popleft()
  pq.append(r.pop())

print(sum(pq))

Buggy submission (verdict: Runtime Error):
import heapq
from collections import deque

X, Y, A, B, C = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

r.sort()

if A < X:
  p += r[C - (X - A):]
  r = r[:C - (X - A)]
  A = X

if B < Y:
  q += r[C - (Y - B):]
  r = r[:C - (Y - B)]
  B = Y

p.sort()
q.sort()

pq = deque((heapq.merge(p[A - X:], q[B - Y:])))

while pq[0] < r[-1]:
  pq.popleft()
  pq.append(r.pop())

print(sum(pq))

Buggy submission (verdict: Runtime Error):
import heapq
from collections import deque

X, Y, A, B, C = list(map(int, input().split()))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort()
q.sort()
r.sort()

pq = deque((heapq.merge(p[A - X:], q[B - Y:])))
r = deque(r)

while pq[0] < r[-1]:
  pq.popleft()
  pq.append(r.pop())

print(sum(pq))
Problem p02755 (python)

Fixed submission:
import math
 
A, B = list(map(int, input().split()))
 
rangeA = [A / 0.08, (A + 1) / 0.08]
rangeB = [B / 0.1, (B + 1) / 0.1]
 
if rangeA[0] < rangeB[0]:
  if math.ceil(rangeB[0]) < rangeA[1]:
    print(math.ceil(rangeB[0]))
    exit(0)
elif rangeA[0] > rangeB[0]:
  if math.ceil(rangeA[0]) < rangeB[1]:
    print(math.ceil(rangeA[0]))
    exit(0)
else:  # rangeA[0] == rangeB[0]
  if math.ceil(rangeA[0]) < rangeB[1] and math.ceil(rangeA[0]) < rangeA[1]: 
    print(math.ceil(rangeA[0]))
    exit(0)
print(-1)

Buggy submission (verdict: Runtime Error):
import math
 
A, B = list(map(int, input().split()))
 
rangeA = [A / 0.08, (A + 1) / 0.08]
rangeB = [B / 0.1, (B + 1) / 0.1]
 
if rangeA[0] < rangeB[0]:
  if math.ceil(rangeB[0]) < rangeA[1]:
    print(math.ceil(rangeB[0]))
    exit(0)
elif rangeA[0] > rangeB[0]:
  if math.ceil(rangeA[0]) < rangeB[1]:
    print(math.ceil(rangeA[0]))
    exit(0)
else:  # rangeA[0] == rangeB[0]
  if math.ceil(rangeA[0]) < rangeB[1] and math.ceil(rangeA[0]) < rangeA[1]: 
    print(math.ceil(rangeA[0]))
  	exit(0)
print(-1)
Problem p02756 (python)

Fixed submission:
from collections import deque

S = input()
pre, post = deque(), deque()
Q = int(input())
reversed = False
for _ in range(Q):
  query = input().split()
  if query[0] == '1':
    reversed = not reversed
    pre, post = post, pre
  else:  # query[0] == 2
    F, C = query[1:]
    if F == '1':
      if reversed:
        pre.append(C)
      else:
        pre.appendleft(C)
    else:  # F == '2'
      if reversed:
        post.appendleft(C)
      else:
      	post.append(C)
if reversed:
  print(''.join(pre)[::-1] + S[::-1] + ''.join(post)[::-1])
else:
  print(''.join(pre) + S + ''.join(post))

Buggy submission (verdict: Runtime Error):
from collections import deque

S = input()
pre, post = deque(), deque()
Q = int(input())
reversed = False
for _ in range(Q):
  query = input().split()
  if query[0] == '1':
    reversed = not reversed
    pre, post = post, pre
  else:  # query[0] == 2
    F, C = query[1:]
    if F == '1':
      if reversed:
        pre.append(C)
      else:
        pre.appendleft(C)
    else:  # F == '2'
      if reversed:
        post.appendleft(C)
      else:
        post.append(C)
if reversed:
  print(''.join(pre[::-1]) + S[::-1] + ''.join(post[::-1]))
else:
  print(''.join(pre) + S + ''.join(post))

Buggy submission (verdict: Runtime Error):
from collections import deque

S = input()
pre, post = deque(), deque()
Q = int(input())
reversed = False
for _ in range(Q):
  query = input().split()
  if query[0] == '1':
    reversed = not reversed
    pre, post = post, pre
  else:  # query[0] == 2
    F, C = query[1:]
    if F == '1':
      if reversed:
        pre.append(C)
      else:
        pre.appendleft(C)
    else:  # F == '2'
      if reversed:
        post.appendleft(C)
      else:
      	post.append(C)
if reversed:
  print(''.join(pre[::-1]) + S[::-1] + ''.join(post[::-1]))
else:
  print(''.join(pre) + S + ''.join(post))
Problem p02780 (python)

Fixed submission:
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))

# cumulated value
c_p = [0] * N
c_p[0] = p[0]

for i in range(1, N):
    c_p[i] = c_p[i - 1] + p[i]

max_e = c_p[K - 1]

for i in range(K, N):
    e = c_p[i] - c_p[i - K]
    max_e = max(max_e, e)

print((max_e + K) / 2)

Buggy submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))

# cumulated value
c_p = [0] * N
c_p[0] = p[0]

for i in range(1, N):
    c_p[i] = c_p[i - 1] + p[i]

max_e = 0

for i in range(N - K + 1):
    e = c_p[i + K] - c_p[i]
    if e > max_e:
        max_e = e

print((max_e + K) / 2)

Buggy submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))

# cumulated value
c_p = [0] * N
c_p[0] = p[0]
for i in range(N - 1):
    c_p[i] = c_p[i - 1] + p[i]

max_e = 0

for i in range(N - K + 1):
    e = c_p[i + K] - c_p[i]
    if e > max_e:
        max_e = e

print((max_e + K) / 2)
Problem p03415 (python)

Fixed submission:
s1 = input()
s2 = input()
s3 = input()

print(s1[0] + s2[1] + s3[2])

Buggy submission (verdict: Runtime Error):
c1, _, _ = input().split()
_, c2, _ = input().split()
_, _, c3 = input().split()

print(c1 + c2 + c3)
Problem p02553 (python)

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

ans = []

if b <= 0 and d <= 0:
    ans.append(a*c)
if b < 0 and d >= 0:
    ans.append(max(c,1)*b)
if b >= 0 and d < 0:
    ans.append(max(a,1)*d)

ans.append(max(b*d, a*c))

print(max(ans))

Buggy submission (verdict: Runtime Error):
f = open("input.txt", "r")
a, b, c, d = list(map(int, f.readline().split()))

if b <= 0 and d <= 0:
    print(a*c)
elif b < 0 and d >= 0:
    print(max(c, 1)*b)
elif b >= 0 and d < 0:
    print(max(a, 1)*d)
else:
    print(b*d)
Problem p02767 (python)

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

P = round(sum(numbers)/N)

sum = 0
for i in range(N):
  sum += (numbers[i] - P)**2

print(sum)

Buggy submission (verdict: Runtime Error):
N = int(input())
in = list(map(int, input.split()))

P = round(sum(in)/N)

sum = 0
for i in range(N):
  sum += (in[i] - P)**2
  
print(sum)

Buggy submission (verdict: Runtime Error):
in = input().split(' ')
in = list(map(int, in))
in.pop(0)

P = round(sum(in)/len(in))

sum = 0
for i in range(len(in)):
  sum += (in[i] - P)**2
  
print(sum)
Problem p02888 (python)

Fixed submission:
import bisect
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)

cnt = 0

for i in range(n):
    for j in range(i+1, n):
        x = bisect.bisect_left(l, l[i]+l[j])
        cnt += x-j-1

print(cnt)

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

cnt = 0

for i in range(n-1, -1, -1):
    for j in range(i-1, -1, -1):
        imin = 0
        imax = j-1

        while imin <= imax:
            mid = (imin + imax)//2
            if test[mid] + l[j] >= l[i]:
                imax = mid-1
            else:
                imin = mid+1

        cnt += j-imin

print(cnt)
Problem p03006 (python)

Fixed submission:
n = int(input())

difs = {}
points = []

for i in range(n):
    x, y = list(map(int, input().split()))

    for j in range(len(points)):
        dif1 = (points[j][0] - x, points[j][1] - y)
        dif2 = (-dif1[0], -dif1[1])

        difs[dif1] = 1 if dif1 not in difs else difs[dif1] + 1
        difs[dif2] = 1 if dif2 not in difs else difs[dif2] + 1

    points.append((x, y))

if n == 1:
    print(1)
else:
    print(n-max(difs.values()))

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

difs = {}
points = []

for i in range(n):
    x, y = list(map(int, input().split()))

    for j in range(len(points)):
        dif1 = (points[j][0] - x, points[j][1] - y)
        dif2 = (-dif1[0], -dif1[1])

        difs[dif1] = 1 if dif1 not in difs else difs[dif1] + 1
        difs[dif2] = 1 if dif2 not in difs else difs[dif2] + 1

    points.append((x, y))

print(n-max(difs.values()))
Problem p03151 (python)

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

surplus = []
short = []

for i in range(n):
    if a[i] > b[i]:
        surplus.append(a[i]-b[i])
    elif b[i] > a[i]:
        short.append(b[i]-a[i])

surplus = sorted(surplus)
taken = False
cnt = 0
for i in range(len(short)):
    cost = short.pop()
    cnt += 1

    while cost > 0:
        if len(surplus) == 0:
            print(-1)
            exit()

        take = min(cost, surplus[-1])
        cost -= take
        surplus[-1] -= take

        if not taken:
            taken = True
            cnt += 1

        if surplus[-1] == 0:
            surplus.pop()
            taken = False

print(cnt)

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

surplus = []
short = []

for i in range(n):
    if a[i] > b[i]:
        surplus.append(a[i]-b[i])
    elif b[i] > a[i]:
        short.append(b[i]-a[i])

surplus = sorted(surplus)
taken = False
cnt = 0
for i in range(len(short)):
    cost = short.pop()
    cnt += 1

    while cost > 0:
        if len(surplus) == 0:
            print(-1)
           	exit()

        take = min(cost, surplus[-1])
        cost -= take
        surplus[-1] -= take

        if not taken:
            taken = True
            cnt += 1

        if surplus[-1] == 0:
            surplus.pop()
            taken = False

print(cnt)
Problem p03160 (python)

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

dp = [-1] * n
dp[0] = 0
dp[1] = abs(h[1]-h[0])

for i in range(2, n):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))

print(dp[n-1])

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

dp = [-1] * n
dp[0] = 0

for i in range(1, min(n, k)):
    dp[i] = min([dp[j] + abs(h[i]-h[j]) for j in range(i)])

for i in range(k, n):
    dp[i] = min([dp[i-j] + abs(h[i]-h[i-j]) for j in range(1, k+1)])

print(dp[n-1])
Problem p03163 (python)

Fixed submission:
n, w = list(map(int, raw_input().split()))
weights = []
values = []

for _ in range(n):
    wi, vi = list(map(int, raw_input().split()))
    weights.append(wi)
    values.append(vi)

dp = [[0 for __ in range(w+1)] for _ in range(n+1)]

for i in range(1, n+1):
    for j in range(1, w+1):
        dp[i][j] = max(dp[i-1][j], dp[i-1][j-weights[i-1]] + values[i-1] if weights[i-1] <= j else 0)

print(dp[n][w])

Buggy submission (verdict: Runtime Error):
n, w = list(map(int, raw_input().split()))
weights = []
values = []

for _ in range(n):
    wi, vi = list(map(int, raw_input().split()))
    weights.append(wi)
    values.append(vi)

dp = [[0 for __ in range(w+1)] for _ in range(n+1)]

for i in range(1, n+1):
    for j in range(1, w+1):
        dp[i][j] = max(dp[i-1][j], dp[i-1][j-weights[i-1]] + values[i-1] if weights[i-1] <= j else 0)

print(dp[n][w])
Problem p03167 (python)

Fixed submission:
h, w = list(map(int, input().split()))
m = 1000000007

grid = [input() for _ in range(h)]

dp = [[0 for _ in range(w)] for _ in range(h)]
dp[0][0] = 1

for y in range(h):
    for x in range(w):
        if grid[y][x] == ".":
            if y > 0:
                dp[y][x] += dp[y-1][x]
            if x > 0:
                dp[y][x] += dp[y][x-1]

            dp[y][x] %= m

print(dp[h-1][w-1])

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

grid = [input() for _ in range(h)]

dp = [[0 for _ in range(w)] for _ in range(h)]
dp[0][0] = 1

for y in range(h):
    for x in range(w):
        if grid[y][x] == ".":
            if y > 0:
                dp[y][x] += dp[y-1][x]
            if x > 0:
                dp[y][x] += dp[y][x-1]

            dp[y][x] %= m

print(dp[h-1][w-1])