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

Fixed submission:
N = int(input())

W = []
for i in range(N):
    if i == 0:
        x = input()
        W.append(x)
    else:
        x = input()
        if x in W:
            print("No")
            exit()
        elif W[i-1][-1] != x[0]:
            print("No")
            exit()
        else:
            W.append(x)

print("Yes")

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

W = []
for i in range(N):
    if i == 0:
        x = input()
        W.append(x)
    else:
        x = input()
        if x in W:
            print("No")
            exit()
        elif W[i-1][len(W[i-1]) - 1] != x[0]:
            print("No")
        else:
            W.append(x)

print("Yes")
Problem p03273 (python)

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

HW_list = []
for i in range(H):
    x = input()
    char_list = list(x)
    if "#" in char_list:
        HW_list.append(char_list)
    else:
        pass

i = 0
while True:
    count = 0
    for j in range(len(HW_list)):
        if HW_list[j][i] == ".":
            count += 1
        
    if count == len(HW_list):
        for j in range(len(HW_list)):
            del HW_list[j][i]

    else:
        i += 1
    if i > len(HW_list[0]) - 1:
        break
    
for j in range(len(HW_list)):
    print("".join(HW_list[j]))

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

HW_list = []
for i in range(H):
    x = input()
    char_list = list(x)
    if "#" in char_list:
        HW_list.append(char_list)
    else:
        pass

i = 0
while True:
    count = 0
    for j in range(len(HW_list)):
        if HW_list[j][i] == ".":
            count += 1
        
    if count == len(HW_list):
        for j in range(len(HW_list)):
            del HW_list[j][i]
    else:
        i += 1
    if i > len(HW_list) - 1:
        break
    
for j in range(len(HW_list)):
    print("".join(HW_list[j]))
Problem p03339 (python)

Fixed submission:
N = int(input())
S = input()

leader = S[0]
right = 0
left = 0

for i in range(1, N):
    if S[i] == "W":
        right += 1
        
result = right

for i in range(1, N):
    if S[i-1] == "E":
        left += 1
    if S[i] == "W":
        right -= 1
    result = max(result, right+left)
    
print(N - result - 1)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()

West = []
East = []
count = 1
if S[0] == "W":
    WE = "W"
else:
    WE = "E"
for i in range(1, N):
    if S[i] == WE:
        count += 1
    else:
        if S[i] == "W":
            East.append(count)
            WE = "W"
        else:
            West.append(count)
            WE = "E"
        count = 1
if S[N-1] == "E":
    East.append(count)
else:
    West.append(count)

print(min(sum(West) - max(East) + 1, sum(East) - max(West) + 1))
Problem p03353 (python)

Fixed submission:
s = input()
K = int(input())
 
sub_s = []
for i in range(1, K+1):
    for j in range(len(s) - i + 1):
        sub_s.append(s[j:j+i])
 
sub_s = sorted(list(set(sub_s)))        
#print(sub_s)
print(sub_s[K-1])

Buggy submission (verdict: Runtime Error):
s = input()
K = int(input())
 
sub_s = []
for i in range(len(s)):
    for j in range(i+1, len(s)+1):
        if s[i:j] not in sub_s and len(s[i:j]) == K:
            sub_s.append(s[i:j])
 
sub_s = sorted(sub_s)        
#print(sub_s)
print(sub_s[K-1])
Problem p03476 (python)

Fixed submission:
def eratosthenes(n):
    is_prime = [True for i in range(n+1)]
    is_prime[0], is_prime[1] = False, False
    prime = []
    for i in range(2, n+1):
        if is_prime[i]:
            prime.append(i)
            for j in range(2*i, n+1, i):
                is_prime[j] = False
    return prime
    

Q = int(input())
N = 10**5

prime = eratosthenes(N)
prime_num = [0 for i in range(N+1)]
for p in prime:
    prime_num[p] = 1
    
