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

Fixed submission:
#ライブラリインポート
from collections import defaultdict
import bisect

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, M = getlist()
	S = list(input())
	nibu = []
	for i in range(N + 1):
		if S[i] == "0":
			nibu.append(i)

	prev = [None] * (N + 1)
	for i in range(1, N + 1):
		if S[i] == "0":
			s = bisect.bisect_left(nibu, i - M)
			x = nibu[s]
			if x != i:
				prev[i] = x
	# print(nibu)
	# print(prev)
	if prev[N] == None:
		print(-1)
	else:
		ans = []
		x = N
		while True:
			ans.append(x - prev[x])
			x = prev[x]
			if prev[x] == None:
				break
		if x == 0:
			ans = ans[::-1]
			print(" ".join(list(map(str, ans))))
		else:
			print(-1)

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
#ライブラリインポート
from collections import defaultdict
import bisect

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, M = getlist()
	S = list(input())
	nibu = []
	for i in range(N + 1):
		if S[i] == "0":
			nibu.append(i)
	DP = [0] * (N + 1)
	prev = [None] * (N + 1)
	for i in range(1, N + 1):
		if S[i] == "0":
			s = bisect.bisect_left(nibu, i - M)
			x = nibu[s]
			if x != i:
				prev[i] = x
				DP[i] = DP[x] + 1
	# print(nibu)
	# print(DP)
	# print(prev)
	if prev[N] == None:
		print(-1)
	else:
		ans = []
		x = N
		while True:
			ans.append(x - prev[x])
			x = prev[x]
			if x == 0:
				break
		ans = ans[::-1]
		print(" ".join(list(map(str, ans))))

if __name__ == '__main__':
	main()
Problem p02913 (python)

Fixed submission:
#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

p = 10 ** 9 + 7
p2 = 10 ** 9 + 9
q = 1007
q2 = 2009

def rollingHash(N, M, A, ans):
	mul1 = 1
	mul2 = 1
	for i in range(M):
		mul1 = (mul1 * q) % p
		mul2 = (mul2 * q2) % p2

	Droll1 = defaultdict(lambda:-1)
	Droll2 = defaultdict(lambda:-1)
	val1 = 0
	val2 = 0
	for i in range(M):
		val1 = val1 * q + A[i]
		val1 %= p
		val2 = val2 * q2 + A[i]
		val2 %= p2

	Droll1[val1] = 0
	Droll2[val2] = 0
	rolling_Hash1 = [None] * (N - M + 1)
	rolling_Hash1[0] = val1
	rolling_Hash2 = [None] * (N - M + 1)
	rolling_Hash2[0] = val2

	for i in range(N - M):
		val1 = (val1 * q - A[i] * mul1 + A[i + M]) % p
		val2 = (val2 * q2 - A[i] * mul2 + A[i + M]) % p2
		rolling_Hash1[i + 1] = val1
		rolling_Hash2[i + 1] = val2

		if Droll1[val1] == -1:
			Droll1[val1] = i + 1
		else:
			if rolling_Hash1[i + 1] == rolling_Hash1[Droll1[val1]] and rolling_Hash2[i + 1] == rolling_Hash2[Droll1[val1]] and i + 1 - Droll1[val1] >= M:
				return M

	return ans

