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

Fixed submission:
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

def prime_factorize(n):
    res = []
    for i in range(2, int(n**(1/2))+1):
        if n % i != 0: continue
        num = 0
        while n % i == 0:
            num += 1
            n /= i
        res.append((i, num))
    if n != 1:
        res.append((n, 1))
    
    return res

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

gcdAB = gcd(A, B)
pf = prime_factorize(gcdAB)

print(len(pf)+1)

Buggy submission (verdict: Runtime Error):
import math

def prime_factorize(n):
    res = []
    for i in range(2, int(n**(1/2))+1):
        if n % i != 0: continue
        num = 0
        while n % i == 0:
            num += 1
            n /= i
        res.append((i, num))
    if n != 1:
        res.append((n, 1))
    
    return res

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

gcdAB = math.gcd(A, B)
pf = prime_factorize(gcdAB)

print(len(pf)+1)
Problem p02936 (python)

Fixed submission:
from collections import deque

n, q = map(int, input().split())

g = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

c = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    c[p-1] += x

q = deque([0])
flag = [False] * n
while q:
    v = q.pop()
    flag[v] = True
    for e in g[v]:
        if flag[e]:
            continue
        c[e] += c[v]
        q.append(e)

print(*c)

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

g = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

c = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    c[p-1] += x

def dfs(now, prev=-1):
    for next in g[now]:
        if next != prev:
            c[next] += c[now]
            dfs(next, now)

dfs(0)
print(*c)

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

