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

Fixed submission:
s = input()
t = input()
dp = [[0 for _ in range(len(t)+1)] for _ in range(len(s)+1)]
for i in range(len(s)):
	for j in range(len(t)):
		if s[i] == t[j]:
			dp[i+1][j+1] = dp[i][j] + 1
		elif dp[i+1][j] >= dp[i][j+1]:
			dp[i+1][j+1] = dp[i+1][j]
		else:
			dp[i+1][j+1] = dp[i][j+1]

ans = ""

i, j = len(s), len(t)

while i > 0 and j > 0:
	#if dp[i][j] == dp[i-1][j-1] + 1:
	if s[i-1] == t[j-1]:
		ans += s[i-1]
		i, j = i-1, j-1
	elif dp[i][j-1] >= dp[i-1][j]:
		j -= 1
	else:
		i -= 1

print(ans[::-1])

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
dp = [[0 for _ in range(len(t)+1)] for _ in range(len(s)+1)]
for i in range(len(s)):
	for j in range(len(t)):
		if s[i] == t[j]:
			dp[i+1][j+1] = dp[i][j] + 1
		elif dp[i+1][j] >= dp[i][j+1]:
			dp[i+1][j+1] = dp[i+1][j]
		else:
			dp[i+1][j+1] = dp[i][j+1]

ans = ""

i, j = len(s), len(t)

while i > 0 or j > 0:
	#if dp[i][j] == dp[i-1][j-1] + 1:
	if s[i-1] == t[j-1]:
		ans += s[i-1]
		i, j = i-1, j-1
	elif dp[i][j-1] >= dp[i-1][j]:
		j -= 1
	else:
		i -= 1

print(ans[::-1])

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
dp = [[0 for _ in range(len(t)+1)] for _ in range(len(s)+1)]
for i in range(len(s)):
	for j in range(len(t)):
		if s[i] == t[j]:
			dp[i+1][j+1] = dp[i][j] + 1
		elif dp[i+1][j] >= dp[i][j+1]:
			dp[i+1][j+1] = dp[i+1][j]
		else:
			dp[i+1][j+1] = dp[i][j+1]

ans = ""

i, j = len(s), len(t)

while i > 0 or j > 0:
	#if dp[i][j] == dp[i-1][j-1] + 1:
	if s[i-1] == t[j-1]:
		ans += s[i-1]
		i, j = i-1, j-1
	elif dp[i][j-1] >= dp[i-1][j]:
		j -= 1
	else:
		i -= 1

print(ans[::-1])
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 p03231 (python)

Fixed submission:
from fractions import gcd

n, m = map(int, input().split())
s = input()
t = input()