#処理内容
def main():
	N = int(input())
	S = list(input())
	for i in range(N):
		S[i] = ord(S[i]) - 97

	ans = 0
	for i in range(1, int(N // 2) + 1):
		ans = rollingHash(N, i, S, ans)

	print(ans)



if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

p = 1 ** 61 - 1
p2 = 10 ** 8 + 7
q = 10 ** 2

def rollingHash(N, M, A, ans):
	mul = 1
	for i in range(M):
		mul = (mul * q) % p

	Droll = defaultdict(lambda:-1)
	val = 0
	for i in range(M):
		val = val * q + A[i]
		val %= p

	Droll[val] = 0
	for i in range(N - M):
		val = (val * q - A[i] * mul + A[i + M]) % p
		if Droll[val] != -1 and i + 1 - Droll[val] >= M:
			return M

		Droll[val] = i + 1
	return ans

#処理内容
def main():
	N = int(input())
	S = list(input())
	for i in range(N):
		S[i] = ord(S[i]) - 97

	ans = 0
	for i in range(1, N):
		ans = rollingHash(N, i, S, ans)

	print(ans)



if __name__ == '__main__':
	main()
Problem p02988 (python)

Fixed submission:
def getlist():
	return list(map(int, input().split()))

n = int(input())
p = getlist()

ans = 0
for i in range(n - 2):
	if p[i] < p[i + 1] and p[i + 1] < p[i + 2]:
		ans += 1
	elif p[i] > p[i + 1] and p[i + 1] > p[i + 2]:
		ans += 1
	else:
		pass

print(ans)

Buggy submission (verdict: Runtime Error):
def getlist():
	return list(map(int, input().split()))

n = int(input())
p = getlist()

ans = 0
for i in range(N - 2):
	if p[i] < p[i + 1] and p[i + 1] < p[i + 2]:
		ans += 1
	elif p[i] > p[i + 1] and p[i + 1] > p[i + 2]:
		ans += 1
	else:
		pass

print(ans)
Problem p03044 (python)

Fixed submission:
from collections import defaultdict
import queue

def getlist():
	return list(map(int, input().split()))

class Graph(object):
    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b, w):
        self.graph[a].append([b, w])

    def get_nodes(self):
        return self.graph.keys()

class BFS(object):
    def __init__(self, graph, N):
        self.g = graph.graph
        self.dist = [0] * (N + 1)
        self.visit = [0] * (N + 1)
        self.Q = queue.Queue()
        self.Q.put(1)

        while not self.Q.empty():
            v = self.Q.get()
            for i, w in self.g[v]:
            	if self.visit[i] == 0:
            		self.dist[i] = self.dist[v] + w
            		self.Q.put(i)
            		self.visit[i] = 1

    def weight(self):
        return self.dist

N = int(input())
G = Graph()
for i in range(N - 1):
    u, v, w = getlist()
    G.add_edge(u, v, w)
    G.add_edge(v, u, w)

XX = BFS(G, N)
ans = XX.weight()
for i in range(1, N + 1):
	if ans[i] % 2 == 0:
		print(0)
	else:
		print(1)

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

def getlist():
	return list(map(int, input().split()))

class Graph(object):
    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b, w):
        self.graph[a].append([b, w])

    def get_nodes(self):
        return self.graph.keys()

class BFS(object):
    def __init__(self, graph, N):
        self.g = graph.graph
        self.dist = [0] * (N + 1)
        self.visit = [0] * (N + 1)
        self.Q = queue.Queue()
        self.Q.put(1)

        while not self.Q.empty():
            v = self.Q.get()
            for i, w in self.g[v]:
            	if self.visit[i] == 0:
            		self.dist[i] = self.dist[v] + w

            	self.Q.put(i)
            	self.visit[i] = 1

    def weight(self):
        return self.dist

N = int(input())
G = Graph()
for i in range(N - 1):
	u, v, w = getlist()
	G.add_edge(u, v, w)
XX = BFS(G, W, N)
ans = XX.weight()

for i in range(1, N + 1):
	if ans[i] % 2 == 0:
		print(0)
	else:
		print(1)
Problem p03101 (python)

Fixed submission:
H, W = list(map(int, input().split()))
h, w = list(map(int, input().split()))
print((H - h) * (W - w))

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

ba = B - A 
if A % 2 == 0:
	ja = "j0"
else:
	ja = "j1"

if B % 2 == 0:
	jb = "j0"
else:
	jb = "j1"

a = A
b = B
a2 = ""
b2 = ""

if a == 0:
	a2 = "0"