count = 0
ans = [0 for i in range(N+1)]
for i in range(1, N+1, 2):
    if prime_num[i] == 1 and prime_num[(i+1)//2] == 1:
        count += 1
    ans[i] = count
    
for i in range(Q):
    l, r = map(int, input().split())
    print(ans[r] - ans[l-2])

Buggy submission (verdict: Runtime Error):
def eratosthenes(n):
    is_prime = [True for i in range(n+1)]
    is_prime[0], is_prime[1] = False, False
    prime = []
    for i in range(2, n+1):
        if is_prime[i]:
            prime.append(i)
            for j in range(2*i, n+1, i):
                is_prime[j] = False
    return prime
    

Q = int(input())
N = 10**5

prime = eratosthenes(N)
prime_num = [0 for i in range(N+1)]
for p in prime:
    prime_num[p] = 1
    
count = 0
ans = [0 for i in range(N+1)]
for i in range(1, N+1, 2):
    if prime_num[i] == 1 and prime_num[(i+1)//2] == 1:
        count += 1
    ans[i] = count
    
for i in range(Q):
    l, r = map(int, input().split())
    print(ans[r+2] - ans[l-2])
Problem p03633 (python)

Fixed submission:
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

N = int(input())

if N == 1:
    T = int(input())
    print(T)
    exit()

T = []
for i in range(N):
    T.append(int(input()))
    
lcm_T = lcm(T[0], T[1])
for i in range(2, N):
    lcm_T = lcm(lcm_T, T[i])
    
print(lcm_T)

Buggy submission (verdict: Runtime Error):
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

N = int(input())

T = []
for i in range(N):
    T.append(int(input()))
    
lcm_T = lcm(T[0], T[1])
for i in range(2, N):
    lcm_T = lcm(lcm_T, T[i])
    
print(lcm_T)
Problem p03722 (python)

Fixed submission:
INF = float('inf')
def bellmanford(n, edges, r):  # r : start
    d = [INF] * n
    d[r] = 0
    for i in range(n):
        for (u, v, c) in edges:
            if d[u] != INF and d[u] + c < d[v]:
                d[v] = d[u] + c
                if i == n-1 and v == n-1:
                    return 'inf'
    return -d[n-1]


N, M = map(int, input().split())
edges = [None] * M
for i in range(M):
    a, b, c = map(int, input().split())
    edges[i] = (a-1, b-1, -c)
ans = bellmanford(N, edges, 0)
print(ans)

Buggy submission (verdict: Runtime Error):
INF = float('inf')
def bellmanford(n, edges, r):  # r : start
    d = [INF] * n
    d[r] = 0
    for i in range(n):
        for (u, v, c) in edges:
            if d[u] != INF and d[u] + c < d[v]:
                d[v] = d[u] + c
                if i == n-1 and v == n-1:
                    return 'inf'
    return d[n-1]


N, M = map(int, input().split())
edges = [None] * M
for i in range(M):
    a, b, c = map(int, input().split())
    edges[i] = (a-1, b-1, -c)
ans = bellmanford(N, edges, 0)
print(-ans)
Problem p02608 (python)

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

N = int(input())

Ret = [0 for _ in range(10**5)]

for i in range(1, 101):
    for j in range(1, 101):
        for k in range(1, 101):
            r = i**2 + j**2 + k**2 + i*j + j*k + i*k
            if r > len(Ret): print(r)
            Ret[r] += 1

for r in Ret[1:N+1]:
    print(r)

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

N = int(input())


Ret = [0 for _ in range(10**4+1)]

for i in range(1, N+1):
    for j in range(1, N+1):
        for k in range(1, N+1):
            r = i**2 + j**2 + k**2 + i*j + j*k + i*k
            Ret[r] += 1

for r in Ret[1:N+1]:
    print(r)
Problem p02684 (python)

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

N, K = map(int, input().split())
A = list(map(int, input().split()))

for i in range(N):
    A[i] -= 1

tele = [0]
#tele = [0,A[0]-1]
z = 0
s = 0
#B = {0:0,A[0]-1:1}
B = {0:0}
for i in range(N):
    if A[tele[-1]] in B and len(B) != 1:
        s = B[A[tele[-1]]]
        break
    B[A[tele[-1]]] = i+1
    tele.append(A[tele[-1]])
    z = tele[-1]

if K <= s:
    print(tele[K]+1)
else:
    K -= s
    amari = K%(len(tele[s:len(tele)]))
    tele = tele[s:len(tele)]*2
    print(tele[amari]+1)

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

N, K = map(int, input().split())
A = list(map(int, input().split()))

tele = [1,A[0]]
B = [0]
z = 0
s = 0
for i in range(N):
    if z in B and len(B) != 1:
        s = B.index(z)
        if s != 0: s+=1
        break
    tele.append(A[tele[-1]-1])
    B.append(tele[-2]-1)
    z = tele[-1]-1

if K <= s:
    print(tele[K])
else:
    K -= s
    amari = K%N
    if s == 0:
        tele = tele[1:len(tele)-1] + tele[:len(tele)-1]
    else:
        tele = tele[s:]*2
    print(tele[amari])
Problem p02690 (python)

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

X = int(input())


ans = {}

for a in range(-200, 201):
    for b in range(-200, 201):
        Y = a**5 - b**5
        ans[Y] = [a, b]

print(str(ans[X][0]) + ' ' + str(ans[X][1]))

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

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


X = int(input())

F = factorization(X)

ans = []

Y = 0
#while Y < 10**9:
f2 = False
nex = F[0][0]
b = - X//nex
a = b + nex
ans = []
while Y<10**9:
    Y = a**5 - b**5
    if X == Y:
        ans = [a,b]
        break
    a += nex
    b += nex


print(str(ans[0]) + ' ' + str(ans[1]))
Problem p02696 (python)

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

A, B, N = map(int, input().split())

f1 = 0
f2 = 0
if N >=B:
    f1 = int(A*(B-1)/B)
    f2 = A*int((B-1)/B)
else:
    f1 = int(A*N/B)
    f2 = A*int(N/B)

ans = f1-f2
print(ans)

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

A, B, N = map(int, input().split())

F12 = []

for i in range(1, B):
    x = i
    f1 = int(A*x/B) 
    f2 = A * int(x/B)
    F12.append(f1-f2)

if N < B:
    print(F12[N-1])
else:
    print(F12[-1])
Problem p02713 (python)

Fixed submission:
#!/usr/bin/env python3
import math
MOD = 10**9
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            if i==j and i==k: g = i
            elif (i==j and i!=k):
                g = math.gcd(i,math.gcd(j,k))*3
            elif (i==k and i!=j):
                g = math.gcd(i,math.gcd(j,k))*3
            elif (j==k and i!=j):
                g = math.gcd(i,math.gcd(j,k))*3
            else : g = math.gcd(i,math.gcd(j,k))*6
            ans += g
print(ans)

Buggy submission (verdict: Runtime Error):


K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            if i==j and i==k: g = i
            elif (i==j and i!=k):
                g = math.gcd(i,math.gcd(j,k))*3
            elif (i==k and i!=j):
                g = math.gcd(i,math.gcd(j,k))*3
            elif (j==k and i!=j):
                g = math.gcd(i,math.gcd(j,k))*3
            else : g = math.gcd(i,math.gcd(j,k))*6
            ans += g
print(ans)
Problem p02714 (python)

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

MOD = 10**9
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

N = int(input())
S = input()


ans = S.count('R') * S.count('G') * S.count('B')

SN = []

for s in S:
    if s == 'R': SN.append(-1)
    elif s == 'G': SN.append(0)
    else: SN.append(1)

rem2 = ['RRR', 'GGG', 'BBB']

count = 0
for i in range(1, N-1):
    index = i
    left = i - 1
    right = i + 1
    f = True
    while f:
        if left == -1 or right == N:
            break
        if SN[left] == SN[index] and SN[index] == SN[right] == 0 : pass
        elif SN[left] + SN[index] + SN[right] == 0 :
            count+= 1
        
        left -= 1
        right += 1

print(ans-count)

Buggy submission (verdict: Runtime Error):

ans = S.count('R') * S.count('G') * S.count('B')

SN = []

for s in S:
    if s == 'R': SN.append(-1)
    elif s == 'G': SN.append(0)
    else: SN.append(1)

rem2 = ['RRR', 'GGG', 'BBB']

count = 0
for i in range(1, N-1):
    index = i
    left = i - 1
    right = i + 1
    f = True
    while f:
        if left == -1 or right == N:
            break
        if SN[left] == SN[index] and SN[index] == SN[right] == 0 : pass
        elif SN[left] + SN[index] + SN[right] == 0 :
            count+= 1
        
        left -= 1
        right += 1

print(ans-count)
Problem p02761 (python)

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

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


sc = []
for i in range(M):
    s, c = map(int, input().split())
    sc.append([s,c])


sc = sorted(sc)
if N == 1: start = 0
else: start = 10 ** (N-1)
end = 10 ** N

ans = -1
for i in range(start, end):
    si = str(i)
    f = True
    for j in range(M):
        if si[sc[j][0]-1] != str(sc[j][1]):
            f = False
            break
    if f:
        ans = i
        break

    
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
N, M = map(int, input().split())

n = {}
exs = {}

for i in range(M):
    n[i+1] = 0
    exs[i+1]=0

f = True

for i in range(M):
    s, c = map(int, input().split())
    exs[s] += 1
    if exs[s] == 1 or c==n[s]:
        n[s] = c
    else:
        f = False
        break
ans = ''
if f:
    for k,v in n.items():
        ans += str(v)
else:
    print(-1)
    exit()

if int(ans) > 0:
    print(ans)
else:
    print(-1)
Problem p02924 (python)

Fixed submission:
N = int(input())
ans = (N-1) * (N) //2
print(int(ans))

Buggy submission (verdict: Runtime Error):
N = int(input)
ans = (1/2) * (N-1) * (N)
print(int(ans))
Problem p03059 (python)

Fixed submission:
# -*- coding: utf-8 -*-

a, b, t = map(int, input().split())

tt=t+0.5

print((int)(tt/a)*b)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)


n = int(input())

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

if n==2:
    print(max(a))
    exit()
'''
L = [gcd(a[0], a[1])]
R = [gcd(a[n-2], a[n-1])]
'''
#L = [0 for i in range(n+1)]
#R = [0 for i in range(n+1)]
L = [0]
R = [0]
for i in range(1,n+1):
    L.append(gcd(L[i-1], a[i-1]))

for i in range(n)[::-1]:
    R.append(gcd(R[i+1], a[i]))

#m = [0 for i in range(n)]
m = []
for i in range(n):
    m.append(gcd(L[i], R[i+1]))

print(max(m))
Problem p03061 (python)

Fixed submission:
# -*- coding: utf-8 -*-

def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)


