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

list2 = []
for i in range(1,N + 1):
    list2.append(i)

if list1 == list2:
    print("YES")
    sys.exit()
for i in range(0,N):
    if list1[i] != i+1:
        if i+1 == list1[list1[i]-1]:
            list1[list1[i]-1] = list1[i]
            list1[i] = i+1
            

        if list1 == list2:
            print("YES")
            sys.exit()
        else:
            print("NO")
            sys.exit()

Fixed submission:
import sys
N = int(input())
p = input()
list1 = list(map(int,p.split()))

list2 = []
for i in range(1,N + 1):
    list2.append(i)

if list1 == list2:
    print("YES")
    sys.exit()
for i in range(0,N):
    if list1[i] != i+1:
        if i+1 == list1[list1[i]-1]:
            list1[list1[i]-1] = list1[i]
            list1[i] = i+1
            

        if list1 == list2:
            print("YES")
            sys.exit()
        else:
            print("NO")
            sys.exit()
Buggy python submission (verdict: Runtime Error):
N = int(input())
p = input()
list1 = list(map(int,p.split()))

list2 = []
for i in range(1,N + 1):
    list2.append(i)

if list1 == list2:
    print("YES")
    exit()
for i in range(0,N):
    if list1[i] != i+1:
        if i+1 == list1[list1[i]-1]:
            list1[list1[i]-1] = list1[i]
            list1[i] = i+1
            

        if list1 == list2:
            print("YES")
            exit()
        else:
            print("NO")
            exit()

Fixed submission:
n = int(input())
a = input()
la = list(map(int,a.split())) #街にいるモンスター数
b = input()
lb = list(map(int,b.split())) #ダメージ

damagecost = 0
killmonster = 0
for i in range(n):
    if lb[i] <= la[i]:
        killmonster += lb[i]
    else:
        killmonster += la[i]
        damagecost = lb[i] - la[i]
        if damagecost >= la[i + 1]:
            killmonster += la[i + 1]
            la[i + 1] = 0
        else:
            killmonster += damagecost
            la[i + 1] = la[i + 1] - damagecost
print(killmonster)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

mod = 10**9+7
s = readline().rstrip().decode('utf-8')

dp = [0]*13 #あまりが0~12の13通りとなる場合の数
dp[0] = 1
dig = 1 #今見てる桁数
for i in range(len(s)-1,-1,-1): #小さい方の桁から見ていく
    c = s[i]
    next_dp = [0]*13 #逐次更新してはいけないので、次の桁の数についてjを回して入れていく
    if c == "?": #?なら0~10の10通り全てについてあたる必要がある
        for d in range(10):
            for j in range(13):
                next_dp[(d*dig + j)%13] += dp[j]
                next_dp[(d*dig + j)%13] %= mod

    
    else:
        d = int(c)
        for j in range(13):
            next_dp[(d*dig + j)%13] += dp[j]
            next_dp[(d*dig + j)%13] %= mod


    dig *= 10
    dp = next_dp

print(dp[5]%mod)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

mod = 10**9+7
s = readline().rstrip().decode('utf-8')

dp = [0]*13 #あまりが0~12の13通りとなる場合の数
dp[0] = 1
dig = 1 #今見てる桁数
for i in range(len(s)-1,-1,-1): #小さい方の桁から見ていく
    c = s[i]
    next_dp = [0]*13 #逐次更新してはいけないので、次の桁の数についてjを回して入れていく
    if c == "?": #?なら0~10の10通り全てについてあたる必要がある
        for d in range(10):
            for j in range(13):
                next_dp[(d*dig + j)%13] += dp[j]
                next_dp[(d*dig + j)%13] %= mod

    
    else:
        d = int(c)
        for j in range(13):
            next_dp[(d*dig + j)%13] += dp[j]
            next_dp[(d*dig + j)%13] %= mod


    dig *= 10
    dig %= 13
    dp = next_dp

print(dp[5]%mod)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
m = 0
for i in range(N):
    m = int(input())
    A.append(m)
    #A[i] = int(A[i])
task = 0
m = 0
for i in range(N):
    task = A.pop(i)
    m = max(A)
    print(m)
    A.insert(i,task)

Fixed submission:
N = int(input())
A = []
m = 0
for i in range(N):
    A.append(int(input()))
task = 0
m = max(A)
m2 = sorted(A)[-2]
maxindex = []
for i in range(N):
    if A[i] == m:
        print(m2)
    else:
        print(m)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = []
