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

Fixed submission:
def main():
	n, q = map(int, input().split())
	s = "."+input()+"."
	pm = [input().split() for _ in range(q)]

	def is_outside(x:int) -> int:
		for point, move in pm:
			if s[x] == point:
				if move == "L":
					x -= 1
				else:
					x += 1
			if x == 0:
				return -1
			if x == n+1:
				return 1
		return 0

	ok, ng = 0, n+1
	while ng - ok > 1:
		mid = (ng + ok) >> 1
		if is_outside(mid) == -1:
			ok = mid
		else:
			ng = mid
	l = ok

	ng, ok = 0, n+1
	while ok - ng > 1:
		mid = (ng + ok) >> 1
		if is_outside(mid) == 1:
			ok = mid
		else:
			ng = mid
	r = ng

	print(max(r-l, 0))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
	n, q = map(int, input().split())
	s = f".{input()}."
	pm = [input().split() for _ in range(q)]

	def is_outside(x:int) -> int:
		for point, move in pm:
			if s[x] == point:
				if move == "L":
					x -= 1
				else:
					x += 1
			if x == 0:
				return -1
			if x == n+1:
				return 1
		return 0

	ok, ng = 0, n+1
	while ng - ok > 1:
		mid = (ng + ok) >> 1
		if is_outside(mid) == -1:
			ok = mid
		else:
			ng = mid
	l = ok

	ng, ok = 0, n+1
	while ok - ng > 1:
		mid = (ng + ok) >> 1
		if is_outside(mid) == 1:
			ok = mid
		else:
			ng = mid
	r = ng

	print(max(r-l, 0))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
	n, q = map(int, input().split())
	s = f".{input()}."
	pm = [input().split() for _ in range(q)]

	def is_outside(x:int) -> int:
		for point, move in pm:
			if s[x] == point:
				if move == "L":
					x -= 1
				else:
					x += 1
			if x == 0:
				return -1
			if x == n+1:
				return 1
		return 0

	ok, ng = 0, n+1
	while ng - ok > 1:
		mid = (ng + ok) >> 1
		if is_outside(mid) == -1:
			ok = mid
		else:
			ng = mid
	l = ok

	ng, ok = 0, n+1
	while ok - ng > 1:
		mid = (ng + ok) >> 1
		if is_outside(mid) == 1:
			ok = mid
		else:
			ng = mid
	r = ng

	print(max(r-l, 0))

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

Fixed submission:
def main():
	n, q = map(int, input().split())
	s = input()
	acs = [0]*(n)
	for i in range(1, n):
		if s[i-1] == "A" and s[i] == "C":
			acs[i] = acs[i-1] + 1
		else:
			acs[i] = acs[i-1]
	results = [0]*q
	for i in range(q):
		l, r = map(int, input().split())
		if l == r:
			continue
		results[i] = acs[r-1] - acs[l-1]
	for result in results:
		print(result)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
	n, q = map(int, input().split())
	s = input()
	acs = [0]*(n+1)
	for i in range(1, n+1):
		if s[i-1] == "A" and s[i] == "C":
			acs[i] = acs[i-1] + 1
		else:
			acs[i] = acs[i-1]
	results = [0]*q
	for i in range(q):
		l, r = map(int, input().split())
		if l == r:
			continue

		results[i] = acs[r] - acs[l]
		if s[r-1] == "A":
			results[i] -= 1
		if s[l-1] == "A" and s[l] == "C":
			results[i] += 1
	for result in results:
		print(result)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
	n, q = map(int, input().split())
	s = input()
	acs = [0]*(n+1)
	for i in range(1, n+1):
		if s[i-1] == "A" and s[i] == "C":
			acs[i] = acs[i-1] + 1
		else:
			acs[i] = acs[i-1]
	results = [0]*q
	for i in range(q):
		l, r = map(int, input().split())
		results[i] = acs[r] - acs[l]
		if s[r-1] == "A" and l != r:
			results[i] -= 1
		if s[l-1] == "A" and l != r:
			results[i] += 1
	for result in results:
		print(result)

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

