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

Fixed submission:
import heapq
import math
n,h=map(int,input().split())
used=[0 for i in range(n)]
que=[]
for i in range(n):
    a,b=map(int,input().split())
    heapq.heappush(que,(-b,-a,i))
count=0
while h>0:
    b,a,i=heapq.heappop(que)
    if used[i]:
        b=-b
        count+=math.ceil(h/b)
        break
    else:
        used[i]=1
        h+=b
        count+=1
        heapq.heappush(que,(a,b,i))
print(count)

Buggy submission (verdict: Runtime Error):
n,h=map(int,input().split())
d=[]
mx=-1
sm=0
for i in range(n):
    a,b=map(int,input().split())
    mx=max(mx,a)
    d.append([b,a])
da=[]
for i in range(n):
    if d[i][0]>mx:
        da.append(d[i])
da=sorted(da,reverse=True)
i=0
for x in da:
    i+=1
    sm+=x[0]
    if sm>=h:
        print(i)
        exit()
da=sorted(da,key= lambda x:-x[1])
print(i+int((h-sm)/da[0][1]+0.5))
Problem p03476 (python)

Fixed submission:
from itertools import accumulate
# Eratosthenes
def eratosthenes(n):
    prime_table = [False,False,True]+[False if i%2!=0 else True for i in range(n-2)]
    i=3
    while i*i<=n:
        if prime_table[i]:
            j=i*i
            while j<=n:
                prime_table[j]=False
                j+=i
        i+=2
    return prime_table