for i in range(N):
    A += input()
    A[i] = int(A[i])
task = 0
m = 0
for i in range(N):
    task = A.pop(i)
    m = max(A)
    print(m)
    A.insert(i,task)

Fixed submission:
N = int(input())
A = []
m = 0
for i in range(N):
    A.append(int(input()))
task = 0
m = max(A)
m2 = sorted(A)[-2]
maxindex = []
for i in range(N):
    if A[i] == m:
        print(m2)
    else:
        print(m)
Buggy python submission (verdict: Time Limit Exceeded):
L,R = map(int,input().split())
list1 = []
i = L
j = L + 1
jcount = 0
while True:
    if i < R:
        list1.append(i*j%2019)
        if j < R:
            j += 1
        else:
            jcount += 1
            j = L+1 + jcount
            i += 1
    else:
        break

if len(list1) == 0:
    print(i*j%2019)

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

Fixed submission:
import sys
L,R = map(int,input().split())
list1 = []
i = L
j = L + 1
jcount = 0
while True:
    if i < R:
        if i*j %2019 == 0:
            print(0)
            sys.exit()
        list1.append(i*j%2019)
        if j < R:
            j += 1
        else:
            jcount += 1
            j = L+1 + jcount
            i += 1
    else:
        break
if len(list1) == 0:
    print(i*j%2019)
print(min(list1))
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())

if a == b:
    print("Bad")
elif b == c:
    print("Bad")
elif c == d:
    print("Bad")
else:
    print("Good")

Fixed submission:
S = input()
list1 = list(map(int,S))
#例えば4つ
a = list1[0]
b = list1[1]
c = list1[2]
d = list1[3]

if a == b:
    print("Bad")
elif b == c:
    print("Bad")
elif c == d:
    print("Bad")
else:
   print("Good")
Buggy python submission (verdict: Time Limit Exceeded):
#ABC130-E Common Subsequence
"""
問題：
整数列のリストが与えられる
空であるものも含めて、sとtの部分列として等しいものの個数を求めよ
解法：
LCSのmaxではなくsumのバージョンでかつ、
数え上げなので重複をなくさなければならない。
具体的には、
dp[i][j]:sをi文字目迄見た時のtをj文字目迄見た時に、
dp0:横方向(j方向)を優先して遷移した後に、縦方向(i方向)への遷移を行った時の合計
dp1:縦方向、横方向への遷移を行った時の合計
として、dp1[-1][-1]が答え。

"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n,m = map(int,readline().split())
s = list(map(int,readline().split())) + [-1]
t = list(map(int,readline().split())) + [-2]
mod = 10**9+7

#dp table
dp0 = [[0]*(m+2) for _ in range(n+2)]
dp1 = [[0]*(m+2) for _ in range(n+2)]
dp0[0][0] = 1
#process1
for i in range(n+1):
    for j in range(m+1):
        dp0[i+1][j] += dp0[i][j]
        dp1[i][j] += dp0[i][j]
        dp1[i][j+1] += dp1[i][j]
        if s[i] == t[j]:
            dp0[i+1][j+1] += dp1[i][j]


print(dp1[n][m]%mod)


Fixed submission:
#ABC130-E Common Subsequence
"""
問題：
整数列のリストが与えられる
空であるものも含めて、sとtの部分列として等しいものの個数を求めよ
解法：
LCSのmaxではなくsumのバージョンでかつ、
数え上げなので重複をなくさなければならない。
具体的には、
dp[i][j]:sをi文字目迄見た時のtをj文字目迄見た時に、
dp0:横方向(j方向)を優先して遷移した後に、縦方向(i方向)への遷移を行った時の合計
dp1:縦方向、横方向への遷移を行った時の合計
として、dp1[-1][-1]が答え。

"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n,m = map(int,readline().split())
s = list(map(int,readline().split())) + [-1]
t = list(map(int,readline().split())) + [-2]
mod = 10**9+7

#dp table
dp0 = [[0]*(m+2) for _ in range(n+2)]
dp1 = [[0]*(m+2) for _ in range(n+2)]
dp0[0][0] = 1
#process1
for i in range(n+1):
    for j in range(m+1):
        dp0[i+1][j] += dp0[i][j]%mod
        dp1[i][j] += dp0[i][j]%mod
        dp1[i][j+1] += dp1[i][j]%mod
        if s[i] == t[j]:
            dp0[i+1][j+1] += dp1[i][j]%mod