else:
	while True:
		if a % 2 == 0:
			a2 += "0"
		else:
			a2 += "1"
		a = int(a // 2)
		if a == 1:
			a2 += "1"
			break
if b == 0:
	b2 = "0"
else:
	while True:
		if b % 2 == 0:
			b2 += "0"
		else:
			b2 += "1"
		b = int(b // 2)
		if b == 1:
			b2 += "1"
			break

a2 += "0" * (len(b2) - len(a2))
c2 = 0

if a2[0] == "0":
	if ba % 4 == 2 or ba % 4 == 1:
		c2 += 1
	else:
		c2 += 0

if a2[0] == "1":
	if ba % 4 <= 1:
		c2 += 1
	else:
		c2 += 0

for i in range(1, len(a2)):
	n = 0
	if a2[i] == "1":
		if ja == "j1":
			n += 1

	if b2[i] == "1":
		if jb == "j0":
			n += 1

	if n % 2 == 0:
		c2 += 0
	else:
		c2 += 2 ** i

print(c2)
Problem p03138 (python)

Fixed submission:
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	A = getlist()
	if K == 0:
		print(sum(A))
		sys.exit()	
	dp = [0] * 41
	j = 0
	while True:
		if K % 2 == 1:
			dp[-1 - j] = 1
		K = K // 2
		if K == 0:
			break
		j += 1
	#print(dp)

	p1 = [0] * 41
	p0 = [N] * 41
	for i in range(N):
		a = A[i]
		j = 0
		while True:
			if a % 2 == 1:
				p1[-1 - j] += 1
			a = a // 2
			if a == 0:
				break
			j += 1
	for i in range(41):
		p0[i] -= p1[i]
	#print(p1)
	#print(p0)

	#DP
	DP0 = [0] * 41
	DP1 = [0] * 41
	s = dp.index(1)
	DP0[0] = (2 ** 40) * p1[0]
	DP1[0] = (2 ** 40) * p1[0]
	for i in range(1, s):
		DP0[i] += DP0[i - 1] + (2 ** (40 - i)) * p1[i]
		DP1[i] += DP1[i - 1] + (2 ** (40 - i)) * p1[i]
	if s != 0:
		DP0[s] = DP0[s - 1] + (2 ** (40 - s)) * p0[s]
		DP1[s] = DP1[s - 1] + (2 ** (40 - s)) * p1[s]
	else:
		DP0[s] = (2 ** (40 - s)) * p0[s]
		DP1[s] = (2 ** (40 - s)) * p1[s]
	for i in range(s + 1, 41):
		if dp[i] == 1:
			DP0[i] = DP0[i - 1] + (2 ** (40 - i)) * p0[i]
			DP1[i] = max(DP1[i - 1] + (2 ** (40 - i)) * max(p0[i], p1[i]), DP0[i - 1] + (2 ** (40 - i)) * p1[i])
		else:
			DP0[i] = DP0[i - 1] + (2 ** (40 - i)) * p1[i]
			DP1[i] = DP1[i - 1] + (2 ** (40 - i)) * max(p0[i], p1[i])
	# print(DP0)
	# print(DP1)
	print(max(DP0[-1], DP1[-1]))

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict
import copy

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	A = getlist()
	B = copy.copy(A)
	num = 0
	n = K.bit_length()
	numL = [0] * 35
	for i in range(N):
		for j in range(35):
			if B[i] & 1 == 1:
				numL[j] += 1
			B[i] = B[i] >> 1
			if B[i] == 0:
				break
	for i in range(n):
		if 2 * numL[i] < N:
			num += 2 ** i
	ans = 0
	for i in range(N):
		ans += num ^ A[i]
	print(ans)

if __name__ == '__main__':
	main()
Problem p03148 (python)

Fixed submission:
from collections import defaultdict

def getlist():
	return list(map(int, input().split()))
D = defaultdict(int)
V = []

N, K = getlist()
for i in range(N):
	t, d = getlist()
	V.append([d, t])

V = sorted(V)

ans = []
ex = []
k = 0
for i in range(N):
	x = V[-1 - i][1]
	if k < K:
		if D[x] == 0:
			ans.append(V[-1 - i])
			D[x] += 1
			k += 1
		else:
			ex.append(V[-1 - i])
	else:
		ex.append(V[-1 - i])


if k < K:
	for i in range(K - k):
		ans.append(ex[i])
	eex = []
	for i in range(K - k, len(ex)):
		eex.append(ex[i])
else:
	eex = ex
ans = sorted(ans)
eex = sorted(eex)


A = 0
for i in range(K):
	A += ans[i][0]
A += k * k
n = min(k, N - K)
for i in range(n):
	if ans[i][0] + ((k - i) ** 2) - ((k - i - 1) ** 2) < eex[-1 - i][0]:
		A += eex[-1 - i][0] - ans[i][0] - ((k - i) ** 2) + ((k - i - 1) ** 2)
	else:
		break

print(A)

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

def getlist():
	return list(map(int, input().split()))
D = defaultdict(int)
V = []

N, K = getlist()
for i in range(N):
	t, d = getlist()
	V.append([d, t])

V = sorted(V)

ans = []
ex = []
k = 0
for i in range(N):
	x = V[-1 - i][1]
	if k < K:
		if D[x] == 0:
			ans.append(V[-1 - i])
			D[x] += 1
			k += 1
	else:
		ex.append(V[-1 - i])


if k < K:
	for i in range(K - k):
		ans.append(ex[i])
	eex = []
	for i in range(K - k, len(ex)):
		eex.append(ex[i])
else:
	eex = ex
ans = sorted(ans)
eex = sorted(eex)


A = 0
for i in range(K):
	A += ans[i][0]
A += k * k
n = min(k, N - K)
for i in range(n):
	if ans[i][0] + ((k - i) ** 2) - ((k - i - 1) ** 2) < eex[-1 - i][0]:
		A += eex[-1 - i][0] - ans[i][0] - ((k - i) ** 2) + ((k - i - 1) ** 2)
	else:
		break

print(A)

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

def getlist():
	return list(map(int, input().split()))
D = defaultdict(int)
V = []

N, K = getlist()
for i in range(N):
	t, d = getlist()
	V.append([d, t])

V = sorted(V)

ans = []
ex = []
k = 0
for i in range(N):
	x = V[-1 - i][1]
	if D[x] == 0:
		ans.append(V[-1 - i])
		D[x] += 1
		k += 1
	else:
		ex.append(V[-1 - i])
	if k == K:
		break

if k < K:
	for i in range(K - k):
		ans.append(ex[i])
	eex = []
	for i in range(K - k, len(ex)):
		eex.append(ex[i])
else:
	eex = ex
ans = sorted(ans)
eex = sorted(eex)


A = 0
for i in range(K):
	A += ans[i][0]
A += k * k
n = min(k, N - K)
for i in range(n):
	if ans[i][0] + ((k - i) ** 2) - ((k - i - 1) ** 2) < eex[-1 - i][0]:
		A += eex[-1 - i][0] - ans[i][0] - ((k - i) ** 2) + ((k - i - 1) ** 2)
	else:
		break

print(A)
Problem p03206 (python)

Fixed submission:
D = int(input())
if D == 25:
	print("Christmas")
elif D == 24:
	print("Christmas Eve")
elif D == 23:
	print("Christmas Eve Eve")
else:
	print("Christmas Eve Eve Eve")

Buggy submission (verdict: Runtime Error):
D = int(input())
if D = 25:
	print("Christmas")
elif D = 24:
	print("Christmas Eve")
elif D = 23:
	print("Christmas Eve Eve")
else:
	print("Christmas Eve Eve Eve")
Problem p03214 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))

