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

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


class UnionFind():
    """ UnionFindはグループの分割はできないことに注意 """
    def __init__(self, n):
        """
            n: 要素数
            parents: 親を示す、-1の場合、自身の親がいない(頂点)であることを示す
        """
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        """
        親の要素が何かを調べる
        同じ要素であれば、同じグループに所属することを示す
        探索しながら、親を頂点につなぎ直すことで、効率的にまとめることができる
        """
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        """
        xとyの所属するグループをまとめる
        """
        x = self.find(x)
        y = self.find(y)

        # 同じ親だった場合、既にグループはまとまっているので処理を終了する
        if x == y:
            return

        # 浅い方を深い方に繋ぐようにする
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def most_depth_root(self):
        return -min(self.parents)


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

union_find = UnionFind(N)
for i in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    union_find.union(x, y)

print(union_find.most_depth_root())

Buggy submission (verdict: Runtime Error):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def most_depth_root(self):
        return -min(self.parents)


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

union_find = UnionFind(N)
for i in range(M):
    x, y = map(int, input().split())
    union_find.union(x, y)

print(union_find.most_depth_root())

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

friend_dict = defaultdict(list)

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

for m in range(M):
  x, y = map(int, input().split())
  friend_dict[x].append(y)
  friend_dict[y].append(x)
  
max_num_group = max([len(set(v)) for v in friend_dict.values()])

print(max_num_group + 1)
Problem p02765 (python)

Fixed submission:
n,r = input().split()
if int(n) >= 10:
  h = int(r)
else:
  h = int(r) + (100 * (10-int(n)))
print(h)

Buggy submission (verdict: Runtime Error):
n,r = input().split()
if int(n) >= 10:
  h = int(r)
else:
  h = int(r) + (100 * (10-n))
print(h)

Buggy submission (verdict: Runtime Error):
n,r = input().split()
if n >= 10:
  h = r
else:
  h = r + (100 * (10-n))
print(h)
Problem p02811 (python)

Fixed submission:
k,x=(int(x) for x in input().split())
a = 500*k
if a >= x:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
k,x=input().split()
if 500 * k >= x:
  print("Yes")
  return
else:
  print("No")

Buggy submission (verdict: Runtime Error):
k,x=input().split()
if 500 * k >= x:
  return "Yes"
else:
  return "No"
Problem p02607 (python)

Fixed submission:
c=0
n = int(input())
a= [int(i) for i in input().split()]
for i in range(0,n,2):
  if a[i]%2==1:
    c+=1

print(c)

Buggy submission (verdict: Runtime Error):

c=0
n = int(input())
a= [int(i) for i in input().split()]
for i in range(0,n+1,2):
  if a[i]%2==1:
    c+=1

print(c)
Problem p02608 (python)