print(dp1[n][m]%mod)
Buggy python submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
lst1 = [list(map(int,readline().split())) for i in range(n)]

cost = 1

#同じベクトルでつなげる要素を最大化する。全点対象にベクトルを求め、多数決。
dic1 = dict()

for i in range(n-1):
    for j in range(i+1,n):
        x,y = lst1[i][0] - lst1[j][0] , lst1[i][1] - lst1[j][1]
        if (x,y) in dic1:
            dic1[(x,y)] += 1
        else:
            dic1[(x,y)] = 1

#線分は頂点-1個。そのうち同ベクトル数が免除される。
cost += n-1
cost -= max(dic1.values())

print(cost)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(readline())
lst1 = [list(map(int,readline().split())) for i in range(n)]
lst1.sort()
cost = 1
if n == 1:
    print(cost)
    exit()
#同じベクトルでつなげる要素を最大化する。全点対象にベクトルを求め、多数決。
dic1 = dict()

for i in range(n-1):
    for j in range(i+1,n):
        x,y = lst1[i][0] - lst1[j][0] , lst1[i][1] - lst1[j][1]
        """
        if x < 0 and y < 0:
            x,y = -x,-y
        elif x < 0 and y >= 0:
            x,y = -x,-y"""
        if (x,y) in dic1:
            dic1[(x,y)] += 1
        else:
            dic1[(x,y)] = 1

#線分は頂点-1個。そのうち同ベクトル数が免除される。
cost += n-1
cost -= max(dic1.values())

print(cost)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())

list1 = []
for i in range(m):
    list1.append(int(input()))

dp = [0]*(n+1)
dp[0] = 1
if not 1 in list1: 
	dp[1] = 1 #i+2まで考えるため、初期設定はi = 1まで必要
for i in range(n-1):
	if i not in list1:
		dp[i+2] += dp[i]
	if i+1 not in list1:
		dp[i+2] += dp[i+1]

print(dp[n]%1000000007)

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


dp = [0]*(n+1)
dp[0] = 1

for i in range(m):
	dp[int(input())] = -1

if dp[1] != -1:
	dp[1] = 1

for i in range(n-1):
	if dp[i+2] != -1:
		if dp[i+1] != -1:
			dp[i+2] += dp[i+1]
		if dp[i] != -1:
			dp[i+2] += dp[i]

print(dp[n]%1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())

list1 = []
for i in range(m):
    list1.append(int(input()))

dp = [0]*(n+1)
dp[0] = 1
if not 1 in list1: 
	dp[1] = 1 #i+2まで考えるため、初期設定はi = 1まで必要
for i in range(n-1):
	if (i in list1)and (i+1 in list1):
		break
	if i in list1 :
		dp[i+2] = dp[i+1]
	elif i+1 in list1:
		dp[i+2] = dp[i]
	else:
		dp[i+2] = dp[i] + dp[i + 1]

print(dp[n]%1000000007)



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


dp = [0]*(n+1)
dp[0] = 1

for i in range(m):
	dp[int(input())] = -1

if dp[1] != -1:
	dp[1] = 1

for i in range(n-1):
	if dp[i+2] != -1:
		if dp[i+1] != -1:
			dp[i+2] += dp[i+1]
		if dp[i] != -1:
			dp[i+2] += dp[i]

print(dp[n]%1000000007)
Buggy python submission (verdict: Runtime Error):
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

"""
A<Bとする。
C<Dの場合：
A～CとB~Dの間に"##"が無ければ達成できる.
C>Dの場合：
上記に加え、B~Cの間に"..."が存在すれば達成できる
"""

n,a,b,c,d = map(int,readline().split())
s = readline().rstrip().decode('utf-8')
a,b,c,d = a-1,b-1,c-1,d-1

flag = 1
space = 0
res = 0
rock = 0
for i in range(a,c+1):
	if s[i] == "#":
		rock += 1
	else:
		rock = 0
	if rock >= 2:
		flag = 0
for i in range(b,d+1):
	if s[i] == "#":
		rock += 1
	else:
		rock = 0
	if rock >= 2:
		flag = 0
if c > d:
	for i in range(b-1,c+2):
		if s[i] == ".":
			space += 1
		else:
			res = max(res,space)
			space = 0
	if res < 3:
		flag = 0


print("Yes" if flag else "No")


Fixed submission:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

"""
A<Bとする。
C<Dの場合：
A～CとB~Dの間に"##"が無ければ達成できる.
C>Dの場合：
上記に加え、B~Cの間に"..."が存在すれば達成できる
"""