n = int(input())

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

if n==2:
    print(max(a))
    exit()
'''
L = [gcd(a[0], a[1])]
R = [gcd(a[n-2], a[n-1])]
'''
L = [0 for i in range(n+1)]
R = [0 for i in range(n+1)]
for i in range(1,n+1):
    L[i] = gcd(L[i-1], a[i-1])

for i in range(n)[::-1]:
    R[i] = gcd(R[i+1], a[i])

m = [0 for i in range(n)]

for i in range(n):
    m[i] = gcd(L[i], R[i+1])

print(max(m))

Buggy submission (verdict: Runtime Error):

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

if n==2:
    print(max(a))
    exit()
'''
L = [gcd(a[0], a[1])]
R = [gcd(a[n-2], a[n-1])]
'''
L = [0 for i in range(n+1)]
R = [0 for i in range(n+1)]
for i in range(1,n+1):
    L[i] = gcd(L[i-1], a[i-1])

for i in range(n)[::-1]:
    R[i] = gcd(R[i+1], a[i])

m = []

for i in range(n):
    m.append(gcd(L[i], R[i+1]))

print(max(m))
Problem p03078 (python)

Fixed submission:
# -*- coding: utf-8 -*-
x,y,z,k = map(int, input().split())

a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)


d = [e1+e2 for e1 in a for e2 in b]
d.sort(reverse=True)
d = d[:k]