ave = sum(a) / N

aa =[abs(a[i] - ave) for i in range(N)]

x = min(aa)

print(aa.index(x))

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

ave = sum(a) / N

aa =[abs(a[i] - ave) for i in range(N)]

x = min(aa)

print(aa.find(x))
Problem p03262 (python)

Fixed submission:
N, X = list(map(int, input().split()))
x = list(map(int, input().split()))

for i in range(N):
	x[i] -= X
if N == 1:
	print(abs(x[0]))
else:
	a = x[0]
	for i in range(N - 1):
		b = x[i + 1]
		a, b = sorted([a, b])
		while True:
			if b % a == 0:
				break
			else:
				a, b = b % a, a
	print(abs(a))

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

for i in range(N):
	x[i] -= X
if N == 1:
	print(abs(x[0]))
else:
	a = x[0]
	for i in range(N - 1):
		b = x[i + 1]
		a, b = sorted([a, b])
		while True:
			if b % a == 0:
				break
			else:
				a, b = b % a, a

print(abs(a))
Problem p03328 (python)

Fixed submission:
a, b = list(map(int, input().split()))
answer = (b - a) * (b - a + 1) / 2 - b
print(int(answer))

Buggy submission (verdict: Runtime Error):
a, b = list(map(int, input()))
answer = (b - a) * (b - a + 1) / 2 - b
print(int(answer))
Problem p03331 (python)