Fixed submission:
def main():
	a,b = map(int, input().split())
	if (b % a) == 0:
		print(a+b)
	else:
		print(b-a)

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	a,b = map(int, input().split())
	if (b %= a) == 0:
		print(a+b)
	else:
		print(b-a)

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	s = input().strip()
	a = s[0]
	b = s[1]
	if (b/a)*a == b:
		print(a+b)
	else:
		print(b-a)

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

Fixed submission:
def main():
	n = int(input())
	xi, yi, hi = [0]*n, [0]*n, [0]*n
	stack = []
	result = []
	for i in range(n):
		xi[i], yi[i], hi[i] = map(int, input().split())
		if hi[i] > 0:
			stack = [xi[i], yi[i], hi[i]]
	for i in range(101):
		for j in range(101):
			guess = stack[2] + abs(stack[0]-i) + abs(stack[1]-j)
			is_result = True
			for k in range(n):
				result = guess - abs(xi[k]-i) - abs(yi[k]-j)
				result = max(result, 0)
				if hi[k] != result:
					is_result = False
					break
			if is_result:
				print(str(i)+" "+str(j)+" "+str(guess))
				return


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
	n = int(input())
	xi, yi, hi = [0]*n, [0]*n, [0]*n
	stack = []
	result = []
	for i in range(n):
		xi[i], yi[i], hi[i] = map(int, input().split())
		if hi[i] > 0:
			stack = [xi[i], yi[i], hi[i]]
	for i in range(101):
		for j in range(101):
			guess = stack[2] + abs(stack[0]-i) + abs(stack[1]-j)
			is_result = True
			for k in range(n):
				result = guess - abs(xi[k]-i) - abs(yi[k]-j)
				result = max(result, 0)
				if hi[k] != result:
					is_result = False
					break
			if is_result:
				print(str(i)+" "+str(j)+" "+str(v))
				return


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

Fixed submission:
from collections import defaultdict
def main():
	N, M = map(int, input().split())
	A = list(map(int, input().split()))
	sums = [0]*(N+1)
	ans = 0
	mod = defaultdict(int)
	mod[0] = 1
	for i in range(1, N+1):
		sums[i] = (sums[i-1] + A[i-1]) % M
		ans += mod[sums[i]]
		mod[sums[i]] += 1

	print(ans)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
	N, M = map(int, input().split())
	A = list(map(int, input().split()))
	sums = [0]*(N+1)
	ans = 0
	mod = [0]*M
	mod[0] = 1
	for i in range(1, N+1):
		sums[i] = (sums[i-1] + A[i-1]) % M
		ans += mod[sums[i]]
		mod[sums[i]] += 1

	print(ans)

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