n,a,b,c,d = map(int,readline().split())
s = readline().rstrip().decode('utf-8')
a,b,c,d = a-1,b-1,c-1,d-1

flag = 1
space = 0
res = 0
rock = 0
for i in range(a,c+1):
	if s[i] == "#":
		rock += 1
	else:
		rock = 0
	if rock >= 2:
		flag = 0
for i in range(b,d+1):
	if s[i] == "#":
		rock += 1
	else:
		rock = 0
	if rock >= 2:
		flag = 0
if c > d:
	for i in range(b-1,d+2):
		if s[i] == ".":
			space += 1
		else:
			res = max(res,space)
			space = 0
	res = max(res,space)
	if res < 3:
		flag = 0

print("Yes" if flag else "No")
Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter
n,m = map(int,input().split())
a_list = list(map(int,input().split()))
b_list = []
for i in range(m):
	b,c = map(int,input().split()) 
	b_list.append([b,c]) #b_list[i][枚数、value]

a_list.sort()
b_list.sort(reverse = True,key = itemgetter(1)) #cについてソート

now_position = 0
for i in range(m):
	if (now_position + b_list[i][0] < len(a_list)) and a_list[now_position + b_list[i][0]] < b_list[i][1]:
		del a_list[now_position:now_position + b_list[i][0]]
		a_list.insert(now_position,b_list[i][1]*b_list[i][0])
		now_position += 1
	else:
		for j in range(b_list[i][0]):
			if (now_position + j < len(a_list)) and a_list[now_position + j] < b_list[i][1]:
				a_list[now_position + j] = b_list[i][1]

			else:
				break
		break

print(sum(a_list))

Fixed submission:
from operator import itemgetter
n,m = map(int,input().split())
a_list = list(map(int,input().split()))
b_list = []
for i in range(m):
	b,c = map(int,input().split()) 
	b_list.append([b,c]) #b_list[i][枚数、value]

a_list.sort()
b_list.sort(reverse = True,key = itemgetter(1)) #cについてソート
sum_list = []
now_position = 0
j = 0
for i in range(m):
	if (now_position + b_list[i][0] <= len(a_list)) and a_list[now_position + b_list[i][0]-1] < b_list[i][1]:
		sum_list.append(b_list[i][1]*b_list[i][0])
		now_position += b_list[i][0] 
	else:
		for j in range(b_list[i][0]):
			if (now_position + j < len(a_list)) and a_list[now_position + j] < b_list[i][1]:
				sum_list.append(b_list[i][1])

			else:
				break
		break
if (now_position + j <= len(a_list)-1):
	print(sum(sum_list)+sum(a_list[now_position+j:]))
else:
	print(sum(sum_list))
Buggy python submission (verdict: Runtime Error):
import fractions as math
#import fractions as math
n = int(input())
list1 = list(map(int,input().split()))
a = math.gcd(list1[0],list1[-1])
b = 0
for i in range(0,n):
	if a > math.gcd(a,list1[i]):
		a = math.gcd(a,list1[i])
		b = list1.index(list1[i])
del list1[b]
a = list1[0]
for i in range(0,len(list1)):
	a = min(a,math.gcd(a,list1[i]))
print(a)


Fixed submission:
a,b,t = map(int,input().split())