g = gcd(n, m)
lcm = n // g * m
ok = True
for i in range(n):
	if (i * (lcm // n)) % (lcm // m) == 0:
		if s[i] != t[(i * (lcm // n)) // (lcm // m)]:
			ok = False
			break
if ok:
	print(lcm)
else:
	print(-1)

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

n, m = map(int, input().split())
s = input()
t = input()

if n % m != 0 and m % n != 0:
	print(n // gcd(n, m) * m)
elif n >= m:
	ok = True
	for i in range(m):
		if s[(n // m) * i] != t[i]:
			ok = False
			break
	if ok:
		print(n)
	else:
		print(-1)
else:
	ok = True
	for i in range(n):
		if t[(m // n) * i] != s[i]:
			ok = False
			break
	if ok:
		print(m)
	else:
		print(-1)
Problem p03246 (python)

Fixed submission:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))

one = sorted(Counter([v[i] for i in range(0, n, 2)]).items(), key=lambda x: x[1], reverse=True)
two = sorted(Counter([v[i] for i in range(1, n, 2)]).items(), key=lambda x: x[1], reverse=True)

#print(one, two)
if one[0][0] != two[0][0]:
	print(n - one[0][1] - two[0][1])
else:
	if len(one) == 1 and len(two) == 1:
		print(n // 2)
	elif len(one) == 1:
		print(n // 2 - two[1][1])
	elif len(two) == 1:
		print(n // 2 - one[1][1])
	else:
		print(min(n - one[0][1] - two[1][1], n - one[1][1] - two[0][1]))

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

n = int(input())
v = list(map(int, input().split()))

one = sorted(Counter([v[i] for i in range(0, n, 2)]).items(), key=lambda x: x[1], reverse=True)
two = sorted(Counter([v[i] for i in range(1, n, 2)]).items(), key=lambda x: x[1], reverse=True)

print(one, two)
if one[0][0] != two[0][0]:
	print(n - one[0][1] - two[0][1])
else:
	if len(one) == 1 and len(two) == 1:
		print(n // 2)
	elif len(one) == 1:
		print(n // 2 - two[1][1])
	elif len(two) == 1:
		print(n // 2 - one[1][1])
	else:
		print(min(n - one[0][1] - two[1][1]), n - one[1][1] - two[0][1])
Problem p03260 (python)

Fixed submission:
a, b = map(int, input().split())
if a != 2 and b != 2:
	print("Yes")
else:
	print("No")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a != 2 and c != 2:
	print("Yes")
else:
	print("No")
Problem p03263 (python)

Fixed submission:
H, W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]
ans = []

for h in range(H-1):
	for w in range(W-1):
		if a[h][w] % 2 == 1:
			ans.append([h+1, w+1, h+1, w+2])
			a[h][w+1] += 1
	if a[h][-1] % 2 == 1:
		ans.append([h+1, W, h+2, W])
		a[h+1][-1] += 1

for w in range(W-1):
	if a[H-1][w] % 2 == 1:
		ans.append([H, w+1, H, w+2])
		a[H-1][w+1] += 1

print(len(ans))
for an in ans:
	print(*an)

Buggy submission (verdict: Runtime Error):
def main():
    H, W = map(int, input().split())
    A = [list(map(int, input().split())) for h in range(H)]
    cnt = 0
    out = []
    for h in range(H):
        for w in range(W):
            if A[h, w]%2 == 1:
                cnt += 1
                if w < W-1:
                    A[h, w+1] += 1
                    out.append(list(map(str, [h+1, w+1, h+1, w+2])))
                elif h < H-1:
                    A[h+1, w] += 1
                    out.append(list(map(str, [h+1, w+1, h+2, w+1])))
                else:
                    cnt -= 1
    print(cnt)
    for posi in out:
        print(" ".join(posi))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    H, W = map(int, input().split())
    A = [input().split() for h in range(H)]
    cnt = 0
    out = []
    for h in range(H):
        for w in range(W):
            if A[h][w]%2 == 1:
                cnt += 1
                if w < W-1:
                    A[h][w+1] += 1
                    out.append(list(map(str, [h+1, w+1, h+1, w+2])))
                elif h < H-1:
                    A[h+1][w] += 1
                    out.append(list(map(str, [h+1, w+1, h+2, w+1])))
                else:
                    cnt -= 1
    print(cnt)
    for posi in out:
        print(" ".join(posi))


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

Fixed submission:
from bisect import bisect_left

n, k = map(int, input().split())
x = list(map(int, input().split()))
pos = bisect_left(x, 0)
#print(bisect_left(x, 0))


if n == 1:
	print(abs(x[0]))
elif x[0] >= 0:
	print(x[k - 1])
elif x[-1] <= 0:
	print(-x[-k])
else:
	ans = float("inf")
	if pos + k <= n:
		ans = x[pos + k - 1]
	if x[pos] == 0:
		if pos - k + 1 >= 0:
			ans = min(ans, -x[pos - k + 1])
	else:
		if pos - k >= 0:
			ans = min(ans, -x[pos - k])
	for i in range(max(0, k - pos - 1), min(k - 1, n - pos)):
		#print(i)
		right = x[pos + i]
		left = -x[pos - (k - i - 1)]
		#print(right, left)
		ans = min(ans, 2 * right + left, 2 * left + right)

	print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

n, k = map(int, input().split())
x = list(map(int, input().split()))
pos = bisect_left(x, 0)
#print(bisect_left(x, 0))


if n == 1:
	print(abs(x[0]))
elif x[0] >= 0:
	print(x[k - 1])
elif x[-1] <= 0:
	print(-x[-k - 1])
else:
	ans = float("inf")
	if pos + k <= n:
		ans = x[pos + k - 1]
	if x[pos] == 0:
		if pos - k + 1 >= 0:
			ans = min(ans, -x[pos - k + 1])
	else:
		if pos - k >= 0:
			ans = min(ans, -x[pos - k])
	for i in range(max(0, k - pos - 1), min(k - 1, n - pos)):
		#print(i)
		right = x[pos + i]
		left = -x[pos - (k - i - 1)]
		#print(right, left)
		ans = min(ans, 2 * right + left, 2 * left + right)

	print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

n, k = map(int, input().split())
x = list(map(int, input().split()))
pos = bisect_left(x, 0)
#print(bisect_left(x, 0))

if x[0] >= 0:
	print(x[k - 1])
elif x[-1] <= 0:
	print(-x[-k - 1])
else:
	ans = float("inf")
	if pos + k <= n:
		ans = x[pos + k - 1]
	if x[pos] == 0:
		if pos - k + 1 >= 0:
			ans = min(ans, -x[pos - k + 1])
	else:
		if pos - k >= 0:
			ans = min(ans, -x[pos - k])
	for i in range(max(0, k - pos - 1), min(k - 1, n - pos)):
		#print(i)
		right = x[pos + i]
		left = -x[pos - (k - i - 1)]
		#print(right, left)
		ans = min(ans, 2 * right + left, 2 * left + right)

	print(ans)
Problem p03277 (python)

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

class BIT():#1-indexed
	def __init__(self, size):
		self.table = [0 for _ in range(size+2)]
		self.size = size

	def b_sum(self, i):
		s = 0
		while i > 0:
			s += self.table[i]
			i -= (i & -i)
		return s

	def b_add(self, i, x):
		while i <= self.size:
			self.table[i] += x
			i += (i & -i)
		return

fr, ba = min(a), max(a)+1

while ba - fr > 1:
	mi = (fr+ba) // 2
	bit = BIT(n+1)
	res = 0
	inv = [0]
	min_tmp = 0
	# あとで全体を-min_tmp+1だけ足さないとバグる
	for j in range(n):
		if a[j] >= mi:
			inv.append(inv[-1]+1)
		else:
			inv.append(inv[-1]-1)
			min_tmp = min(min_tmp, inv[-1])

	for j in range(n+1):
		res += bit.b_sum(inv[j] - min_tmp + 1)
		bit.b_add(inv[j] - min_tmp + 1, 1)

	if res >= (n * (n+1) / 4):
		fr = mi
	else:
		ba = mi

print(fr)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left

n, k = map(int, input().split())
x = list(map(int, input().split()))
pos = bisect_left(x, 0)
#print(bisect_left(x, 0))

if x[0] >= 0:
	print(x[k - 1])
elif x[-1] <= 0:
	print(-x[-k])
else:
	ans = float("inf")
	if pos + k <= n:
		ans = x[pos + k - 1]
	if x[pos] == 0:
		if pos - k - 1 >= 0:
			ans = min(ans, -x[pos - k - 1])
	else:
		if pos - k >= 0:
			ans = min(ans, -x[pos - k])
	for i in range(max(pos, k - 1 - pos), min(pos + k - 1, n)):
		#print(i)
		right = x[i]
		left = -x[pos - (k - (i - pos + 1))]
		#print(right, left)
		ans = min(ans, 2 * right + left, 2 * left + right)

	print(ans)
Problem p03312 (python)

Fixed submission:
from bisect import bisect, bisect_left

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

ans = float("inf")
for j in range(2, n-1):
	c = []
	f = bisect(b, b[j]/2)
	f -= 1
	if f == 0 or j == 2:
		c += [b[1]-b[0], b[j]-b[1]]
	elif f == j-1:
		c += [b[j-1]-b[0], b[j]-b[j-1]]
	else:
		if abs(b[f]-b[0] - (b[j]-b[f])) <= abs(b[f+1]-b[0] - (b[j]-b[f+1])):
			c += [b[f]-b[0], b[j]-b[f]]
		else:
			c += [b[f+1]-b[0], b[j]-b[f+1]]

	l = bisect(b, b[j]+((b[n]-b[j])/2))
	l -= 1
	#print(l)
	if l == j or j == n-2:
		c += [b[j+1]-b[j], b[n]-b[j+1]]
	elif l == n-1:
		c += [b[n-1]-b[j], b[n]-b[n-1]]
	else:
		if abs(b[l]-b[j] - (b[n]-b[l])) <= abs(b[l+1]-b[j] - (b[n]-b[l+1])):
			c += [b[l]-b[j], b[n]-b[l]]
		else:
			c += [b[l+1]-b[j], b[n]-b[l+1]]

	ans = min(ans, max(c)-min(c))

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = [0 for _ in range(n + 1)]
for i in range(n):
	b[i + 1] = b[i] + a[i]
# b[i] = sum(a[:i])

suma = sum(a)
border = suma / 4

def func1(start_index, bit):
	# bit: 0 -> border を超えない, 1 -> border を超える
	end_index = start_index + 1
	
	if bit == 0:
		while b[end_index] - b[start_index] < border:
			end_index += 1
		if end_index == start_index + 1:
			return end_index, b[end_index] - b[start_index]
		else:
			return end_index - 1, b[end_index - 1] - b[start_index]

	elif bit == 1:
		while b[end_index] - b[start_index] < border:
			end_index += 1
		return end_index, b[end_index] - b[start_index]

def func2(bits):
	# bits: 0~7
	starts = [0]
	sums = []

	for i in range(3):
		f = func1(starts[-1], bits % 2)
		bits = bits // 2
		starts.append(f[0])
		sums.append(f[1])

	sums.append(b[n] - b[f[0]])

	return max(sums) - min(sums)

candidates = []

for i in range(8):
	candidates.append(func2(i))

print(min(candidates))
Problem p03338 (python)

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

former = set(s[0])
latter = set(s[1:])
ans = len(former & latter)

for i in range(2, n):
	former = set(s[:i])
	latter = set(s[i:])
	if len(former & latter) > ans:
		ans = len(former & latter)
        
print(ans)

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

former = set(s[0])
latter = set(s[1:])
ans = len(former & latter)

for i in range(2, n):
	former = set(s[:i])
    latter = set(s[i:])
    if len(former & latter) > ans:
    	ans = len(former & latter)
        
print(ans)
Problem p03355 (python)

Fixed submission:
s = list(input())
K = int(input())

subs = list()

for k in range(K):
	for i in range(len(s) - k):
		subs.append("".join(s[i : i + k + 1]))

subs = sorted(set(subs))
print(subs[K - 1])

Buggy submission (verdict: Runtime Error):
class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]

	def find(self, x):
		if self.table[x] < 0:
			return x
		else:
			self.table[x] = self.find(self.table[x]) #xをxの根に直接つなぐ
			return self.table[x]

	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 == s2:
			return
		else:
			st1 = self.table[s1]
			st2 = self.table[s2]
			if st1 > st2:
				self.table[s2] = s1
			elif st1 < st2:
				self.table[s1] = s2
			else:
				self.table[s1] = s2
				self.table[s2] -= 1


n, m = map(int, input().split())
p = list(map(int, input().split()))

uf = UnionFind(n)

for i in range(m):
	x, y = map(int, input().split())
	uf.union(x - 1, y - 1)

ans = 0
for i, pp in enumerate(p):
	if pp - 1 == i:
		ans += 1
	elif uf.find(pp - 1) == uf.find(i):
		ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]

	def find(self, x):
		while self.table[x] >= 0:
			x = self.table[x]
		return x

	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 == s2:
			return
		else:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
			elif self.table[s1] < self.table[s2]:
				self.table[s1] = s2
			else:
				self.table[s1] = s2
				self.table[s2] -= 1


n, m = map(int, input().split())
p = list(map(int, input().split()))

uf = UnionFind(n)

for i in range(m):
	x, y = map(int, input().split())
	uf.union(x - 1, y - 1)

ans = 0
for i, pp in enumerate(p):
	if pp - 1 == i:
		ans += 1
	elif uf.find(pp - 1) == uf.find(i):
		ans += 1

print(ans)
Problem p03356 (python)

Fixed submission:
class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]

	def find(self, x):
		if self.table[x] < 0:
			return x
		else:
			self.table[x] = self.find(self.table[x]) #xをxの根に直接つなぐ
			return self.table[x]

	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 == s2:
			return
		else:
			st1 = self.table[s1]
			st2 = self.table[s2]
			if st1 > st2:
				self.table[s2] = s1
			elif st1 < st2:
				self.table[s1] = s2
			else:
				self.table[s1] = s2
				self.table[s2] -= 1


n, m = map(int, input().split())
p = list(map(int, input().split()))

uf = UnionFind(n)

for i in range(m):
	x, y = map(int, input().split())
	uf.union(x - 1, y - 1)

ans = 0
for i, pp in enumerate(p):
	if pp - 1 == i:
		ans += 1
	elif uf.find(pp - 1) == uf.find(i):
		ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]

    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x]) #xをxの根に直接つなぐ
            return self.table[x]

	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 == s2:
			return
		else:
			st1 = self.table[s1]
			st2 = self.table[s2]
			if st1 > st2:
				self.table[s2] = s1
			elif st1 < st2:
				self.table[s1] = s2
			else:
				self.table[s1] = s2
				self.table[s2] -= 1


n, m = map(int, input().split())
p = list(map(int, input().split()))

uf = UnionFind(n)

for i in range(m):
	x, y = map(int, input().split())
	uf.union(x - 1, y - 1)

ans = 0
for i, pp in enumerate(p):
	if pp - 1 == i:
		ans += 1
	elif uf.find(pp - 1) == uf.find(i):
		ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]

	def find(self, x):
		while self.table[x] >= 0:
			x = self.table[x]
		return x

	def union(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 == s2:
			return
		elif:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
			elif self.table[s1] < self.table[s2]:
				self.table[s1] = s2
			else:
				self.table[s1] = s2
				self.table[s2] -= 1


n, m = map(int, input().split())
p = list(map(int, input().split()))

uf = UnionFind(n)

for i in range(m):
	x, y = map(int, input().split())
	uf.union(x - 1, y - 1)

ans = 0
for i, pp in enumerate(p):
	if pp - 1 == i:
		ans += 1
	elif uf.find(pp - 1) == uf.find(i):
		ans += 1

print(ans)
Problem p03357 (python)

Fixed submission:
class BIT():#1-indexed
	def __init__(self, size):
		self.table = [0 for _ in range(size+2)]
		self.size = size

	def Sum(self, i):#1からiまでの和
		s = 0
		while i > 0:
			s += self.table[i]
			i -= (i & -i)
		return s

	def Add(self, i, x):#
		while i <= self.size:
			self.table[i] += x
			i += (i & -i)
		return

n = int(input())
s = [input().split() for _ in range(2*n)]
costb = [[0 for _ in range(n+1)] for _ in range(n+1)]
costw = [[0 for _ in range(n+1)] for _ in range(n+1)]
bitb, bitw = BIT(n), BIT(n)
for i in range(2*n-1, -1, -1):
	c, x = s[i][0], int(s[i][1])
	if c == "B":
		base = bitb.Sum(x-1)
		for j in range(n+1):
			costb[x-1][j] = base + bitw.Sum(j)
		bitb.Add(x, 1)
	else:
		base = bitw.Sum(x-1)
		for j in range(n+1):
			costw[j][x-1] = base + bitb.Sum(j)
		bitw.Add(x, 1)

dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(n+1):
	for j in range(n+1):
		if i+j == 0:
			continue
		if i == 0:
			dp[i][j] = dp[i][j-1] + costw[i][j-1]
		elif j == 0:
			dp[i][j] = dp[i-1][j] + costb[i-1][j]
		else:
			dp[i][j] = min(dp[i][j-1] + costw[i][j-1], dp[i-1][j] + costb[i-1][j])

print(dp[n][n])

Buggy submission (verdict: Runtime Error):
import sys, time
def input():
	return sys.stdin.readline()[:-1]

n = int(input())
a = [list(map(int, input().split()))[::-1] for _ in range(n)]
#print(*a, sep="\n")
opponent = [-1 for _ in range(n)]
match = 0
day = 0
start_time = time.time()
while match < n*(n-1)//2:
	approved = False
	for i in range(n):
		if a[i] != [] and opponent[i] == -1:
			opponent[i] = a[i].pop()-1
	#print(opponent)
	for i in range(n):
		if opponent[i] != -1 and opponent[opponent[i]] == i:
			approved = True
			match += 1
			opponent[opponent[i]] = -1
			opponent[i] = -1
	#print(opponent)
	if not approved:
		print(-1)
		sys.exit()
	now = time.time()
	#print(start_time, now, now - start_time)
	if now-start_time > 1.6:
		print(n*(n-1)//2)
		sys.exit()
	day += 1
print(day)
Problem p03390 (python)

Fixed submission:
from math import sqrt

def func(a, b):
	if a == b:
		return (a - 1) * 2
	else:
		sq = int(sqrt(a * b))
		if a * b == sq ** 2:
			return (sq - 1) * 2 - 1
		elif sq * (sq + 1) > a * b:
			return (sq - 1) * 2
		elif sq * (sq + 1) == a * b:
			if abs(a - b) == 1:
				return (sq - 1) * 2
			else:
				return (sq - 1) * 2
		else:
			return sq * 2 - 1

q = int(input())
for _ in range(q):
	a, b = map(int, input().split())
	print(func(a, b))

Buggy submission (verdict: Runtime Error):
from math import sqrt

def func(a, b):
	if a == b:
		return (a - 1) * 2
	else:
		sq = int(sqrt(a * b))
		if a * b == sq ** 2:
			return (sq - 1) * 2 - 1
		elif sq * (sq + 1) >= a * b:
            return (sq - 1) * 2
		else:
			return sq * 2 - 1

q = int(input())
for _ in range(q):
	a, b = map(int, input().split())
	print(func(a, b))
Problem p03393 (python)

Fixed submission:
S = input()
alphabet = list("abcdefghijklmnopqrstuvwxyz")

if S == "zyxwvutsrqponmlkjihgfedcba":
     print(-1)
        
elif len(S) < 26:
    print(S + min(set(alphabet) - set(S)))
    
else:
    for i in range(1, 27):
        if list(S)[-i] > list(S)[-(i + 1)]:
            break
    T = sorted(list(S)[-i:])
    #print(T)
    for t in T:
        if t > list(S)[-(i + 1)]:
            break
    print("".join(list(S)[:-(i + 1)]) + t)

Buggy submission (verdict: Runtime Error):
S = input()
alphabet = list("abcdefghijklmnopqrstuvwxyz")

if S == "zyxwvutsrqponmlkjihgfedcba":
     print(-1)
        
elif len(S) < 26:
    print(S + min(set(alphabet) - set(S)))
    
else:
    for i in range(26):
        if list(S)[-i] > list(S)[-(i + 1)]:
            j = i
            T = list.copy(list(S))
            a = min(T[-j + 1:])
            while a < T[-j + 1]:
                T.remove(a)
                j -= 1
                a = min(T[-i + 1:])
            
            print("".join(S[:-(i + 1)]) + min(list(S)[-i:]))
            break
Problem p03490 (python)

Fixed submission:
s = input().split("T")
x, y = map(int, input().split())
x -= len(s[0])
s.pop(0)

list_yoko = [len(s[i]) for i in range(1, len(s), 2)]
list_tate = [len(s[i]) for i in range(0, len(s), 2)]

if list_yoko == []:
	list_yoko = [0]

if list_tate == []:
	list_tate = [0]
	
set_yoko = {list_yoko[0], -list_yoko[0]}
set_tate = {list_tate[0], -list_tate[0]}

for i in list_yoko[1:]:
	sy = set()
	for j in set_yoko:
		sy |= {j + i, j - i}
	set_yoko = sy

for i in list_tate[1:]:
	st = set()
	for j in set_tate:
		st |= {j + i, j - i}
	set_tate = st

if (x in set_yoko) and (y in set_tate):
	print("Yes")
else:
	print("No")

Buggy submission (verdict: Runtime Error):
s = input().split("T")
x, y = map(int, input().split())
x -= len(s[0])
s.pop(0)

list_yoko = [len(s[i]) for i in range(1, len(s), 2)]
list_tate = [len(s[i]) for i in range(0, len(s), 2)]

set_yoko = {list_yoko[0], -list_yoko[0]}
set_tate = {list_tate[0], -list_tate[0]}

for i in list_yoko[1:]:
	sy = set()
	for j in set_yoko:
		sy |= {j + i, j - i}
	set_yoko = sy

for i in list_tate[1:]:
	st = set()
	for j in set_tate:
		st |= {j + i, j - i}
	set_tate = st

if (x in set_yoko) and (y in set_tate):
	print("Yes")
else:
	print("No")

Buggy submission (verdict: Runtime Error):
import sys

s = input().split("T")
x, y = map(int, input().split())
x -= len(s[0])
s.pop(0)

list_yoko = [len(s[i]) for i in range(1, len(s), 2)]
list_tate = [len(s[i]) for i in range(0, len(s), 2)]

set_yoko = {list_yoko[0], -list_yoko[0]}
set_tate = {list_tate[0], -list_tate[0]}

for i in list_yoko[1:]:
	sy = set()
	for j in set_yoko:
		sy |= {j + i, j - i}
	set_yoko = sy

for i in list_tate[1:]:
	st = set()
	for j in set_tate:
		st |= {j + i, j - i}
	set_tate = st

if (x in sy) and (y in st):
	print("Yes")
else:
	print("No")
Problem p03526 (python)

Fixed submission:
import sys
def input():
	return sys.stdin.buffer.readline()[:-1]
n = int(input())
men = [tuple(map(int, input().split())) for _ in range(n)]
men.sort(key=lambda x: (x[0]+x[1], -x[0]))
allowed = [-1 for _ in range(n)]
allowed[n-1] = men[-1][0]
for i in range(n-2, -1, -1):
	allowed[i] = max(allowed[i+1], men[i][0])

INF = 10**10
dp = [INF for _ in range(n+1)]
dp[0] = 0
for i in range(n):
	for j in range(i+1, 0, -1):
		if dp[j-1] <= men[i][0]:
			dp[j] = min(dp[j], dp[j-1] + men[i][1])

#print(dp)
for i in range(n+1):
	if dp[i] < INF:
		ans = i
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
men = [list(map(int, input().split())) for _ in range(n)]
men.sort(key=lambda x: x[0]+x[1], x[0])
dp = [[0, 0] for _ in range(n+1)]
for i in range(1, n+1):
	for j in range(i):
		if dp[j][0] <= men[i-1][0]:
			if dp[j][1]+1 == dp[i][1]:
				dp[i][0] = min(dp[i][0], dp[j][0] + men[i-1][1])
			elif dp[j][1]+1 > dp[i][1]:
				dp[i][1] = dp[j][1]+1
				dp[i][0] = dp[j][0] + men[i-1][1]
ans = 0
for i in range(1, n+1):
	ans = max(ans, dp[i][1])
print(ans)