Fixed submission:
N = int(input())
L = []
for i in range(N - 1):
	a = list(str(i + 1))
	b = list(str(N - i - 1))
	asum = sum(list(map(int, a)))
	bsum = sum(list(map(int, b)))
	
	L.append(asum + bsum)
print(min(L))

Buggy submission (verdict: Runtime Error):
N = int(input())
L = []
for i in range(N):
	a = i + 1
	b = N - i - 1
	s = sum(list(map,(int, list(str(a))))) + sum(list(map,(int, list(str(b)))))
	L.append(s)
print(min(L))
Problem p03393 (python)

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

D = [0 for i in range(26)]
for i in range(N):
    D[ord(S[i]) - 97] = 1

if N != 26:
    for i in range(26):
        if D[i] == 0:
            s = chr(97 + i)
            break
    print(S + s)

else:
    if S == "abcdefghijklmnopqrstuvwxyz"[::-1]:
        print(-1)
    else:
        c = 2
        for i in range(N):
            if ord(S[-2 - i]) - ord(S[-1 - i]) >= 1:
                c += 1
            else:
                break
        s = sorted(list(S[26 - c:]))
        for i in s:
            if ord(i) > ord(S[-c]):
                key = i
                break

        print(S[:26 - c] + key)

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

D = [0 for i in range(26)]
for i in range(N):
    D[ord(S[i]) - 97] = 1

if N != 26:
    for i in range(N):
        if D[i] == 0:
            s = chr(97 + i)
            break
    print(S + s)

else:
    if S == "abcdefghijklmnopqrstuvwxyz"[::-1]:
        print(-1)
    else:
        c = 2
        for i in range(N):
            if ord(S[-2 - i]) - ord(S[-1 - i]) == 1:
                c += 1
            else:
                break
        print(S[:26 - c] + S[-1])
Problem p03424 (python)

Fixed submission:
N = int(input())
S = list(input().split())
y = 0
for i in range(N):
	if S[i] == "Y":
		y = 1
if y == 0:
	print("Three")
else:
	print("Four")

Buggy submission (verdict: Runtime Error):
N = int(input())
S = list(map(int, input().split()))
y = 0
for i in range(N):
	if S[i] == "Y":
		y = 1
if y == 0:
	print("Three")
else:
	print("Four")
Problem p03441 (python)

Fixed submission:
#設定
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

	def get_nodes(self):
		return self.graph.keys()

#val = 0

def DFS(G, anstenna, edge_num, have, visit, node):
	cnt = 0
	for i in G.graph[node]:
		if visit[i] != "Yes":
			visit[i] = "Yes"
			DFS(G, anstenna, edge_num, have, visit, i)
			if have[i] == 1:
				cnt += 1
				anstenna[node] += anstenna[i]

	if cnt < edge_num[node] - 1:
		anstenna[node] += edge_num[node] - 1 - cnt
	if anstenna[node] >= 1:
		have[node] = 1

#処理内容
def main():
	N = int(input())
	G = Graph()
	for i in range(N - 1):
		a, b = getlist()
		G.add_edge(a, b)
		G.add_edge(b, a)

	if N == 2:
		print(1)
		return

	#DFS
	anstenna = [0] * (N + 1)
	have = [0] * (N + 1)
	edge_num = [len(G.graph[i]) - 1 for i in range(N + 1)]

	if max(edge_num) <= 1:
		print(1)
		return

	visit = ["No"] * (N + 1)
	visit[N] = "Yes"
	s = None
	for i in range(N):
		if edge_num[i] >= 1:
			s = i
			break
	G.add_edge(N, s)
	G.add_edge(s, N)
	edge_num[s] += 1

	DFS(G, anstenna, edge_num, have, visit, N)
	ans = anstenna[N]
	if edge_num[s] == 2:
		cnt = 0
		for i in G.graph[s]:
			if have[i] == 1:
				cnt += 1
		if cnt <= 2:
			ans += 1

	print(ans)

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
#設定
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

	def get_nodes(self):
		return self.graph.keys()