print(t//a*b)
Buggy python submission (verdict: Runtime Error):
"""
#の右に.が無いようにしたい
一番左にある#.もしくは一番右にある#の部分
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
s = readline().rstrip().decode('utf-8')
ans = 10**9
res = 0
for i in range(n-1):
    if s[i] == "#":
        if s[i+1] == ".":
            res = i
            break

ans = min(ans,s[i:].count("."))

ans = min(ans,s.count("#"),s.count("."))

print(ans)

Fixed submission:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
s = readline().rstrip().decode('utf-8')
res = s.count(".")
ans = res
for i in range(n):
    if s[i] == "#":
        res += 1
    else:
        res -= 1
    ans = min(ans,res)

print(ans)
Buggy python submission (verdict: Runtime Error):
list1 = list(input())

#貪欲
for i in range(1,len(list1)):
	if list1[i] == list1[i-1]:
		if list1[i] == "1":
			list1[i] = "0"
		else:
			list1[i] = "1"
		count += 1
print(count)

Fixed submission:
list1 = list(input())
count = 0
#貪欲
for i in range(1,len(list1)):
	if list1[i] == list1[i-1]:
		if list1[i] == "1":
			list1[i] = "0"
		else:
			list1[i] = "1"
		count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
list_str = []
list1 = []
for i in range(5):
	a = input()
	list_str.append(list(a))
	list1.append(int(a))


abs_max = 10
count = 0
for i in range(5):
	if int(list_str[i][-1]) != 0 and int(list_str[i][-1]) < abs_max:
		abs_max = int(list_str[i][-1])
for i in range(5):
	count += math.ceil(list1[i]/10)

if abs_max == 10:
	print(int(count*10))
else:
	print(int(count*10)-10+abs_max)

Fixed submission:
import math
list_str = []
list1 = []
for i in range(5):
	a = input()
	list_str.append(list(a))
	list1.append(int(a))


abs_max = 10
count = 0
for i in range(5):
	if int(list_str[i][-1]) != 0 and int(list_str[i][-1]) < abs_max:
		abs_max = int(list_str[i][-1])
for i in range(5):
	count += math.ceil(list1[i]/10)

if abs_max == 10:
	print(int(count*10))
else:
	print(int(count*10)-10+abs_max)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
list1 = list(input())
del list1[-1]
ans = 0
def func(flist):
    i = 0
    flag = 0
    global ans
    while len(flist)>i+1:
        if flist[i] != flist[i+1]:
            flag = 1
            del flist[i],flist[i]
            ans += 1
        else:
            i+=1
    if not flag:
        return False
    else:
        return True
if __name__ == "__main__":
    while True:
        if not func(list1):
            break
    print(ans*2)

Fixed submission:
import sys
input = sys.stdin.readline
list1 = list(input())
del list1[-1]
ans = 0
def func(flist):
    count0 = 0
    for i in flist:
        if i == "0":
            count0 += 1
    count1 = len(flist)-count0
    return len(flist)-abs(count1-count0)

if __name__ == "__main__":
    print(func(list1))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a,b,q = map(int,readline().split())

jinja = [-(2*10**10+10)]

for i in range(a):
    jinja.append(int(input()))

tera = [-(2*10**10+10)]

for i in range(b):
    tera.append(int(input()))

#add big number
jinja.append(2*10**10+10)
tera.append(2*10**10+10)

for query in range(q):
    x = int(input())
    j_r = bisect.bisect_left(jinja,x)
    j_l = jinja[j_r-1]
    t_r = bisect.bisect_left(tera,x)
    t_l = tera[t_r-1]
    j_r = jinja[j_r]
    t_r = tera[t_r]
    ans = min((x-j_l)*2+(t_r-x),(x-t_l)*2+(j_r-x),(x-j_l)+(t_r-x)*2,(x-t_l)+(j_r-x)*2)
    ans = min (ans,x - min(j_l,t_l), max(j_r,t_r)-x)
    print(ans)


Fixed submission:
import sys
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a,b,q = map(int,readline().split())

jinja = [-(10**10+10)]

for i in range(a):
    jinja.append(int(readline()))

tera = [-(10**10+10)]

for i in range(b):
    tera.append(int(readline()))

#add big number
jinja.append(2*10**10+10)
tera.append(2*10**10+10)

for query in range(q):
    x = int(readline())
    j_r = bisect.bisect_left(jinja,x)
    j_l = jinja[j_r-1]
    t_r = bisect.bisect_left(tera,x)
    t_l = tera[t_r-1]
    j_r = jinja[j_r]
    t_r = tera[t_r]
    ans = min((x-j_l)*2+(t_r-x),(x-t_l)*2+(j_r-x),(x-j_l)+(t_r-x)*2,(x-t_l)+(j_r-x)*2)
    ans = min (ans,x - min(j_l,t_l), max(j_r,t_r)-x)
    print(ans)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
list1 = list(map(int,input().split()))
list1.sort()
list2 = []
for i in range(m-1):
	list2.append(list1[i+1]-list1[i])
list2.sort(reverse = True)
cut = 0
for j in range(n-1):
	cut+= list2[j]
print(max(list1)-min(list1)-cut)

Fixed submission:
n = int(input())
list1 = list(map(int,input().split()))
import fractions as math
gcd = 10**9
for i in range(n-1):
    gcd = min(gcd,math.gcd(list1[i],list1[i+1]))
print(gcd)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
list1 = list(map(int,input().split()))
list1.sort()
list2 = []
for i in range(m-1):
	list2.append(list1[i+1]-list1[i])
list2.sort(reverse = True)
cut = 0
for j in range(n-1):
	cut+= list2[j]
print(max(list1)-min(list1)-cut)

Fixed submission:
n,m = map(int,input().split())
if n>=m:
  print(0)
  exit()
list1 = list(map(int,input().split()))
list1.sort()
list2 = []
for i in range(m-1):
	list2.append(list1[i+1]-list1[i])
list2.sort(reverse = True)
cut = 0
for j in range(n-1):
	cut+= list2[j]
print(max(list1)-min(list1)-cut)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
INF = 10**18
dp = [INF] * 100000
h = list(map(int, input().split()))
dp[0] = 0
for i in range(n):
    for j in range(1,k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i]-h[i+j]))
print(dp[n-1])

Fixed submission:
n,k = map(int,input().split())
list1 = list(map(int,input().split()))
dp = [10**9]*n
dp[0] = 0

for i in range(1,n):
    for j in range(1,k+1):
        if i - j < 0:
            break
        dp[i] = min(dp[i],dp[i-j]+abs(list1[i]-list1[i-j]))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
list1 = list(map(int,input().split()))
dp = [10**9]*n
dp[0] = 0

for i in range(1,n):
    for j in range(1,k+1):
        if i - j < 0:
            break
        dp[i] = min(dp[i],dp[i-j]+abs(list1[i]-list1[i-j]))

print(dp[-1])

Fixed submission:
n,k = map(int,input().split())
list1 = list(map(int,input().split()))
dp = [10**9]*n
dp[0] = 0

for i in range(1,n):
    for j in range(1,k+1):
        if i - j < 0:
            break
        dp[i] = min(dp[i],dp[i-j]+abs(list1[i]-list1[i-j]))

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
list1 = [list(int(input())) for i in range(n) ]
list1.sort(reverse = True)
print(list1[0]//2+sum(list1[1:]))

Fixed submission:
n = int(input())
list1 = [int(input()) for i in range(n) ]
list1.sort(reverse = True)
print(list1[0]//2+sum(list1[1:]))
Buggy python submission (verdict: Runtime Error):
#Tenka1 Programmer Beginner Contest-C Align
"""
リストを並び替えて隣り合う要素の差の最大を出力
"""
import sys
from collections import deque
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = []
for i in range(n):
    lst1.append(int(readline()))

d = deque()

lst1.sort()
lst2 = lst1[:n//2] #小さい方
lst1 = lst1[n//2:] #大きい方
large = deque(lst1)
small = deque(lst2)
#2又に分かれるまで手動
res1 = large.pop()
res2 = small.popleft()
def func(x):
    global res1,res2
    if abs(res1-x) > abs(res2-x):
        res = abs(res1-x)
        res1 = x
        return res
    else:
        res = abs(res2-x)
        res2 = x
        return res

ans = res1-res2
ans += func(small.popleft())
while True:
    if not len(large):
        pass
    else:
        ans += func(large.pop())
    if not len(large):
        pass
    else:
        ans += func(large.pop())
    if not len(small):
        pass
    else:
        ans += func(small.popleft())
    if not len(small):
        pass
    else:
        ans += func(small.popleft())
    if not (len(large) or len(small)):
        print(ans)
        exit()


Fixed submission:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
lst1 = []
for i in range(n):
    lst1.append(int(readline()))
lst1.sort(reverse=True)
if n % 2 == 1:
    minority = n//2
    majority = n - minority
    A = sum(lst1[:minority])*2 - sum(lst1[minority:])*2+sum(lst1[minority:minority+2])
    B = sum(lst1[:majority])*2 - sum(lst1[majority:])*2 - sum(lst1[majority-2:majority])
    ans = max(A, B)
else:
    C = sum(lst1[:n//2])*2 - sum(lst1[n//2:])*2 + lst1[n//2]-lst1[n//2-1]
    D = -C
    ans = max(C, D)
print(ans)
Buggy python submission (verdict: Runtime Error):
import bisect
n,k = map(int,input().split())
x = list(map(int,input().split()))
bindex = bisect.bisect_left(x,0)
mainasu = x[:bindex+1]

listr = []
for i in range(len(x)):
  if i == 0:
    listr.append(x[i])
    continue
  listr.append(listr[-1]+x[i])
ans = 10**9
for i in range(n-k+1):
  ans = min(ans,listr[i+k]-listr[i])

print(ans)

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

print(n-i+1)

Buggy python submission (verdict: Runtime Error):
n = int(input())
i = int(input())

print(n-1+1)

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

print(n-i+1)