Fixed submission:
n = int(input())
a = [0 for i in range(n)]
c = 0
total = n
for x in range(1, n//2):
    for y in range(x, n//2):
        for z in range(y, n//2):
            total = int(((x+y)**2 + (z+y)**2 + (x+z)**2) / 2)
            try:
                if x == y == z:
                    a[total-1] += 1
                elif x == y or y == z:
                    a[total-1] += 3
                else:
                    a[total-1] += 6
            except:
                break
for i in a:
    print(i)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
for i in range(1,n+1):
    c = 0
    total = n
    while 1:
        for x in range(1,math.sqrt(i)):
            for y in range(x,math.sqrt(i)):
                for z in range(y,math.sqrt(i)):
                    total = ((x+y)**2 + (z+y)**2 + (x+z)**2) / 2
                    if total == i:
                        if x==y==z:
                            c += 1
                        elif x ==y or y == z:
                            c += 3
                        else:
                            c += 6
                        break
                    elif total>i:
                        break
                if total==i:
                    break
            if total==i:
                break
        if total>i:
            break
    print(c)
Problem p02641 (python)

Fixed submission:
x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
if n == 0:
    ans = x
else:
    p = sorted(p)
    min_p = min(p)
    max_p = max(p)
    j = 0
    ans = 0
    if x < min_p:
        ans = x
    elif x > max_p:
        ans = x
    elif x == min_p:
        ans = min_p-1
    elif x == max_p:
        if max_p-1 == p[len(p)-2]:
            ans = max_p+1
        else:
            ans = max_p-1
    else:
        for i in range(min_p-1, max_p+1):
            if i == p[j]:
                j += 1
                if len(p) == j:
                    im_i = p[j-1] +1
                    if abs(ans-x) > abs(im_i-x):
                        ans = im_i
            else:
                if abs(ans-x) > abs(i-x):
                    ans = i
print(ans)

Buggy submission (verdict: Runtime Error):
x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
if n == 0:
    ans = x
else:
    p = sorted(p)
    min_p = min(p)
    max_p = max(p)
    j = 0
    ans = 0
    if x < min_p:
        ans = x
    elif x > max_p:
        ans = x
    elif x == min_p:
        if min_p+1 == p[1]:
            ans = min_p-1
        else:
            ans = min_p+1
    elif x == max_p:
        if max_p-1 == p[len(p)-2]:
            ans = max_p+1
        else:
            ans = max_p-1
    else:
        for i in range(min_p+1, max_p):
            if i == p[j+1]:
                j += 1
            else:
                if abs(ans-x) > abs(i-x):
                    ans = i
print(ans)

Buggy submission (verdict: Runtime Error):
x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
if n == 0:
    ans = x
else:
    p = sorted(p)
    min_p = min(p)
    max_p = max(p)
    j = 0
    ans = 0
    if x < min_p:
        ans = x
    elif x > max_p:
        ans = x
    elif x == min_p:
        if min_p+1 == p[1]:
            ans = min_p-1
        else:
            ans = min_p+1
    elif x == max_p:
        if max_p-1 == p[len(p)-1]:
            ans = max_p+1
        else:
            ans = max_p-1
    else:
        for i in range(min_p+1, max_p):
            if i == p[j+1]:
                j += 1
            else:
                if abs(ans-x) > abs(i-x):
                    ans = i
print(ans)
Problem p02658 (python)

Fixed submission:
a = int(input())
A = [int(i) for i in input().split()]
total = 1
for i in A:
    if total != -1:
        total *= i
        if total > 10**18:
            total = -1
    else:
        if i==0:
            total = 0
            break
print(total)

Buggy submission (verdict: Runtime Error):
a = int(input())
A = [int(i) for i in input().split()]
total = 1
for i in A:
    total *= i
if total > 10**18:
    total = -1
print(total)
Problem p02641 (python)

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

for i in range(200):
    ans1 = x - i
    ans2 = x + i
    if ans1 not in p:
        print(ans1)
        break
    if ans2 not in p:
        print(ans2)
        break

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

val = []
ans = []
if p:
    for i in range(1,101):
        if i not in p:
            val.append(abs(x-i))
    if x - min(val) not in p:
        ans.append(x - min(val))
    if x + min(val) not in p:
        ans.append(x + min(val))
    print(min(ans))

else:
    print(x)
Problem p02720 (python)

Fixed submission:
n = int(input())
lunlun = [[1,2,3,4,5,6,7,8,9]]

for _ in range(9):
    tmp = []
    for i in lunlun[-1]:
        if i % 10 == 0 :
            tmp.append(10 * i + i % 10)
            tmp.append(10 * i + i % 10 + 1)
        elif i % 10 == 9:
            tmp.append(10 * i + i % 10 - 1)
            tmp.append(10 * i + i % 10)
        else:
            tmp.append(10 * i + i % 10 - 1)
            tmp.append(10 * i + i % 10)
            tmp.append(10 * i + i % 10 + 1)
    lunlun.append(tmp)
ans = []
for i in lunlun:
    for j in i:
        ans.append(j)
print(ans[n-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
lunlun = [[1,2,3,4,5,6,7,8,9]]

for _ in range(2):
    tmp = []
    for i in lunlun[-1]:
        if i % 10 == 0 :
            tmp.append(10 * i + i % 10)
            tmp.append(10 * i + i % 10 + 1)
        elif i % 10 == 9:
            tmp.append(10 * i + i % 10 - 1)
            tmp.append(10 * i + i % 10)
        else:
            tmp.append(10 * i + i % 10 - 1)
            tmp.append(10 * i + i % 10)
            tmp.append(10 * i + i % 10 + 1)
    lunlun.append(tmp)
ans = []
for i in lunlun:
    for j in i:
        ans.append(j)
print(ans[n-1])
Problem p02732 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
dic = {}
for i in a:
    if i in dic:
        dic[i] +=1
    else:
        dic[i] = 1

ans = 0
for i in dic.values():
    ans += i * (i - 1) // 2

for i in a:
    sa = dic[i] * (dic[i] - 1) // 2 - ((dic[i] - 1) * (dic[i] - 2) // 2)
    print(ans - sa)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
dic = {}
for i in a:
    s.add(i)
    if i in dic:
        dic[i] +=1
    else:
        dic[i] = 1

ans = 0
for i in dic.values():
    ans += i * (i - 1) // 2

for i in a:
    sa = dic[i] * (dic[i] - 1) // 2 - ((dic[i] - 1) * (dic[i] - 2) // 2)
    print(ans - sa)
Problem p02768 (python)

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

#制限なしで全ての花束の作り方
wa = pow(2, n, 10 ** 9 + 7) - 1

#a本の花束の作り方
#val1 = comb(n, a, exact=True)
#val2 = comb(n, b, exact = True)

x = 1
y = 1
for i in range(a):
    x = (x * (n-i)) % (10 ** 9 + 7)
    y = (y * (i+1)) % (10 ** 9 + 7)
val1 = (x * pow(y, 10 ** 9 + 7 - 2, 10 ** 9 + 7)) % (10 ** 9 + 7)

x = 1
y = 1
for i in range(b):
    x = (x * (n-i)) % (10 ** 9 + 7)
    y = (y * (i+1)) % (10 ** 9 + 7)

val2 = (x * pow(y, 10 ** 9 + 7 - 2, 10 ** 9 + 7)) % (10 ** 9 + 7)

ans = wa - val1 - val2
for i in range(100):
    if ans < 0:
        ans += 10 ** 9 + 7
print(ans)

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

#制限なしで全ての花束の作り方
wa = pow(2, n, 10 ** 9 + 7) - 1

#a本の花束の作り方
#val1 = comb(n, a, exact=True)
#val2 = comb(n, b, exact = True)

x = 1
y = 1
for i in range(a):
    x = (x * (n-i)) % (10 ** 9 + 7)
    y = (y * (i+1)) % (10 ** 9 + 7)
val1 = (x * pow(y, 10 ** 9 + 7 - 2, 10 ** 9 + 7)) % (10 ** 9 + 7)

x = 1
y = 1
for i in range(b):
    x = (x * (n-i)) % (10 ** 9 + 7)
    y = (y * (i+1)) % (10 ** 9 + 7)

val2 = (x * pow(y, 10 ** 9 + 7 - 2, 10 ** 9 + 7)) % (10 ** 9 + 7)

ans = wa - val1 - val2
for i in range(100):
if ans < 0:
    ans += 10 ** 9 + 7
print(ans)
Problem p02947 (python)

Fixed submission:
n = int(input())
s = []
for i in range(n):
    s.append(input())
    
dic = dict()
ans = 0
for i in s:
    if "".join(sorted(i)) in dic:
        ans += dic["".join(sorted(i))]
        dic["".join(sorted(i))] +=1
    else:
        dic["".join(sorted(i))] = 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = []
for i in range(n):
    s.append(input())
    
dic = dict()
ans = 0
for i in s:
    if "".join(sorted(i)) in dic:
        ans += dic[i]
        dic["".join(sorted(i))] +=1
        print(dic)
    else:
        dic["".join(sorted(i))] = 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = []
for i in range(n):
    s.append(input())
    
dic = dict()
ans = 0
for i in s:
    if "".join(sorted(i)) in dic:
        ans += dic[i]
        dic[i] +=1
    else:
        dic["".join(sorted(i))] = 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = []
for i in range(n):
    s.append(input())
    
dic = dict()
ans = 0
for i in s:
    if "".join(sorted(i)) in dic.keys():
        ans += dic[i].values()
        dic[i] +=1
    else:
        dic[i] = 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = []
for i in range(n):
    s.append(input())
    
dic = dict()
ans = 0
for i in s:
    if "".join(sorted(i)) in dic:
        ans += dic[i]
        dic[i] +=1
    else:
        dic[i] = 1
print(ans)
Problem p02952 (python)

Fixed submission:
n = int(input())
ans = 0
for i in range(1, n+1):
    if (len(str(i))) % 2 == 1:
        ans +=1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 0
for i in range(1, n+1):
    if (i // 10 + 1) % 2 == 1:
        ans +=1
print(ans
Problem p02993 (python)

Fixed submission:
s = input()
s = s + "*"
ans = "Good"
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        ans = "Bad"
        break
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
s = s + "*"
ans = "Good"
for i in range(len(s)):
    if s[i] == s[i+1]:
        ans = "Bad"
        break
print(ans)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n = int(input())
g = [[] for _ in range(n)]

for _ in range(n-1):
    u,v,w = map(int,input().split())
    g[u-1].append((v-1,w))
    g[v-1].append((u-1,w))
    
ans = [0] * n

def dfs(v,p,c):
    ans[v] = c
    for i in g[v]:
        if i[0] != p:
            if i[1] % 2 ==0:
                dfs(i[0],v,c)
            else:
                dfs(i[0],v,1-c)

dfs(0,-1,0)

for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
sys.setrecursionlimit(10**7)
n = int(input())
g = [[] for _ in range(n)]

for _ in range(n-1):
    u,v,w = map(int,input().split())
    g[u-1].append((v-1,w))
    g[v-1].append((u-1,w))
    
ans = [0] * n

def dfs(v,p,c):
    ans[v] = c
    for i in g[v]:
        if i[0] != p:
            if i[1] % 2 ==0:
                dfs(i[0],v,c)
            else:
                dfs(i[0],v,1-c)

dfs(0,-1,0)

for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
n = int(input())
g = [[] for _ in range(n)]

for _ in range(n-1):
    u,v,w = map(int,input().split())
    g[u-1].append((v-1,w))
    g[v-1].append((u-1,w))
    
ans = [0] * n

def dfs(v,p,c):
    ans[v] = c
    for i in g[v]:
        if i[0] != p:
            if i[1] % 2 ==0:
                dfs(i[0],v,c)
            else:
                dfs(i[0],v,1-c)

dfs(0,-1,0)

for i in ans:
    print(i)
Problem p03049 (python)

Fixed submission:
import math
N = int(input())
S = []
counterBX = 0
counterXA = 0
counterBXA = 0
counterAB = 0
for i in range(N):
    S.append(input())
    if S[i][0] == 'B' and S[i][-1] != 'A':
        counterBX +=1
    if S[i][0] != 'B' and S[i][-1] == 'A':
        counterXA +=1
    if S[i][0] == 'B' and S[i][-1] == 'A':
        counterBXA +=1
    if len(S[i]) > 1:
        for j in range(len(S[i]) - 1):
            if S[i][j] == 'A' and S[i][j+1] == 'B':
                counterAB +=1
minval = min(counterBX,counterXA)
sa = abs(counterBX - counterXA)

if counterBXA == 0:
    ans = counterAB + min(counterXA,counterBX)
elif counterBXA >=1 and counterXA == 0 and counterBX == 0:
    ans = counterAB + counterBXA - 1
elif counterBXA >=1 and counterXA >=1 and counterBX == 0:
    ans = counterAB + (counterBXA - 1) + 1 + min(counterXA - 1,counterBX)
elif counterBXA >=1 and counterXA == 0 and counterBX >=1:
    ans = counterAB + (counterBXA - 1) + 1 +min(counterXA,counterBX - 1)
else:
    ans = counterAB + (counterBXA - 1) + 2 + min(counterXA - 1, counterBX - 1)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
S = []
counterBX = 0
counterXA = 0
counterBXA = 0
counterAB = 0
for i in range(N):
    S.append(input())
    if S[i][0] == 'B' and S[i][-1] != 'A':
        counterBX +=1
    if S[i][0] != 'B' and S[i][-1] == 'A':
        counterXA +=1
    if S[i][0] == 'B' and S[i][-1] == 'A':
        counterBXA +=1
    if len(S[i]) > 1:
        for j in range(len(S[i]) - 1):
            if S[i][j] == 'A' and S[i][j+1] == 'B':
                counterAB +=1
minval = min(counterBX,counterXA)
sa = abs(counterBX - counterXA)

if counterBXA == 0:
    ans = counterAB + min(counterXA,counterBX)
elif counterBXA >=1 and counterXA == 0 and counterBX == 0:
    ans = counterAB + counterBXA - 1
elif counterBXA >=1 and counterXA >=1 and counterBX == 0:
    ans = counterAB + (counterBXA - 1) + 1 + min(counterXA - 1,counterBX)
elif counterBXA >=1 and counterXA == 0 and counterBX >=1:
    ans = counterAB + (counterBXA - 1) + 1 +min(counterXA,counterBX - 1)
else:
    ans = counter(BXA - 1) + 2 + min(counterXA - 1, counterBX - 1)
print(ans)
Problem p03061 (python)

Fixed submission:
from fractions import gcd
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
L = [A[0]]
R = [A[-1]]
for i in range(N-1):
    L.append(gcd(L[i],A[i+1]))
    R.append(gcd(R[(i)],A[-(i+2)]))
ans = []    
for i in range(N):
    if i == 0:
        ans.append(R[N - 2])
    elif i <= N - 2:
        ans.append(gcd(L[i - 1],R[N - i - 2]))
    else:
        ans.append(L[N - 2])

print(max(ans))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
    tmp_arr = A[:i] + A[i+1:]
    ans_tmp = reduce(math.gcd,tmp_arr)
    if ans < ans_tmp:
        ans = ans_tmp
print(ans)
Problem p03068 (python)

Fixed submission:
n = int(input())
s = input()
k = int(input())

moji = s[k-1]
ans = ''
for i in range(n):
    if s[i] == moji:
        ans = ans + moji
    else:
        ans = ans + '*'
print(ans)

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

moji = s[k]
ans = ''
for i in range(n):
    if s[i] == moji:
        ans = ans + moji
    else:
        ans = ans + '*'
print(ans)
Problem p03076 (python)

Fixed submission:
from math import ceil
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

def f(S,v):
    if S:
        res = []
        for i in range(len(S)):
            res += f(S[:i] + S[i+1:], 10 * ceil(v / 10) + S[i])
        return res
    else:
        return [v]
ans = min(f([a,b,c,d,e],0))
print(ans)

Buggy submission (verdict: Runtime Error):
from math import ceil
a,b,c,d,e = map(int,input().split())

def f(S,v):
    if S:
        res = []
        for s in S:
            res += f(S - {s}, 10 * ceil(v / 10) + s)
        return res
    else:
        return [v]
ans = min(f({a,b,c,d,e},0))
print(ans)
Problem p03086 (python)

Fixed submission:
S = input()
ans = []
for n in range(len(S)):
    counter = 0
    for i in range(n,len(S)):
        if (S[i] == 'A' or S[i] == 'C' or S[i] == 'G' or S[i] =='T'):
            counter+=1
        else:
            break
    ans.append(counter)
print(max(ans))

Buggy submission (verdict: Runtime Error):
s = input()

moji = ("A","C","G","T")
count = []
tmp = 0
for i in range(len(s)):
    if s[i] in moji:
        tmp +=1
    else:
        count.append(tmp)
        tmp = 0
print(max(count))
Problem p03103 (python)

Fixed submission:
var = list(map(int, input().split()))
N = var[0]
M = var[1]
 
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
C = zip(A,B)
C = sorted(C)
A, B = zip(*C)
 
index = 0
count = 0
for i in range(N):
      if(count<=M):
        index = i
      count += B[i]
count = 0
sum = 0
for i in range (index):
    sum+=A[i]*B[i]
    count+=B[i]
sum +=A[index]*(M-count)
print(sum)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
C = zip(A,B)
C = sorted(C)
A, B = zip(*C)
index = 0
count = 0

for i in range(N):
      if(count<=M):
        index = i
        sum += A[i]*B[i]
        count += B[i]
sum +=A[index]*(M-count)
print(sum)
Problem p03150 (python)

Fixed submission:
s = input()
flg = 0
for i in range(len(s)):
    for j in range(len(s)):
        if i <= j:
            tmp = s[:i] + s[j:]
            if tmp == "keyence":
                flg = 1
if flg == 1:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
s = input()
fl = 0
for i in range(len(s)):
    for j in range(len(s)):
        if i <= j:
            tmp = s[:i] + s[j:]
            if tmp == "keyence":
                flg = 1
if flg == 1:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
s = input()
key = "keyence"
j = 0
counter = 0
judge = []
word = key[j]
for i in range(len(s)):
    if s[i] == key[j] and j != 7:
        j +=1
    else:
        judge.append(i)

for i in range(len(judge) - 1):
    if judge[i+1] - judge[i] > 1:
        counter +=1

if j == 7 and counter == 0:            
    print("YES")
else:
    print("NO")
Problem p03163 (python)

Fixed submission:
N,W = map(int,input().split())
w, v = zip(*(map(int, input().split()) for _ in range(N)))

dp = [0] * (W+1)

for i in range(N):
    for j in range(W,0,-1):
        if j - w[i] >= 0 and dp[j] < dp[j - w[i]] + v[i]:
            dp[j] = dp[j - w[i]] + v[i] #jは重さ、w[i]も重さ、dp[j]は重さjの時の価値、v[i]は重さw[i]の時の価値
    if dp[w[i]] == 0 or dp[w[i]] < v[i]:
        dp[w[i]] = v[i]
print(max(dp))

Buggy submission (verdict: Runtime Error):
N,W = map(int,input().split())
w = []
v = []
for i in range(n):
    a,b = map(int,input().split())
    w.append(a)
    v.append(b)
dp = [0] * (W+1)

for i in range(N):
    tmp_w = w[i]
    tmp_v = v[i]
    for j in range(W):
        if dp[j] != 0:
            if j + tmp_w <= W:
                if dp[j + tmp_w] < tmp_v:
                    dp[j + tmp_w] = dp[j] + tmp_v
    if dp[tmp_w] < tmp_v:
        dp[tmp_w] = tmp_v
print(max(dp))

Buggy submission (verdict: Runtime Error):
N,W = map(int,input().split())
w = []
v = []
for i in range(n):
    a,b = map(int,input().split())
    w.append(a)
    v.append(b)
dp = [0] * (W+1)

for i in range(N):
    tmp_w = w[i]
    tmp_v = v[i]
    for j in range(W):
        if dp[j] != 0:
            if j + tmp_w <= W:
                if dp[j + tmp_w] < tmp_v:
                    dp[j + tmp_w] = dp[j] + tmp_v
    if dp[tmp_w] < tmp_v:
        dp[tmp_w] = tmp_v
print(max(dp))
Problem p03212 (python)

Fixed submission:
from itertools import product
N = input()
length = len(N)
T = [''.join(t) for t in product(('3','5','7'),repeat = 3)]

def f(N,s):
    if len(s) == length:
        if int(s) <= int(N) and '3' in s and '5' in s and '7' in s:
            return 1
        else:
            return 0
    else:
        if '3' in s and '5' in s and '7' in s:
            a = 1
        else:
            a = 0
        a += sum(f(N,s+c) for c in('3','5','7'))
        return a
if int(N)<357:
    print(0)
else:
    print(sum(f(N, t) for t in T))

Buggy submission (verdict: Runtime Error):
from itertools import product
N = input()
length = len(N)
T = [''.join(t) for t in product(('3','5','7'),repeat = 3)]

def f(N,s):
    if len(s) == length:
        if int(s) < int(N) and '3' in s and '5' in s and '7' in s:
            return 1
        else:
            return 0
    else:
        if '3' in s and '5' in s and '7' in s:
            a = 1
        else:
            a = 0
        a += sum(f(N,s+c) for c in('3','5','7'))
        return a
print(sum(f(N, t) for t in T))
Problem p03303 (python)

Fixed submission:
s = input()
w = int(input())
ans = ''
for i in range(len(s)):
    ans+=s[i*w]
    if (i+1) * w > len(s) - 1:
        break
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
w = int(input())
ans = ''
for i in range(len(s)):
    ans+=s[i*w]
    if (i+1) * w > len(s):
        break
print(ans)