e = [e1+e2 for e1 in d for e2 in c]
e.sort(reverse=True)


for i in range(k):
    print(e[i])

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
x,y,z,k = map(int, input().split())

a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

v = []
count = 0


for i in range(x):
    for j in range(y):
        v.append(a[i]+b[j])

v = sorted(v, reverse=True)
c = sorted(c, reverse=True)

vv = []
l = len(v)
if k > l: l=k
for i in range(l):
    for j in range(z):
        vv.append(v[i]+c[j])

vv = sorted(vv, reverse=True)

for i in vv[0:k]:
    print(i)
Problem p03086 (python)

Fixed submission:
# -*- coding: utf-8 -*-


def is_acgt(s):
    if s=='A' or s=='C' or s=='G' or s=='T':
        return 1
    else: return 0


x = raw_input()


count = []
c = 0
for s in x:
    a = is_acgt(s)
    if a == 0:
        count.append(c)
        c = 0
        continue
    else:
        c += 1

    count.append(c)

if len(count)==0:
    print 0
    exit()
print max(count)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-


def is_acgt(s):
    if s=='A' or s=='C' or s=='G' or s=='T':
        return 1
    else: return 0


x = raw_input()


count = []
c = 0
for s in x:
    a = is_acgt(s)
    if a == 0:
        count.append(c)
        c = 0
    else:
        c += 1