pt=eratosthenes(100000)
ok=[0 for i in range(100000)]
i=1
while i<100000:
    if pt[i] and pt[(i+1)//2]:
        ok[i]=1
    i+=2
ok=list(accumulate(ok))

q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    print(ok[r]-ok[l-1])

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
# Eratosthenes
def eratosthenes(n):
    prime_table = [False,False,True]+[False if i%2!=0 else True for i in range(n-2)]
    i=3
    while i*i<=n:
        if prime_table[i]:
            j=i*i
            while j<=n:
                prime_table[j]=False
                j+=i
        i+=2
    return prime_table

pt=eratosthenes(10001)
ok=[0 for i in range(10001)]
i=1
while i<10001:
    if pt[i] and pt[(i+1)//2]:
        ok[i]=1
    i+=2
ok=list(accumulate(ok))

q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    print(ok[r]-ok[l-1])
Problem p03543 (python)

Fixed submission:
# coding: utf-8
a,b,c,d=input()
print('Yes' if a==b==c or b==c==d else 'No')

Buggy submission (verdict: Runtime Error):
# coding: utf-8
s=input()
d=[]
for c in s:
    if s.count(c)>=3:
        d.append(c)
if d[0]*3 in s:
    print('Yes')
else:
    print('No')
Problem p03611 (python)

Fixed submission:
dic={}
for i in range(100002):
    dic[i]=0
input()
for n in map(int,input().split()):
    dic[n]+=1
m=0
for i in range(0,100000):
    m=max(m,dic[i]+dic[i+1]+dic[i+2])
print(m)

Buggy submission (verdict: Runtime Error):
dic={}
for i in range(10001):
    dic[i]=0
input()
for n in map(int,input().split()):
    dic[n]+=1
m=0
for i in range(1,9999):
    m=max(m,dic[i]+dic[i+1]+dic[i+2])
print(m)
Problem p03612 (python)

Fixed submission:
input()
data=list(map(int,input().split()))
count=0
for i in range(len(data)-1):
    if data[i]==i+1:
        data[i],data[i+1]=data[i+1],data[i]
        count+=1
if data[-1]==len(data):
    count+=1
print(count)

Buggy submission (verdict: Runtime Error):
input()
data=list(map(int,input().split()))
count=0
for i in range(len(data)):
    if data[i]==i+1:
        data[i],data[i+1]=data[i+1],data[i]
        count+=1
print(count)
Problem p03633 (python)

Fixed submission:
def func(a,b):
    return a if b==0 else func(b,a%b)
n = int(input())
num = int(input())
for i in range(n-1):
    d = int(input())
    num = num*d//func(num,d)
print(num)

Buggy submission (verdict: Runtime Error):
from functools import reduce
n=int(input())
data=[]
for i in range(n):
    data.append(int(input()))
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
print(reduce(lcm,data))
Problem p03651 (python)

Fixed submission:
# coding: utf-8
# Your code here!
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

n,k=map(int,input().split())
a=list(map(int,input().split()))
if n==1:
    if k==a[0]:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
    exit()
g=gcd(a[0],a[1])
mx=max(a)
for i in range(2,n):
    g=gcd(g,a[i])
if k%g==0 and k<=mx:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

n,k=map(int,input().split())
a=list(map(int,input().split()))
g=gcd(a[0],a[1])
mx=max(a)
for i in range(2,n):
    g=gcd(g,a[i])
if k%g==0 and k<=mx:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
Problem p03697 (python)

Fixed submission:
a,b=map(int,input().split())
print(a+b if a+b<10 else 'error')

Buggy submission (verdict: Runtime Error):
data=[]
for i in range(int(input())):
    data.append(int(input()))
un=[num for num in data if num%10==0]
data=[num for num in data if num%10!=0]
if len(data)==0:
    print(0)
else:
    if sum(un+data)%10!=0:
        print(sum(un+data))
    else:
        print(sum(un+data)-min(data))
Problem p03866 (python)

Fixed submission:
from heapq import heappush, heappop
sx,sy,gx,gy=map(int,input().split())
n=int(input())
g = [[] for i in range(n+2)]
data=[(sx+sy*1j,0)]
for i in range(n):
    a,b,c=map(int,input().split())
    data.append((a+b*1j,c))
data.append((gx+gy*1j,0))

for i in range(n+2):
    for j in range(i+1,n+2):
        tmp=abs(data[i][0]-data[j][0])-data[i][1]-data[j][1]
        g[i].append((tmp,j))
        g[j].append((tmp,i))

dist=[2828427127 for i in range(n+2)]
visited=[False for i in range(n+2)]
dist[0]=0
que=[]
heappush(que,(0,0))

while que:
    c,v=heappop(que)
    if visited[v]:
        continue
    visited[v]=True
    for x in g[v]:
        if visited[x[1]]:
            continue
        tmp=x[0]+c if not x[0]<0 else c
        if tmp<dist[x[1]]:
            dist[x[1]]=tmp
            heappush(que,(tmp,x[1]))
print(dist[n+1])

Buggy submission (verdict: Runtime Error):
sx,sy,gx,gy=map(int,input().split())
n=int(input())
g = [[] for i in range(n+2)]
data=[(sx,sy,0)]
for i in range(n):
    data.append(tuple(map(int,input().split())))
data.append((gx,gy,0))
for i in range(n+2):
    for j in range(i+1,n+2):
        tmp=(data[i][0]-data[j][0])**2+(data[i][1]-data[j][1])**2)**0.5-data[i][2]-data[j][2]
        if tmp<0:
            tmp=0
        g[i].append((tmp,j))
        g[j].append((tmp,i))

def dijkstra(g,st,ed):
    from heapq import heappush, heappop, heapify
    dist=[2828427127 for i in range(len(g))]
    dist[st]=0
    que=[]
    heappush(que,(0,st))
    while que:
        c,v=heappop(que)
        if dist[v]<c:
            continue
        for i in range(len(g[v])):
            tmp=g[v][i][0]+c
            if tmp<dist[g[v][i][1]]:
                dist[g[v][i][1]]=tmp
                heappush(que,(tmp,g[v][i][1]))
    return dist[ed]

print(dijkstra(g,0,n+1))
Problem p03994 (python)

Fixed submission:
# coding : utf-8
s=list(map(lambda c:ord(c)-ord('a'),input()))
k=int(input())
for i in range(len(s)):
    if 26-s[i]<=k and s[i]!=0:
        k-=(26-s[i])
        s[i]=0
s[-1]=(s[-1]+k)%26
for n in s:
    print(chr(ord('a')+n),end='')
print()

Buggy submission (verdict: Runtime Error):
# coding : utf-8
s=list(map(lambda c:ord(c)-ord('a'),input()))
k=int(input())
for i in range(len(s)):
    if 26-s[i]<=k:
        k-=(26-s[i])
        s[i]=0
s[-1]+=k
for n in s:
    print(chr(ord('a')+n),end='')
print()
Problem p04029 (python)

Fixed submission:
# coding: utf-8
n=int(input())
a=0
for i in range(1,n+1):
    a+=i
print(a)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
n=int(input().split())
a=0
for i in range(1,n+1):
    a+=i
print(a)
Problem p02899 (python)

Fixed submission:
#import numpy as np
N = int(input())
A = list(map(int, input().split()))
#A = np.array(A)
B = [0]*N
#indices = [*range(len(A))]
#sorted_indices = sorted(indices, key=lambda i: A[i])
#for i in range(1, N+1):
#    B.append(A.index(i)+1)
#print(B)
#sorted_indices = sorted_indices + B
for i in range(N):
    B[A[i]-1] = i + 1
print(*B)
#print(*sorted_indices)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
B = np.array([1]*N)
indices = [*range(len(A))]
sorted_indices = sorted(indices, key=lambda i: A[i])
#for i in range(1, N+1):
#    B.append(A.index(i)+1)
#print(B)
sorted_indices = sorted_indices + B

print(*sorted_indices)
Problem p02910 (python)

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

N = len(S)

for i in range(N//2):
    if (S[i*2] == 'R' or S[i*2] == 'U' or S[i*2] == 'D') and \
            (S[i*2 + 1] == 'L' or S[i*2 + 1] == 'U' or S[i*2 + 1] == 'D'):
        continue
    else:
        print('No')
        exit(0)
if N%2 != 0:
    if S[N-1] == 'R' or S[N-1] == 'U' or S[N-1] == 'D':
        print('Yes')
    else:
        print('No')
        exit(0)
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
S = input()
S.split()

N = len(S)

for i in range(N//2):
    if (S[i*2] == 'R' or S[i*2] == 'U' or S[i*2] == 'D') and \
            (S[i*2 + 1] == 'L' or S[i*2 + 1] == 'U' or S[i*2 + 1] == 'D'):
        continue
    else:
        print('No')
        exit(1)
if N%2 != 0:
    if S[N-1] == 'R' or S[N-1] == 'U' or S[N-1] == 'D':
        print('Yes')
    else:
        print('No')
        exit(1)
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
S = input()
S.split()

N = len(S)

for i in range(N//2):
    if (S[i*2] == 'R' or S[i*2] == 'U' or S[i*2] == 'D') and \
            (S[i*2 + 1] == 'L' or S[i*2 + 1] == 'U' or S[i*2 + 1] == 'D'):
        continue
    else:
        print('No')
        exit(1)
if N%2 != 0:
    if S[N-1] == 'R' or S[N-1] == 'U' or S[N-1] == 'D':
        print('Yes')
    else:
        print('No')
        exit(1)
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
S = input()
S.split()

N = len(S)
cnt = 0
#odd_S = S[1::2]
#even_S = S[0::2]
for i in range(N//2):
    if (S[i*2] == 'R' or S[i*2] == 'U' or S[i*2] == 'D') and \
            (S[i*2 + 1] == 'L' or S[i*2 + 1] == 'U' or S[i*2 + 1] == 'D'):
        continue
    else:
        print('No')
        exit(1)
if N%2 != 0:
    if S[N-1] == 'R' or S[N-1] == 'U' or S[N-1] == 'D':
        print('Yes')
    else:
        print('No')
        exit(1)
else:
    print('Yes')
Problem p02995 (python)

Fixed submission:
import fractions

def lcm(a,b):
    res = a*b // fractions.gcd(a,b)
    return res
def f(x,y,z):
    res = x
    res -= x//y
    res -= x//z
    res += x//lcm(y,z)
    return res


A, B, C, D = map(int, input().split())
ans1 = f(B,C,D)
ans2 = f(A-1,C,D)
ans = ans1 - ans2
print(int(ans))

Buggy submission (verdict: Runtime Error):
import math

def lcm(a,b):
    res = a*b / math.gcd(a,b)
    return res
def ll(x,y,z):
    res = x
    res -= x/y
    res -= x/z
    res += x/lcm(y,z)
    return res
A, B, C, D = map(int, input().split())
ans = ll(B,C,D) - ll(A-1,C,D)
print(int(ans))

Buggy submission (verdict: Runtime Error):
import math

def lcm(a,b):
    res = a*b / math.gcd(a,b)
    return res


def ll(x,y,z):
    res = x
    res -= x/y
    res -= x/z
    res += x/lcm(y,z)
    return res


A, B, C, D = map(int, input().split())
ans = ll(B,C,D) - ll(A-1,C,D)
print(int(ans))
Problem p03161 (python)

Fixed submission:
import sys

n,k = list(map(int, input().split()))
l = list(map(int, input().split()))
dp = [sys.maxsize]*n
dp[0]=0
for i in range(1,n):
    for j in range(1,k+1):
        if i-j>=0:
            dp[i]=min(dp[i],dp[i-j]+abs(l[i]-l[i-j]))   
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
import sys

n,k = list(map(int, input().split()))
l = list(map(int, input().split()))
dp = [sys.maxsize]*n
dp[0]=0
# for i in range(1,n):
#     for j in range(1,k+1):
#         if i-j>=0:
#             dp[i]=min(dp[i],dp[i-j]+abs(l[i]-l[i-j]))
dp[1] = abs(l[1]-l[0])
for i in range(2,n):
    if i-j>=0:
        dp[i]=min(dp[i],dp[i-j]+abs(l[i]-l[i-j]))
print(dp[n-1])
Problem p03162 (python)

Fixed submission:
n = int(input())
dp=[0]*3
cost=[0]*3
for _ in range(n):
    l = list(map(int, input().split()))
    for i in range(3):
        for j in range(3):
            if i!=j:
                dp[i]=max(dp[i],l[i]+cost[j])
    cost=dp.copy()
print(max(dp[0],max(dp[1],dp[2])))

Buggy submission (verdict: Runtime Error):
n = int(input())
dp=[0]*3
cost=[0]*3
for _ in range(n):
    l = list(map(int, input().split()))
    for i in range(3):
        for j in range(3):
            if i!=j:
                dp[i]=max(dp[i],l[i]+cost[j])
    cost=dp.copy()
print(max(dp[0],max(dp[1],dp[2])))

Buggy submission (verdict: Runtime Error):
n = int(input())
dp=[0]*3
cost=[0]*3
for _ in range(n):
    l = list(map(int, input().split()))
    for i in range(3):
        for j in range(3):
            if i!=j:
                dp[i]=max(dp[i],l[i]+cost[j])
    cost=dp.copy()
print(max(dp[0],max(dp[1],dp[2])))
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

def f(x):
    if dp[x]!=-1:
        return dp[x]
    ans=0
    for e in d[x]:
        ans=max(ans,1+f(e))
    dp[x]=ans
    return ans

n,m = list(map(int, input().split()))
d={}
dp=[-1]
for i in range(1,n+1):
    d[i]=[]
    dp.append(-1)
for _ in range(m):
    a,b = list(map(int, input().split()))
    d[a].append(b)
ans=0
for i in range(1,n+1):
    ans=max(ans,f(i))
print(ans)

Buggy submission (verdict: Runtime Error):
def f(x):
    ans=0
    for e in d[x]:
        ans=max(ans,1+f(e))
    return ans

n,m = list(map(int, input().split()))
d={}
for i in range(1,n+1):
    d[i]=[]
for _ in range(m):
    a,b = list(map(int, input().split()))
    d[a].append(b)
ans=0
for i in range(1,n+1):
    ans=max(ans,f(i))
print(ans)
Problem p03171 (python)

Fixed submission:
import sys

def f(l,beg,end):
    if beg==end:
        dp[beg][end]=l[beg]
        return l[beg]
    if beg+1==end:
        dp[beg][end] = max(l[beg],l[end]) 
        return max(l[beg],l[end])
    if dp[beg][end]!=-1:
        return dp[beg][end]
    ans1=l[beg]+min(f(l,beg+2,end),f(l,beg+1,end-1))
    ans2=l[end]+min(f(l,beg,end-2),f(l,beg+1,end-1))
    dp[beg][end]=max(ans1,ans2)
    return max(ans1,ans2)

n = int(input())
l = list(map(int, input().split()))
tl = sum(l)
dp=[]
for _ in range(n):
    dp.append([-1]*n)
a = f(l,0,n-1)
b = tl-a
print(a-b)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

def f(l,beg,end):
    if beg==end:
        dp[beg][end]=l[beg]
        return l[beg]
    # if beg+1==end:
    #     return max(l[beg],l[end])
    if dp[beg][end]!=-1:
        return dp[beg][end]
    ans1=l[beg]+min(f(l,beg+2,end),f(l,beg+1,end-1))
    ans2=l[end]+min(f(l,beg,end-2),f(l,beg+1,end-1))
    dp[beg][end]=max(ans1,ans2)
    return max(ans1,ans2)

n = int(input())
l = list(map(int, input().split()))
tl = sum(l)
dp=[]
for _ in range(n):
    dp.append([-1]*n)
a = f(l,0,n-1)
b = tl-a
print(a-b)
print(dp)
Problem p02717 (python)

Fixed submission:
def main():
	a,b,c = [int(x) for x in input().split()]
	a, b = b, a
	a, c = c, a
	print(a, b, c)
    
main()

Buggy submission (verdict: Runtime Error):
def main():
	a,b,c = [int(x) for x in input().split()]
	a, b = b, a
	a, c = c, a
    print(a, b, c)

main()

Buggy submission (verdict: Runtime Error):
def main():
	a,b,c = [int(x) for x in input().split()]
    a, b = b, a
    a, c = c, a
  	print(a, b, c)

main()
Problem p02720 (python)

Fixed submission:
from collections import deque
def main(k):
    q = deque([])
    for i in range(1, 10):
        q.append(i)
    
    count = 0
    top = -1
    
    while True:
        top = q.popleft()
 
        count += 1
        if count == k:
            return top
 
        if top%10 != 0:
            q.append(top*10 + top%10-1)
        q.append(top*10 + top%10)
        if top%10 != 9:
            q.append(top*10 + top%10 + 1)
 
    return top
k = int(input())
print(main(k))

Buggy submission (verdict: Runtime Error):
from collections import deque
def main(k):
    q = deque([])
    for i in range(1, 10):
        q.append(i)
    
    count = 0
    top = -1
    
    while True:
        top = q.popleft()

        count += 1
        if count == k:
            return top

        if top%10 != 0:
            q.append(top*10 + top%10-1)
        q.append(top*10 + top%10)
        if top%10 != 9:
            q.append(top*10 + top%10 + 1)

    return top

main(k)
Problem p02957 (python)

Fixed submission:
a, b = [int(i) for i in raw_input().split()]

if abs(a-b)%2==1:
  print "IMPOSSIBLE"
else:
  print (a+b)/2

Buggy submission (verdict: Runtime Error):
k = int(input())
x, y = [int(i) for i in raw_input().split()]
 
def solve(k, x, y):
    if x < 0:
        x = -x
    if y < 0:
        y = -y
 
    if x==0 and y==0:
        print 0
        return
 
    if (x-y)%2==1 and k%2==0:
        print -1
        return
 
    output = [(x,y)]
    while True:
        # print 'while', x,y
        if x+y == k:
            break
        if x==0 and y == 0:
            break
        if x+y<k:
            output.append((abs((x-y)/2), k - abs((x-y)/2)))
            x, y = abs((x-y)/2), k - abs((x-y)/2)
 
        elif x+y <2*k:
            output.append((abs((x-y)/2), k - abs((x-y)/2)))
            x, y = abs((x-y)/2), k - abs((x-y)/2)
            # print 'x,y',x,y
        elif x > k:
            x -= k
            output.append((x,y))
        elif y > k:
            y -= k
            output.append((x,y))
        else:
            x = 0
            y -= x
            output.append((x,y))
 
    print len(output)
 
    for (a,b) in output[::-1]:
        print a, b
 
# k=4
# x,y=9,9
solve(k, x, y)
Problem p02958 (python)

Fixed submission:
N = int(raw_input())
inp = [int(i) for i in raw_input().split()]

sorted_inp = sorted(inp)

diff = 0

for i in range(len(inp)):
  if inp[i] != sorted_inp[i]:
    diff += 1

if diff == 0 or diff==2:
  print "YES"
else:
  print "NO"

Buggy submission (verdict: Runtime Error):
N = int(i)
inp = [int(i) for i in raw_input().split()]

sorted_inp = sorted(inp)

diff = 0

for i in range(len(inp)):
  if inp[i] != sorted_inp[i]:
    diff += 1

if diff ==  or diff==2:
  print "YES"
else:
  print "NO"

Buggy submission (verdict: Runtime Error):
inp = [int(i) for i in raw_input().split()]

sorted_inp = sorted(inp)

diff = 0

for i in range(len(inp)):
  if inp[i] != sorted_inp[i]:
    diff += 1

if diff ==  or diff==2:
  print "YES"
else:
  print "NO"

Buggy submission (verdict: Runtime Error):
inp = [int(i) for i in raw_input().split()]

sorted_inp = sorted(inp)

diff = 0

for i in range(len(inp)):
	if inp[i] != sorted_inp[i]:
      diff += 1

if diff ==  or diff==2:
  print "YES"
else:
  print "NO"
Problem p03162 (python)

Fixed submission:
n = int(raw_input())

a = []
b = []
c = []

for _ in range(n):
    ai, bi, ci = [int(i) for i in raw_input().split()]
    a.append(ai)
    b.append(bi)
    c.append(ci)


def vacation_planning(a,b,c):
    n = len(a)
    fa = [0] * n 
    fb = [0] * n
    fc = [0] * n

    fa[0] = a[0]
    fb[0] = b[0]
    fc[0] = c[0]

    for i in range(1, n):
        fa[i] = a[i] + max(fb[i-1], fc[i-1])
        fb[i] = b[i] + max(fa[i-1], fc[i-1])
        fc[i] = c[i] + max(fa[i-1], fb[i-1])

    return max(fa[-1], fb[-1], fc[-1])

print(vacation_planning(a,b,c))

Buggy submission (verdict: Runtime Error):
print(vacation_planning(a,b,c))
Problem p03163 (python)

Fixed submission:
n, s = [int(i) for i in  raw_input().split()]
weights = []
values = []

for _ in xrange(n):
    w, v = [int(i) for i in raw_input().split()]
    weights.append(w)
    values.append(v)

def knapsack(weights, values, limit):
    n = len(weights)
    # f = [[0 for _ in xrange(limit+1)] for _ in xrange(n)]

    prev = [0 for _ in xrange(limit+1)]

    if weights[0] <= limit:
        for w in xrange(weights[0], limit+1):
            prev[w] = values[0]

    for i in xrange(1, n):
        # print prev
        current = [0] * (limit+1)
        for w in xrange(1, limit+1):
            current[w] = max(prev[w], current[w])
            if weights[i] <= w:
                current[w] = max(current[w], prev[w-weights[i]] + values[i])
        prev = list(current)

    return prev[-1]

# weights = [10, 20, 30]
# values = [60, 100, 120]
print(knapsack(weights, values, s))

Buggy submission (verdict: Runtime Error):
s, n = [int(i) for i in  raw_input().split()]
weights = []
values = []

for _ in range(n):
    w, v = [int(i) for i in raw_input().split()]
    weights.append(w)
    values.append(v)

def knapsack(weights, values, limit):
    n = len(weights)
    f = [[0 for _ in range(limit+1)] for _ in range(n)]

    if weights[0] <= limit:
        for w in range(weights[0], limit):
            f[0][w] = values[0]

    for w in range(1, limit+1):
        for i in range(1, n):
            f[i][w] = max(f[i-1][w], f[i][w])
            if weights[i] <= w:
                f[i][w] = max(f[i][w], f[i-1][w-weights[i]] + values[i])

    return f[-1][-1]

# weights = [10, 20, 30]
# values = [60, 100, 120]
print(knapsack(weights, values, s))
Problem p02714 (python)

Fixed submission:
n = int(input())
s = str(input())
rn = s.count("R")
gn = s.count("G")
bn = s.count("B")

ct=0
for i in range(n):
  for j in range(i+1,n):
    if 2*j - i >= n:
      break
    elif s[i]!=s[j] and s[j]!=s[2*j-i] and s[i]!=s[2*j-i]:
      ct += 1
 
print(rn*gn*bn-ct)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = str(input())
rn = s.count("R")
gn = s.count("G")
bn = s.count("B")

ct=0
for i in range(n):
  for j in range(i+1,n):
    k = 2*j - i
    if k = n:
      break
    elif s[i]!=s[j] and s[j]!=s[k]and s[i]!=s[k]:
      ct += 1
 
print(rn*gn*bn-ct)
Problem p03240 (python)

Fixed submission:
n = int(input())

w = [(list(map(int, input().split()))) for i in range(n)]#x,y,h
w.sort(key=lambda x:(x[2]),reverse=True)
hcon1 = 0
hcon2 = 0
for cx in range(101):
    for cy in range(101):
        for i in range(n):
            if w[i][2] > 0:
                if i == 0:
                    hcon1 = abs(w[i][0] - cx) + abs(w[i][1] - cy) + w[i][2]
                elif i != 0 and i != n - 1:
                    hcon2 = abs(w[i][0] - cx) + abs(w[i][1] - cy) + w[i][2]
                    if hcon1 != hcon2:
                        break
                    else:
                        hcon1 = hcon2
                else:
                    hcon2 = abs(w[i][0] - cx) + abs(w[i][1] - cy) + w[i][2]
                    if hcon1 != hcon2:
                        break
                    else:
                        print(cx,cy,hcon1)
                        exit()
            else:
                if i == 0:
                    hcon1 = 1
                elif i != 0 and i != n - 1:
                    if hcon1 > abs(w[i][0] - cx) + abs(w[i][1] - cy) + w[i][2]:
                        break
                else:
                    if hcon1 > abs(w[i][0] - cx) + abs(w[i][1] - cy) + w[i][2]:
                        break
                    else:
                        print(cx, cy, hcon1)
                        exit()

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

w = [(list(map(int, input().split()))) for i in range(n)]#x,y,h

for cx in range(101):
    for cy in range(101):
        for i in range(n):
            if w[i][2] > 0:
                if i == 0:
                    hcon1 = abs(w[i][0] - cx) + abs(w[i][1] - cy) + w[i][2]
                elif i != 0 and i != n - 1:
                    hcon2 = abs(w[i][0] - cx) + abs(w[i][1] - cy) + w[i][2]
                    if hcon1 != hcon2:
                        break
                    else:
                        hcon1 = hcon2
                else:
                    hcon2 = abs(w[i][0] - cx) + abs(w[i][1] - cy) + w[i][2]
                    if hcon1 != hcon2:
                        break
                    else:
                        print(cx,cy,hcon1)
                        exit()