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

Fixed submission:
import sys

n = int(input())
l = list(map(int, input().split(" ")))
dp= [0]*n
dp[1] = abs(l[1] - l[0])

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

print(dp[n-1])

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

for i in range(0, N):
	for w in range(1, W+1):
        weight, vvalue = list(map(int, input().split(" ")))
		if w >= weight:
			dp[i + 1][w] = max([dp[i][w - weight] + value, dp[i][w]])
		else:
			dp[i + 1][w] = dp[i][w]
print(dp[N][W])

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(200000)
 
n = int(input())
l = list(map(int, input().split(" ")))
 
def dp(i, curr_cost):
	if n -1 < i:
		return curr_cost
	one = dp(i+1, curr_cost + abs(l[i] - l[i+1]))
	two = dp(i+2, curr_cost + abs(l[i] - l[i+2]))	
	return max[one, two]
 
print(dp(0, 0))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(200000)
 
n = int(input())
l = list(map(int, input().split(" ")))
 
def dp(i, curr_cost):
	if n -1 < i:
		return curr_cost
	one = dp(i+1, curr_cost + abs(l[i] - l[i+1]))
	two = dp(i+2, curr_cost + abs(l[i] - l[i+2]))	
	return max[one, two]
 
print(dp(0, 0))

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

def dp(i, curr_cost):
	if n -1 == i:
		return curr_cost
	one = dp(i+1, curr_cost + abs(l[i] - l[i+1])) if n - 1 >= i + 1 else 9999999
	two = dp(i+2, curr_cost + abs(l[i] - l[i+2])) if n - 1 >= i + 2 else 9999999	
	return one if one < two else two

print(dp(0, 0))
Problem p03162 (python)

Fixed submission:
import sys

sys.setrecursionlimit(200000)

n = int(input())
 
m ={}
def dp(i, a, b, c):
	if (i,a,b,c) in m:
		return m[(i,a,b,c)]
	if i == -1: return 0
	a_v = dp(i-1, a=False, b=True, c=True) + al[i] if a else -1
	b_v = dp(i-1, a=True, b=False, c=True) + bl[i] if b else -1
	c_v = dp(i-1, a=True, b=True, c=False) + cl[i] if c else -1
	m[(i,a,b,c)] = max([a_v, b_v, c_v])
	return max([a_v, b_v, c_v])
 
al = []
bl = []
cl = []
for i in range(n):
	a, b, c = list(map(int, input().split(" ")))
	al.append(a)
	bl.append(b)
	cl.append(c)
    
print(dp(n-1, a=True, b=True, c=True))

Buggy submission (verdict: Runtime Error):
n = int(input())
 
m ={}
def dp(i, a, b, c):
	if (i,a,b,c) in m:
		return m[(i,a,b,c)]
	if i == -1: return 0
	a_v = dp(i-1, a=False, b=True, c=True) + al[i] if a else -1
	b_v = dp(i-1, a=True, b=False, c=True) + bl[i] if b else -1
	c_v = dp(i-1, a=True, b=True, c=False) + cl[i] if c else -1
	m[(i,a,b,c)] = max([a_v, b_v, c_v])
	return max([a_v, b_v, c_v])
 
al = []
bl = []
cl = []
for i in range(n):
	a, b, c = list(map(int, input().split(" ")))
	al.append(a)
	bl.append(b)
	cl.append(c)
    
print(dp(n-1, a=True, b=True, c=True))

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

def dp(i, a, b, c):
	if i == -1: return 0
	a_v = dp(i-1, a=False, b=True, c=True) + al[i] if a else -1
	b_v = dp(i-1, a=True, b=False, c=True) + bl[i] if b else -1
	c_v = dp(i-1, a=True, b=True, c=False) + cl[i] if c else -1
	return max([a_v, b_v, c_v])

al = []
bl = []
cl = []
for i in range(n):
	a, b, c = list(map(int, input().split(" ")))
	al.append(a)
	bl.append(b)
	cl.append(c)
    
print(dp(n-1, a=True, b=True, c=True))

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