#val = 0

def DFS(G, anstenna, edge_num, have, visit, node):
	cnt = 0
	for i in G.graph[node]:
		if visit[i] != "Yes":
			visit[i] = "Yes"
			DFS(G, anstenna, edge_num, have, visit, i)
			if have[i] == 1:
				cnt += 1
				anstenna[node] += anstenna[i]

	if cnt < edge_num[node] - 1:
		anstenna[node] += edge_num[node] - 1 - cnt
	if anstenna[node] >= 1:
		have[node] = 1

#処理内容
def main():
	N = int(input())
	G = Graph()
	for i in range(N - 1):
		a, b = getlist()
		a -= 1; b -= 1
		G.add_edge(a, b)
		G.add_edge(b, a)

	if N == 2:
		print(1)
		return

	#DFS
	anstenna = [0] * (N + 1)
	have = [0] * (N + 1)
	edge_num = [len(G.graph[i]) - 1 for i in range(N + 1)]
	visit = ["No"] * (N + 1)
	visit[N] = "Yes"
	s = None
	for i in range(N):
		if edge_num[i] >= 1:
			s = i
			break
	G.add_edge(N, s)
	G.add_edge(s, N)
	edge_num[s] += 1

	DFS(G, anstenna, edge_num, have, visit, N)
	ans = anstenna[N]
	if edge_num[s] == 2:
		cnt = 0
		for i in G.graph[s]:
			if have[i] == 1:
				cnt += 1
		if cnt <= 2:
			ans += 1

	print(ans)

if __name__ == '__main__':
	main()
Problem p03469 (python)

Fixed submission:
S = list(input())
S[3] = "8"
print("".join(S))

Buggy submission (verdict: Runtime Error):
S = list(input())
S[3] = 8
print("".join(S))
Problem p03476 (python)

Fixed submission:
import bisect

Q = int(input())

L = [1 for i in range(100001)]
L[0] = 0
L[1] = 0
for i in range(100001):
	if L[i] == 1:
		c = 2
		while True:
			if i * c <= 100000:
				L[i * c] = 0
				c += 1
			else:
				break