g = [[] * n for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

c = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    c[p-1] += x

def dfs(now, prev=-1):
    for next in g[now]:
        if next != prev:
            c[next] += c[now]
            dfs(next, now)

dfs(0)
print(*c)
Problem p02995 (python)

Fixed submission:
from fractions import gcd

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

num1 = B // C - (A-1) // C
num2 = B // D - (A-1) // D
gcdCD = C * D // gcd(C, D)
num3 = B // gcdCD - (A-1) // gcdCD

print(B - A - num1 - num2 + num3 + 1)

Buggy submission (verdict: Runtime Error):
import math

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

num1 = B // C - (A-1) // C
num2 = B // D - (A-1) // D
gcdCD = C * D // math.gcd(C, D)
num3 = B // gcdCD - (A-1) // gcdCD

print(B - A - num1 - num2 + num3 + 1)
Problem p03026 (python)

Fixed submission:
import heapq

n = int(input())

g = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

c = list(map(lambda x: -int(x), input().split()))
heapq.heapify(c)
print(min(c) - sum(c))

ans = []
s = [-1] * n
leaf = -1
for i, a in enumerate(g):
    if len(a) == 1:
        leaf = i
        break

que = [leaf]
while que:
    t = que.pop()
    for e in g[t]:
        if s[e] == -1:
            s[e] = -heapq.heappop(c)
            que.append(e)

print(*s)

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

n = int(input())

g = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

c = list(map(int, input().split()))
c.sort()

ans = []
s = [0] * n
que = deque([0])
while que:
    t = que.popleft()
    ans.append(c.pop())
    s[t] = 1
    for e in g[t]:
        if not s[e]:
            que.append(e)

print(sum(c) - max(c))
print(*ans)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(500*500)

N = int(input())
edges = [list(map(int, input().split())) for _ in range(N-1)]

A = [[] for _ in range(N+1)]

for edge in edges:
    A[edge[0]].append([edge[1], edge[2]])
    A[edge[1]].append([edge[0], edge[2]])

depth = [-1] * (N+1)
depth[1] = 0

def dfs(A, s):
    for v in A[s]:
        if depth[v[0]] == -1:
            depth[v[0]] = depth[s] + v[1]
            dfs(A, v[0])

dfs(A, 1)
for d in depth[1:]:
    if d % 2 == 0:
        print(0)
    else:
        print(1)

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

N = int(input())
edges = [list(map(int, input().split())) for _ in range(N-1)]

A = [[] for _ in range(N+1)]

for edge in edges:
    A[edge[0]].append(edge[1], edge[2])
    A[edge[1]].append(edge[0], edge[2])

depth = [-1] * (N-1)
depth[1] = 0

def dfs(A, s):
    for v in A[s]:
        if depth[v[0]] == -1:
            depth[v[0]] = depth[s] + v[1]
            dfs[A, v[0]]

dfs[A, 1]
for d in depth[1:]:
    if d % 2 == 0:
        print(0)
    else:
        print(1)
Problem p03050 (python)

Fixed submission:
n = int(input())

ans = 0
for k in range(1, int(n**(1/2))+1):
    m = (n - k) // k
    if m <= 0: continue
    if n // m == n % m:
        ans += m

print(ans)

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

ans = 0
for k in range(1, int(n**(1/2))+1):
    m = (n - k) // k
    if n // m == n % m:
        ans += m

print(ans)
Problem p03074 (python)

Fixed submission:
n, k = map(int, input().split())
s = list(input())

cnt = []
if s[0] == '0': cnt.append(0)
i = 0
while i < n:
    j = i
    while j < n and s[j] == s[i]:
        j += 1
    cnt.append(j- i)
    i = j
if s[-1] == '0': cnt.append(0)

m = len(cnt)
cs = [0] * (m+1)
for i in range(m):
    cs[i+1] = cs[i] + cnt[i]

ans = 0
for l in range(0, m+1, 2):
    r = l + 2 * k + 1
    if r > m: r = m
    ans = max(ans, cs[r] - cs[l])

print(ans)

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

cnt = []
if s[0] == '0': cnt.append(0)

i = 0
while i < n:
    j = i
    while j < n and s[j] == s[i]:
        j += 1
    cnt.append(j- i)
    i = j
if s[-1] == '0': cnt.append(0)

cs = [0] * (len(cnt)+1)
for i in range(len(cnt)):
    cs[i+1] = cs[i] + cnt[i]

ans = 0
m = 2 * k + 1
for i in range(0, len(cnt), 2):
    ans = max(ans, cs[i+m] - cs[i])

print(ans)
Problem p03141 (python)

Fixed submission:
n = int(input())

ab = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append((a+b, a, b))

ab.sort(key= lambda x:x[0])

ans = 0
for i in range(n):
    v, a, b = ab.pop()
    if i % 2 == 0:
        ans += a
    else:
        ans -= b

print(ans)

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

ia = []
ib = []
for i in range(n):
    a, b = map(int, input().split())
    ia.append((i, a))
    ib.append((i, b))

ia.sort(key=lambda x:x[1])
ib.sort(key=lambda x:x[1])

ans = 0
for i in range(n):
    if i % 2 == 0:
        if ia[0][1] == ia[-1][1]:
            j, b = ib.pop()
            _, a = ia.pop(j)
        else:
            j, a = ia.pop()
            _, b = ib.pop(j)
        ans += a
    else:
        if ib[0][1] == ib[-1][1]:
            j, a = ia.pop()
            _, b = ib.pop(j)
        else:
            j, b = ib.pop()
            _, a = ia.pop(j)
        ans -= b
print(ans)
Problem p03164 (python)

Fixed submission:
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

dp = [0] + [float("inf")] * 10**5

for i in range(N):
    for j in range(10**5, v[i]-1, -1):
        dp[j] = min(dp[j], dp[j-v[i]] + w[i])

res = 0
for v, e in enumerate(dp):
    if e <= W:
        res = v

print(res)

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

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

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

print(max(dp[N-1]))
Problem p03436 (python)

Fixed submission:
from collections import deque

def bfs():
    d = [[float("inf")] * w for i in range(h)]

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((sx, sy))
    d[sx][sy] = 0

    while que:
        p = que.popleft()
        if p[0] == gx and p[1] == gy:
            break

        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] != "#" and d[nx][ny] == float("inf"):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1
    
    return d[gx][gy]

h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
sx, sy = 0, 0
gx, gy = h-1, w-1