Fixed submission:
def main():
	N = int(input())
	A = list(map(int, input().split()))
	for i in range(N):
		A[i] -= i+1
	A.sort()


	mid1 = A[N//2]
	mid2 = A[N//2]
	if N >= 2:
		mid2 = A[N//2 + 1]

	ans1 = 0
	ans2 = 0
	for i in range(N):
		ans1 += abs(A[i] - mid1)
		ans2 += abs(A[i] - mid2)

	print(min(ans1, ans2))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
	N = int(input())
	A = list(map(int, input().split()))
	for i in range(N):
		A[i] -= i+1
	A.sort()

	mid1 = A[N//2]
	mid2 = A[N//2 + 1]
	ans1 = 0
	ans2 = 0
	for i in range(N):
		ans1 += abs(A[i] - mid1)
		ans2 += abs(A[i] - mid2)

	print(min(ans1, ans2))


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

Fixed submission:
def main():
	D, N = map(int, input().split())
	if N == 100:
		N += 1
	print(N * (100**D))

if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	D, N = map(int, input().split())
	if N == 100:
		N += 1
	print(N * (100**D)

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

Fixed submission:
def main():
	H, W = map(int,input().split())
	pos = [""]*H
	for i in range(H):
		pos[i] = input()

	offset = [[-1, 0], [1, 0], [0, -1], [0, 1]]
	def bfs(s, h, w):
		queue = [[0, 0, 0]]
		is_visited = [[False for _ in range(w)] for _ in range(h)]
		is_visited[0][0] = True
		while queue:
			cur = queue.pop(0)
			for o in offset:
				y, x = cur[0]+o[0], cur[1]+o[1]
				if x < 0 or x >= w or y < 0 or y >= h:
					continue
				if x == w-1 and y == h-1:
					return cur[2]+1
				if is_visited[y][x]:
					continue
				if s[y][x] == ".":
					queue.append([y, x, cur[2]+1])
					is_visited[y][x] = True
		return -1

	white_num = 0
	for i in range(H):
		for j in range(W):
			if pos[i][j] == ".":
				white_num += 1
	route = bfs(pos, H, W)
	if route == -1:
		print(-1)
	else:
		print(white_num-route-1)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
	H, W = map(int,input().split())
	pos = [""]*H
	for i in range(H):
		pos[i] = input()
	x = min(W, H)
	can_clear = True
	for dist in range(H+W-1):
		impossible_range = True
		for i in range(H):
			if i > dist:
				break
			if dist-i > W:
				continue
			if pos[i][dist-i] == ".":
				impossible_range = False
				break
		if impossible_range:
			can_clear = False
			break
	if not can_clear:
		print(-1)
		return

	offset = [[-1, 0], [1, 0], [0, -1], [0, 1]]
	def bfs(s, h, w):
		queue = [[0, 0, 0]]
		is_visited = [[False for _ in range(w)] for _ in range(h)]
		is_visited[0][0] = True
		while queue:
			cur = queue.pop(0)
			for o in offset:
				y, x = cur[0]+o[0], cur[1]+o[1]
				if x < 0 or x >= w or y < 0 or y >= h:
					continue
				if x == w-1 and y == h-1:
					return cur[2]+1
				if is_visited[y][x]:
					continue
				if s[y][x] == ".":
					queue.append([y, x, cur[2]+1])
					is_visited[y][x] = True
		return -1

	white_num = 0
	for i in range(H):
		for j in range(W):
			if pos[i][j] == ".":
				white_num += 1
	print(white_num-bfs(pos, H, W)-1)

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

Fixed submission:
def main():
	N, K = map(int,input().split())
	points = [0]*N
	max_x, max_y, min_x, min_y = -10**9, -10**9, 10**9, 10**9
	for i in range(N):
		points[i] = list(map(int, input().split()))
		max_x = max(max_x, points[i][0])
		min_x = min(min_x, points[i][0])
		max_y = max(max_y, points[i][1])
		min_y = min(min_y, points[i][1])

	points.sort(key=lambda x:x[0])
	ans = (max_x-min_x)*(max_y-min_y)
	for r in range(K, N+1):
		for l in range(N-r+1):
			w = points[r+l-1][0] - points[l][0]
			this_points = sorted(list(points[l:l+r]), key=lambda x:x[1])
			for b in range(r-K+1):
				h = this_points[b+K-1][1] - this_points[b][1]
				ans = min(ans, w*h)
	print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
	N, K = map(int,input().split())
	points = [0]*N
	max_x, max_y, min_x, min_y = -10**9, -10**9, 10**9, 10**9
	for i in range(N):
		points[i] = list(map(int, input().split()))
		max_x = max(max_x, points[i][0])
		min_x = min(min_x, points[i][0])
		max_y = max(max_y, points[i][1])
		min_y = min(min_y, points[i][1])

	points.sort(key=lambda x:x[0])
	ans = (max_x-min_x)*(max_y-min_y)
	for lr in range(1, N-K+1):
		for l in range(lr):
			this_points = list(points[l:N-lr+l])
			w = this_points[-1][0]-this_points[0][0]
			if w <= 0:
				continue
			this_points.sort(key=lambda x:x[1])
			for t in range(N-K-lr+1):
				h = this_points[t+N-K-lr-1][1] - this_points[t][1]
				if h <= 0:
					continue
				ans = min(ans, w*h)
	print(ans)


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

Fixed submission:
def main():
	N, K = map(int,input().split())
	A = list(map(int,input().split()))
	A.sort(reverse=True)
	no_need = 0
	sub = 0
	for ai in A:
		if sub+ai < K:
			sub += ai
			no_need += 1
		else:
			no_need = 0

	print(no_need)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
	N, K = map(int,input().split())
	A = list(map(int,input().split()))
	A.sort()
	l, r = 0, N-1
	while l < r:
		m = (l+r)>>1
		p = True
		if m == 0 and solve(N, K, A[1:], A[0]):
			l = m+1
			continue
		if solve(N, K, A[:m]+A[m+1:], A[m]):
			l = m+1
		else:
			r = m
	if l == N-1 and solve(N, K, A[:N-1], A[N-1]):
		l = N
	print(l)


def solve(n, k, a, ai):
	dp = [[False for _ in range(k+1)] for _ in range(n)]
	dp[0][0] = True
	if a[0] > k:
		dp[0][k] = True
	else:
		dp[0][a[0]] = True
	for i in range(1, n-1):
		for j in range(k-1):
			if not dp[i-1][j]:
				continue
			dp[i][j] = True
			if j + a[i] > k:
				dp[i][k] = True
			else:
				dp[i][j+a[i]] = True
	return not any(map(lambda j: dp[n-2][j], range(k-ai, k)))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
	N, K = map(int,input().split())
	A = list(map(int,input().split()))
	A.sort()
	l, r = 0, N-1
	while l < r:
		m = (l+r)>>1
		p = True
		if solve(N, K, A[:m]+A[m+1:], A[m]):
			l = m+1
		else:
			r = m
	if l == N-1 and solve(N, K, A[:N-1], A[N-1]):
		l = N
	print(l)


def solve(n, k, a, ai):
	dp = [[False for _ in range(k+1)] for _ in range(n)]
	dp[0][0] = True
	if a[0] > k:
		dp[0][k] = True
	else:
		dp[0][a[0]] = True
	for i in range(1, n-1):
		for j in range(k-1):
			if not dp[i-1][j]:
				continue
			dp[i][j] = True
			if j + a[i] > k:
				dp[i][k] = True
			else:
				dp[i][j+a[i]] = True
	return not any(map(lambda j: dp[n-2][j], range(k-ai, k)))


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

Fixed submission:
def main():
	H, W, A, B = map(int, input().split())
	H, W= H-1, W-1
	DIV = 10**9+7
	size = H+W+1

	fact = [0]*size
	inverse = [0]*size
	inv_cal = [0]*size
	fact[:2] = [1, 1]
	inverse[:2] = [1, 1]
	inv_cal[:2] = [0, 1]

	for i in range(2, size):
		fact[i] = (fact[i-1]*i%DIV)
		inv_cal[i] = (-inv_cal[DIV%i]*(DIV//i))%DIV
		inverse[i] = inverse[i-1]*inv_cal[i]%DIV

	def C(n, r):
		ans = fact[n]*inverse[r]%DIV
		return ans*inverse[n-r]%DIV

	ans = 0
	for x in range(B, W+1):
		y = H-A
		tmp = (C(x+y, x)%DIV)*(C(H+W-x-y-1, W-x)%DIV)%DIV
		ans += tmp
		ans %= DIV

	print(ans)


if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	H, W, A, B = map(int, input().split())
	H, W= H-1, W-1
	DIV = 10**9+7
	size = H+W+1

	fact = [0]*size
	inverse = [0]*size
	inv_cal = [0]*size
	fact[:2] = [1, 1]
	inverse[:2] = [1, 1]
	inv_cal[:2] = [0, 1]

	for i in range(2, size):
		fact[i] = (fact[i-1]*i%DIV)
		inv_cal[i] = (-inv_cal[DIV%i]*(DIV//i))%DIV
		inverse[i] = inverse[i-1]*inv_cal[i]%DIV

	def C(n, r):
		ans = fact[n]*inverse[r]%DIV
		return ans*inverse[n-r]%DIV

	ans = 0
	for x in range(B, W+1):
		y = H-A
		tmp = (C(x+y, x)*(C(H+W-x-y-1, W-x))%DIV
		ans += tmp
		ans %= DIV

	print(ans)


if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
def main():
	H, W, A, B = map(int, input().split())
	H, W= H-1, W-1
	DIV = 10**9+7

	fact = [0]*(H+W-A+1)
	inverse = [0]*(H+W-A+1)
	inv_cal = [0]*(H+W-A+1)
	fact[:2] = [1, 1]
	inverse[:2] = [1, 1]
	inv_cal[:2] = [0, 1]

	for i in range(2, H+W-A+1):
		fact[i] = (fact[i-1]*i%DIV)
		inv_cal[i] = (-inv_cal[DIV%i]*(DIV//i))%DIV
		inverse[i] = inverse[i-1]*inv_cal[i]%DIV

	def C(n, r):
		ans = fact[n]*inverse[r]%DIV
		return ans*inverse[n-r]%DIV

	ans = 0
	for x in range(B, W+1):
		y = H-A
		tmp = (C(x+y, x)%DIV)*(C(H+W-x-y-1, W-x)%DIV)%DIV
		ans += tmp
		ans %= DIV

	print(ans)


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

Fixed submission:
r = int(input())
print(r**2*3)

Buggy submission (verdict: Runtime Error):
print(r**2*3)

Buggy submission (verdict: Runtime Error):
echo(r^2*3)
Problem p02995 (python)

Fixed submission:
import math
import fractions
A, B, C, D = map(int, input().split())
g = int(C*D/fractions.gcd(C,D))
N = B - A + 1
E = B - B//C  - B//D + B//g
F = A-1 - (A-1)//C - (A-1)//D + (A-1)//g
print(int(E-F))

Buggy submission (verdict: Runtime Error):
import math
from math import gcd as bltin_gcd
def coprime2(a, b):
    return bltin_gcd(a, b) == 1

A, B, C, D = map(int, input().split())
N = B - A + 1  #整数列の長さ

if C == D:
    tmp = 0   #最後にNから引く
    mod = A % C
    tmp += math.ceil((N-mod)/C)
    print(N-tmp)
elif coprime2(C, D):
    tmp = 0   #最後にNから引く
    mod = A % C
    tmp += math.ceil((N-mod)/C)
    mod = A % D
    tmp += math.ceil((N-mod)/D)
    mod = A % (D*C)
    tmp -= math.ceil((N-mod)/(D*C))
    print(N-tmp)
else:
    tmp = 0   #最後にNから引く
    mod = A % min(C, D)
    tmp += math.ceil((N-mod)/min(C, D))
    print(N-tmp)
Problem p02999 (python)

Fixed submission:
#A
X, A =  map(int, input().split())
if X < A:
    print("0")
else:
    print("10")

Buggy submission (verdict: Runtime Error):
#A
X, A =  map(int, input().split())
if X < A:
    print(f"0")
else:
    print(f"10")
Problem p03000 (python)

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

RES = []
ichi = 0
RES.append(ichi)
for i in LIST:
    ichi = ichi + i
    RES.append(ichi)

cnt = 0
for i in RES:
    if i <= X:
        cnt = cnt + 1

print(cnt)

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
LIST = list(map(int, input().split()))
 
d = 0
i = 0
 
while d <= X:
    d = d + LIST[i]
    i = i + 1
    
print(i)
Problem p03001 (python)

Fixed submission:
#C
W, H, x, y = map(int, input().split())
S = W*H/2
ans = '0'
if W/2 == x and H/2 == y:
    ans = '1'

print("{} {}".format(S, ans))

Buggy submission (verdict: Runtime Error):
#C
W, H, x, y = map(int, input().split())
S = W*H/2
ans = '0'
if W/2 == x and H/2 == y:
    ans = '1'

print(f"{S} {ans}")

Buggy submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())
S = W * H / 2

if x == W // 2 and y == H //2:
    flg = 1

print("{} {}".format(S, flg))
Problem p03032 (python)

Fixed submission:
import bisect
from collections import deque
N, K = map(int, input().split())
D = list(map(int, input().split()))

ans = 0
for pull_num in range(K+1):
    if pull_num > N:
        continue
    push_num = K - pull_num
    for left_num in range(pull_num+1):
        right_num = pull_num - left_num
        left_D = D[:left_num];  right_D = D[N-right_num:]
        temochi = left_D + right_D
        temochi.sort()
        index = bisect.bisect_left(temochi, 0)
        if push_num >= index:
            ans = max(ans, sum(temochi[index:]))
        else:
            ans = max(ans, sum(temochi[push_num:]))
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
from collections import deque
N, K = map(int, input().split())
D = list(map(int, input().split()))

ans = 0
for pull_num in range(K+1):
  	if pull_num > N:
        continue
    push_num = K - pull_num
    #print('pull_num:{}'.format(pull_num))
    for left_num in range(pull_num+1):
        right_num = pull_num - left_num
        #print('left_num:{} right_num:{}'.format(left_num, right_num))
        left_D = D[:left_num];  right_D = D[N-right_num:]
        #print('left_D:{} right_D:{}'.format(left_D, right_D))
        temochi = left_D + right_D
        temochi.sort()
        #print('temochi:{}'.format(temochi))
        index = bisect.bisect_left(temochi, 0)
        #print('index:{}'.format(index))
        #print('push_num:{}'.format(push_num))
        if push_num >= index:
            ans = max(ans, sum(temochi[index:]))
        else:
            ans = max(ans, sum(temochi[push_num:]))
print(ans)
Problem p03035 (python)

Fixed submission:
Age, Full_cost= map(int, input().split())

if Age >= 13:
    print(Full_cost)
elif 6 <= Age <=12:
    print(int(Full_cost/2))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
if A >= 13:
    print(B)
elif 6 <= A < 13:
    print(b/2)
else:
    print('0')

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
if A >= 13:
    print(B)
elif 6 <= A < 13:
    print(b/2)
else:
    print('0)
Problem p03037 (python)

Fixed submission:
def kasanari(A, B, C, D):
    if B < C or A > D:
        return 0
    elif B <= D:
        if A >= C:
            return [A, B]
        else:
            return [C, B]
    else:
        if A >= C:
            return [A, D]
        else:
            return [C, D]

N, M = map(int, input().split())
L = []
for _ in range(M):
    L.append(list(map(int, input().split())))

tmp = [L[0][0], L[0][1]]
L.pop(0)
for i in L:
    L1 = tmp[0]
    R1 = tmp[1]
    tmp = kasanari(L1, R1, i[0], i[1])
    if tmp == 0:
        print(0)
        exit()
print(tmp[1]-tmp[0]+1)

Buggy submission (verdict: Runtime Error):
#C
N, M = map(int, input().split())
Table = [list(map(int, input().split())) for _ in range(M)]
Table.sort(key=lambda x:x[0])
Table.sort(key=lambda x:x[1])
#print(f'Table:{Table}')
first = Table[0][0]
end = Table[0][1]
Table.pop(0)

#print(f'first:{first} end:{end}')
for task in Table:
    #print(f'task:{task}')
    num = task[0]
    #print(f'num:{num}')
    if num <= end:
        first = num
    else:
        ans = 0
        break

if ans == 0:
    print(ans)
else:
    print(end-first+1)
Problem p03062 (python)

Fixed submission:
import bisect
total = 0
N = int(input())
A = list(map(int, input().split()))
hu = [i for i in A if i < 0]
sei = [i for i in A if i >= 0]
hu.sort()
sei.sort()
if len(hu) % 2 == 0:
    print(sum(sei)+sum(hu)*-1)
else:
    if sei:
        print(sum(sei)+sum(hu)*-1 - min(-1*hu[-1], sei[0])*2)
    else:
        print(sum(sei)+sum(hu)*-1 + 1*hu[-1]*2)

Buggy submission (verdict: Runtime Error):
import bisect
N = int(input())
A = list(map(int, input().split()))
A.sort()
insert_index = bisect.bisect_left(A,0)
if insert_index == 0:
    print(sum(A) - A[0]*2)
if insert_index == len(A):
    print(Ans = -1*sum(A) + A[-1]*2)
if len(A[:insert_index]) % 2 == 0:
    print(-1*sum(A[:insert_index])+sum(A[insert_index:]))
else:
    tmp = -1*sum(A[:insert_index])+sum(A[insert_index:])
    print(max(tmp-A[insert_index]*2, tmp+A[insert_index-1]*2))

Buggy submission (verdict: Runtime Error):
import bisect
N = int(input())
A = list(map(int, input().split()))
A.sort()
insert_index = bisect.bisect_left(A,0)
if len(A[:insert_index]) % 2 == 0:
    Ans = -1*sum(A[:insert_index])+sum(A[insert_index:])
else:
    Tmp = -1*sum(A[:insert_index])+sum(A[insert_index:])
    if insert_index == 0:   #全て正のとき
        Ans = Tmp - A[0]*2
    else:
        if insert_index < len(A):
            Ans = max(Tmp-A[:insert_index]*2, Tmp+A[insert_index-1]*2)
        else:
            Ans = Tmp + A[-1]
print(Ans)

Buggy submission (verdict: Runtime Error):
import bisect
N = int(input())
A = list(map(int, input().split()))
A.sort()
insert_index = bisect.bisect_left(A,0)
if len(A[:insert_index]) % 2 == 0:
    Ans = -1*sum(A[:insert_index])+sum(A[insert_index:])
else:
    Tmp = -1*sum(A[:insert_index])+sum(A[insert_index:])
    if insert_index == 0:   #全て正のとき
        Ans = Tmp - A[0]*2
    else:
        Ans = max(Tmp-A[insert_index]*2, Tmp+A[insert_index-1]*2)
print(Ans)
Problem p03434 (python)

Fixed submission:
N = int(input())
LIST = list(map(int, input().split()))
LIST.sort()
Bob = 0
Alice = 0

while True:
    if len(LIST) == 0:
        break
    Alice = Alice + LIST.pop()
    if len(LIST) == 0:
        break
    Bob = Bob + LIST.pop()

print(Alice - Bob)

Buggy submission (verdict: Runtime Error):
N = int(input())
LIST = list(map(int, input().split()))
LIST.sort()
Bob = 0
Alice = 0

while True:
    if len(LIST)==0:
        break
    Alice = Alice + LIST.pop()
    Bob = Bob + LIST.pop()

print(Alice - Bob)
Problem p03565 (python)

Fixed submission:
S = input()
T = input()
L = []
slide_num = len(S) - len(T)
if slide_num < 0:
    print('UNRESTORABLE')
    exit()
for slide in range(slide_num+1):
    for j in range(len(T)):
        if S[j+slide] == T[j] or S[j+slide] == '?':
            None
        else:
            break
    else:
        L.append((S[:slide] + T + S[slide+len(T):]).replace('?', 'a'))

if L:
    print(L.pop())
else:
    print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
S = input()
T = input()
slide_num = len(S) - len(T)
if slide_num < 0:
    exit()
for slide in range(slide_num+1):
    for j in range(len(S)-slide):
        if S[j+slide] == T[j] or S[j+slide] == '?':
            None
        else:
            break
    else:
        print((S[:slide] + T + S[slide+len(T):]).replace('?', 'a'))
        exit()
print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
S = input()
T = input()
slide_num = len(S) - len(T)
if slide_num < 0:
    exit()
for slide in range(slide_num+1):
    for j in range(len(S)-slide):
        if S[j+slide] == T[j] or S[j+slide] == '?':
            None
        else:
            break
    else:
        print((S[:2] + T + S[2+len(T):]).replace('?', 'a'))
        exit()
print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
S = input()
T = input()
slide_num = len(S) - len(T)
if slide_num < 0:
    pass
for slide in range(slide_num+1):
    for j in range(len(S)-slide):
        if S[j+slide] == T[j] or S[j+slide] == '?':
            None
        else:
            break
    else:
        print((S[:2] + T + S[2+len(T):]).replace('?', 'a'))
        exit()
print('UNRESTORABLE')