Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
D = list(map(int,input().split(" ")))

ans = D[:]


D.sort()

for i in range(N):
	if i % 2 == 0:
		D_1.append(24-D[i])
		D_2.appned(D[i])
	else:
		D_2.append(24-D[i])
		D_1.appned(D[i])


for i in range(N):
	for j in range(i+1,N):
		df1 = abs(D_1[j] - D_1[i])
		df2 = abs(D_2[j] - D_2[i])
		
		df1 = min([df1,24-df1])
		df2 = min([df2,24-df2])
			
		ans.append(df1)
		ans.append(df2)

print(min(df1))






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

ans = D[:]
D.sort()
D_1 = []
D_2 = []

for i in range(N):
	if i % 2 == 0:
		D_1.append(24-D[i])
		D_2.append(D[i])
	else:
		D_2.append(24-D[i])
		D_1.append(D[i])


for i in range(N):
	for j in range(i+1,N):
		df1 = abs(D_1[j] - D_1[i])
		df2 = abs(D_2[j] - D_2[i])
		
		df1 = min([df1,24-df1])
		df2 = min([df2,24-df2])
			
		ans.append(df1)
		ans.append(df2)

print(min(ans))
Buggy python submission (verdict: Runtime Error):
N,Z,W = map(int,input().split(" "))
a = list(map(int,input().split(" "))
print(abs(a[-1]-W))

Fixed submission:
# D問題

N,Z,W =  map(int,input().split(" "))

a = list(map(int,input().split(" ")))

if N == 1:
	ans = abs(a[-1]-W)
else:
	ans = max(abs(a[-1]-a[-2]),abs(a[-1]-W))


print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S_raw = input()
T_raw = input()

S = list(S_raw)
T = list(T_raw)

i = 0
j = 0

j_list = []
S_list = []

lt = len(T)
ls = len(S)

while True:
	if j == ls or i == lt:
		if not i == lt:
			print("UNRESTORABLE")
			exit(0)
		elif j != ls:
			j_list.append(j)
			i = 0
			j = j - lt 
		else:
			j_list.append(j)
			break

	if T[i] == S[j]:
		i += 1
		j += 1
	elif S[j] == '?':
		i += 1
		j += 1
	else:
		i = 0
		j += 1


for j in j_list:
	for i,c in zip(range(j-lt,j),T):
		S[i] = c

	S_tmp = ''

	for i in range(ls):
		if S[i] == '?':
			S_tmp += 'a'
		else:
			S_tmp += str(S[i])

	S_list.append(S_tmp)

S_list.sort()
print(S_list[0])

Fixed submission:
S_raw = input()
T_raw = input()

S = list(S_raw)
T = list(T_raw)

i = 0
j = 0

j_list = []
S_list = []

lt = len(T)
ls = len(S)

while True:
	if (j >= ls) or (i >= lt):
		if i < lt  :
			if j_list == []:
				print("UNRESTORABLE")
				exit(0)
			else:
				break
		elif j < ls:
			j_list.append(j)
			i = 0
			j = j - lt + 1

		else:
			j_list.append(j)
			break

	if T[i] == S[j]:
		i += 1
		j += 1
	elif S[j] == '?':
		i += 1
		j += 1
	else:
		j -= (i - 1)
		i = 0

for k in j_list:
	M = S[:]
	for i,c in zip(range(k-lt,k),T):
		M[i] = c

	S_tmp = ''

	for i in range(ls):
		if M[i] == '?':
			S_tmp += 'a'
		else:
			S_tmp += M[i]

	S_list.append(S_tmp)

S_list.sort()
print(S_list[0])

Buggy python submission (verdict: Runtime Error):
S_raw = input()
T_raw = input()

S = list(S_raw)
T = list(T_raw)

i = 0
j = 0

j_list = []
S_list = []

lt = len(T)
ls = len(S)

while True:
	if j == ls or i == lt:
		if not i == lt:
			print("UNRESTORABLE")
			exit(0)
		elif j != ls:
			j_list.append(j)
			i = 0
			j = j - lt + 2
		else:
			j_list.append(j)
			break

	if T[i] == S[j]:
		i += 1
		j += 1
	elif S[j] == '?':
		i += 1
		j += 1
	else:
		i = 0
		j += 1


for j in j_list:
	for i,c in zip(range(j-lt,j),T):
		S[i] = c

	S_tmp = ''

	for i in range(ls):
		if S[i] == '?':
			S_tmp += 'a'
		else:
			S_tmp += str(S[i])

	S_list.append(S_tmp)

S_list.sort()
print(S_list[0])

Fixed submission:
S_raw = input()
T_raw = input()

S = list(S_raw)
T = list(T_raw)

i = 0
j = 0

j_list = []
S_list = []

lt = len(T)
ls = len(S)

while True:
	if (j >= ls) or (i >= lt):
		if i < lt  :
			if j_list == []:
				print("UNRESTORABLE")
				exit(0)
			else:
				break
		elif j < ls:
			j_list.append(j)
			i = 0
			j = j - lt + 1

		else:
			j_list.append(j)
			break

	if T[i] == S[j]:
		i += 1
		j += 1
	elif S[j] == '?':
		i += 1
		j += 1
	else:
		j -= (i - 1)
		i = 0

for k in j_list:
	M = S[:]
	for i,c in zip(range(k-lt,k),T):
		M[i] = c

	S_tmp = ''

	for i in range(ls):
		if M[i] == '?':
			S_tmp += 'a'
		else:
			S_tmp += M[i]

	S_list.append(S_tmp)

S_list.sort()
print(S_list[0])
Buggy python submission (verdict: Runtime Error):
#! usr/bin/env python3

# A :

S = input()

if "AC" in S:
	print("Yes")

else:

Fixed submission:
#! usr/bin/env python3

# A :

S = input()

if "AC" in S:
	print("Yes")

else:
	print("No")
Buggy python submission (verdict: Runtime Error):
#! usr/bin/env python3
#B:

N = int(input())

A = list(map(int,input().split(" ")))

count = 1

for i in A:
	if A % 2 == 0:
		count *= 2
	else:
		pass

ans = (3 ** len(A)) - count

print(ans)

Fixed submission:
#! usr/bin/env python3
#B:

N = int(input())

A = list(map(int,input().split(" ")))

count = 1

for i in A:
	if i % 2 == 0:
		count *= 2
	else:
		pass

ans = (3 ** len(A)) - count

print(ans)
Buggy python submission (verdict: Runtime Error):
! /usr/bin/env python3
# -*- coding: utf-8 -*-
S = input()
if S in "YAKI":
	print("Yes")

else:
	print("No")

Fixed submission:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
S = input()

S = S[0:4]

if "YAKI" in S:
	print("Yes")

else:
	print("No")

Buggy python submission (verdict: Runtime Error):
#! /usr/bin/env python3
# -*- coding: utf-8 -*-S = input()
if S in "YAKI":
	print("Yes")

else:
	print("No")

Fixed submission:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
S = input()

S = S[0:4]

if "YAKI" in S:
	print("Yes")

else:
	print("No")
Buggy python submission (verdict: Time Limit Exceeded):
#C問題 together

N = int(input())
a = list(map(int,input().split(" ")))

minval = min(a)
maxval = max(a)

a2 = []

ans = []

for j in a:
	for i in [-1,0,1]:
		a2.append(i+j)

for i in range(minval-1,maxval+2):
	ans.append(a2.count(i)) 

print(max(ans))


Fixed submission:
#C問題 together
 
N = int(input())
a = list(map(int,input().split(" ")))
 

 
minval = min(a)
maxval = max(a)
l = (maxval - minval +1)
 
num = [0]*(l+2)

for i in a:
	num[i-minval] += 1

ans = 0
for i in range(1,l+1):
	ans = max(ans,num[i-1]+num[i]+num[i+1])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#C問題 together

N = int(input())
a = list(map(int,input().split(" ")))

a.sort()

minval = a[0]
maxval = a[-1]
l = (maxval - minval +1)

num = [0]*l
num_ans = []


num[0] = a.count(minval)

for i in a:
	if num[i-minval] == 0:
		num[i-minval] = a.count(i)

if l == 1:
	print(num[0])
	exit(0)

num_ans.append(num[0]+num[1]) 

if l == 2:
	print(num_ans[0])
	exit(0)

for i in range(1,l-1):
	num_ans.append(num[i-1]+num[i]+num[i+1])
num_ans.append(num[-2]+num[-1])

print(max(num_ans))

Fixed submission:
#C問題 together
 
N = int(input())
a = list(map(int,input().split(" ")))
 

 
minval = min(a)
maxval = max(a)
l = (maxval - minval +1)
 
num = [0]*(l+2)

for i in a:
	num[i-minval] += 1

ans = 0
for i in range(1,l+1):
	ans = max(ans,num[i-1]+num[i]+num[i+1])

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

free = 0
arr = [0] * 8

for i in a:
	limit = 400
	while (limit <= 3200):
		if i < limit:
			arr[(limit // 400)-1] +=  1
			break
		else:
			limit += 400

	if limit== 3600:
		free += 1

color =  0
for i in arr:
	if i > 0:
		color += 1


print(str(max(1,str(color))) + " " + str(min(color + free,8)))




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

free = 0
arr = [0] * 8

for i in a:
	limit = 400
	while (limit <= 3200):
		if i < limit:
			arr[(limit // 400)-1] +=  1
			break
		else:
			limit += 400

	if limit== 3600:
		free += 1

color =  0
for i in arr:
	if i > 0:
		color += 1


print(str(max(1,color)) + " " + str(color + free))

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

free = 0
arr = [0] * 8

for i in a:
	limit = 400
	while (limit <= 3200):
		if i < limit:
			arr[(limit // 400)-1] +=  1
			break
		else:
			limit += 400

	if limit== 3600:
		free += 1

color =  0
for i in arr:
	if i > 0:
		color += 1


print(max(1,str(color)) + " " + str(min(color + free,8)))




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

free = 0
arr = [0] * 8

for i in a:
	limit = 400
	while (limit <= 3200):
		if i < limit:
			arr[(limit // 400)-1] +=  1
			break
		else:
			limit += 400

	if limit== 3600:
		free += 1

color =  0
for i in arr:
	if i > 0:
		color += 1


print(str(max(1,color)) + " " + str(color + free))
Buggy python submission (verdict: Runtime Error):
N,T = map(int,input().split(" "))
t = list(map(int,input().split(" ")))
scope = [[t[0],t[0]+T]]

for i in range(1,N):
	if t[i] < scope[-1][1]:
		scope[-1][1] = t[i] + T

	else:
		scope.appned([t[i],t[i]+T])

total = 0
for begin,end in scope:
	total += (end - begin)

print(total)

	


Fixed submission:
N,T = map(int,input().split(" "))
t = list(map(int,input().split(" ")))
scope = [[t[0],t[0]+T]]

for i in range(1,N):
	if t[i] < scope[-1][1]:
		scope[-1][1] = t[i] + T

	else:
		scope.append([t[i],t[i]+T])

total = 0
for begin,end in scope:
	total += (end - begin)

print(total)
Buggy python submission (verdict: Runtime Error):
from math import sqrt
N = int(input())

max_v = int(sqrt(N))
for num in range(max_v,1,(-1)):
	if N % num == 0:
		div = num
		break

print(max(len(str(div)),len(str(N//max_v))))

Fixed submission:
from math import sqrt
N = int(input())

div = 1
max_v = int(sqrt(N))
for num in range(max_v,1,(-1)):
	if N % num == 0:
		div = num
		break

#print(div)
print(max(len(str(div)),len(str(N//div))))
Buggy python submission (verdict: Runtime Error):
X = int(input())

sumval = 0
for i in range(1,X):
	sumval += i
	if sumval >= X:
		ans = i
		break

print(ans)


Fixed submission:
X = int(input())

sumval = 0
for i in range(1,X+1):
	sumval += i
	if sumval >= X:
		ans = i
		break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())
pos = [0]

for i in range(1,X+1):
	tmp = []
	for j in pos:
		tmp.append(j + i)
		if j + i ==  X:
			print(i)
			exit(0)

	pos.extend(tmp)
	pos = list(set(pos))


Fixed submission:
X = int(input())

sumval = 0
for i in range(1,X+1):
	sumval += i
	if sumval >= X:
		ans = i
		break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split(" ")))

dic = {}
one = []
for i in range(N):
	if not A[i] in one:
		one.append(A[i])

ans = len(one)
print(ans - ((ans+1) % 2))





Fixed submission:
N = int(input())
A = list(map(int,input().split(" ")))
print(len(set(A)) - ((len(set(A))+1) % 2))
Buggy python submission (verdict: Runtime Error):
s,op,s2 = map(str,input().split(" "))

if op == '+':
  print(s+s2)

else:
  print(s-s2)

Fixed submission:
A,op,B = map(str,input().split(" "))
if op == "+":
  print(int(A)+int(B))
else:
  print(int(A)-int(B))

Buggy python submission (verdict: Runtime Error):
s,op,s2 = map(int,input().split(" "))

if op == '+':
  print(s+s2)

else:
  print(s-s2)

Fixed submission:
A,op,B = map(str,input().split(" "))
if op == "+":
  print(int(A)+int(B))
else:
  print(int(A)-int(B))
Buggy python submission (verdict: Runtime Error):
import bisect
N,K = map(str,input().split(" "))
D = list(map(int,input().split(" ")))
D_bar = []
for i in range(1,10):
	if not i in D:
		D_bar.append(i)
D_bar.sort()

l = len(N)
ans = N
if int(N[0]) in D:
	if N[0] == '9':
		ans = '10' + '0'*(l-1)
	else:
		p = bisect. bisect_left(D_bar,int(N[0]))
		ans = str(D_bar[p]) + '0'*(l-1)

else:
	for i in range(1,l):
		num = int(N[i])
		if num in D:
			index = i
			if N[i] == '9':
				ans = N[:i-1] + '10' + ('0'*max(0,l-i-1))
			else:
				p = bisect. bisect_left(D_bar,num)
				ans = N[:i] + str(D_bar[p]) + ('0'*max(0,l-i-1))

			break

print(ans)






Fixed submission:
import bisect
n,K = map(str,input().split(" "))
D = list(map(int,input().split(" ")))
N = list(n)

D_bar = []
for i in range(10):
	if not i in D:
		D_bar.append(i)

mv = str(D_bar[0])
ld = 10 - int(K)
l = len(N)
index = -1
for i in range(l):
	if int(N[i]) in D:
		index = i
		break

if index == (-1):
	print(n)
	exit(0)

for i in range(index,-1,-1):
	p = bisect.bisect_left(D_bar,int(N[i]))
	if p == ld:
		N[i] = mv
		if i == 0:
			m = str(D_bar[0]) if D_bar[0] != 0 else str(D_bar[1])
			N[0] = mv
			N.insert(0,m)
		else:
			N[i-1] = str(int(N[i-1]) + 1)
	else:
		N[i] = str(D_bar[p])
		break

for i in range(index+1,len(N)):
	N[i] = mv
print(''.join(N))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
A = tuple(map(int, input().split()))
C = Counter(A)

ansers = dict()
for i in range(N):
    if A[i] in ansers:
        print(ansers[A[i]])
    else:
        temp = sum(v*(v-1)//2 if A[i]!=k else (v-1)*(v-2)//2 for k, v in C.items())
        print(temp)
        ansers[A[i]] = temp

Fixed submission:
from collections import Counter

N = int(input())
A = tuple(map(int, input().split()))
C = Counter(A)

MX = sum(v*(v-1) for v in C.values())//2
for i in range(N):
    print(MX-C[A[i]]+1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
A = tuple(map(int, input().split()))
C = Counter(A)

ansers = dict()
for i in range(N):
    print(sum(v*(v-1)//2 if A[i]!=k else (v-1)*(v-2)//2 for k, v in C.items()))


Fixed submission:
from collections import Counter

N = int(input())
A = tuple(map(int, input().split()))
C = Counter(A)

MX = sum(v*(v-1) for v in C.values())//2
for i in range(N):
    print(MX-C[A[i]]+1)
Buggy python submission (verdict: Runtime Error):
AC, BC, MC = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
M = [tuple(map(int, input().split())) for _ in range(MC)]

ans = min(A) + min(B)
for x, y, c in M:
    ans = min(ans, A[x - 1] + B[x - 1] - c)
print(ans)

Fixed submission:
AC, BC, MC = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
M = [tuple(map(int, input().split())) for _ in range(MC)]

ans = min(A) + min(B)
for x, y, c in M:
    ans = min(ans, A[x - 1] + B[y - 1] - c)
print(ans)

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

M = [[0 for _ in range(AC)] for __ in range(BC)]
for i in range(MC):
    x, y, c = map(int, input().split())
    M[x-1][y-1] = max(M[x-1][y-1], c)

ans = 10**8
for a in range(AC):
    for b in range(BC):
        ans = min(ans, A[a-1] + B[b-1] - M[a-1][b-1])
print(ans)

Fixed submission:
AC, BC, MC = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
M = [tuple(map(int, input().split())) for _ in range(MC)]

ans = min(A) + min(B)
for x, y, c in M:
    ans = min(ans, A[x - 1] + B[y - 1] - c)
print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(M)]

matches = []
for i in range(0, 1000):
    if len(str(i)) == N:
        temp = True
        for s, c in sc:
            if str(i)[s - 1] != str(c):
                temp = False
        if temp: matches.append(i)
print(-1) if len(matches) == 0 else print(min(matches))

Fixed submission:
N = int(input())
print(((N+2)-1)//2)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
gates = [tuple(map(int, input().split())) for _ in range(M)]

lmax = max(gates, key=lambda x: x[0])[0]
rmin = min(gates, key=lambda x: x[1])[1]

print(max(rmin-lmax+1), 0)

Fixed submission:
N, M = map(int, input().split())
gates = [tuple(map(int, input().split())) for _ in range(M)]

lmax = max(gates, key=lambda x: x[0])[0]
rmin = min(gates, key=lambda x: x[1])[1]

print(max(rmin-lmax+1, 0))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
cards = sorted(list(map(int, input().split())))
op = sorted([tuple(map(int, input().split())) for _ in range(M)], key = lambda x: x[1], reverse=True)

cursor = 0
for b, c in op:
    for i in range(b):
        if cards[cursor] < c:
            cards[cursor] = c
            cursor += 1
        else:
            break
print(sum(cards))


Fixed submission:
N, M = map(int, input().split())
cards = sorted(list(map(int, input().split())))
op = sorted([tuple(map(int, input().split())) for _ in range(M)], key = lambda x: x[1], reverse=True)

cursor = 0
for b, c in op:
    for i in range(b):
        if  cursor < N and cards[cursor] < c:
            cards[cursor] = c
            cursor += 1
        else:
            break
print(sum(cards))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().aplit())
print(N - K + 1)

Fixed submission:
N, K = map(int, input().split())
print(N-K+1)
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

ans = 0
for r in range(N//R+1):
  for g in range(N//G+1):
    if  r*R+g*G <= N and (N-r*R-g*G) % B == 0:
      ans += 1
print(ans)

Fixed submission:
R, G, B, N = map(int, input().split())
 
ans = 0
for r in range(N//R+1):
  for g in range(N//G+1):
    tmp = r*R+g*G
    if  tmp <= N and (N-tmp) % B == 0:
      ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

ans = 0
for i in range(1, int(N**0.5)+1):
  if (N-i)%i == 0:
    tmp = (N-i)/i
    if N%tmp == i:
      ans += int(tmp)
print(ans)


Fixed submission:
N = int(input())

ans = 0
for i in range(1, int(N**0.5)+1):
  if (N-i)%i == 0:
    tmp = (N-i)/i
    if tmp != 0 and N%tmp == i:
      ans += int(tmp)
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
h1 = H[0]
h2 = H[1]

ans = 0
for i in range(1,N):
  if H[i] >= h1 and H[i] >=h2 and H[i] >= H[i-1]:
    ans += 1
    
print(ans+1)

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

ans = 1
if N > 1:
  for i in range(1, N):
    if H[i] >= max(H[:i]):
      ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))

ans = 0
if N > 1:
  for i in range(1, N):
    if (H[i] >= H[i - 1]:
      ans += 1

print(ans + 1)

Fixed submission:
import itertools
S = input()

p1 = itertools.cycle('01')
p2 = itertools.cycle('10')

ans1=0
ans2=0
for s,P1,P2 in zip(S,p1,p2):
  if s == P1:
    ans1 += 1
  if s == P2:
    ans2 += 1
print(min(ans1,ans2))
Buggy python submission (verdict: Time Limit Exceeded):
_, q = map(int, input().split())
s = input()

for i in range(q):
  l, r = map(int, input().split())
  print(s[l-1:r].count('AC'))
  

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

t = [0] * (n)
for i in range(n-1):
    if s[i:i+2] == 'AC':
        t[i+1] = t[i]+1
    else:
        t[i+1] = t[i]

for _ in range(q):
    l, r = map(int, input().split())
    print(t[r-1]-t[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
_, q = map(int, input().split())
s = input()

for i in range(q):
  l, r = map(int, input().split())
  print(s[l-1:r].count('AC'))
  

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

t = [0] * (n)
for i in range(n-1):
    if s[i:i+2] == 'AC':
        t[i+1] = t[i]+1
    else:
        t[i+1] = t[i]

for _ in range(q):
    l, r = map(int, input().split())
    print(t[r-1]-t[l-1])
Buggy python submission (verdict: Runtime Error):
import datetime

d0 = datetime.date(2019, 4, 30)
d = datetime.date(map(int, *input().split('/')))

if d <= d0:
  print('Heisei')
else:
  print('TBD')

Fixed submission:
import datetime
 
d0 = datetime.date(2019, 4, 30)
d = datetime.date(*map(int, input().split('/')))
 
if d <= d0:
  print('Heisei')
else:
  print('TBD')
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
H = list(map(int, input().split()))

DP = [0] * N
DP[0] = 0
DP[1] = abs(H[0] - H[1])

for i in range(2, N):
    DP[i] = min(DP[i-x] + abs(H[i-x]-H[i]) for x in range(1, min(i+1, K+1)))
print(DP[N-1])


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

DP = [10**8] * (N+1)
DP[0] = 0
DP[1] = abs(H[0] - H[1])

for i in range(2, N):
    DP[i] = min(DP[i-x] + abs(H[i-x]-H[i]) for x in range(1, min(i+1, K+1)))
print(DP[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
H = list(map(int, input().split()))

DP = [10**8] * (N+1)
DP[0] = 0
DP[1] = abs(H[0] - H[1])

for i in range(2, N):
    DP[i] = min(DP[i-x] + abs(H[i-x]-H[i]) for x in range(1, min(i+1, K+1)))
print(DP[N-1])


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

DP = [10**8] * (N+1)
DP[0] = 0
DP[1] = abs(H[0] - H[1])

for i in range(2, N):
    DP[i] = min(DP[i-x] + abs(H[i-x]-H[i]) for x in range(1, min(i+1, K+1)))
print(DP[N-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = int(input())
B = int(input())

print('Hello World') if N == 1 else print(A+B)


Fixed submission:
if int(input()) == 1:
    print('Hello World')
else:
    A = int(input())
    B = int(input())
    print(A+B)
Buggy python submission (verdict: Runtime Error):
import collections


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

if len(set(l)) == 1:
    print(n//2)
    exit()

leven = [x for x in l[::2]]
lodd  = [x for x in l[1::2]]

ce = collections.Counter(leven)
co = collections.Counter(lodd)
ce = sorted(ce.items(), key=lambda x:x[1])
co = sorted(co.items(), key=lambda x:x[1])

if ce[-1][0] != ce[-1][0]:
	print(n - ce[-1][1] - co[-1][1])
elif ce[-2][1] > co[-2][1]:
    print(n - ce[-2][1] - co[-1][1])
else:
    print(n - ce[-1][1] - co[-2][1])


Fixed submission:
import collections


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

if len(set(l)) == 1:
    print(n//2)
    exit()

leven = [x for x in l[::2]]
lodd  = [x for x in l[1::2]]

ce = collections.Counter(leven)
co = collections.Counter(lodd)
ce = sorted(ce.items(), key=lambda x:x[1])
co = sorted(co.items(), key=lambda x:x[1])

if ce[-1][0] != co[-1][0]:
	print(n - ce[-1][1] - co[-1][1])
elif ce[-2][1] > co[-2][1]:
    print(n - ce[-2][1] - co[-1][1])
else:
    print(n - ce[-1][1] - co[-2][1])

Buggy python submission (verdict: Runtime Error):
import collections


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

if len(set(l)) == 1:
    print(n//2)
    exit()

leven = [x for x in l[::2]]
lodd  = [x for x in l[1::2]]
ce = collections.Counter(leven)
co = collections.Counter(lodd)

ce = sorted(ce.items(), key=lambda x:x[1])
co = sorted(co.items(), key=lambda x:x[1])

if ce[-1][0] != ce[-1][0]:
	print(n - ce[-1][1] - co[-1][1])
elif ce[-2][1] > co[-2][1]:
    print(n - ce[-2][1] - ce[-1][1])
else:
    print(n - ce[-1][1] - ce[-2][1])


Fixed submission:
import collections


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

if len(set(l)) == 1:
    print(n//2)
    exit()

leven = [x for x in l[::2]]
lodd  = [x for x in l[1::2]]

ce = collections.Counter(leven)
co = collections.Counter(lodd)
ce = sorted(ce.items(), key=lambda x:x[1])
co = sorted(co.items(), key=lambda x:x[1])

if ce[-1][0] != co[-1][0]:
	print(n - ce[-1][1] - co[-1][1])
elif ce[-2][1] > co[-2][1]:
    print(n - ce[-2][1] - co[-1][1])
else:
    print(n - ce[-1][1] - co[-2][1])
Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)
S = input()
Q = int(input())
inv = 0
head=''
tail=''
for _ in range(Q):
    q = input()
    if q == '1':
        inv = 1 - inv
    else:
        (T,F,C) = list(q.split())
        #print(T,F,C)
        if inv == 0:
            if F == '1':
                head += C
            else:
                tail += C
        else:
            if F == '1':
                tail +=C
            else:
                head +=C
    # print(head,S,tail)
k = ''.join(list(reversed(head))) + S + tail
if inv == 0:
    print(k)
else:
    print(''.join(list(reversed(k))))
    


Fixed submission:
import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)
S = input()
Q = int(input())

inv = 0
head=[]
tail=[]
for _ in range(Q):
    q = input()
    if q == '1':
        inv = 1 - inv
    else:
        (T,F,C) = list(q.split())
        #print(T,F,C)
        if inv == 0:
            if F == '1':
                head.append(C)
            else:
                tail.append(C)
        else:
            if F == '1':
                tail.append(C)
            else:
                head.append(C)
    # print(head,S,tail)

if inv == 0:
    print(''.join(list(reversed(head))) + S + ''.join(tail))
else:
    print(''.join(list(reversed(tail))) + ''.join(list(reversed(S))) + ''.join(head))