white = 0
for i in range(h):
    for j in range(w):
        if maze[i][j] == ".":
            white += 1

res = bfs()

if 0 < res < float("inf"):
    print(white-res-1)
else:
    print(-1)

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

def bfs():
    d = [[float("inf")] * w for _ in range(h)]

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((sx, sy))
    d[sx][sy] = 0

    while que:
        p = que.popleft()
        if p[0] == gx and p[1] == gy:
            break

        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            if 0 <= nx < w and 0 <= ny < h and maze[nx][ny] != "#" and d[nx][ny] == float("inf"):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]] + 1
    
    return d[gx][gy]

h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
sx, sy = 0, 0
gx, gy = h-1, w-1

white = 0
for i in range(h):
    for j in range(w):
        if maze[i][j] == ".":
            white += 1

res = bfs()

if 0 < res < float("inf"):
    print(white-res-1)
else:
    print(-1)

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

def bfs():
    d = [[float("inf")] * w for _ in range(h)]

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((sx,sy))
    d[sx][sy] = 0

    while que:
        p = que.popleft()
        if p[0] == gx and p[1] == gy:
            break

        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            if 0 <= nx < w and 0 <= ny < h and maze[nx][ny] != "#" and d[nx][ny] == float("inf"):
                que.append((nx,ny))
                d[nx][ny] = d[p[0]][p[1]] + 1
    
    return d[gy][gx]

h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
sx, sy = 0, 0
gx, gy = h-1, w-1

white = 0
for i in range(h):
    for j in range(w):
        if maze[i][j] == ".":
            white += 1

res = bfs()

if 0 < res < float("inf"):
    print(white-res-1)
else:
    print(-1)
Problem p03565 (python)

Fixed submission:
s = input()
t = input()

result = []
for i in range(len(s)-len(t)+1):
    temp = '?'*i + t + '?'*(len(s)-len(t)-i)
    
    ans = ''
    flag = True
    for j in range(len(s)):
        if s[j] == '?' or s[j] == temp[j]:
            ans += temp[j]
        elif s[j] != '?' and temp[j] == '?':
            ans += s[j]
        else:
            flag = False

    if flag:
        result.append(ans.replace('?', 'a'))

if result:
    result.sort()
    print(result[0])
else:
    print("UNRESTORABLE")

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

result = []
for i in range(len(s)-len(t)+1):
    temp = '?'*i + t + '?'*(len(s)-len(t)-i)
    
    ans = ''
    flag = True
    for j in range(len(s)):
        if s[j] == '?' or s[j] == temp[j]:
            ans += temp[j]
        elif s[j] != '?' and temp[j] == '?':
            ans += s[j]
        else:
            flag = False

    if flag:
        result.append(ans)

if ans:
    result.sort()
    print(result[0])
else:
    print("UNRESTORABLE")
Problem p03612 (python)

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

ans = 0
for i in range(n):
    if i == n-1 and i+1 == p[i]:
        ans += 1
    elif i+1 == p[i]:
        temp = p[i]
        p[i] = p[i+1]
        p[i+1] = temp
        ans += 1


print(ans)

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

ans = 0
for i in range(n):
    if i+1 == p[i]:
        temp = p[i]
        p[i] = p[i+1]
        p[i+1] = temp
        ans += 1
    if i == n-1 and i+1 == p[i]:
        ans += 1        

print(ans)

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

ans = 0
for i in range(n):
    if i+1 == p[i]:
        temp = p[i]
        p[i] = p[i+1]
        p[i+1] = temp
        ans += 1

print(ans)
Problem p03651 (python)

Fixed submission:
import functools
import fractions

n, k = map(int, input().split())
a = list(map(int, input().split()))
m = max(a)

if k > m:
    print("IMPOSSIBLE")
else:
    gcd = functools.reduce(fractions.gcd, a)
    if k % gcd == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
import functools
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))
m = max(a)

if k > m:
    print("IMPOSSIBLE")
else:
    gcd = functools.reduce(math.gcd, a)
    if k % gcd == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
