Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def main():
    x, y, a, b, c = map(int, input().split())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    R = list(map(int, input().split()))
    t = [1]
    t.sort()
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)

    s = P[:x] + Q[:y]
    s.sort()
    for i in range(x + y):
        if s[i] < R[i] and i < c:
            s[i] = R[i]
        else:
            break
    print(sum(s))

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    x, y, a, b, c = map(int, input().split())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    R = list(map(int, input().split()))
    t = [1]
    t.sort()
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)

    s = P[:x] + Q[:y]
    s.sort()
    for i in range(x + y):
        if i < c:
            if s[i] < R[i]:
                s[i] = R[i]
            else:
                break
        else:
            break
    print(sum(s))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    x, y, a, b, c = map(int, input().split())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    R = list(map(int, input().split()))
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)

    s = P[:x] + Q[:y]
    s.sort()
    for i in range(x + y):
        if s[i] < R[i]:
            s[i] = R[i]
        else:
            break
    print(sum(s))

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    x, y, a, b, c = map(int, input().split())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    R = list(map(int, input().split()))
    t = [1]
    t.sort()
    P.sort(reverse=True)
    Q.sort(reverse=True)
    R.sort(reverse=True)

    s = P[:x] + Q[:y]
    s.sort()
    for i in range(x + y):
        if i < c:
            if s[i] < R[i]:
                s[i] = R[i]
            else:
                break
        else:
            break
    print(sum(s))


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
l = int(input())
a = l/3
print(round(a**3,13))

Fixed submission:
n,m = map(int,input().split())
ans = n*(n-1)//2 + m*(m-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
from copy import deepcopy

n = int(input())
a = list(map(int,input().split()))
for i in range(n):
  copy_a = deepcopy(a)
  copy_a.pop(i)
  cnt = Counter(copy_a)
  ans = 0
  for _,c in cnt.items():
    if c >= 2:
      ans += c*(c-1)//2
  print(ans)



Fixed submission:
from collections import Counter

n = int(input())
a = list(map(int,input().split()))
cnt = dict(Counter(a))
ans = 0
for _,c in cnt.items():
  if c >= 2:
    ans += c*(c-1)//2
    
for i in range(n):
  pop_i = a[i]
  # n(n-1)/2 - (n-1)(n-2)/2 = n-1
  dif = cnt[pop_i]-1
  print(ans-dif)
Buggy python submission (verdict: Time Limit Exceeded):

n, a, b = map(int, input().split())
l = []
while len(l) <= n:
    for _ in range(a):
    	l.append("b")
    for _ in range(b):
        l.append("r")

print(l[:n].count("b"))


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

l = a + b
set_cnt = n // l
rest = n % l
if rest >= a:
    ans = set_cnt * a + a
else:
    ans = set_cnt * a + rest

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
q = int(input())
ans = deque(s)
for _ in range(q):
    inp = readline().rstrip()
    if inp[0] == "2":
        if inp[2] == "1":
            ans.appendleft(inp[4])
        else:
            ans.append(inp[4])
    else:
        ans = deque(list(ans)[::-1])

print("".join(ans))


Fixed submission:
import sys
from collections import deque
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
q = int(input())
ans = deque(s)
cnt = 0
for _ in range(q):
    inp = readline().rstrip()
    if inp[0] == "2":
        if inp[2] == "1":
            if cnt % 2 == 0:
                ans.appendleft(inp[4])
            else:
                ans.append(inp[4])
        else:
            if cnt % 2 == 1:
                ans.appendleft(inp[4])
            else:
                ans.append(inp[4])
    else:
        cnt += 1

if cnt % 2 == 1:
    ans = list(ans)[::-1]
    