def dp(i, a, b, c):
	if i == -1: return 0
	a_v = dp(i-1, a=False, b=True, c=True) + al[i] if a else -1
	b_v = dp(i-1, a=True, b=False, c=True) + bl[i] if b else -1
	c_v = dp(i-1, a=True, b=True, c=False) + cl[i] if c else -1
	return max([a_v, b_v, c_v])

al = []
bl = []
cl = []
for i in range(n):
	a, b, c = list(map(int, input().split(" ")))
	al.append(a)
	bl.append(b)
	cl.append(c)
    
print(dp(n-1, a=True, b=True, c=True))
Problem p03163 (python)

Fixed submission:
N, W = list(map(int, input().split(" ")))
dp =  [[0] * (W+1) for _ in range(N+1)]
 
for i in range(0, N):
	weight, value = map(int, input().split(" "))
	for w in range(1, W+1):
		if w >= weight:
			dp[i + 1][w] = max([dp[i][w - weight] + value, dp[i][w]])
		else:
			dp[i + 1][w] = dp[i][w]
print(dp[N][W])

Buggy submission (verdict: Runtime Error):
N, W = list(map(int, input().split(" ")))
 
for i in range(0, N):
	for w in range(1, W+1):
		weight, vvalue = list(map(int, input().split(" ")))
		if w >= weight:
			dp[i + 1][w] = max([dp[i][w - weight] + value, dp[i][w]])
		else:
			dp[i + 1][w] = dp[i][w]
print(dp[N][W])
Problem p02574 (python)