Problem p03910 (python)

Fixed submission:
n = int(input())

s = 0
i = 0
while s < n:
    s += i
    i += 1

if i == 1:
    print(1)
else:
    ans = list(range(1,i))
    if s - n != 0: ans.remove(s-n)
    print('\n'.join(map(str,ans)))

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

s = 0
i = 0
while s < n:
    s += i
    i += 1

if i == 1:
    print(1)
    exit()
ans = list(range(1,i))
ans.remove(s-n)
print('\n'.join(map(str,ans)))
Problem p03994 (python)

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

for i in range(n):
    x = ord(s[i]) - ord('a')
    if x == 0 or 26 -x > k: continue
    k -= 26 - x
    s[i] = 'a'

if k:
    s[-1] = chr((ord(s[-1]) - ord('a') + k) % 26 + ord('a'))

print(''.join(s))

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

d = [0] * n
for i in range(n):
    if s[i] != 'a':
        d[i] = ord('z') - ord(s[i]) + 1

ans = list(s)
for i in range(n):
    if d[i] != 0 and d[i] <= k:
        k -= d[i]
        ans[i] = 'a'
    if k == 0: break
    if i == n-1:
        ans[i] = chr(ord(s[i]) + k)

print(''.join(ans))

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

d = [0] * n
for i in range(n):
    if s[i] != 'a':
        d[i] = ord('z') - ord(s[i]) + 1

ans = list(s)
for i in range(n):
    if d[i] != 0 and d[i] <= k:
        k -= d[i]
        c = ord(s[i]) + d[i]
        ans[i] = chr(c - ord('z') + ord('a') - 1) if c > ord('z') else chr(c)
    if k == 0: break
    if i == n-1:
        ans[i] = chr(ord(s[i]) + k)

print(''.join(ans))
Problem p04020 (python)

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]

ans = 0
i = 0
while i < n:
    res = 0
    for j in range(i, n):
        if a[j] == 0: break
        res += a[j]
    ans += res // 2
    i = j + 1

print(ans)

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

dp = [0] * n
for i in range(n):
    dp[i] = max(dp[i-1] + a[i]//2,dp[i-2] + min(a[i-1], a[i]))

print(dp[-1])
Problem p04030 (python)

Fixed submission:
s = list(input())
n = len(s)

ans = []
for i in range(n):
    if s[i] == '0':
        ans.append('0')
    if s[i] == '1':
        ans.append('1')
    if s[i] == 'B':
        if ans:
            ans.pop()

print("".join(ans))

Buggy submission (verdict: Runtime Error):
s = list(input())
n = len(s)

ans = []
for i in range(n):
    if s[i] == '0':
        ans.append('0')
    if s[i] == '1':
        ans.append('1')
    if s[i] == 'B':
        ans[-1] = ''

print("".join(ans))
Problem p02971 (python)

Fixed submission:
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
  
sorted_a = sorted(a, reverse=True)

for v in a:
  if v == sorted_a[0]:
    print(sorted_a[1])
  else:
    print(sorted_a[0])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
  
sorted_a = sorted(a)

for v in a:
  if v == sorted[0]:
    print(sorted[1])
  else:
    print(sorted[0])
Problem p03160 (python)

Fixed submission:
def cal_min_cost(cnt):
    return min([
      abs(hight_list[i] - hight_list[i-diff]) + cost_list[i-diff]
      for diff in range(1,3)
      ])

hight_list = []
cost_list = [0,0]
N = int(input())
hight_list = list(map(int, input().split()))
hight_list.insert(0,hight_list[0])
for i in range(2, N+1):
    cost_list.append(cal_min_cost(i))
print(cost_list[-1])

Buggy submission (verdict: Runtime Error):
def cal_min_cost(cnt):
    return min([
      abs(hight_list[i] - hight_list[i-diff]) + cost_list[i-diff])
      for diff in range(1,3)
      ])