print max(count)
Problem p03087 (python)

Fixed submission:
#!/usr/bin/env python3
N, Q = map(int, input().split())
S = input()
LR = []
for i in range(Q):
    l, r = map(int, input().split())
    LR.append([l,r])

A = [0]

cnt = 0
for i in range(1, len(S)):
    if S[i-1:i+1] == 'AC':
        cnt += 1
    A.append(cnt)

for l, r in LR:
    print(A[r-1] - A[l-1])

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np
import re
pattern = 'AC'
n, q = map(int, raw_input().split())
s = raw_input()

x = [raw_input() for i in range(q)]

result = re.finditer(pattern, s)

ac = np.zeros(len(s))
count = 0
for match in result:
    count += 1
    ac[match.span()[0]] = count

#print ac



for d in x:
    r = d.split(' ')
    start = int(r[0])-1
    end = int(r[1])
    for i in range(end-1, start, -1):
        if ac[i]!=0:
            m = ac[i]
#            print 'm', m
            break
    m2 = 0
    for i in range(start-1, -1, -1):
        if ac[i]!= 0:
            m2 = ac[i]
#            print 'm2',m2
            break
    wa = m-m2
#    wa = np.sum(ac[start:end] == 1)
#    wa = ac[start:end].count(1)
#    wa = sum(ac[start:end])
    if ac[end-1]!=0: wa = wa-1
    print int(wa)
Problem p03103 (python)

Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
n, m = map(int, raw_input().split())

dic = {} # yen: many

for i in range(n):
    a, b = map(int, raw_input().split())
    if a in dic: dic[a] += b
    else: dic.update({a:b})

dic = sorted(dic.items())

count = 0
yen = 0
for k, v in dic:

    if v < m-count:
        yen += k*v
        count += v
    else:
        yen += k*(m-count)
        count += m-count
        print yen
        break

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 整数の入力
N, M = map(int, raw_input().split())

dic = {} # yen: many

for i in range(N):
    A, B = map(int, raw_input().split())
    dic.update({A:B})

dic = sorted(dic.items())

count = 0
yen = 0
for k, v in dic:

    if v <= M-count:
        yen += k*v
        count += v
    else:
        yen += k*(M-count)
        count += M-count
    if count == M: break

print(yen)
Problem p03160 (python)

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



N = int(input())
H = list(map(int, input().split()))

dp = [float('inf') for i in range(N+1)]

dp[1] = 0
dp[2] = abs(H[1]-H[0])
for i in range(3, N+1):
    dp[i] = min(dp[i-1]+abs(H[i-1]-H[i-2]), dp[i-2]+abs(H[i-1]-H[i-3]))

print(dp[N])

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


def dp(index, cos):
    if index == N-1:
        #cost.append(cos)
        return cos

    if index+1<N:
        d = dp(index+1, cos+abs(H[index]-H[index+1]))
    if index+2<N:
        d = dp(index+2, cos+abs(H[index]-H[index+2]))
    
    cost.append(d)
    return 10**9



