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

Fixed submission:
N, M = map(int, input().split())
S = str(input())
T = str(input())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
 
def lcm(x, y):
    return (x * y) // gcd(x, y)
X = lcm(N ,M)
 
if S[0] != T[0]:
    print(-1)
elif X == N*M:
    print(N*M)
else:
        L = X
        match = lcm(  L // N,  L // M)
        for j in range(1, (L // match) ):
            if S[j * N * match // L] != T[ j * M * match // L]:
                L = -1
                break
        if L == X :
            print(L)
        else:
            print(-1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = str(input())
T = str(input())

def lcm(x, y):
    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a
    return (x * y) // gcd(x, y)
X = lcm(N ,M)

if S[0] != T[0]:
    print(-1)
elif X == N*M:
    print(N*M)
else:
    for i in range(1,(N*M//X)+1):
        L = X * i
        counter = L
        y = L // N
        z = L // M
        match = lcm( y, z)
        for j in range(1, (L // match) ):
            if S[j * N * match // L] != T[l = j * M * match // L]:
                counter = -1
                break
        if counter == L:
            break
    print(counter)
Problem p03274 (python)

Fixed submission:
N, K = map(int, input().split())
x = list(map(int, input().split()))
L = [0]*(N-K+1) 

for i in range(N-K+1):
    L[i] = min((abs(x[i])+abs(x[i+K-1]-x[i])),(abs(x[i+K-1])+abs(x[i+K-1]-x[i])))
        
print(min(L))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
x = list(map(int, input().split()))
L = [0]*(N-K+1) 

for i in range(N-K+1):
    L[i] = min((abs(x[i])+abs(x[i+K-1]-x[i])),(abs(x[i+K-1])+abs(x[i+K-1]-x[i]))
        
print(min(L))
Problem p02802 (python)

Fixed submission:
import collections


def solve(n, m, hist):
    cor = 0
    pen = 0
    for p, tries in hist.items():
        for i, t in enumerate(tries):
            if t == 'AC':
                cor += 1
                pen += i
                break
    return '{0} {1}'.format(cor, pen)


def input_to_int():
    return [int(r) for r in input().split(' ')]


if __name__ == "__main__":
    n, m = input_to_int()
    hist = collections.defaultdict(list)
    for _ in range(m):
        p, s = input().split(' ')
        hist[p].append(s)
    print(solve(n, m, hist))

Buggy submission (verdict: Runtime Error):
import collections


def solve(n, m, hist):
    cor = 0
    pen = 0
    for p, tries in hist.items():
        for i, t in enumerate(tries):
            if t == 'AC':
                cor += 1
                pen += i
                break
    return f'{cor} {pen}'


def input_to_int():
    return [int(r) for r in input().split(' ')]


if __name__ == "__main__":
    n, m = input_to_int()
    hist = collections.defaultdict(list)
    for _ in range(m):
        p, s = input().split(' ')
        hist[p].append(s)
    print(solve(n, m, hist))
Problem p02801 (python)

Fixed submission:
a=input()
b = chr(ord(a)+1)
print(b)

Buggy submission (verdict: Runtime Error):
a=input()
print(str(ord(a)+1)
Problem p02803 (python)

Fixed submission:
from collections import deque
import copy

def cha(maze,h,w):
    maze = copy.deepcopy(maze)
    for i in range(h):
        for j in range(w):
            if maze[i][j] == ".":
                maze[i][j] = 10**10
            if maze[i][j] == "#":
                maze[i][j] = -1
    return maze

def bfs(maze,sy,sx):
    maze = copy.deepcopy(maze)
    maze[sy][sx] = 0
    que = deque([[sy,sx]])
    while que:
        y,x = que.popleft()
        for next_y,next_x in [(y+1,x),(y-1,x),(y,x+1),(y,x-1)]:
            if maze[next_y][next_x] == -1:
                continue
            dist = maze[next_y][next_x]
            if dist > maze[y][x] + 1:
                maze[next_y][next_x] = maze[y][x] + 1
                que.append([next_y,next_x])
    return maze

def search(maze):
    c = 0
    for i in maze:
        i.append(c)
        c = max(i)
    return c

def _main():
    h,w = map(int,input().split())
    maze = [["#"]*w]
    for _ in range(h):
        maze.append(list(input()))
    maze.append(["#"]*w)
    for i in range(h+2):
        maze[i].insert(0,"#")
        maze[i].insert(w+1,"#")
    C = 0
    for sy in range(h+2):
        for sx in range(w+2):
            if maze[sy][sx] == ".":
                C = max((search(bfs(cha(maze,h+2,w+2),sy,sx)),C))
    print(C)

if __name__=="__main__":
    _main()

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

def cha(maze,h,w):
    maze = copy.deepcopy(maze)
    for i in range(h):
        for j in range(w):
            if maze[i][j] == ".":
                maze[i][j] = math.inf
            if maze[i][j] == "#":
                maze[i][j] = -1
    return maze

def bfs(maze,sy,sx):
    maze = copy.deepcopy(maze)
    maze[sy][sx] = 0
    que = deque([[sy,sx]])
    while que:
        y,x = que.popleft()
        for next_y,next_x in [(y+1,x),(y-1,x),(y,x+1),(y,x-1)]:
            if maze[next_y][next_x] == -1:
                continue
            dist = maze[next_y][next_x]
            if dist > maze[y][x] + 1:
                maze[next_y][next_x] = maze[y][x] + 1
                que.append([next_y,next_x])
    return maze

def search(maze):
    c = 0
    for i in maze:
        i.append(c)
        c = max(i)
    return c

def _main():
    h,w = map(int,input().split())
    maze = [["#"]*w]
    for _ in range(h):
        maze.append(list(input()))
    maze.append(["#"]*w)
    for i in range(h+2):
        maze[i].insert(0,"#")
        maze[i].insert(w+1,"#")
    C = 0
    for sy in range(h+2):
        for sx in range(w+2):
            if maze[sy][sx] == ".":
                C = max((search(bfs(cha(maze,h+2,w+2),sy,sx)),C))
    print(C)
if __name__=="__main__":
  	_main()
Problem p02814 (python)

Fixed submission:
import numpy as np
import copy
n,m = map(int,input().split())
A = np.array([int(i) for i in input().split()])//2
lcm_ = 1
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a
def lcm(a,b):
    return a*b//gcd(a,b)

for i in A:
    lcm_ = lcm(lcm_,i)
c = 0
lcm_2 = copy.deepcopy(lcm_)
for _ in range(30):
    if lcm_2 % 2 == 0:
        c += 1
        lcm_2 = lcm_2//2
if np.all(A%(2**c) == 0):
    c = m//lcm_
    print(c//2 + c%2)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import numpy as np
n,m = map(int,input().split())
A = np.array([int(i) for i in input().split()])
A_half = A//2
lcm = 1
for i in A_half:
    lcm = np.lcm(lcm,i)
c = m//lcm
print(c//2 + c%2)
Problem p03838 (python)

Fixed submission:
x,y = map(int,input().split())
if 0 <= x < y:
    print(y-x)
elif x < 0 and y > 0 and abs(x) > abs(y):
    print(abs(x)-y+1)
elif x < 0 and y > 0 and abs(x) < abs(y):
    print(y-abs(x)+1)
elif x > y > 0:
    print(x-y+2)
elif x > 0 and y == 0:
    print(x+1)
elif x > 0 and y < 0 and abs(x) > abs(y):
    print(x-abs(y)+1)
elif x > 0 and y < 0 and abs(x) < abs(y):
    print(abs(y)-x+1)
elif abs(x) == abs(y):
    print(1)
elif x < y <= 0:
    print(y-x)
elif x == 0 and y < 0:
    print(abs(y)+1)
else:
    print(x-y+2)

Buggy submission (verdict: Runtime Error):
x,y = map(int,input().split())
if 0 < x < y:
    print(y-x)
elif x < 0 and y > 0 and abs(x) > abs(y):
    print(abs(x)-y+1)
elif x < 0 and y > 0 and abs(x) < abs(y):
    print(y-abs(x)+1)
elif x > y > 0:
    print(x-y+2)
elif x > 0 and y < 0 and abs(x) > abs(y):
    print(x-abs(y)+1)
elif x > 0 and y < 0 and abs(x) < abs(y):
    print(abs(y)-x+1)
elif abs(x) == abs(y):
    print(1)
elif x < y < 0:
    print(y-x)
else:
    print(x-y+2

Buggy submission (verdict: Runtime Error):
x,y = map(int,input().split())
if 0 < x < y:
    print(y-x)
elif x < 0 and y > 0 and abs(x) > abs(y):
    print(abs(x)-y+1)
elif x < 0 and y > 0 and abs(x) < abs(y):
    print(y-abs(x)+1)
elif x > y > 0:
    print(x-y+2)
elif x > 0 and y < 0 and abs(x) > abs(y):
    print(x-abs(y)+1)
elif x > 0 and y < 0 and abs(x) < abs(y):
    print(abs(y)-x+1)
elif abs(x) == abs(y):
    print(1)
elif x < y < 0:
    print(y-x)
else:
    print(x-y+2
Problem p02812 (python)

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

count=0
for i in range(0,N):
    if(S[i]=="A"):
        if(i<=N-3):
            if(S[i+1]=="B"):
                if(S[i+2]=="C"):
                    count+=1

print(count)

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

count=0
for i in range(0,N):
    if(S[i]=="A"):
        if(S[i+1]=="B"):
            if(S[i+2]=="C"):
                count+=1

print(count)

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

count=0
for i in range(0,N):
    if(S[i]=="A"):
        i=i+1
        if(S[i]=="B"):
            i=i+1
            if(S[i]=="C"):
                count+=1

print(count)
Problem p02900 (python)

Fixed submission:
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        count=0
        while n % b == 0:
            n //= b
            count+=1
            if(count==1):
                fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

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

A,B=map(int,input().split())
g=gcd(A,B)
if(g==1):
    print("1")
else:
    print(len(factorize(g))+1)

Buggy submission (verdict: Runtime Error):
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        count=0
        while n % b == 0:
            n //= b
            count+=1
            if(count==1):
                fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

import math
A,B=map(int,input().split())
g=math.gcd(A,B)
if(g==1):
    print("1")
else:
    print(len(factorize(g))+1)

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split())

def get_cd(x1,x2):
    cd=[]
    for i in range(1,min(x1,x2)+1):
        if x1%i==0 and x2%i==0:
            cd.append(i)
    return cd

cd_AB=get_cd(A,B)

for j in range (0,len(cd_AB)-1):
    for k in range(j+1,len(cd_AB)):
            if(len(get_cd(cd_AB[j],cd_AB[k]))>1):
            cd_AB[k]=0

print(len(cd_AB)-cd_AB.count(0))
Problem p02909 (python)

Fixed submission:
S=input()

if(S=="Sunny"):
    print("Cloudy")
elif(S=="Cloudy"):
    print("Rainy")
elif(S=="Rainy"):
    print("Sunny")

Buggy submission (verdict: Runtime Error):
import heapq
N,M=map(int,input().split())
A=[-int(x) for x in input().split()]
heapq.heapify(A)
    
for i in range(0,M):
    tmp=heapq.heappop(A)
    heapq.heappush(A,-int(-tmp/2))
print(-sum(A))
Problem p02995 (python)

Fixed submission:
def gcd(a,b):
    if(a<b):
        tmp=b
        b=a
        a=tmp
    while(a%b!=0):
        tmp_1=b
        tmp_2=a%b
        a=tmp_1
        b=tmp_2
    return b
    
def lcm(x,y):
    return int(x*y/gcd(x,y))

A,B,C,D=map(int,input().split())

S=B-A+1
if(A%C==0):
    n_C=B//C-A//C+1
else:
     n_C=B//C-A//C

if(A%D==0):
    n_D=B//D-A//D+1
else:
    n_D=B//D-A//D

if(A%lcm(C,D)==0):
    n_CD=B//lcm(C,D)-A//lcm(C,D)+1
else:
    n_CD=B//lcm(C,D)-A//lcm(C,D)
    
print(S-n_C-n_D+n_CD)

Buggy submission (verdict: Runtime Error):
import numpy as np
def lcm(x,y):
    return int(x*y/np.gcd(x,y))
A,B,C,D=map(int,input().split())

S=B-A+1
if(A%C==0):
    n_C=B//C-A//C+1
else:
     n_C=B//C-A//C

if(A%D==0):
    n_D=B//D-A//D+1
else:
    n_D=B//D-A//D

if(A%lcm(C,D)==0):
    n_CD=B//lcm(C,D)-A//lcm(C,D)+1
else:
    n_CD=B//lcm(C,D)-A//lcm(C,D)
    
print(S-n_C-n_D+n_CD)
Problem p03000 (python)

Fixed submission:
N,X=map(int,input().split())
L=[int(x)for x in input().split()]

count=0
D=0
n=0
for i in range(0,N):
    n+=1
    if(D>X):
        break
    else:
        count+=1
        D=D+L[i]
    
if(n==N and D<=X):
    count+=1
print(count)

Buggy submission (verdict: Runtime Error):
N,X=map(int,input().split())
L=[int(x)for x in input().split()]

count=0
D=0
for i in range(0,N+1):
    if(D>X):
        break
    else:
        count+=1
        D=D+L[i]
print(count)

Buggy submission (verdict: Runtime Error):
N,X=map(int,input().split())
L=[int(x)for x in input().split()]

count=1
D=1
for i in range(0,N+1):
    if(D>X):
        break
    else:
        D=D+L[i]
        count+=1

print(count)
Problem p02900 (python)

Fixed submission:
def prime_factor(n):
    ass = set()
    for i in range(2,int(n**0.5)+1):
        while n % i==0:
            ass.add(i)
            n = n//i
    if n != 1:
        ass.add(n)
    return ass

A,B = map(int, input().split())
num_set = set()

A_set = prime_factor(A)
B_set = prime_factor(B)

num_set = A_set.intersection(B_set)

#while True:
#    if(A%i==0 and B%i==0):
#        num_set.add(i)
#        A = A//i
#        B = B//i
#        if(coprime2(A,B)==1):
#            break
#    else:
#        i = i+1
print(len(num_set)+1)

Buggy submission (verdict: Runtime Error):
from math import gcd as bltin_gcd

def coprime2(a, b):
    return bltin_gcd(a, b) == 1

A,B = map(int, input().split())
num_set = set()
i=2
while True:
    if(A%i==0 and B%i==0):
        num_set.add(i)
        A = A//i
        B = B//i
        if(coprime2(A,B)==1):
            break
    else:
        i = i+1
print(len(num_set)+1)
Problem p02934 (python)

Fixed submission:
tmp = int(input())
A = [int(i) for i in input().split()]
sum = 0
for i in range(0,tmp):
    sum = sum + 1/A.pop()
print(1/sum)

Buggy submission (verdict: Runtime Error):
tmp = int(input())
A = []
for i in range(0,tmp):
    A.append(int(input()))
sum = 0
for i in range(0,tmp):
    sum = sum + 1/A.pop()

print(1/sum)
Problem p02921 (python)

Fixed submission:
s = input()
t = input()
count = 0
for i in range(len(s)):
    if s[i] == t[i]:
        count += 1
print(count)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
max_count = 0
count = 0
for i in range(1, n):
    if h[i - 1] >= h[i]:
        count += 1
    else:
        if max_count < count:
            max_count = count
        count = 0
if max_count < count:
    max_count = count
print(max_count)
Problem p02960 (python)

Fixed submission:
S = input()
 
MOD = 10 ** 9 + 7
N = 13
 
DP = [0] * N
 
# 初期値
DP[0] = 1
digit = 1
 
# 0 -> 5 -> ?5 -> ??5 -> ...に対する余りがどこになるかを更新していく
for i in range(len(S) - 1, -1, -1):
    nextDP = [0] * N
 
    if S[i] == "?":
        for k in range(10):
            for j in range(N):
                nextDP[(k * digit + j) % N] += DP[j]
                nextDP[(k * digit + j) % N] %= MOD
    else:
        k = int(S[i])
        for j in range(N):
            nextDP[(k * digit + j) % N] += DP[j]
            nextDP[(k * digit + j) % N] %= MOD
 
    digit *= 10
    digit %= N
    DP = nextDP[:]
 
print(DP[5])
 
"""
??2??5

"""

Buggy submission (verdict: Runtime Error):
import numpy as np

S = input()
 
MOD = 10 ** 9 + 7
N = 13
 
DP = np.zeros(N)
 
# 初期値
DP[0] = 1
digit = 1
 
# 0 -> 5 -> ?5 -> ??5 -> ...に対する余りがどこになるかを更新していく
for i in range(len(S) - 1, -1, -1):
    nextDP = np.zeros(N)
 
    if S[i] == "?":
        for k in range(10):
            for j in range(N):
                nextDP[(k * digit + j) % N] += DP[j]
                nextDP[(k * digit + j) % N] %= MOD
    else:
        k = int(S[i])
        for j in range(N):
            nextDP[(k * digit + j) % N] += DP[j]
            nextDP[(k * digit + j) % N] %= MOD
 
    digit *= 10
    digit %= N
    DP = nextDP
 
print(int(DP[5]))

Buggy submission (verdict: Runtime Error):
S = input()
 
MOD = 10 ** 9 + 7
N = 13
 
DP = [0] * N
 
# 初期値
DP[0] = 1
digit = 1
 
# 0 -> 5 -> ?5 -> ??5 -> ...に対する余りがどこになるかを更新していく
for i in range(len(S) - 1, -1, -1):
    nextDP = [0] * N
 
    if S[i] == "?":
        for k in range(10):
            for j in range(N):
                nextDP[(k * digit + j) % N] += DP[j]
                nextDP[(k * digit + j) % N] %= MOD
    else:
        k = int(S[i])
        for j in range(N):
            nextDP[(k * digit + j) % N] += DP[j]
            nextDP[(k * digit + j) % N] %= MOD
 
    digit *= 10
    digit %= N
    DP = nextDP[:]
 
print(DP[5])
 
 
 
S = input()

MOD = 10 ** 9 + 7
N = 13

DP = [0] * N

# 初期値
DP[0] = 1
digit = 1

# 0 -> 5 -> ?5 -> ??5 -> ...に対する余りがどこになるかを更新していく
for i in range(len(S) - 1, -1, -1):
    nextDP = [0] * N

    if S[i] == "?":
        for k in range(10):
            for j in range(N):
                nextDP[(k * digit + j) % N] += DP[j]
                nextDP[(k * digit + j) % N] %= MOD
    else:
        k = int(S[i])
        for j in range(N):
            nextDP[(k * digit + j) % N] += DP[j]
            nextDP[(k * digit + j) % N] %= MOD

    digit *= 10
    digit %= N
    DP = nextDP[:]

print(DP[5])
Problem p02981 (python)

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

if A * N < B:
    B = A * N

print(B)

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

# 解法メモ
# ひとつでも山の雨の量がわかれば全て求まる
# 3つの山があり、1つめの山の値をxとしたとき
# 1つめ: x
# 2つめ：A1 - x
# 3つめ：A2 - (A1 - x)
# 1つめ：A3 - (A2 - (A1 - x))
# 1つめ２つを式にする
# x = A3 - (A2 - (A1 - x))
# x = A3 - A2 + A1 - x
# 2x = A3 - A2 + A1
summary = 0

for i in range(N):
    if i % 2 == 0:
        summary += A[i]
    else:
        summary -= A[i]

for i in range(N):
    print(summary)
    summary = (A[i] - (summary//2)) * 2
Problem p02983 (python)

Fixed submission:
L, R = map(int, input().split())

R = min(R, L + 2019)
out = 2020
for i in range(L, R):
    for j in range(i + 1, R + 1):
        out = min(out, (i * j) % 2019)

print(out)

Buggy submission (verdict: Runtime Error):
import numpy as np
L, R = map(int, input().split())

LR = np.arange(L, R+1, dtype="int64")
LR %= 2019
LR.sort

print(LR[0] * LR[1])

Buggy submission (verdict: Runtime Error):
import numpy as np
L, R = map(int, input().split())

LR = np.arange(L, R+1, dtype="int")
LR %= 2019
LR.sort

print(LR[0] * LR[1])
Problem p03160 (python)

Fixed submission:
# --------------------------------------
# 関数定義
# --------------------------------------


def chmin(a, b):
    if a > b:
        a = b
    return a

# --------------------------------------
# メイン処理
# --------------------------------------


def main():
    INF = 10 ** 10
    N = int(input())
    h = list(map(int, input().split()))

    dp = [INF] * N
    dp[0] = 0

    for i in range(1, N):
        dp[i] = chmin(dp[i], dp[i-1] + abs(h[i]-h[i-1]))
        if i >= 2:
            dp[i] = chmin(dp[i], dp[i-2] + abs(h[i]-h[i-2]))

    print(dp[N - 1])


# --------------------------------------
# 実行
# --------------------------------------
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline


def chmax(a, b):
    """
    2値の大きい値を返す

    Args:
        a   (int)   : 値１
        b   (int)   : 値２
    Return:
        a   (int)   : aまたはbの大きい値
    """
    if a < b:
        a = b
    return a


def main():

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

    # knopsock[n][0] = w    :   n = 品物の位置 , w = 重さ
    # knopsock[n][1] = v    :   n = 品物の位置 , v = 価値
    knapsack = [list(map(int, readline().split())) for _ in range(N)]

    # db[n][w] = v          :   w = 現在の重さ, n = 見てきた品物の数, v = 現在の価値
    dp = [[0] * (W + 1) for _ in range(N + 1)]

    for n in range(1, N + 1):
        for w in range(W + 1):
            if w - knapsack[n - 1][0] < 0:
                dp[n][w] = dp[n - 1][w]
            else:
                dp[n][w] = chmax(dp[n - 1][w], dp[n - 1]
                                 [w - knapsack[n - 1][0]] + knapsack[n - 1][1])

    print(dp[N][W])


if __name__ == "__main__":
    main()
Problem p03163 (python)

Fixed submission:
import sys
readline = sys.stdin.readline


def chmax(a, b):
    """
    2値の大きい値を返す

    Args:
        a   (int)   : 値１
        b   (int)   : 値２
    Return:
        a   (int)   : aまたはbの大きい値
    """
    if a < b:
        a = b
    return a


def main():

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

    # knopsock[n][0] = w    :   n = 品物の位置 , w = 重さ
    # knopsock[n][1] = v    :   n = 品物の位置 , v = 価値
    knapsack = [list(map(int, readline().split())) for _ in range(N)]

    # db[n][w] = v          :   w = 現在の重さ, n = 見てきた品物の数, v = 現在の価値
    dp = [[0] * (W + 1) for _ in range(N + 1)]

    for n in range(1, N + 1):
        for w in range(W + 1):
            if w - knapsack[n - 1][0] < 0:
                dp[n][w] = dp[n - 1][w]
            else:
                dp[n][w] = chmax(dp[n - 1][w], dp[n - 1]
                                 [w - knapsack[n - 1][0]] + knapsack[n - 1][1])

    print(dp[N][W])


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# 再帰関数使用時は再帰上限を十分にとること
import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
 
# グローバル変数定義
INF = 10 ** 13
N, W = map(int, input().split())
 
# knopsock[n][0] = w    :   n = 品物の位置 , w = 重さ
# knopsock[n][1] = v    :   n = 品物の位置 , v = 価値
knapsack = [list(map(int, input().split())) for _ in range(N)]
 
# db[n][w] = v          :   w = 現在の重さ, n = 見てきた品物の数, v = 現在の価値
db = [[INF] * W for _ in range(N)]
 
 
def dfs(n, w):
    """
    品物に対する深さ優先探索による全探索（メモ化再帰）。
 
    Args:
        n (int) : 見てきた品物の数
        w (int) : ここまでの重さの総和
 
    Returns:
        v (int) : 価値の総和の最大値
    """
 
    # 終了条件：現在の個数が全ての品物の個数を越える
    if n >= N:
        return 0
 
    if w + knapsack[n][0] > W:
        # １つ前までの重さ + 今回の品物の重さが重さの最大値を越えていたら今回の品物は選べない
        return dfs(n + 1, w)
    else:
        # 今回の品物を選ぶか選ばないかで全探索
        return max([dfs(n + 1, w), dfs(n + 1, w + knapsack[n][0]) + knapsack[n][1]])
 
 
def main():
    out = dfs(0, 0)
    print(out)
 
 
if __name__ == "__main__":
    main()
# 再帰関数使用時は再帰上限を十分にとること
import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline

# グローバル変数定義
INF = 10 ** 13
N, W = map(int, input().split())

# knopsock[n][0] = w    :   n = 品物の位置 , w = 重さ
# knopsock[n][1] = v    :   n = 品物の位置 , v = 価値
knapsack = [list(map(int, input().split())) for _ in range(N)]

# db[n][w] = v          :   w = 現在の重さ, n = 見てきた品物の数, v = 現在の価値
db = [[INF] * W for _ in range(N)]


def dfs(n, w):
    """
    品物に対する深さ優先探索による全探索（メモ化再帰）。

    Args:
        n (int) : 見てきた品物の数
        w (int) : ここまでの重さの総和

    Returns:
        v (int) : 価値の総和の最大値
    """

    # 終了条件：現在の個数が全ての品物の個数を越える
    if n >= N:
        return 0

    if w + knapsack[n][0] > W:
        # １つ前までの重さ + 今回の品物の重さが重さの最大値を越えていたら今回の品物は選べない
        return dfs(n + 1, w)
    else:
        # 今回の品物を選ぶか選ばないかで全探索
        return max([dfs(n + 1, w), dfs(n + 1, w + knapsack[n][0]) + knapsack[n][1]])


def main():
    out = dfs(0, 0)
    print(out)


if __name__ == "__main__":
    main()
提出情報
提出日時	2019-11-17 17:37:04
問題
Problem p02900 (python)

Fixed submission:
from sys import stdin

a, b = [int(x) for x in stdin.readline().split()]

while b != 0:
    a, b = b, a % b

c = 1
lim = a ** 0.5 + 10
n = 0
i = 2
while a > 1 and i <= lim:
    n = 0
    while a % i == 0:
        a //= i
        n += 1
    if n > 0:
        c += 1
    i += 1
if a > 1:
    c += 1

print(c)

Buggy submission (verdict: Runtime Error):
from sys import stdin
from math import gcd

def factorization(a):
    if a < 2:
        return []
    fac = []
    lim = int(a ** 0.5)
    i = 2
    while a > 1 and i <= lim:
        n = 0
        while a % i == 0:
            a //= i
            n += 1
        if n > 0:
            fac += [(i, n)]
        i += 1
    if a > 1 or fac == []:
        fac += [(a, 1)]
    return fac

a, b = [int(x) for x in stdin.readline().split()]

print(len(factorization(gcd(a, b))) + 1)
Problem p02814 (python)

Fixed submission:
N, M = map(int, input().split())
A = set(i//2 for i in map(int, input().split()))
B = []
for i in A:
	B = B + [0]
	while i % 2 == 0:
		i //= 2
		B[-1] += 1
if len(set(B)) == 1:
	m = max(A)
	A.remove(m)
	base = 0
	for i in range(m,M+1,2*m):
		semi = True
		for j in A:
			if i % j != 0 or (i // j) % 2 == 0:
				semi = False
				break
		if semi:
			base = i
			break
	if base == 0:
		print(0)
	else:
		print(((M // base) + 1)//2)
else:
	print(0)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(int(i/2) for i in map(int, input().split()))
m = max(A)
A.remove(m)

for i in range(m,M+1,2*m):
	semi = True
	for j in A:
		if i not in range(j,M+1,2*j):
			semi = False
			break
	if semi:
		base = i
		break

print(int(((M // base) + 1)/2))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(list(range(int(i/2),M+1,2*int(i/2))) for i in map(int, input().split()))
P = set(A[0]).intersection(*A[1:])
print(len(P))