print("".join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, k = map(int, input().split())
P = np.array(list(map(int, input().split())))
M = 0
for i in range(n - k + 1):
    M = max(M,P[i:i + k].sum())

ans = (M + k) / 2
print(ans)


Fixed submission:
import numpy as np
n, k = map(int, input().split())
P = np.array([0] + list(map(int, input().split())))
C = np.cumsum(P)
#print(C)
M = 0
for i in range(n - k + 1):
    #print(C[i + k],C[i])
    M = max(M, C[i + k] - C[i])

ans = (M + k) / 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n, k = map(int, input().split())
P = np.array(list(map(int, input().split())))
A = np.array([])
for i in range(n - k + 1):
    A = np.append(A,P[i:i + k].sum())

M = np.max(A)
ans = (M + k) / 2
print(ans)


Fixed submission:
import numpy as np
n, k = map(int, input().split())
P = np.array([0] + list(map(int, input().split())))
C = np.cumsum(P)
#print(C)
M = 0
for i in range(n - k + 1):
    #print(C[i + k],C[i])
    M = max(M, C[i + k] - C[i])

ans = (M + k) / 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
P = list(map(int, input().split()))
A = []
for i in range(n - k + 1):
    A.append(sum(P[i:i + k]))

M = max(A)
ans = (M + k) / 2
print(ans)


Fixed submission:
import numpy as np
n, k = map(int, input().split())
P = np.array([0] + list(map(int, input().split())))
C = np.cumsum(P)
#print(C)
M = 0
for i in range(n - k + 1):
    #print(C[i + k],C[i])
    M = max(M, C[i + k] - C[i])

ans = (M + k) / 2
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
import collections

n = int(input())
d = list(map(int,input().split()))
MOD = 998244353
  
#同じ長さの位置に何個頂点があるか
cnt = dict(collections.Counter(d))
#print(cnt)
try:
  if cnt[0]!=0:
    ans = 1
    for i in range(len(dict(cnt))-1):
      val_1 = cnt[i]
      val_2 = cnt[i+1]
      ans *= (val_1**val_2)%MOD

    print(ans%MOD)
except KeyError:
  print(0)
  


Fixed submission:
n = int(input())
if n % 2 == 0:
  print(n//2-1)
else:  
  print(n//2)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
half = math.floor(n**0.5)
#print(half)

for i in range(half+1,0,-1):
  if n % i == 0 and 1 <=n/i<=9 :
    num1,num2 = i,n//i  
    #print("Yes")
    break

if not num1:
  print(n-1)
else:
  print(num1+num2-2)
    

Fixed submission:
import math
n = int(input())
half = math.floor(n**0.5)
#print(half)

num1 = 0
for i in range(half+1,0,-1):
  if n % i == 0:
    num1,num2 = i,n//i  
    #print("Yes")
    break

if num1 == 0:
  print(n-1)
else:
  print(num1+num2-2)

Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
half = math.floor(n**0.5)
#print(half)

for i in range(half+1,0,-1):
  if n % i == 0 and 1 <=n/i<=9 :
    num1,num2 = i,n//i  
    #print("Yes")
    break

print(num1+num2-2)
    

Fixed submission:
import math
n = int(input())
half = math.floor(n**0.5)
#print(half)

num1 = 0
for i in range(half+1,0,-1):
  if n % i == 0:
    num1,num2 = i,n//i  
    #print("Yes")
    break

if num1 == 0:
  print(n-1)
else:
  print(num1+num2-2)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n = int(input())
  l = list(map(int,input().split()))
  cnt = 0
  for i in range(n):
    for j in range(i+1,n):
      for k in range(j+1,n):
        if l[i]<l[j]+l[k] and l[j]<l[k]+l[i] and l[k]<l[i]+l[j]:
          cnt += 1
  print(cnt)

if __name__ == '__main__':
    main()

Fixed submission:
def solve(string):
    n, *l = map(int, string.split())
    l.sort(reverse=True)
    nums = 0
    for i, a in enumerate(l[:-2]):
        j, k = i + 1, n - 1
        while (j < k):
            if (a < l[j] + l[k]):
                nums += k - j
                j += 1
            else:
                k -= 1
    return str(nums)
 
 
if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))
Buggy python submission (verdict: Time Limit Exceeded):
#ソートしてでかいやつから割引券使っていって、次に値段が高いやつよりも値段が低くなれば次にいく。
#これを繰り返せばいい。
#一周してもまだ割引券が余っていればもう一度ソートして同じことをする。
#途中で割引券がなくなれば終了して、合計を計算する。
#実際に買い物をする順番は気にしなくていい。どこで何枚使うのが最適かが分かればいい
#ということは割引券を使うたび毎回ソートする？

n,m = map(int,input().split())
A = list(map(int,input().split()))
#print(A)
A.sort(reverse=True)

while m!=0:
  M_A = max(A)
  A[0] = M_A //2
  m -= 1
  A.sort(reverse=True)
  
print(sum(A))  
  
  



Fixed submission:
#ソートしてでかいやつから割引券使っていって、次に値段が高いやつよりも値段が低くなれば次にいく。
#これを繰り返せばいい。
#一周してもまだ割引券が余っていればもう一度ソートして同じことをする。
#途中で割引券がなくなれば終了して、合計を計算する。
#実際に買い物をする順番は気にしなくていい。どこで何枚使うのが最適かが分かればいい
#ということは割引券を使うたび毎回ソートする？
#毎回ソートしてるとやっぱりTLEになる。次に値段が高いやつよりも値段が低くなれば次にいく。でいい

#n,m = map(int,input().split())
#A = list(map(int,input().split()))
#print(A)
#A.sort(reverse=True)
#while m!=0:
#  while A[0] > A[1]:
 #   M_A = max(A)
  #  A[0] = M_A //2
   # m -= 1
  #A.sort(reverse=True)
#print(sum(A))

n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
  a[i]=a[i]*(-1)
  
import heapq
#小さい順に並べる
heapq.heapify(a)
for j in range(m):
  # 最小値を取り出して-1をかけ,bとする。
  b=heapq.heappop(a)*(-1)
  # b//2に-1をかけて,aに入れる。
  heapq.heappush(a,(b//2)*(-1))
  #print(a)
c=sum(a)
print(c*(-1))
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
if b == 1:
  print(0)
  exit()
  
cnt = 0  
for i in range(1,a+1):
  cnt = (a-1)*(i-1)+a
  if cnt>=b:
    ans = i
    break
print(ans)    
  


Fixed submission:
a,b = map(int,input().split())
if b == 1:
  print(0)
  exit()
  
cnt = 0  
for i in range(1,100):
  cnt = (a-1)*(i-1)+a
  if cnt>=b:
    ans = i
    break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0
for i in range(n-1,0,-1):
  ans += i%(i+1)
print(ans)  
     
  
  


Fixed submission:
n = int(input())
ans = (n-1)*n//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
cnt = 0
A = []
lists = []
for i in range(n):
  lists += [input()]
  a = []
  for x in lists[i]:
    a += [x]
  a.sort()  
  lists[i] = a
     
for j in range(n-1):
  for k in range(j+1,n):
    if lists[j] == lists[k]:
      cnt += 1
print(cnt)   

Fixed submission:
import collections

n = int(input())
def sort_string(st):
  res = list(st)
  res.sort()
  return "".join(res)

s = [sort_string(input()) for _ in range(n)]
c = collections.Counter(s)
ans = 0
for n in c.values():
  ans += n*(n-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lists = [input() for i in range(n)]
cnt = 0
for i in range(n-1):
  for j in range(i+1,n):
    a = lists[i]
    b = lists[j]
    c = []
    d = []
    for x in a:
      c += [x]
    for y in b:
      d += [y]
    c.sort()
    d.sort()
    if c == d:
      cnt += 1
print(cnt)      

Fixed submission:
import collections

n = int(input())
def sort_string(st):
  res = list(st)
  res.sort()
  return "".join(res)

s = [sort_string(input()) for _ in range(n)]
c = collections.Counter(s)
ans = 0
for n in c.values():
  ans += n*(n-1)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
x = a + b
y = a-b
z = a* b
print(max(x,y,z))

Fixed submission:
a,b,c = map(int,input().split())
ans = c - a + b
if  ans < 0:
  print(0)
else:
  print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
h = list(map(int,input().split()))
d = [0]*(n-1)
cmd = [0]*(n-1)

for i in range(n-1):
  d[i]= h[i+1]-h[i]

m = 0
 
if n==1:
  print("Yes")
  sys.exit()
  
elif min(d) <= -2:
  print("No")
  sys.exit()

else:
  for i in range(n-1):
    if h[i] == h[i+1]:
      cmd[i] == 0
    elif h[i]+1 == h[i+1] and cmd[i]==1:
      print("No")
      sys.exit()
    elif h[i]+1 == h[i+1] and cmd[i]==0:
      cmd[i+1] == 1  
  print("Yes")      
      
  
     

Fixed submission:
import sys
n = int(input())
h = list(map(int,input().split()))
mi = h[0]-1
if n == 1:
  print("Yes")
  sys.exit()
  
for i in range(1,n):
  if h[i-1]-1 == h[i]:
    if mi > h[i]:
      print("No")
      sys.exit()
    mi = h[i]
  elif h[i-1] > h[i]:
    print("No")
    sys.exit()
    
print("Yes")

Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
h = list(map(int,input().split()))
d = [0]*(n-1)

for i in range(n-1):
  d[i]= h[i+1]-h[i]

sd = sorted(d)
if min(sd) <= -2:
  print("No")
  sys.exit()
  
elif -1 in d:
  indexes = [i for i, x in enumerate(d) if x == -1]
  for j in range(len(indexes)-1):
    if d[j+1] != 0:
      print("No")
      sys.exit()

print("Yes")
  

Fixed submission:
import sys
n = int(input())
h = list(map(int,input().split()))
mi = h[0]-1
if n == 1:
  print("Yes")
  sys.exit()
  
for i in range(1,n):
  if h[i-1]-1 == h[i]:
    if mi > h[i]:
      print("No")
      sys.exit()
    mi = h[i]
  elif h[i-1] > h[i]:
    print("No")
    sys.exit()
    
print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d = map(int,input().split())
cnt = 0
for i in range(a,b+1):
  if i%c != 0 and i%d !=0:
    cnt+=1
print(cnt)    
    

Fixed submission:
a,b,c,d = map(int,input().split())
def gcd(x, y):
	while y:
		x, y = y, x % y
	return x

def lcm(x, y):
  return x * y // gcd (x, y)  

def cal(n):
  if a%n ==0 and b%n ==0:
    return b//n - a//n + 1
  else:
    return b//n - a//n
    
cd = lcm(c, d)
ans = (b-a+1) - (b//c - (a-1)//c) - (b//d - (a-1)//d) + (b//cd - (a-1)//cd)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,M= map(int,input().split())
LRlis = [list(map(int, input().split())) for i in range(M)]
A = list(range(LRlis[0][0],LRlis[0][1]+1))
for i in range(M):
  B = list(range(LRlis[i][0],LRlis[i][1]+1))
  C = list(set(A) & set(B))

print(len(C))

Fixed submission:
N,M= map(int,input().split())
LRlis = [list(map(int, input().split())) for i in range(M)]
maxL = 0
minR = 10**5
for i in range(M):
  maxL = max(LRlis[i][0],maxL)
  minR = min(LRlis[i][1],minR)

ans = minR-maxL    
if ans>=0:
  print(ans+1)
else:
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
a = list(map(int, input().split()))
bc = [tuple(map(int, input().split())) for _ in range(M)]
bc.sort(key=lambda x: x[1], reverse=True)
for b, c in bc:
  a += [c] * b
a.sort(reverse=True)
print(sum(a[:N]))

Fixed submission:
N, M = map(int, input().split())
a = list(map(int, input().split()))
bc = [tuple(map(int, input().split())) for _ in range(M)]
bc.sort(key=lambda x: -x[1])
rest = N
for b, c in bc:
  a += [c] * min(rest, b)
  rest -= min(rest, b)
a.sort(reverse=True)
print(sum(a[:N]))

Buggy python submission (verdict: Time Limit Exceeded):
N,M= map(int,input().split())
A = list(map(int,input().split()))
A.sort()
BClis = [list(map(int, input().split())) for i in range(M)]
m = 0 
for i in range(M):
  A.sort()
  for j in range(BClis[i][0]):
    if  A[j] < BClis[i][1]:
      A[j] = BClis[i][1]
print(sum(A))

Fixed submission:
N, M = map(int, input().split())
a = list(map(int, input().split()))
bc = [tuple(map(int, input().split())) for _ in range(M)]
bc.sort(key=lambda x: -x[1])
rest = N
for b, c in bc:
  a += [c] * min(rest, b)
  rest -= min(rest, b)
a.sort(reverse=True)
print(sum(a[:N]))
Buggy python submission (verdict: Runtime Error):
import math
N,K = map(int, input().split())
#出た目をｎとすると、n>=K以上が最初に出れば勝ち
#1からK-1のときで負ける確率を考える
ans=0
S=[]
for i in range(1,K):
  x = math.log(K/i,2)
  for j in range(17):
    if j >= x:
      S.append(j)
    ans+=1-(1/2)**S[0]
 
win_rate = 1-ans
print(win_rate)
  

Fixed submission:
import math
N,K = map(int, input().split())
x=0
ans=0
for i in range(1,N+1):
  if i >=K:
    ans += 1
  else: 
    j = math.log(K/i,2)
    x = math.ceil(j)
    ans += (0.5)**x
   
win_rate = ans/N 
print(win_rate)
Buggy python submission (verdict: Runtime Error):
R,G,B,N = map(int,input().split())
for r in range(N+1):
  for g in range(N+1):
    n=N-R*r-G*g
    if n>=0 and n%B==0:
      b=int(n/B)
      print(r,g,b) 

Fixed submission:
N,K = map(int,input().split())
print(N-K+1)

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

Fixed submission:
N,K = map(int,input().split())
print(N-K+1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

h, w = map(int, input().split())
M = []
q = []
for i in range(h):
    line = input().strip()
    M.append(list(line))
    for j in range(w):
        if line[j] == "#":
            M[i][j] = 0
            q.append((j, i))

dir = [[1, 0], [-1, 0], [0, 1], [0, -1]]
cnt = 0
while q:
    next_q = []
    cnt += 1
    for x, y in q:
        for dx,dy in dir:
            next_x, next_y = x + dx, y + dy
            if 0 <= next_y <= h - 1 and 0 <= next_x <= w - 1:
                if M[next_y][next_x] == ".":
                    M[next_y][next_x] = M[y][x] + 1
                    q.append((next_x, next_y))
    q = next_q

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, M[i][j])
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

h, w = map(int, input().split())
M = []
q = []
for i in range(h):
    line = input().strip()
    M.append(list(line))
    for j in range(w):
        if line[j] == "#":
            M[i][j] = 0
            q.append((j, i))

dir = [[1, 0], [-1, 0], [0, 1], [0, -1]]
cnt = 0
while q:
    next_q = []
    cnt += 1
    for x, y in q:
        for dx,dy in dir:
            next_x, next_y = x + dx, y + dy
            if 0 <= next_y <= h - 1 and 0 <= next_x <= w - 1:
                if M[next_y][next_x] == ".":
                    M[next_y][next_x] = M[y][x] + 1
                    q.append((next_x, next_y))
    q = next_q

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, M[i][j])
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))

cnt = 0
for i in range(N):
  if V[i]-C[i] >0:
    cnt += V[i]-C[i]
print(cnt)    

Fixed submission:
A,B,T = map(int,input().split())
cnt = 0
n = A
while n <= T:
  n += A 
  cnt += B
print(cnt)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
ans = 0

#最大公約数を求めるfunction
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a  

def gcd_list(list,N):
  a = list[0]
  for i in range(1, N):
      b = gcd(a, list[i])
  return b

for i in range(N):
  newA = copy.copy(A)
  if i != N-1:
    newA[i] = newA[i+1]
  else:
    newA[i] = newA[i-1]
  ans = max(gcd_list(newA,N),ans)
print(ans)  

Fixed submission:
from fractions import gcd
 
n = int(input())
a = list(map(int, input().split()))
 
rs, ls = [0], [0]
for i in range(n-1):
  rs.append(gcd(rs[i], a[i]))
  ls.append(gcd(ls[i], a[-i-1]))
 
print(max(gcd(r, l) for r, l in zip(rs, ls[::-1])))
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input())
m = max(a,b)
m1 = m*2-1
m2 = a+b
ans = max(m1,m2)
print(ans)

Fixed submission:
a,b = map(int,input().split())
m = max(a,b)
m1 = m*2-1
m2 = a+b
ans = max(m1,m2)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = [int(input()) for i in range(6)]
n = s[0]
#a,b,c,d,e = s[1],s[2],s[3],s[4],s[5]
dp = [n]+[0]*5
cnt = 0
while dp[-1] < n:
  for i in reversed(range(1,6)):
    if dp[i-1] <= s[i]:
      dp[i] += dp[i-1]
      dp[i-1] = 0
    else:
      dp[i] += s[i]
      dp[i-1] -= s[i]
  cnt += 1

print(cnt)

Fixed submission:
import math
n = int(input())
s = [int(input()) for i in range(5)]
m = min(s)
ans = 4 + math.ceil(n/m)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]+[None]*(N-1) 
for i in range(1,N):
  dp[i] = min(dp[j] + abs(h[i]-h[j]) for j in range(max(i-K,0),i)) 
