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

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

upper = [1 for i in range(N)]
for i in range(1, N):
	x = N-i-1
	if P[x] < P[x+1]:
		upper[x] = upper[x+1] + 1

skip = [-1,-1]
flg = False
for i in range(N):
	if upper[N-i-1] >= K:
		skip.append(N-i-1)

skip.pop()
deq_min = deque([P[0]])
deq_max = deque([P[0]])
minlen = 1
maxlen = 1
for i in range(1, K):
	while minlen > 0 and deq_min[-1] > P[i]:
		deq_min.pop()
		minlen -= 1
	deq_min.append(P[i])
	minlen += 1
	while maxlen > 0 and deq_max[-1] < P[i]:
		deq_max.pop()
		maxlen -= 1
	deq_max.append(P[i])
	maxlen += 1

ans = 1
next_skip = skip.pop()
for i in range(1, N-K+1):
	new_i = i+K-1
	min_rem = (deq_min[0] == P[i-1])
	max_add = (deq_max[0] < P[new_i])
	if not (min_rem and max_add):
		if i != next_skip:
			ans += 1
	if i == next_skip:
		next_skip = skip.pop()
	if min_rem:
		deq_min.popleft()
		minlen -= 1
	if deq_max[0] == P[i-1]:
		deq_max.popleft()
		maxlen -= 1
	while minlen > 0 and deq_min[-1] > P[new_i]:
		deq_min.pop()
		minlen -= 1
	deq_min.append(P[new_i])
	minlen += 1
	while maxlen > 0 and deq_max[-1] < P[new_i]:
		deq_max.pop()
		maxlen -= 1
	deq_max.append(P[new_i])
	maxlen += 1
print(ans)

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

upper = [1 for i in range(N)]
for i in range(1, N):
	x = N-i-1
	if P[x] < P[x+1]:
		upper[x] = upper[x+1] + 1

skip = [-1,-1]
flg = False
for i in range(N):
	if upper[N-i-1] >= K:
		skip.append(N-i-1)

skip.pop()
deq_min = deque([P[0]])
deq_max = deque([P[0]])
minlen = 1
maxlen = 1
for i in range(1, K):
	while minlen > 0 and deq_min[-1] > P[i]:
		deq_min.pop()
		minlen -= 1
	deq_min.append(P[i])
	minlen += 1
	while maxlen > 0 and deq_max[-1] < P[i]:
		deq_max.pop()
		maxlen -= 1
	deq_max.append(P[i])
	maxlen += 1

ans = 1
next_skip = skip.pop()
for i in range(1, N-K+1):
	new_i = i+K-1
	min_rem = (deq_min[0] == P[i-1])
	max_add = (deq_max[0] < P[new_i])
	if not (min_rem and max_add):
		if i != next_skip:
			ans += 1
	if i == next_skip:
		next_skip = skip.pop()
	if min_rem:
		deq_min.popleft()
	while minlen > 0 and deq_min[-1] > P[new_i]:
		deq_min.pop()
		minlen -= 1
	deq_min.append(P[new_i])
	minlen += 1
	while maxlen > 0 and deq_max[-1] < P[new_i]:
		deq_max.pop()
		maxlen -= 1
	deq_max.append(P[new_i])
	maxlen += 1
print(ans)
Problem p02975 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
setA = list(set(A))
if len(setA) == 1 and setA[0] == 0:
	print("Yes")
	exit()
if N % 3 != 0:
	print("No")
	exit()
if len(setA) == 1 or len(setA) > 3:
	print("No")
	exit()
if len(setA) == 2:
	if 0 in setA:
		setA.sort()
		if A.count(0) == N // 3 and A.count(setA[1]) == (N // 3) * 2:
			print("Yes")
			exit()
	print("No")
	exit()

if setA[0] ^ setA[1] != setA[2]:
	print("No")
	exit()
for a in setA:
	if A.count(a) != N // 3:
		print("No")
		exit()
print("Yes")
exit()

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
setA = list(set(A))
if len(setA) == and setA[0] == 0:
	print("Yes")
	exit()
if N % 3 != 0:
	print("No")
	exit()
if len(setA) == 1 or len(setA) > 3:
	print("No")
	exit()
if len(setA) == 2:
	if 0 in setA:
		setA.sort()
		if A.count(0) == N // 3 and A.count(setA[1]) == (N // 3) * 2:
			print("Yes")
			exit()
	print("No")
	exit()