N = int(input())
H = list(map(int, input().split()))

cost = []

dp(0, 0)

if len(cost)==0: print(0)
else: print(min(cost))

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


def dp(index, cos):
    if index == N-1:
        cost.append(cos)

    if index+1<N:
        d = dp(index+1, cos+abs(H[index]-H[index+1]))
    if index+2<N:
        d = dp(index+2, cos+abs(H[index]-H[index+2]))



N = int(input())
H = list(map(int, input().split()))

cost = []

dp(0, 0)

if len(cost)==0: print(0)
else: print(min(cost))

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


def dp(index, cos):
    if index == N-1:
        cost.append(cos)

    if index+1<N:
        d = dp(index+1, cos+abs(H[index]-H[index+1]))
    if index+2<N:
        d = dp(index+2, cos+abs(H[index]-H[index+2]))



N = int(input())
H = list(map(int, input().split()))

cost = []

dp(0, 0)

if len(cost)==0: print(0)
else: print(min(cost))

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


def dp(index, cos):
    if index == N-1:
        cost.append(cos)

    if index+1<N:
        d = dp(index+1, cos+abs(H[index]-H[index+1]))
    if index+2<N:
        d = dp(index+2, cos+abs(H[index]-H[index+2]))



N = int(input())
H = list(map(int, input().split()))

cost = []

dp(0, 0)

print(min(cost))
Problem p03163 (python)

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

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

weight = []
value = []

for i in range(N):
    w, v = map(int, input().split())
    weight.append(w)
    value.append(v)

#dp = [[0]*110]*11010
dp=[[0 for _ in range(W+1)] for _ in range(N+1)]
#dp=[[0 for _ in range(110)] for _ in range(11010)]


for i in range(N):
    for w in range(W+1):
        if w >= weight[i]:
            dp[i+1][w] = max(dp[i][w-weight[i]]+value[i], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]

print(dp[N][W])

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

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

weight = []
value = []

for i in range(N):
    w, v = map(int, input().split())
    weight.append(w)
    value.append(v)

#dp = [[0]*110]*11010
#dp=[[0 for _ in range(W+1)] for _ in range(N+1)]
dp=[[0 for _ in range(110)] for _ in range(11010)]


for i in range(N):
    for w in range(W+1):
        if w >= weight[i]:
            dp[i+1][w] = max(dp[i][w-weight[i]]+value[i], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]

print(dp[N][W])
Problem p03231 (python)

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

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

N, M = map(int, input().split())
S = input()
T = input()
if S[0] != T[0]:
    print(-1)
    exit()

l = lcm(N, M)

Moji = {}
Moji[0] = S[0]

for i in range(1, N):
    index = i * (l//N) + 1
    Moji[index-1] = S[i]

for i in range(1, M):
    index = i * (l//M) + 1
    if index-1 in Moji and Moji[index-1] != T[i]:
        print(-1)
        exit()

print(l)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

N, M = map(int, input().split())
S = input()
T = input()
if S[0] != T[0]:
    print(-1)
    exit()

l = lcm(N, M)

Moji = ['']*l
Moji[0] = S[0]

for i in range(1, N):
    index = i * (l//N) + 1
    if Moji[index-1] == '':
        Moji[index-1] = S[i]

for i in range(1, M):
    index = i * (l//M) + 1
    if Moji[index-1] == '':
        Moji[index-1] = T[i]
    else:
        if Moji[index-1] != T[i]:
            print(-1)
            exit()

print(l)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

N, M = map(int, input().split())
S = input()
T = input()
if S[0] != T[0]:
    print(-1)
    exit()

l = lcm(N, M)

Moji = ['']*l
Moji[0] = S[0]

for i in range(1, N):
    index = i * (l//N) + 1
    if Moji[index-1] == '':
        Moji[index-1] = S[i]

for i in range(1, M):
    index = i * (l//M) + 1
    if Moji[index-1] == '':
        Moji[index-1] = T[i]
    else:
        if Moji[index-1] != T[i]:
            print(-1)
            exit()

print(l)