hight_list = []
cost_list = [0,0]
N = int(input())
hight_list = list(map(int, input().split()))
hight_list.insert(0,self.hight_list[0])
for i in range(2, N+1):
    cost_list.append(cal_min_cost(i))
print(cost_list[-1])
Problem p03141 (python)

Fixed submission:
n = input()
ans = 0
l = []
for i in xrange(n):
	a,b = map(int, raw_input().split())
	ans -= b
	l.append(a+b)
l.sort(reverse = True)
for i in xrange(0,n,2):
	ans += l[i]
print ans

Buggy submission (verdict: Runtime Error):
n = input()
flag = [0 for i in xrange(n)]
a = []
b = []
for i in xrange(n):
	x,y = map(int, raw_input().split())
	a.append((x,y,i))
	b.append((y,x,i))
a.sort(reverse = True)
b.sort(reverse = True)
ptr1 = 0
ptr2 = 0
turn = 0
ans1 = 0
ans2 = 0
while ptr1 < n and ptr2 < n:
	if turn == 0:
		while flag[a[ptr1][2]] == 1:
			ptr1 += 1
		if ptr1 < n:
			ans1 += a[ptr1][0]
			flag[a[ptr1][2]] = 1
			ptr1 += 1
		turn = 1
	else:
		while flag[b[ptr2][2]] == 1:
			ptr2 += 1
		if ptr2 < n:
			ans2 += b[ptr2][0]
			flag[b[ptr2][2]] = 1
			ptr2 += 1
		turn = 0
print ans1-ans2
Problem p03282 (python)

Fixed submission:
s = raw_input()
k = input()
index = -1
for i in xrange(len(s)):
	if s[i] > '1':
		index = i
		break
index += 1
if k >= index:
	print s[index-1]
else:
	print 1

Buggy submission (verdict: Runtime Error):
s = raw_input()
k = input()
index = -1
for i in xrange(len(s)):
	if s[i] > '1':
		index = i
		break
index += 1
if k >= index:
	print s[index]
else:
	print 1
Problem p03231 (python)

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


N, M = map(int, input().split())
S = input()
T = input()
gcd = gcd(N, M)