Fixed submission:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = {-1:1}
    def prime_factorize(n):
        a = set()
        while n % 2 == 0:
            a.add(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                a.add(f)
                n //= f
            else:
                f += 2
        if n != 1:
            a.add(n)
        for i in a:
            d[i] = d.get(i, 0) + 1
    for x in A:
        prime_factorize(x)
    m = max(d.values())
    if m == 1:
        return 'pairwise coprime'
    if m == N:
        return 'not coprime'
    return 'setwise coprime'
print(main())

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = {}
    def prime_factorize(n):
        a = set()
        while n % 2 == 0:
            a.add(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                a.add(f)
                n //= f
            else:
                f += 2
        if n != 1:
            a.add(n)
        for i in a:
            d[i] = d.get(i, 0) + 1
    for x in A:
        prime_factorize(x)
    m = max(d.values())
    if m == 1:
        return 'pairwise coprime'
    if m == N:
        return 'not coprime'
    return 'setwise coprime'
print(main())
Problem p02709 (python)

Fixed submission:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    AA = [(v, i) for i, v in enumerate(A)]
    AA.sort(reverse=True)
    dp = [[0] * (N+1) for _ in range(N+1)]
    for i, (a, b) in enumerate(AA, start=1):
        for x in range(i+1):
            y = i - x
            if y == 0:
                dp[x][y] = dp[x-1][y] + abs(b - x+1) * a
            elif x == 0:
                dp[x][y] = dp[x][y-1] + abs(N-y-b) * a
            else:
                dp[x][y] = max(dp[x-1][y] + abs(b - x + 1) * a, dp[x][y-1] + abs(N-y-b) * a)
    r = 0
    for i in range(N+1):
        r = max(r, dp[i][N-i])
    return r
print(main())

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    AA = [(v, i) for i, v in enumerate(A)]
    AA.sort(reverse=True)
    dp = [[0] * (N+1) for _ in range(N+1)]
    for i, (a, b) in enumerate(AA, start=1):
        for x in range(i+1):
            y = i - x
            if y == 0:
                dp[x][y] = dp[x-1][y] + abs(b - x+1) * a
            elif x == 0:
                dp[x][y] = dp[x][y-1] + abs(N-y-b) * a
            else:
                dp[x][y] = max(dp[x-1][y] + abs(b - x + 1) * a, dp[x][y-1] + abs(N-y-b) * a)
    for i in range(N+1):
        r = max(r, dp[i][N-i])
    return r
print(main())
Problem p02716 (python)

Fixed submission:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    dp = [[-1 * pow(10, 15)] * 3 for _ in range(N)]
    if N == 2:
        return max(A)
    dp[0][0] = A[0]
    dp[1][1] = A[1]
    dp[2][2] = A[2]
    for i in range(N):
        if i < 2:
            continue
        dp[i][0] = dp[i-2][0] + A[i]
        if i < 3:
            continue
        dp[i][1] = max(dp[i-3][0], dp[i-2][1]) + A[i]
        if i < 4:
            continue
        dp[i][2] = max(dp[i-4][0], dp[i-3][1], dp[i-2][2]) + A[i]
    if N % 2 == 0:
        return max(dp[-1][1], dp[-2][0])
    else:
        return max(dp[-1][2], dp[-2][1], dp[-3][0])
print(main())

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    dp = [[-1 * pow(10, 15)] * 3 for _ in range(N)]
    dp[0][0] = A[0]
    dp[1][1] = A[1]
    dp[2][2] = A[2]
    for i in range(N):
        if i < 2:
            continue
        dp[i][0] = dp[i-2][0] + A[i]
        if i < 3:
            continue
        dp[i][1] = max(dp[i-3][0], dp[i-2][1]) + A[i]
        if i < 4:
            continue
        dp[i][2] = max(dp[i-4][0], dp[i-3][1], dp[i-2][2]) + A[i]
    if N % 2 == 0:
        return max(dp[-1][1], dp[-2][0])
    else:
        return max(dp[-1][2], dp[-2][1], dp[-3][0])
print(main())
Problem p02727 (python)

Fixed submission:
import heapq
def main():
    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p.sort(reverse=True)
    q.sort(reverse=True)
    r.sort(reverse=True)
    h = []
    for i in p[:X]:
        heapq.heappush(h, (i, 'r'))
    for i in q[:Y]:
        heapq.heappush(h, (i, 'g'))
    a = sum(p[:X]) + sum(q[:Y])
    ra = 0
    ga = 0
    i = 0
    while h:
        t = heapq.heappop(h)
        if r[i] < t[0]:
            break
        if t[1] == 'r' and ra <= X:
            a += r[i]
            a -= t[0]
            ra += 1
            i += 1
        elif t[1] == 'g' and ga <= Y:
            ga += 1
            a += r[i]
            a -= t[0]
            i += 1
        if ra == X and ga == Y:
            break
        if i >= C:
            break
    return a
print(main())

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)
class fact():
    def __init__(self, i, mod):
        self.l = [1] * (i+1)
        for i in range(1, i+1):
            self.l[i] = self.l[i-1] * i
        self.mod = mod
        self.g1 = [1, 1]
        self.g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, 2 * (10 ** 5) + 1):
            self.g1.append((self.g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            self.g2.append((self.g2[-1] * inverse[-1]) % mod)


def main():
    N = int(input())
    d = {}
    mod = 10**9 + 7
    f = fact(N, mod)
    for i in range(N-1):
        a, b = map(int, input().split())
        if a in d:
            d[a].append(b)
        else:
            d[a] = [b]
        if b in d:
            d[b].append(a)
        else:
            d[b] = [a]
    for i in range(1, N+1):
        v = set()
        r, t = solve(i, N, v, f, d)
        print(r % mod)
def solve(n, a, v, f, d):
    v.add(n)
    x = 0
    unv = []
    for i in d[n]:
        if i not in v:
            x += 1
            unv.append(i)
    if x == 1:
        r, t = solve(unv[0], a-1, v, f, d)
        return r, t + 1
    if x == 0:
        return 1, 1
    t = 1
    r = 1
    for i in unv:
        rr, tt = solve(i, a-1, v, f, d)
        t += tt
        r *= rr
        r *= f.g2[tt]
    r *= f.l[t-1]
    return r, t
main()
Problem p02744 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
def main():
    N = int(input())
    s = ''
    l = []
    def calc3(s, N, i):
        if len(s) == N:
            l.append(s)
            return
        if len(s) > 0:
            s2 = s[:]
            z = i + 2
            for j in range(z):
                st = s[:]
                st += chr(ord('a')+j)
                if j == i + 1:
                    calc3(st[:], N, i+1)
                else:
                    calc3(st[:], N, i)
        else:
            s += 'a'
            calc3(s[:], N, i)
    calc3(s[:], N, 0)
    l = sorted(set(l))
    for i in l:
        print(i)
main()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)
l = []
def calc3(s, N):
    if len(s) == N:
        l.append(s)
        return
    if len(s) > 0:
        c = s[-1]
        s2 = s[:]
        z = ord(c) - ord('a') + 2
        for i in range(z):
            st = s[:]
            st += chr(ord('a')+i)
            calc3(st[:], N)
    else:
        c = 'a'
        s += chr(ord(c))
        calc3(s[:], N)
def main():
    N = int(input())
    s = ''
    calc3(s[:], N)
    l = sorted(set(l))
    for i in l:
        print(i)
main()
Problem p02786 (python)

Fixed submission:
import math
def main():
    H = int(input())
    t = int(math.log2(H))
    r = 2**(t + 1) - 1
    print(r)
main()

Buggy submission (verdict: Runtime Error):
import math
def main():
    H = int(input())
    t = int(math.log2(H))
    r = 2**(t + 1) - 1
    print(r)
main()
Problem p02787 (python)

Fixed submission:
def main():
    H, N = map(int, input().split())
    l = []
    for _ in range(N):
        a, b = map(int, input().split())
        l.append((a,b))
    dp = [[0] * N for _ in range(H+1)]
    for w in range(H+1):
        if w % l[0][0] == 0:
            dp[w][0] = l[0][1] * (w//l[0][0])
        else:
            dp[w][0] = l[0][1] * (1 + (w//l[0][0]))
    for i in range(1, N):
        for w in range(H+1):
            if w > l[i][0]:
                dp[w][i] = min(dp[w-l[i][0]][i] + l[i][1], dp[w][i-1])
            else:
                dp[w][i] = min(dp[w][i-1], l[i][1])
    print(min(dp[-1]))
main()

Buggy submission (verdict: Runtime Error):
import numpy as np
def main():
    H, N = map(int, input().split())
    l = []
    for _ in range(N):
        a, b = map(int, input().split())
        l.append((a,b))
    dp = np.array([[0] * N for _ in range(H)])
    for w in range(H):
        if (w+1) % l[0][0] == 0:
            dp[w][0] = l[0][1] * ((w+1)//l[0][0])
        else:
            dp[w][0] = l[0][1] * (1 + ((w+1)//l[0][0]))
    for i in range(1, N):
        for w in range(H):
            if w + 1 > l[i][0]:
                m = min(dp.T[i][w-l[i][0]:w])
                dp[w][i] = min(m + l[i][1], dp[w][i-1])
            else:
                dp[w][i] = dp[w][i-1]
    print(min(dp[-1]))
main()
Problem p02803 (python)

Fixed submission:
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
def main():
    H, W = map(int, input().split())
    m = []
    for _ in range(H):
        l = input()
        m.append(l)
    edge = []
    v = H * W
    for i in range(H):
        for j in range(W):
            t = i * W + j
            edge.append([10 ** 9] * v)
            if m[i][j] == '.':
                if i > 0 and m[i-1][j] == '.':
                    edge[t][(i-1) * W + j] = 1
                if j > 0 and m[i][j -1] == '.':
                    edge[t][i * W + j - 1] = 1
                if i < H-1 and m[i+1][j] == '.':
                    edge[t][(i + 1)*W + j] = 1
                if j < W - 1 and m[i][j+1] == '.':
                    edge[t][i * W + j + 1] = 1
    G = csgraph_from_dense(edge, null_value=10**9)
    d = floyd_warshall(G)
    m = 0
    for i in range(v):
        for j in range(v):
            if d[i][j] != float('inf') and d[i][j] > m:
                m = d[i][j]
    print(int(m))
main()

Buggy submission (verdict: Runtime Error):
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
def main():
    H, W = map(int, input().split())
    m = []
    for _ in range(H):
        l = input()
        m.append(l)
    edge = []
    v = H * W
    for i in range(H):
        for j in range(W):
            t = i * H + j
            edge.append([10 ** 9] * v)
            if m[i][j] == '.':
                if i > 0 and m[i-1][j] == '.':
                    edge[t][(i-1) * H + j] = 1
                if j > 0 and m[i][j -1] == '.':
                    edge[t][i * H + j - 1] = 1
                if i < H-1 and m[i+1][j] == '.':
                    edge[t][(i + 1)*H + j] = 1
                if j < W - 1 and m[i][j+1] == '.':
                    edge[t][i * H + j + 1] = 1
    G = csgraph_from_dense(edge, null_value=10**9)
    d = floyd_warshall(G)
    m = 0
    for i in range(v):
        for j in range(v):
            if d[i][j] != float('inf') and d[i][j] > m:
                m = d[i][j]
    print(int(m))
main()
Problem p02814 (python)

Fixed submission:
import fractions
def main():
    N, M = map(int, input().split())
    a = tuple(map(int, input().split()))
    s = a[0]
    s2 = a[0]
    s3 = 0
    while True:
        if s2 % 2 == 0:
            s2 /= 2
            s3 +=1
        else:
            break
    if s3 == 0:
        print(0)
        return 0
    for i in a:
        if i % (2 ** s3) != 0:
            print(0)
            return 0
        elif i % (2 ** (s3 + 1)) == 0:
            print(0)
            return 0
    for i in range(1,N):
        s = s * a[i] // fractions.gcd(s, a[i])
        if s > M*2:
            print(0)
            return 0
    s /= 2
    a = int(M // (2*s))
    if (M // s) % 2 == 0:
        print(a)
    else:
        print(a+1)
main()

Buggy submission (verdict: Runtime Error):
import fractions
def main():
    N, M = map(int, input().split())
    a = tuple(map(int, input().split()))
    s = a[0]
    s2 = max(a)
    s3 = 0
    while True:
        if s2 % 2 == 0:
            s2 /= 2
            s3 +=1
        else:
            break
    for i in a:
        if i % (2 ** s3) != 0:
            print(0)
            return 0
    for i in range(1,N):
        s = s * a[i] // fractions.gcd(s, a[i])
    s /= 2
    a = int(M // (2*s))
    if (M // s) % 2 == 0:
        print(a)
    else:
        print(a+1)
main()

Buggy submission (verdict: Runtime Error):
import fractions
def main():
    N, M = map(int, input().split())
    a = tuple(map(int, input().split()))
    s = a[0]
    for i in range(1,N):
        s = s * a[i] // fractions.gcd(s, a[i])
    s /= 2
    a = int(M // (2*s))
    if (M // s) % 2 == 0:
        print(a)
    else:
        print(a+1)
main()
Problem p02839 (python)

Fixed submission:
import sys
def main():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    A = []
    B = []
    M = 80 * (H + W)
    for _ in range(H):
        a = tuple(map(int, input().split()))
        A.append(a)
    for _ in range(H):
        b = tuple(map(int, input().split()))
        B.append(b)
    AB = [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            AB[i][j] = abs(A[i][j] - B[i][j])
    l = [set([]) for _ in range(W)]
    lt = [set([]) for _ in range(W)]
    for i in range(H):
        for j in range(W):
            if i == 0 and j == 0:
                lt[j].add(AB[0][0])
            else:
                t = AB[i][j]
                if i > 0:
                    for k in l[j]:
                        lt[j].add(k+t)
                        lt[j].add(abs(k-t))
                if j > 0:
                    for k in lt[j-1]:
                        lt[j].add(k+t)
                        lt[j].add(abs(k-t))
        l = lt
        lt = [set([]) for _ in range(W)]
    return min(l[-1])
print(main())

Buggy submission (verdict: Runtime Error):
def main():
    H, W = map(int, input().split())
    A = []
    B = []
    M = 80 * H * W
    for _ in range(H):
        a = tuple(map(int, input().split()))
        A.append(a)
    for _ in range(H):
        b = tuple(map(int, input().split()))
        B.append(b)
    l = [[[0] * (M+1) for _ in range(W)] for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if i == 0 and j == 0:
                t = abs(A[0][0] - B[0][0])
                l[i][j][t] = 1
            else:
                t = abs(A[i][j] - B[i][j])
                for k in range(M+1):
                    if i > 0 and l[i-1][j][k] == 1:
                        if k + t <= M:
                            l[i][j][k+t] = 1
                        if k - t >= 0:
                            l[i][j][k-t] = 1
                        if t - k >= 0:
                            l[i][j][t-k] = 1
                    if j > 0 and l[i][j-1][k] == 1:
                        if k + t <= M:
                            l[i][j][k+t] = 1
                        if k - t >= 0:
                            l[i][j][k-t] = 1
                        if t - k >= 0:
                            l[i][j][t-k] = 1
    for k in range(M):
        if l[-1][-1][k] == 1:
            return k
print(main())
Problem p02889 (python)

Fixed submission:
#dame datta...
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix
def main():
    N, M, L = map(int, input().split())
    l = [[0] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        if c > L:
            continue
        l[a-1][b-1] = c
        l[b-1][a-1] = c
    G = csr_matrix(l)
    d = floyd_warshall(G)
    l = [[0] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j] <= L:
                l[i][j] = 1
    G = csr_matrix(l)
    d = floyd_warshall(G)
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        s -= 1
        t -= 1
        x = d[s][t]
        if x != float('inf'):
            print(int(x)-1)
        else:
            print(-1)
main()

Buggy submission (verdict: Runtime Error):
#dame datta...
from scipy.sparse.csgraph import floyd_warshall, csgraph_from_dense
def main():
    N, M, L = map(int, input().split())
    l = [[-1] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        if c > L:
            continue
        l[a-1][b-1] = c
        l[b-1][a-1] = c
    G = csgraph_from_dense(l, null_value=-1)
    d = floyd_warshall(G)
    l = [[-1] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if d[i][j] <= L:
                l[i][j] = 1
    G = csgraph_from_dense(l, null_value=-1)
    d = floyd_warshall(G)
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        s -= 1
        t -= 1
        x = d[s][t]
        if x != float('inf'):
            print(int(x)-1)
        else:
            print(-1)
main()
Problem p02900 (python)

Fixed submission:
import math
def gcd(a, b):
  while b > 0:
    a, b = b, a % b
  return a
def div(a):
  r = []
  i = 2
  k = int(math.sqrt(a))
  while i <= k:
    if a % i == 0:
      r.append(i)
      while a % i == 0:
        a //= i
      k = math.sqrt(a)
    i += 1
  if a > 1:
    r.append(a)
  return r

a, b = map(int, input().split())
if a > b:
  a, b = b, a
c = gcd(a,b)
print(len(div(c))+1)

Buggy submission (verdict: Runtime Error):
import math
def gcd(n, m):
  while m % n != 0:
    m, n = n, m % n
  return m
def div(n):
  d = []
  for i in range(2, int(math.sqrt(n))+2):
    if n % i == 0:
      for j in d:
        if i % j == 0:
          break
      else:
        d.append(i)
  if len(d) == 0 and n > 1:
    return 1
  return len(d)

a, b = map(int, input().split())
if a > b:
  a, b = b, a
c = math.gcd(a,b)
print(div(c) + 1)

Buggy submission (verdict: Runtime Error):
import math
def div(n):
  d = []
  for i in range(2, int(math.sqrt(n))+2):
    if n % i == 0:
      for j in d:
        if i % j == 0:
          break
      else:
        d.append(i)
  if len(d) == 0 and n > 1:
    return 1
  return len(d)

a, b = map(int, input().split())
if a > b:
  a, b = b, a
c = math.gcd(a,b)
print(div(c) + 1)

Buggy submission (verdict: Runtime Error):
import math
def div(n, m):
  if n > m:
    n = m
  d = []
  for i in range(2, int(math.sqrt(n))+1):
    if n % i == 0 and m % i == 0:
        d.append(i)
  if m % n == 0:
    d.append(i)
  return d

a, b = map(int, input().split())
lc = div(a,b)
print(len(lc) + 1)
Problem p02921 (python)

Fixed submission:
S = input()
T = input()
r = 0
for i in range(3):
    if S[i] == T[i]:
        r += 1
print(r)

Buggy submission (verdict: Runtime Error):
S = input()
T = input()
r = 0
for i in range(3):
	if S[i] == T[i]:
    	r += 1
print(r)