p2017 = []
for i in range(3, 100001):
	if i % 2 != 0:
		if L[i] == 1 and L[int((i + 1) // 2)] == 1:
			p2017.append(i)


for i in range(Q):
	l, r = list(map(int, input().split()))
	a = bisect.bisect_left(p2017, l)
	b = bisect.bisect_right(p2017, r)
	print(b - a)

Buggy submission (verdict: Runtime Error):
import bisect

Q = int(input())

L = [1 for i in range(100001)]
L[0] = 0
L[1] = 0
for i in range(100001):
	if L[i] == 1:
		c = 2
		while True:
			if i * c <= 100000:
				L[i * c] = 0
				c += 1
			else:
				break
p2017 = []
for i in range(3, 100001):
	if i % 2 != 0:
		if L[i] == 1 and L[int((i + 1) // 2)] == 1:
			p2017.append(i)

for i in range(Q):
	l, r = list(map(int, input().split()))
	a = bisect.bisect_left(p2017, l)
	b = bisect.bisect_left(p2017, r)
	if p2017[b] == r:
		b += 1
	print(b - a)
Problem p03490 (python)

Fixed submission:
from collections import defaultdict

s = list(input())
x, y = list(map(int, input().split()))

X = []
Y = []
judge = "x"
l = 0
for i in s:
	if i == "F":
		l += 1
	else:
		if judge == "x":
			if l != 0:
				X.append(l)
			judge = "y"
		else:
			if l != 0:
				Y.append(l)
			judge = "x"
		l = 0

if judge == "x":
	if l != 0:
		X.append(l)
else:
	if l != 0:
		Y.append(l)

jj = "bad"
if len(s) >= 2:
	if s[0] == "T":
		jj = "good"


dx = defaultdict(int)
if X != []:
	if jj == "good":
		dx[X[0]] = 1
		dx[-X[0]] = 1
	else:
		dx[X[0]] = 1
	X.remove(X[0])
else:
	dx[0] = 1

for i in range(len(X)):
	D = defaultdict(int)
	for j in dx:
		if dx[j] == 1:
			D[j + X[i]] = 1
			D[j - X[i]] = 1
	dx = D


dy = defaultdict(int)
if Y != []:
	dy[Y[0]] = 1
	dy[-Y[0]] = 1
	Y.remove(Y[0])
else:
	dy[0] = 1

for i in range(len(Y)):
	D = defaultdict(int)
	for j in dy:
		if dy[j] == 1:
			D[j + Y[i]] = 1
			D[j - Y[i]] = 1
	dy = D

if dx[x] == 1 and dy[y] == 1:
	print("Yes")
else:
	print("No")

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

s = list(input())
x, y = list(map(int, input().split()))

X = []
Y = []
judge = "x"
l = 0
for i in s:
	if i == "F":
		l += 1
	else:
		if judge == "x":
			X.append(l)
			judge = "y"
		else:
			judge == "y"
			Y.append(l)
			judge = "x"
		l =0

if judge == "x":
	X.append(l)
else:
	Y.append(l)


dx = defaultdict(int)
dx[X[0]] = 1
X.remove(X[0])
for i in range(len(X)):
	D = defaultdict(int)
	for j in dx:
		if dx[j] >= 1:
			D[j + X[i]] = 1
			D[j - X[i]] = 1
	dx = D

dy = defaultdict(int)
dy[Y[0]] = 1
dy[-Y[0]] = 1
Y.remove(Y[0])
for i in range(len(Y)):
	D = defaultdict(int)
	for j in dy:
		if dy[j] >= 1:
			D[j + Y[i]] = 1
			D[j - Y[i]] = 1
	dy = D

if dx[x] == 1 and dy[y] == 1:
	print("Yes")
else:
	print("No")
Problem p03640 (python)

Fixed submission:
H, W = list(map(int, input().split()))
N = int(input())
A = []
a = list(map(int, input().split()))
for i in range(N):
    A += [i + 1] * a[i]

L = [[0 for i in range(W)] for j in range(H)]
for i in range(H * W):
    if int((i // W)) % 2 == 0:
        L[int((i // W))][i % W] = A[i]
    else:
        L[int((i // W))][-1 - i % W] = A[i]

for i in range(H):
    L[i] = list(map(str, L[i]))


for i in range(H):
    print(" ".join(L[i]))

Buggy submission (verdict: Runtime Error):
H, W = list(map(int, input().split()))
N = int(input())
A = []
a = list(map(int, input().split()))
for i in range(N):
    A += [a[i]] * (i + 1)

L = [[0 for i in range(W)] for j in range(H)]
for i in range(H * W):
    if int((i // W)) % 2 == 0:
        L[int((i // W))][i % W] = A[i]
    else:
        L[int((i // W))][-1 - i % W] = A[i]

for i in range(H):
    L[i] = list(map(str, L[i]))


for i in range(H):
    print(" ".join(L[i]))
Problem p03651 (python)

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

if N == 1:
	x = A[0]
else:
	a = A[0]
	for i in range(N - 1):
		b = A[i + 1]
		a, b = sorted([a, b])
		while True:
			if b % a == 0:
				break
			else:
				a, b = b % a, a
	x = a

if K % x == 0 and max(A) >= K:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

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

if N == 1:
	x = a
else:
	a = A[0]
	for i in range(N - 1):
		b = A[i + 1]
		a, b = sorted([a, b])
		while True:
			if b % a == 0:
				break
			else:
				a, b = b % a, a
	x = a

if K % x == 0 and max(A) >= K:
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")