print(dp[-1])


Fixed submission:
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]+[None]*(N-1) 
def func(N,K,h,dp):
  for i in range(1,N):
    dp[i] = min(dp[j] + abs(h[i]-h[j]) for j in range(max(i-K,0),i)) 

func(N,K,h,dp)
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*N 
for i,hi in enumerate(h):
  if i==0:continue;
  dp[i] += min(dp[j] + abs(hi-h[j]) for j in range(max(i-K,0),i)) 
print(dp[-1])


Fixed submission:
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]+[None]*(N-1) 
def func(N,K,h,dp):
  for i in range(1,N):
    dp[i] = min(dp[j] + abs(h[i]-h[j]) for j in range(max(i-K,0),i)) 

func(N,K,h,dp)
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*N 
for i in range(N):
  if i==0:continue;
  dp[i] = min(dp[j] + abs(h[i]-h[j]) for j in range(max(i-K,0),i)) 
print(dp[N-1])


Fixed submission:
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]+[None]*(N-1) 
def func(N,K,h,dp):
  for i in range(1,N):
    dp[i] = min(dp[j] + abs(h[i]-h[j]) for j in range(max(i-K,0),i)) 

func(N,K,h,dp)
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
  b.append(a[i]-i-1)
  
b.sort()

center = n//2
c1 = b[center]
c2 = b[center+1]