if setA[0] ^ setA[1] != setA[2]:
	print("No")
	exit()
for a in setA:
	if A.count(a) != N // 3:
		print("No")
		exit()
print("Yes")
exit()
Problem p03029 (python)

Fixed submission:
A,P = map(int,input().split())
p = A*3 + P
print(p//2)

Buggy submission (verdict: Runtime Error):
A,P = map(int,input().split())
p = A*3 + p
print(p//2)
Problem p03035 (python)

Fixed submission:
A,B = map(int, input().split())
if A < 6:
  print(0)
elif A < 13:
  print(B//2)
else:
  print(B)

Buggy submission (verdict: Runtime Error):
A,B = map(input().split())
if A < 7:
  print(0)
elif A < 13:
  print(B//2)
else:
  print(B)
Problem p03096 (python)

Fixed submission:
MOD = 10**9 + 7
N = int(input())
C = []
last_idx = [0 for i in range(200001)]
bef = [0 for i in range(N+1)]
for i in range(1,N+1):
	c = int(input())
	C.append(c)
	bef[i] = last_idx[c]
	last_idx[c] = i
dp = [0 for i in range(N+1)]
dp[1] = 1
if N == 1 or N == 2:
	print(1)
	exit()

for i in range(2, N+1):
	if bef[i] < i-1:
		dp[i] = (dp[i-1] + dp[bef[i]]) % MOD
	else:
		dp[i] = dp[i-1]
print(dp[N])

Buggy submission (verdict: Runtime Error):
MOD = 10**9 + 7
N = int(input())
C = []
last_idx = [0 for i in range(200000)]
bef = [0 for i in range(N+1)]
for i in range(1,N+1):
	c = int(input())
	C.append(c)
	bef[i] = last_idx[c]
	last_idx[c] = i
dp = [0 for i in range(N+1)]
dp[1] = 1
if N == 1 or N == 2:
	print(1)
	exit()

for i in range(2, N+1):
	if bef[i] < i-1:
		dp[i] = (dp[i-1] + dp[bef[i]]) % MOD
	else:
		dp[i] = dp[i-1]
print(dp[N])

Buggy submission (verdict: Runtime Error):
MOD = 10**9 + 7
N = int(input())
C = []
last_idx = [0 for i in range(N+1)]
bef = [0 for i in range(N+1)]
for i in range(1,N+1):
	c = int(input())
	C.append(c)
	bef[i] = last_idx[c]
	last_idx[c] = i
dp = [0 for i in range(N+1)]
dp[1] = 1
if N == 1 or N == 2:
	print(1)
	exit()

for i in range(2, N+1):
	if bef[i] < i-1:
		dp[i] = (dp[i-1] + dp[bef[i]]) % MOD
	else:
		dp[i] = dp[i-1]
print(dp[N])

Buggy submission (verdict: Runtime Error):
MOD = 10**9 + 7
N = int(input())
C = []
last_idx = [None for i in range(N+1)]
bef = [None for i in range(N+1)]
for i in range(1,N+1):
	c = int(input())
	C.append(c)
	if last_idx[c] != None:
		bef[i] = last_idx[c]
	last_idx[c] = i
dp = [0 for i in range(N+1)]
dp[1] = 1
for i in range(2, N+1):
	if bef[i] != None and bef[i] < i-1:
		dp[i] = (dp[i-1] + dp[bef[i]]) % MOD
	else:
		dp[i] = dp[i-1]
print(dp[N])

Buggy submission (verdict: Runtime Error):
N = int(input())
C = []
last_idx = [None for i in range(N+1)]
bef = [None for i in range(N+1)]
for i in range(1,N+1):
	c = int(input())
	C.append(c)
	if last_idx[c] != None:
		bef[i] = last_idx[c]
	last_idx[c] = i
dp = [0 for i in range(N+1)]
dp[1] = 1
for i in range(2, N+1):
	if bef[i] != None and bef[i] < i-1:
		dp[i] = dp[i-1] + dp[bef[i]]
	else:
		dp[i] = dp[i-1]
print(dp[N])
Problem p03223 (python)

Fixed submission:
N = int(input())
A = []
for i in range(N):
	A.append(int(input()))
A.sort()
if N % 2 == 0:
	print(-2*sum(A[:N//2-1]) + 2*(sum(A[N//2+1:])) + A[N//2] - A[N//2-1])
	exit()

a = 2*sum(A[N//2+1:]) - 2*sum(A[:N//2-1]) - A[N//2] - A[N//2-1]
b = 2*sum(A[N//2+2:]) - 2*sum(A[:N//2]) + A[N//2] + A[N//2+1]
print(max(a,b))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = []
for i in range(N):
	A.append(int(input()))
A.sort()
ary1 = [A[0]]
ary2 = [A[N-1]]
fst = 0
lst = N
fst_flg = False
sum1, sum2 = 0,0
while fst + 1 < lst:
	if fst_flg:
		fst_flg = False
		if fst + 2 != lst:
			fst += 1
			ary1 = [A[fst]] + ary1 + [A[fst+1]]
			ary2 = [A[N-1-fst]] + ary2 + [A[N-1-fst-1]]
			fst += 1
			l = len(ary1)
			sum1 += abs(ary1[0]-ary1[1]) + abs(ary1[l-1]-ary1[l-2])
			sum2 += abs(ary2[0]-ary2[1]) + abs(ary2[l-1]-ary2[l-2])
		else:
			fst += 1
			ary1 = [A[fst]] + ary1
			ary2 = [A[N-1-fst]] + ary2
			sum1 += abs(ary1[0]-ary1[1])
			sum2 += abs(ary2[0]-ary2[1])
	else:
		fst_flg = True
		if fst + 2 != lst:
			lst -= 1
			ary1 = [A[lst]] + ary1 + [A[lst-1]]
			ary2 = [A[N-1-lst]] + ary2 + [A[N-lst]]
			lst -= 1
			sum1 += abs(ary1[0]-ary1[1]) + abs(ary1[l-1]-ary1[l-2])
			sum2 += abs(ary2[0]-ary2[1]) + abs(ary2[l-1]-ary2[l-2])
		else:
			lst -= 1
			ary1 = [A[lst]] + ary1
			ary2 = [A[N-1-lst]] + ary2
			sum1 += abs(ary1[0]-ary1[1])
			sum2 += abs(ary2[0]-ary2[1])
print(max(sum1,sum2))
Problem p03246 (python)

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

v_e_cnt = [0 for i in range(10**6)]
v_o_cnt = [0 for i in range(10**6)]
for x in range(n):
	if x % 2 == 0:
		v_e_cnt[v[x]] += 1
	else:
		v_o_cnt[v[x]] += 1

max_e = [(0,0),(0,0)]
max_o = [(0,0),(0,0)]
for i in range(10**5+1):
	if max_e[1][0] < v_e_cnt[i]:
		if max_e[0][0] < v_e_cnt[i]:
			max_e[1] = max_e[0]
			max_e[0] = (v_e_cnt[i], i)
		else:
			max_e[1] = (v_e_cnt[i], i)
	if max_o[1][0] < v_o_cnt[i]:
		if max_o[0][0] < v_o_cnt[i]:
			max_o[1] = max_o[0]
			max_o[0] = (v_o_cnt[i], i)
		else:
			max_o[1] = (v_o_cnt[i], i)

ans = n - max_e[0][0] - max_o[0][0]
if max_e[0][1] == max_o[0][1]:
	ans = n - max(max_e[0][0] + max_o[1][0], max_e[1][0] + max_o[0][0])

print(ans)

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

v_e_cnt = [0 for i in range(10**6)]
v_o_cnt = [0 for i in range(10**6)]
for x in range(n):
	if x % 2 == 0:
		v_e_cnt[v[x]] += 1
	else:
		v_o_cnt[v[x]] += 1

max_e = [(0,0),(0,0)]
max_o = [(0,0),(0,0)]
for i in range(10**5+1):
	if max_e[1][0] < v_e_cnt[i]:
		if max_e[0][0] < v_e_cnt[i]:
			max_e[1] = max_e[0]
			max_e[0] = (v_e_cnt[i], i)
		else:
			max_e[1] = (v_e_cnt[i], i)
	if max_o[1][0] < v_o_cnt[i]:
		if max_o[0][0] > v_o_cnt[i]:
			max_o[1] = max_o[0]
			max_o[0] = (v_o_cnt[i], i)
		else:
			max_o[0] = (v_o_cnt[i], i)

ans = n - e[0][0] - o[0][0]
if e[0][1] == o[0][1]:
	ans = n - max(e[0][0] + o[1][0], e[1][0] + o[0][0])

print(ans)
Problem p03389 (python)

Fixed submission:
l = sorted(list(map(int,input().split())))
C,B,A = l[0],l[1],l[2]
cnt = 0
while A != B or B != C or C != A:
	if A == B:
		if C < A:
			C += 2
			cnt += 1
		elif C > A:
			A += 1
			B += 1
			cnt += 1
	else:
		B += 1
		C += 1
		cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
Q = int(input())
for i in range(Q):
	A,B = map(int,input().split())
	if A == 1 and B == 1:
		print(0)
		continue
	score = A * B
	root = int((score-1) ** 0.5)
	ans = 2 * root
	if root >= A:
		ans -= 1
	if root >= B:
		ans -= 1
	if (score - 1) // root == root:
		ans -= 1
	print(ans)
Problem p03437 (python)

Fixed submission:
x,y = map(int,input().split())
if x % y == 0:
	print(-1)
	exit()
ans = 0
for i in range(y):
	ans += x
	if ans % y > 0:
		break
if ans == x*y:
	print(-1)
	exit()
print(ans)

Buggy submission (verdict: Runtime Error):
X,Y = map(int,input().split())
if x%y > 0 or y%x > 0:
	print(-1)
	exit()
if 2*x % y == 0:
	print(2*x)
	exit()
else:
	print(-1)
Problem p03547 (python)

Fixed submission:
x,y = input().split()
if x < y:
	print('<')
elif x == y:
	print('=')
else:
	print('>')

Buggy submission (verdict: Runtime Error):
x,y = input().split()
if x < y:
	print('<')
elif x == y:
	print('=')
else
	print('>')
Problem p03550 (python)

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

std = abs(Z-W)
last = a[N-1]

absList = [abs(last-i) for i in a]
absList.pop(N-1)
ans = max(abs(last-W), abs(last-a[N-2]))
for i in range(N-1):
	testList = absList[i+1:]
	if min(absList) > ans:
		ans = max(absList)
print(ans)

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

std = abs(Z-W)
last = a[0]

absList = [abs(last-i) for i in a]

ans = ans(last-W)
for i in range(N-1):
	testList = absList[i+1:]
	if min(absList) > ans:
		ans = max(absList)
print(ans)
Problem p03564 (python)

Fixed submission:
N = int(input())
K = int(input())
ans = 1
for i in range(N):
	if ans < K:
		ans *= 2
	else:
		ans += K
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
K = int(input())
ans = 1
for i in range(N)
	if ans < K:
		ans *= 2
	else:
		ans += K
print(ans)
Problem p03565 (python)

Fixed submission:
S = input()
T = input()

start = len(S) - len(T)
end = len(S)

ans = ''
while start >= 0:
	test = S[start:end]
	solve = True
	for i in range(len(T)):
		c1,c2 = test[i],T[i]
		if c1 != c2 and c1 != '?':
			solve = False
			break
	if solve:
		ans = S[:start] + T + S[end:]
		break
	start -= 1
	end -= 1
if len(ans) > 0:
	print(ans.replace('?', 'a'))
else:
	print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

start = len(S) - len(T)
end = len(S)

ans = ''
while start >= 0:
	test = S[start:end]
	solve = True
	for i in range(len(T)):
		c1,c2 = test[i],T[i]
		if c1 != c2 and c1 != '?':
			solve = False
			break
	if solve:
		ans = S[:start] + T + S[end:]
		break
	start -= 1
	end -= 1
if len(ans > 0):
	print(ans.replace('?', 'a'))
else:
	print('UNRESTORABLE')
Problem p03573 (python)

Fixed submission:
A,B,C = map(int,input().split())
if A == B:
	print(C)
elif B == C:
	print(A)
else:
	print(B)

Buggy submission (verdict: Runtime Error):
A,B,C = map(int,input.split())
if A == B:
	print(C)
elif B == C:
	print(A)
else:
	print(B)
Problem p03759 (python)

Fixed submission:
a,b,c = map(int,input().split())
if a+c == 2*b:
	print('YES')
else:
	print('NO')

Buggy submission (verdict: Runtime Error):
a,b,c = map(raw_input().split(), int)
if a+c == 2*b:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
a,b,c = map(raw_input().split(), int)
if a+c == 2*b:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
a,b,c = map(raw_input().split(), int)
2.if a+c == 2*b:
3.    print('YES')
4.else:
5.    print('NO')

Buggy submission (verdict: Runtime Error):
a,b,c = map(input().split(), int)
2.if a+c == 2*b:
3.    print('YES')
4.else:
5.    print('NO')

Buggy submission (verdict: Runtime Error):
a,b,c = map(input().split(), int)
if a+c == 2*b:
    print('YES')
else:
    print('NO')
Problem p03848 (python)

Fixed submission:
N = int(raw_input())
A = list(map(int,raw_input().split()))
A.sort()
MOD = 10**9 + 7
def calc(a):
	if N % 2 == 0:
		B = [int(i/2)*2 + 1 for i in range(0,N)]
		if A != B:
			return 0
	else:
		B = [int(i/2)*2 for i in range(1,N+1)]
		if A != B:
			return 0
	return 2 ** int(N/2)

print(calc(A) % MOD)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
MOD = 10**9 + 7
def calc(a):
	if 0 in a:
		if a.count(0) != 1:
			return 0
		for i in [x*2 for x in range(1,int(N/2) + 1)]:
			if a.count(i) != 2:
				return 0
	else:
		for i in [x*2 - 1 for x in range(1,int(N/2) + 1)]:
			if a.count(i) != 2:
				return 0
	return 2 ** int(N/2)
if N % 2 is 0:
	if len(filter(lambda n:n%2==0, A)) > 0:
		print(0)
	else:
		print(calc(A) % MOD)
else:
	if len(filter(lambda n:n%2==1, A)) > 0:
		print(0)
	else:
		print(calc(A) % MOD)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
MOD = 10**9 + 7
def calc(a):
	if 0 in a:
		if a.count(0) != 1:
			return 0
		for i in [x*2 for x in range(1,int(N/2) + 1)]:
			if a.count(i) != 2:
				return 0
	else:
		for i in [x*2 - 1 for x in range(1,int(N/2) + 1)]:
			if a.count(i) != 2:
				return 0
	return 2 ** int(N/2)
if N % 2 is 0:
	if len(filter(lambda n:n%2==0, A)) > 0:
		print(0)
	else:
		print(calc(A) % MOD)
else:
	if len(filter(lambda n:n%2==1, A)) > 0:
		print(0)
	else:
		print(calc(A) % MOD)
Problem p04030 (python)

Fixed submission:
S = input()
s = ['' for c in S]
i = 0
for c in S:
  if c == '0' or c == '1':
    s[i] = c
    i += 1
  else:
    if i > 0:
      i -= 1
      s[i]=''
print(''.join(s))

Buggy submission (verdict: Runtime Error):
S = input()
s = ""
i = 0
for c in S:
  if c == '0' or c == '1':
    s[i] = c
    i += 1
  else:
    if i > 0:
      s[i] = ''
      i -= 1
Problem p02718 (python)

Fixed submission:
n,m = list(map(int,input().split()));
a = list(map(int,input().split()));
 
a.sort(reverse = True);
 
i = 0;
while i<n and a[i] >= sum(a)/(4*m):
    i += 1;
 
if i >= m :
    print('Yes');
else :
    print('No');

Buggy submission (verdict: Runtime Error):
n,m = list(map(int,input().split()));
a = list(map(int,input().split()));
 
a.sort(reverse = True);
 
i = 0;
while 4*m*a[i] >= sum(a) and i < n:
    i += 1;
 
if i >= m :
    print('Yes');
else :
    print('No');

Buggy submission (verdict: Runtime Error):
n,m = list(map(int,input().split()));
a = list(map(int,input().split()));
 
a.sort(reverse = True);
 
i = 0;
while a[i] >= sum(a)//(4*m) and i < n:
    i += 1;
 
if i >= m :
    print('Yes');
else :
    print('No');
Problem p03006 (python)

Fixed submission:
n = int(input());
if n==1:
	print(n)
	exit(0)
point = [[0]*2 for i in range(n) ];
for i in range(n) :
	s = input().split(" ");
	point[i][0] = int(s[0]);
	point[i][1] = int(s[1]);

dict = {}
for i in range(n) :
	for j in range(n) :
		if i != j  :
			x = point[i][0] - point[j][0];
			y = point[i][1] - point[j][1];
			if (x,y) in dict:
				dict[(x,y)] += 1
			else:
				dict[(x,y)] = 1
print(n-max(dict.values()));

Buggy submission (verdict: Runtime Error):
n = int(input());
point = [[0]*2 for i in range(n) ];
for i in range(n) :
	s = input().split(" ");
	point[i][0] = int(s[0]);
	point[i][1] = int(s[1]);

dict = {}
for i in range(n) :
	for j in range(n) :
		if i != j  :
			x = point[i][0] - point[j][0];
			y = point[i][1] - point[j][1];
			if (x,y) in dict:
				dict[(x,y)] += 1
			else:
				dict[(x,y)] = 1
print(n-max(dict.values()));
Problem p03136 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split(' ')))
 
ok = True
 
for i in range(N):
  if a[i] >= sum(a) - a[i]:
    ok = False
 
print("Yes" if ok else "No")

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

ok = True

for i in range(N):
  if a[i] >= sum(a) - a[i]:
    ok = False

print("Yes" if ok else "No")
Problem p03469 (python)

Fixed submission:
s = input()
print(s[:3] + '8' + s[4:])

Buggy submission (verdict: Runtime Error):
R = lambda type_ = "int": list(map(eval(type_), input().split(' ')))

N, H = R()
a, b = 0, []
while N:
    a_, b_ = R()
    b.append(b_)
    a = max(a, a_)
    N -= 1

b.sort()
i = len(b) - 1
while i >= 0 and H > 0 and b[i] >= a:
    H -= b[i]
    i -= 1
    
if i < 0 and H > 0:
    print(len(b) + (H - 1) // a + 1)
elif H <= 0:
    print(len(b) - i - 1)
elif a > b[i]:
    print(len(b) - i - 1 + (H - 1) // a + 1)
Problem p02576 (python)

Fixed submission:
import math

n,x,t = map(int,input().split())

print(math.ceil(n/x) * t)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
typedef long long int ll;
 
int dh[4] = {1,0,-1,0};
int dw[4] = {0,1,0,-1};
int ddx[20] = {1,1,-1,-1,2,2,2,2,2,1,1,0,0,-1,-1,-2,-2,-2,-2,-2};
int ddy[20] = {1,-1,1,-1,2,1,0,-1,-2,2,-2,2,-2,2,-2,2,1,0,-1,-2};
 
int main()
{
    int dh[4] = {1,0,-1,0};
    int dw[4] = {0,1,0,-1};
  	int ddx[20] = {1,1,-1,-1,2,2,2,2,2,1,1,0,0,-1,-1,-2,-2,-2,-2,-2};
  	int ddy[20] = {1,-1,1,-1,2,1,0,-1,-2,2,-2,2,-2,2,-2,2,1,0,-1,-2};
  	
    int r,c;
    cin >> r >> c;
    int sy,sx,gy,gx;
    cin >> sy >> sx;
  	cin >> gy >> gx;
    sy--,sx--,gy--,gx--;
    vector<vector<char>>v(r,vector<char>(c,'.'));
    for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) cin >> v[i][j];
    vector<vector<int>>dist(r,vector<int>(c,10000000));
    dist[sy][sx] = 0;
    queue<pair<int,int>>que;
    que.push(pair(sy,sx));
  
    while(!que.empty())
    {
        pair<int,int>p;
        p = que.front();
        que.pop();
        int y = p.first;
        int x = p.second;
        for(int i = 0; i < 4; i++)
        {
            int ny = y + dh[i];
            int nx = x + dw[i];
            if(ny >= r || ny < 0 || nx >= c || nx < 0) continue;
            if(dist[ny][nx] <= dist[y][x]) continue;
            if(v[ny][nx] == '#') continue;
            dist[ny][nx] = dist[y][x];
            que.push(pair(ny,nx));
        }
      
      	for(int i = 0; i < 20; i++)
        {
            int ny = y + ddy[i];
            int nx = x + ddx[i];
            if(ny >= r || ny < 0 || nx >= c || nx < 0) continue;
            if(dist[ny][nx] <= dist[y][x]+1) continue;
            if(v[ny][nx] == '#') continue;
            dist[ny][nx] = dist[y][x] + 1;
            que.push(pair(ny,nx));
        }
      	
      
    }
  	if (dist[gy][gx] == 10000000)
    {
      printf("-1");
    }
  	else
    {
    	cout << dist[gy][gx] << endl;
    }
}
Problem p02718 (python)

Fixed submission:
n,m = map(int,input().split())
a = list(map(int,input().split()))
fl = "Yes"

a.sort(reverse = True)
s = sum(a)

for i in range(m):
    if a[i] < s * (1 / (4*m)):
        fl = "No"
        
print(fl)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = list(map(int,input().split()))
fl = "Yes"

a.sort(reverse = True)
s = sum(a)

for i in range(m):
    if a[m] < s * (1 / (4*m)):
        fl = "No"
        
print(fl)
Problem p02814 (python)

Fixed submission:
from fractions import gcd

n,m = map(int,input().split())
a = set(map(int,input().split()))
a = list(a)
nn = len(a)

g = a[0]
    
x = a[0]
for i in range(1,nn):
    t = gcd(x,a[i])
    x *= a[i]
    x //= t
    
fl = 1
ff = x//2
for i in range(nn):
    if ff % a[i] != a[i] // 2:
        fl = 0
        
if fl == 1:
    xx = (m-ff) // x + 1
else:
    xx = 0
    
print(xx)

Buggy submission (verdict: Runtime Error):
import math

n,m = map(int,input().split())
a = set(map(int,input().split()))
a = list(a)
nn = len(a)

g = a[0]
for i in range(nn):
    t = math.gcd(g,a[i])
    
x = a[0]
for i in range(1,nn):
    x *= a[i]
    x //= t
    
fl = 1
ff = x//2
for i in range(nn):
    if ff % a[i] != a[i] // 2:
        fl = 0
        
if fl == 1:
    xx = (m-ff) // x + 1
else:
    xx = 0
    
print(xx)
Problem p02903 (python)

Fixed submission:
h,w,a,b = map(int,input().split())
ans = [[0]*w for i in range(h)]
fl = True

for i in range(a):
    for j in range(b):
        ans[j][i] = 1
        
for i in range(w-a):
    for j in range(h-b):
        ans[b+j][a+i] = 1
        
for i in range(h):
    print(*ans[i],sep = "")

Buggy submission (verdict: Runtime Error):
h,w,a,b = map(int,input().split())
ans = [[0]*w for i in range(h)]
fl = True

if h == 1:
    for i in range(a):
        ans[0][i] = 1
elif w == 1:
    for i in range(b):
        ans[i][0] = 1
else:
    if h % b == 0 and w % a == 0 and h // b == w // a:
        al = h // b
        for i in range(al):
            for j in range(b):
                for k in range(a):
                    ans[b*i+j][a*i+k] = 1
                    
    else:
        fl = False
        
if fl:
    for i in range(h):
        print(*ans[i],sep = "")
else:
    print("No")
Problem p02936 (python)

Fixed submission:
from collections import deque

n,q = map(int,input().split())
r = [[] for _ in range(n)]
bonus = [0] * n
score = [0] * n

for i in range(n-1):
    a,b = map(int,input().split())
    r[a-1].append(b-1)
    r[b-1].append(a-1)
for i in range(q):
    p,x = map(int,input().split())
    bonus[p-1] += x
q = deque()
q.append(0)
used = [False]*n
used[0] = True
score[0] = bonus[0]

while q:
    p = q.popleft()
    for i in r[p]:
        if not used[i]:
            used[i] = True
            score[i] += score[p] + bonus[i]
            q.append(i)
        
print(*score)

Buggy submission (verdict: Runtime Error):
n,q = map(int,input().split())
r = [[] for _ in range(n+1)]
bonus = [0] * (n+1)
score = [0] * (n+1)

for i in range(n-1):
    a,b = map(int,input().split())
    r[a].append(b)
for i in range(q):
    p,x = map(int,input().split())
    bonus[p] += x 

def dfs(d,u):
    s[u] = True
    score[u] += bonus[d]
    
    for v in r[u]:
        if not s[v]:
            dfs(d,v)
    
for i in range(1,n+1):
    s = [False] * (n+1)
    dfs(i,i)
        
print(*score[1:])
Problem p03089 (python)

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

for i in range(n):
    nn = len(b)
    for j in range(nn-1,-1,-1):
        if b[j] == j+1:
            p.append(b[j])
            b = b[:j]+b[j+1:]
            break
            
if b == []:
    for i in range(n-1,-1,-1):
        print(p[i])
else:
    print(-1)

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

for i in range(n):
    nn = len(b)
    for j in range(nn-1,-1,-1):
        if b[j] == j+1:
            b = b[:j]+b[j+1:]
            p.append(c[j])
            break
            
if b == []:
    for i in range(n-1,-1,-1):
        print(p[i])
else:
    print(-1)