sl = [i for i in range(0, N, N//gcd)]
tl = [i for i in range(0, M, M//gcd)]
for i in range(len(sl)):
    if S[sl[i]] != T[tl[i]]:
        print(-1)
        break
else:
    print(N*M//gcd)

Buggy submission (verdict: Runtime Error):
import math

N, M = map(int, input().split())
S = input()
T = input()
gcd = math.gcd(N, M)

if gcd == 1:
    print(N*M)
else:
    sl = [i for i in range(0, N, N//gcd)]
    tl = [i for i in range(0, M, M//gcd)]
    for i in range(len(sl)):
        if S[sl[i]] != T[tl[i]]:
            print(-1)
            break
    else:
        print(N*M//gcd)
Problem p03240 (python)

Fixed submission:
N = int(input())
lst = [list(map(int, input().split())) for _ in range(N)]

for cx in range(101):
    for cy in range(101):
        for l in lst:
            if l[2] != 0:
                H = abs(cx-l[0]) + abs(cy-l[1]) + l[2]
        for l in lst:
            if l[2] != max(0, H - abs(cx-l[0]) - abs(cy-l[1])):
                break
        else:
            print(cx, cy, H)
            exit(0)

Buggy submission (verdict: Runtime Error):
import math
N, M = map(int, input().split())
sqrt = int(math.sqrt(M)) + 1
ans = 0
for i in range(1, sqrt):
    if M % i == 0:
        if ans < i <= M//N:
            ans = i
        if ans < M//i <= M//N:
            ans = M//i
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ls = []
for _ in range(N):
    ls.append(list(map(int, input().split())))

for cx in range(101):
    for cy in range(101):
        n = -1
        for l in ls:
            if l[2] != 0:
                if n == -1:
                    H = abs(cx - l[0]) + abs(cy - l[1]) + l[2]
                    n += 1
                if abs(cx-l[0])+abs(cy-l[1])+l[2] != H:
                    break
        else:
            print(cx, cy, H)
            exit(1)

Buggy submission (verdict: Runtime Error):
N = int(input())
ls = []
for _ in range(N):
    ls.append(list(map(int, input().split())))

for cx in range(101):
    for cy in range(101):
        n = -1
        for l in ls:
            if l[2] != 0:
                if n == -1:
                    H = abs(cx - l[0]) + abs(cy - l[1]) + l[2]
                    n += 1
                if abs(cx-l[0])+abs(cy-l[1])+l[2] != H:
                    break
        else:
            print(cx, cy, H)
            exit(1)
Problem p03476 (python)

Fixed submission:
isPrime = [True for i in range(100001)]
isPrime[0] = False
isPrime[1] = False

for i in range(2, 100001):
    if isPrime[i]:
        j = 2
        while i*j <= 100000:
            isPrime[i*j] = False
            j += 1

isSimilar = [True for i in range(100001)]
for i in range(100001):
    if isPrime[i] and isPrime[(i+1)//2]:
        pass
    else:
        isSimilar[i] = False

cnt = [0 for i in range(1, 100010)]
for i in range(1, 100001):
    cnt[i] = cnt[i-1] + [0, 1][isSimilar[i]]

q = int(input())
lrs = list()
for i in range(q):
    lrs.append(list(map(int, input().split())))

for l, r in lrs:
    print(cnt[r]-cnt[l-1])

Buggy submission (verdict: Runtime Error):
isPrime = [True for i in range(10001)]
isPrime[1] = False
isPrime[0] = False

for i in range(2, 10001):
    if isPrime[i]:
        j = 2
        while i*j <= 10000:
            isPrime[i*j] = False
            j += 1

q = int(input())
qu = list()
for i in range(q):
    qu.append(list(map(int, input().split())))

for a in qu:
    ans = 0
    for i in range(a[0], a[1]+1):
        if isPrime[i]:
            if isPrime[(i+1)//2]:
                ans += 1
    print(ans)

Buggy submission (verdict: Runtime Error):
isPrime = [True for i in range(10001)]
isPrime[1] = False
isPrime[0] = False

for i in range(2, 10001):
    if isPrime[i]:
        j = 2
        while i*j <= 10000:
            isPrime[i*j] = False
            j += 1

q = int(input())
qu = list()
for i in range(q):
    qu.append(list(map(int, input().split())))

for a in qu:
    ans = 0
    for i in range(a[0], a[1]+1):
        if isPrime[i]:
            if isPrime[(i+1)//2]:
                ans += 1
    print(ans)
Problem p03469 (python)

Fixed submission:
S = str(input())

print(S.replace(S[0:4],"2018"))

Buggy submission (verdict: Runtime Error):
N = int(input())
D = [0]*100

count = 0

for i in range(N):
    D[i] = int(input())

for k in D:
    m = max(D)
    D.remove(max(D))
    count += 1
    if max(D) == 0:
        break
    while m == max(D):
        D.remove(max(D))
    if max(D) == 0:
        break

print("{}".format(count))
Problem p02995 (python)

Fixed submission:

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

def gcd (a, b):
    while b != 0:
        a, b = b, a % b
    return a
gcd = gcd(c, d)

large_c = b // c
large_d = b // d
large_cd = b // ((c * d) // gcd)
large = large_c + large_d - large_cd

small_c = (a - 1) // c
small_d = (a - 1) // d
small_cd = (a - 1) // ((c * d) // gcd)
small = small_c + small_d - small_cd

print(int((b - (a - 1)) - (large - small)))

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

large_c = b // c
large_d = b // d
large_cd = b // ((c * d) / math.gcd(c, d))
large = large_c + large_d - large_cd

small_c = (a - 1) // c
small_d = (a - 1) // d
small_cd = (a - 1) // ((c * d) / math.gcd(c, d))
small = small_c + small_d - small_cd

print(int((b - (a - 1)) - (large - small)))