ans1 = 0
ans2 = 0
for i in range(n):
  ans1 += abs(b[i]-c1)
  ans2 += abs(b[i]-c2)
print(min(ans1,ans2))

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

center = n//2
c1 = b[center]

ans = 0
for i in range(n):
  ans += abs(b[i]-c1)
print(ans)
Buggy python submission (verdict: Runtime Error):
import collections
n = int(input())
s = input()
dic = dict(collections.Counter(s))
left_w = 0
right_e = dic["E"]
cnt = [[] for _ in range(n)]
#(左あるWの数+右にあるEの数)の最小値が答え
ans = n
for i in range(n):
  if s[i] == "W":
    #cnt[i] = [left_w,right_e]
    ans = min(ans,left_w+right_e)
    left_w += 1
  elif s[i] == "E":
    #cnt[i] = [left_w,right_e]
    ans = min(ans,left_w+right_e)
    right_e -= 1
  
print(ans)



Fixed submission:
import collections
n = int(input())
s = input()
dic = dict(collections.Counter(s))
#W,Eどちらかしか無い場合
if len(dic)==1:
  print(0)
  exit()
left_w = 0
right_e = dic["E"]
cnt = [[] for _ in range(n)]
#(左にあるWの数+右にあるEの数)の最小値が答え


ans = n
for i in range(n):
  if s[i] == "W":
    cnt[i] = [left_w,right_e]
    ans = min(ans,left_w+right_e)
    left_w += 1
  elif s[i] == "E":
    cnt[i] = [left_w,right_e]
    ans = min(ans,left_w+right_e)
    right_e -= 1

#(右にあるWの数+左にあるEの数)の最小値が答えの場合もあるか
left_e = 0
right_w = dic["W"]

for i in range(n-1,-1,-1):
  if s[i] == "E":
    ans = min(ans,left_e+right_w)
    left_e += 1
  elif s[i] == "W":
    ans = min(ans,left_e + right_w)
    right_w -= 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
n = int(input())
x=list(map(int,input().split()))
for i in range(n):
  l=copy.copy(x)
  l.pop(i)
  l.sort()
  print(l[n//2-1])
  

Fixed submission:
import copy
n = int(input())
x=list(map(int,input().split()))
l=copy.copy(x)
l.sort()
n1 = l[n//2-1]
n2 = l[n//2]
for i in range(n):
  if x[i]>n1:
    print(n1)
  else:
    print(n2)