Harryxun/stf_run huggingface dataset:
def draw(i):
    global p,q,hd,wd
    B[p][q] = i
    if (q < W-1 and hd != -1):
        hd = 1
        wd = 0
    elif (hd == 1 and q == W-1) or (hd == -1 and q == 0):
        hd = 0
        wd = 1
    else:
        hd = -1
        wd = 0
    p += wd
    q += hd

if __name__ == '__main__':
    p = 0
    q = 0
    hd = 1
    wd = 0
    H, W = list(map(int, input().split()))
    N = int(input())
    As = list(map(int, input().split()))
    B = [[0 for i in range(W)] for j in range(H)]

    for i in range(N):
        for j in range(As[i]):
            draw(i+1)

    for i in range(H):
        s = list(map(str, B[i]))
        print(' '.join(s))

### FIXED CODE ###


def draw(i):
    global p,q,hd,wd
    B[p][q] = i
    if (q < W-1 and hd != -1):
        hd = 1
        wd = 0
    elif (hd == 1 and q == W-1) or (hd == -1 and q == 0):
        hd = 0
        wd = 1
    elif (q > 0 and hd != 1):
        hd = -1
        wd = 0
    p += wd
    q += hd

if __name__ == '__main__':
    p = 0
    q = 0
    hd = 1
    wd = 0
    H, W = list(map(int, input().split()))
    N = int(input())
    As = list(map(int, input().split()))
    B = [[0 for i in range(W)] for j in range(H)]

    for i in range(N):
        for j in range(As[i]):
            draw(i+1)

    for i in range(H):
        s = list(map(str, B[i]))
        print(' '.join(s))
strs = str(input())
arr1 = strs.split()
stone = int(arr1[0])
times = int(arr1[1])
arr1 = str(input())
arr1 = arr1.split()
arr = []
for i in arr1:
    arr.append(int(i))
cost = [9999999] * stone
cost[0] = 0
for i in range(stone):
    if i == (stone - 1):
        break
    if i == 0:
        for j in range(i+1 ,times + 1):
            if j >= stone:
                break
            kkt = arr[0] - arr[j]
            cost[j] = min(cost[j], abs(kkt))
    else:
        for j in range(i+1 ,i +1+ times):
            if j >= stone:
                break
            kkt = arr[i] - arr[j]
            tj = ( abs(kkt) + cost[i])
            #print(tj)
            cost[j] = min(cost[j], tj )
    #print(cost)
if cost[-1] == 9999999:
    print(0)
else:
    print(cost[-1])
        
        
        
        
        
        
        



### FIXED CODE ###

n = int(input())
arr1 = str( input() )
arr1 = arr1.split()
arr = []

for i in arr1:
    arr.append(int(i))

leng = len(arr)
dp = [99999999999] * leng 
dp[0] = 0 

for i in range(leng):
    if (i + 1) >= leng:
        continue 
    dp[i + 1] = min ( dp[i] + abs(arr[i] - arr[i + 1]), dp[i + 1] )
    
    if (i + 2) >= leng:
        continue 
    dp[i + 2] = min(  ( dp[i] + abs( arr[i] - arr[i + 2] ) , dp[i + 2]) )

print(dp[-1])
import numpy as np
P=998244353
N,K=map(int,input().split())
LR=[]
for _ in range(K):
  l,r=map(int,input().split())
  LR+=range(l,r+1)
LR=list(set(LR))
LR=np.array(LR)
c=[0]*N
c[0]=1
for k in range(N):
  S=list(LR[LR<=k])
  while len(S):
    c[k]+=c[k-S[-1]]%P
    S.pop()
print(c[-1]%P)

### FIXED CODE ###

a=input()
print(a+"s" if a[-1]!="s" else a+"es")
s=input()

def sigma(n):
  return n*(n+1)//2

total=0
cnt=0
while s[0]=='>':
  cnt+=1
  s=s[1:]
total+=sigma(cnt)
  
flag=True
while flag:
  l=[]
  if '>' in s:
    for i in range(s.find('>')):
      l.append(s[i])
    s=s[s.find('>'):]
  else:
    l.extend(['<']*len(s))
    s=''
    flag=False
  if '<' in s:
    for i in range(s.find('<')):
      l.append(s[i])
    s=s[s.find('<'):]
  else:
    l.extend(['>']*len(s))
    s=''
    flag=False
  if l.count('<')<=l.count('>'):
    total+=sigma(l.count('>'))+sigma(l.count('<')-1)
  else:
    total+=sigma(l.count('<'))+sigma(l.count('>')-1)

print(total)

### FIXED CODE ###

s=input()

def sigma(n):
  return n*(n+1)//2

total=0
if s[0]=='>':
  cnt=s.find('<')
  if cnt==-1:
    cnt=len(s)
    s=''
  else:
    s=s[cnt:]
  total+=sigma(cnt)
  
flag=True
while flag:
  l=[]
  index1=s.find('>')
  if index1!=-1:
    for i in range(index1):
      l.append(s[i])
    s=s[index1:]
  else:
    l.extend(['<']*len(s))
    s=''
    flag=False
  index2=s.find('<')
  if index2!=-1:
    for i in range(index2):
      l.append(s[i])
    s=s[index2:]
  else:
    l.extend(['>']*len(s))
    s=''
    flag=False
  cnt1=l.count('>')
  cnt2=l.count('<')
  if cnt2<=cnt1:
    total+=sigma(cnt1)+sigma(cnt2-1)
  else:
    total+=sigma(cnt2)+sigma(cnt1-1)

print(total)
import sys
from collections import defaultdict

sys.setrecursionlimit(4000)

n = int(input())
arr = map(int, input().split())
arr = tuple(sorted(enumerate(arr), key=lambda tpl: -tpl[1]))

dp = {}
def cal(ln, rn):
  if ln + rn > n:
    return

  if ln > 0 or rn > 0:
    idx = ln + rn - 1
    p, a = arr[idx]
    val_l = dp[ln - 1, rn] + a * abs(p - (ln - 1)) if ln > 0 else 0
    val_r = dp[ln, rn - 1] + a * abs(p - (n - rn)) if rn > 0 else 0

    dp[ln, rn] = max(val_l, val_r)
  else:
    dp[ln, rn] = 0

  cal(ln + 1, rn)
  cal(ln, rn + 1)

cal(0, 0)

print(max([dp[i, n - i] for i in range(n + 1)]))


### FIXED CODE ###


def main():

  n = int(input())
  arr = map(int, input().split())
  arr = tuple(sorted(enumerate(arr), key=lambda tpl: -tpl[1]))

  dp = [[0] * (n + 1) for _ in range(n + 1)]
  for i, (p, a) in enumerate(arr):
    for l in range(i + 1):
      dp[i + 1][l] = max(dp[i + 1][l], dp[i][l] + a * abs(p - (n - (i - l) - 1)))
      dp[i + 1][l + 1] = max(dp[i + 1][l + 1], dp[i][l] + a * abs(p - l))

  print(max(dp[n]))

main()
H, W = map(int, input().split())
Inf = 10**9

S = [input() for i in range(H)]
dis = [[Inf]*(H*W) for i in range(H*W)]

for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        if i - 1 >= 0 and S[i-1][j] != "#":
            dis[i*W+j][(i-1)*W+j] = 1
        if i + 1 < H and S[i+1][j] != "#":
            dis[i*W+j][(i+1)*W+j] = 1
        if j - 1 >= 0 and S[i][j-1] != "#":
            dis[i*W+j][i*W+j-1] = 1
        if j + 1 < H and S[i][j+1] != "#":
            dis[i*W+j][i*W+j+1] = 1

for i in range(H*W):
    for j in range(H*W):
        for k in range(H*W):
            dis[j][k] = min(dis[j][i] + dis[i][k], dis[j][k])

max_ans = -10**9
for i in range(H*W):
    for j in range(H*W):
        if dis[i][j] > max_ans and dis[i][j] != Inf:
            max_ans = dis[i][j]

print(max_ans)

### FIXED CODE ###

H, W = map(int, input().split())
Inf = 10**9

S = [input() for i in range(H)]
dis = [[Inf]*(H*W) for i in range(H*W)]

for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        if i - 1 >= 0 and S[i-1][j] == ".":
            dis[i*W+j][(i-1)*W+j] = 1
        if i + 1 < H and S[i+1][j] == ".":
            dis[i*W+j][(i+1)*W+j] = 1
        if j - 1 >= 0 and S[i][j-1] == ".":
            dis[i*W+j][i*W+j-1] = 1
        if j + 1 < W and S[i][j+1] == ".":
            dis[i*W+j][i*W+j+1] = 1

for i in range(H*W):
    for j in range(H*W):
        for k in range(H*W):
            dis[j][k] = min(dis[j][i] + dis[i][k], dis[j][k])

max_ans = 0
for i in range(H*W):
    for j in range(H*W):
        if i == j or dis[i][j] == Inf:
            continue        
        max_ans = max(dis[i][j], max_ans)

print(max_ans)
def localInp():
    import sys
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')

def find(s,t):
    if (len(s)==0 or len(t)==0):
        return ""
    if(s[0]==t[0]):
        if(len(s)==1 or len(t)==1):
            return s[0]
        return s[0]+find(s[1:],t[1:])
    x=y=""
    if(len(t)>1):
        x=find(s,t[1:])
    if(len(s)>1):
        y=find(s[1:],t)
    if(len(x)>len(y)):
        return x
    else:
        return y
def solve():
    s=input()
    t=input()
    ans=find(s,t)
    print(ans)

#solve()



localInp()
t=int(input())
for i in range(t):
    print("Case",i+1)
    solve()


### FIXED CODE ###

from subprocess import*
call(('pypy3','-c',"""
s=input()
t=input()
a=len(s)
b=len(t)
dp=[[0]*(b+1) for i in range(a+1)]
for i in range(a):
  for j in range(b):
    if s[i]==t[j]:
      dp[i+1][j+1]=dp[i][j]+1
    else:
      dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j])
res=''
while a!=0 and b!=0:
  if dp[a][b]==dp[a-1][b]:
    a-=1
  elif dp[a][b]==dp[a][b-1]:
    b-=1
  else:
    a-=1
    b-=1
    res=s[a]+res
print(res)
"""))
"""
from subprocess import*
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
# import numpy as np
starttime = time.time()
# import numpy as np
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

try:
    # sys.setrecursionlimit(int(pow(10,6)))
    # sys.stdin = open("input.txt", "r")
    # sys.stdout = open("../output.txt", "w")
except:
    pass

"""
a=int(input())
if a%2==0:
  print(a)
else:
  print(2a)

### FIXED CODE ###

a=int(input())
if a%2==0:
  print(a)
else:
  print(2*a)
import math

Num,HP = (map(int,input().split()))
Katanas = [list(map(int,input().split())) for x in range(Num)]

amax = max([x[0] for x in Katanas])
bpower = sorted([x[1] for x in Katanas if x[1] > amax],reverse=True)
while HP > 0:
    attake += 1
    HP -= bpower[0]
    bpower = bpower[1:]
else:
    attake += math.ceil(HP/amax)
print(attake)

### FIXED CODE ###

import math

Num,HP = (map(int,input().split()))
#Katanas = [list(map(int,input().split())) for _ in range(Num)]

CKatanaMax = 0
katanas = []

for _ in range(Num):
    a,b = map(int,input().split())
    CKatanaMax = max(CKatanaMax,a)
    katanas.append(b)

Tkatanas = sorted([x for x in katanas if x > CKatanaMax],reverse=True)

attake = 0
for Tkatana in Tkatanas:
    HP -= Tkatana
    attake += 1
    if HP <= 0:
        break
else:
    attake += math.ceil(HP/CKatanaMax)
print(attake)
class unionfind():
    def __init__(self, n):
        self.parents = [-1 for i in range(n)]
    
    def find(self, a):
        if self.parents[a] < 0:
            return a
        self.parents[a] = self.find(a)
        return self.parents[a]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if x < y:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self):
        return len(list(filter(lambda x: x < 0, self.parents))) - 1

n, m = map(int, input().split())
uf = unionfind(n)
for i in range(m):
    tmp = list(map(int, input().split()))
    uf.union(tmp[0] - 1, tmp[1] - 1)

print(uf.size())


### FIXED CODE ###

class unionfind():
    def __init__(self, n):
        self.parents = [-1 for i in range(n)]

    def find(self, a):
        if self.parents[a] < 0:
            return a
        self.parents[a] = self.find(self.parents[a])
        return self.parents[a]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if x < y:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self):
        return len(list(filter(lambda x: x < 0, self.parents))) - 1

n, m = map(int, input().split())
uf = unionfind(n)
for i in range(m):
    tmp = list(map(int, input().split()))
    uf.union(tmp[0] - 1, tmp[1] - 1)

print(uf.size())
n,h =map(int,input().split())
a,b = [0]*n,[0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split())
c = h//max(a) + [0,1][h%max(a)]
if sum(b) >= h:
    c0 = 0
    d = 0
    e = reversed(sorted(b))
    while d < h:
        d += e[i] 
        c0 += 1
        i += 1
    c = min(c,c0)
print(c)

### FIXED CODE ###

n,h =map(int,input().split())
a,b = [0]*n,[0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split())
A = max(a)
s = list()
for i in range(n):
    if b[i] > A:
        s.append(b[i])
s.sort()
s.reverse()
c = sum(s)
if c < h:
    print(len(s) + (h-c)//A + [1,0][(h-c)%A==0])
else:
    S = 0
    for i in range(len(s)):
        S += s[i]
        if S >= h:
            print(i+1)
            break
A=[list(map(int,input().split())) for i in range(3)]
n=int(input())
for i in range(n):
    b=int(input())
    for Row in range(3):
        for Col in range(3):
            if b==A[Row][Col]:
                A[Row][Col]=0  

print(A)

### FIXED CODE ###

n=int(input())
print(-(-n//2))
S = input()
if S.len('a') == 1 and S.len('b') == 1:
  print('Yes')
  exit()
print('No')

### FIXED CODE ###

S = input()
if S.count('a') == 1 and S.count('b') == 1:
  print('Yes')
  exit()
print('No')
lista=input().split
a=int(lista[0])
b=int(lista[1])
c=int(lista[2])
if a+b>=c:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

lista=input().split()
a=int(lista[0])
b=int(lista[1])
c=int(lista[2])
if a+b>=c:
  print('Yes')
else:
  print('No')
N = int(input())
list = [int(a) for a in input().split()]

A = sum(list)//N
sum = 0
sum_new = 0

for i in range(-100:100):
    for j in range(N):
        sum = sum + (list[j] - A) ** 2
        sum_new = sum_new + (list[j] - i) ** 2
        if(sum > sum_new):
            sum = sum_new
print(sum)


### FIXED CODE ###


N = int(input())
list = [int(a) for a in input().split()]

A = sum(list)//N
ans = 0

for k in range(N):
    ans = ans + (list[k] - A) ** 2

for i in range(-100,100):
    sum_new = 0
    for j in range(N):
        sum_new = sum_new + (list[j] - i) ** 2
    if(ans > sum_new):
        ans = sum_new

print(ans)
a,b=input().split()
a=int(a)
b=int(b)
a/b=d
d=int(d)
a%b=r
r=int(r)
a/b=f
f = float(f)
print(d,r,f)


### FIXED CODE ###

a,b = input().split()
a = int(a)
b = int(b)
d = a // b
r = a % b
f = a / b
print(d,r,"{:.5f}".format(f))
a,b=map(int,input().split())
s=[2*a-1,a+b,2*b-1]
print(s.max())

### FIXED CODE ###

a,b=map(int,input().split())
s=[2*a-1,a+b,2*b-1]
print(max(s))
import math
n = int(input()) 

def is_prime(n):
    if n == 1: return True

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

if(is_prime(n)):
    print(n)
else:
    while(is_prime(n) == False):
        n = n + 1
        is_prime(n)
    print(n)
        
    

### FIXED CODE ###

s = input().split()

print(s[1]+s[0])
A,B=map(int,input().split());print("YNeos"[all(A%3,B%3,(A+B)%3)::2])

### FIXED CODE ###

A,B=map(int,input().split());print("PIomspsoisbslieb l e"[all([A%3,B%3,(A+B)%3])::2])
N = int(input())
texts = []
for i in range(N):
    texts.append((input()))

import collections
counters = []
count = 0
for text in texts:
    text_list = list(text)
    text_list.sort()
    text = "".join(text_list) 
    c = collections.Counter(text)
    counters.append(c)



ccccc = []
anss = 0
for ccc in counters:
    ccc = str(ccc)
    ccccc.append(ccc)
    

dd = collections.Counter(ccccc)
for v in dd.values():
    ans = v * (v-1) / 2
    anss.append(ans)
    
print(int(sum(anss)))

### FIXED CODE ###

N = int(input())
texts = []
for i in range(N):
    texts.append((input()))

import collections
counters = []
count = 0
for text in texts:
    text_list = list(text)
    text_list.sort()
    text = "".join(text_list) 
    c = collections.Counter(text)
    counters.append(c)



ccccc = []
anss = []
for ccc in counters:
    ccc = str(ccc)
    ccccc.append(ccc)
    

dd = collections.Counter(ccccc)
for v in dd.values():
    ans = v * (v-1) / 2
    anss.append(ans)
    
print(int(sum(anss)))
s = str(input())
ACGT = {"A", "C", "G", "T"}

ans = 0
for i in range(len(s)):
    for j in range(i, len(s) + 1):
        k = s[i: j]
        for l in k:
            if l not in ACGT:
                break
        else:
            ans = max(ans, len(t))
print(ans)


### FIXED CODE ###

s = str(input())
ACGT = {"A", "C", "G", "T"}

ans = 0
for i in range(len(s)):
    for j in range(i, len(s) + 1):
        t = s[i: j]
        for k in t:
            if k not in ACGT:
                break
        else:
            ans = max(ans, len(t))
print(ans)
import sys
input = sys.stdin.buffer.readline

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations
from itertools import accumulate
from math import ceil, sqrt, pi

def LIS(arr):
    from bisect import bisect_left
    INF = 10 ** 15
    
    len_arr = len(arr)
    LIS = [INF for i in range(len_arr + 1)]
  
    for a in arr:
      LIS_i = bisect_left(LIS, a)
      LIS[LIS_i] = min(LIS[LIS_i], a)

    for i in range(len_arr + 1):
      if LIS[i] == INF:
        return i

MOD = 10 ** 9 + 7
INF = 10 ** 18

N = int(input())
A = [0] + list(map(int, input().split()))
UV = [list(map(int, input().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N + 1)]
for uv in UV:
    u, v = uv
    graph[u].append(v)
    graph[v].append(u)
#print(graph)

answer = [0] * (N + 1)
def dfs(prev, n, lst):
    answer[n] = LIS(lst)
    for g in graph[n]:
        if g != prev:
            dfs(n, g, lst + [A[g]])

dfs(-1, 1, [A[0]])

for a in answer[1:]:
    print(a)


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict
from itertools import combinations, permutations
from itertools import accumulate
from math import ceil, sqrt, pi

def LLL(a, ls):
    INF = 10 ** 15
    
    flag = 0
    prev = 0
    indx = 0
    ls_i = bisect_left(ls, a)
    if a < ls[ls_i]:
        flag = 1
        prev = ls[ls_i]
        indx = ls_i
    ls[ls_i] = min(ls[ls_i], a)

    ls_ii = bisect_left(ls, INF)
    return ls_ii, ls, flag, prev, indx

MOD = 10 ** 9 + 7
INF = 10 ** 18

N = int(input())
A = [0] + list(map(int, input().split()))
UV = [list(map(int, input().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N + 1)]
for uv in UV:
    u, v = uv
    graph[u].append(v)
    graph[v].append(u)
#print(graph)

INF = 10 ** 15

LIS = [INF for i in range(N + 2)]

answer = [0] * (N + 1)
def dfs(prev, n, LIS):
    answer[n], LIS, flag, prv, indx = LLL(A[n], LIS)
    #print(n, LIS, flag, prv, indx)
    for g in graph[n]:
        if g != prev:
            dfs(n, g, LIS)
    if flag:
        LIS[indx] = prv

dfs(-1, 1, LIS)

for a in answer[1:]:
    print(a)
#!/usr/bin/env python
# -*- coding: utf-8 -*-

N, M, K = map(int, input().split())
result = 0 # max
a_time = list(map(int, input().split()))
b_time = list(map(int, input().split()))

sum = 0

a_num = 0
for i in range(N):
    sum += a_time[i]
    a_num += 1
    if sum > K:
        sum -= a_time[i]
        a_num -= 1
        break
i = a_num
while i >= 0:
    sum -= a_time[i]
    for j in range(M):
        sum += b_time[j]
        if sum > K:
            sum -= b_time[j]
            break
    print('result={} i={} j={}'.format(result, i, j))
    if result < i + j:
        result = i + j
    i -= 1

print(result)


### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

N, M, K = map(int, input().split())
result = 0 # max
a_time = list(map(int, input().split()))
b_time = list(map(int, input().split()))

sum = 0

a_num = 0
for i in range(N):
    sum += a_time[i]
    a_num += 1
    if sum > K:
        sum -= a_time[i]
        a_num -= 1
        break
i = a_num
j = 0
while i >= 0:
    while sum < K and j < M:
        sum += b_time[j]
        j += 1
    if sum > K:
        j -= 1
        sum -= b_time[j]
    if result < i + j:
        result = i + j
    i -= 1
    sum -= a_time[i]

print(result)
import numpy as np

inp = list(map(input(), int))
inp = np.sort(inp)
print(inp[0]*10+np.sum(inp[1:])

### FIXED CODE ###

import numpy as np
 
inp = np.asarray(input().split(), dtype=int)
inp = np.sort(inp)
print(np.sum(inp)+inp[2]*9)
import sys
sys.setrecursionlimit(400000000)
def main():
    n,k=map(int,input().split())
    h=tuple(map(int,input().split()))
    flog=[-1]*n
    #初期値は0
    def Num(dest,flog,h):
        q=dest-1
        if flog[q]>0:
            return flog[q]
        if dest<k+2:
            res=abs(h[q]-h[0])
            flog[q]=res
            return res
        
        min=Num(q)+abs(h[q]-h[q-1])
        for i in range(2,k+1):
            tmp=Num(dest-i,flog,h)+abs(h[q]-h[q-i])
            if min>tmp:
                min=tmp
        flog[q]=min
        return min   
    print(Num(n,flog,h))
if __name__=="__main__":
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(400000000)
def main():
    n,k=map(int,input().split())
    h=tuple(map(int,input().split()))
    flog=[-1]*n
    for i in range(n):#dest=i 0が１
        if i<k+1:#0~k
            flog[i]=abs(h[i]-h[0])
        else:
            min=10**9
            for j in range(1,k+1):#1~k
                tmp=flog[i-j]+abs(h[i]-h[i-j])
                if tmp<min:
                    min=tmp
            flog[i]=min
    print(flog[n-1])
   # print(flog)
if __name__=="__main__":
    main()
k, n = map(int, input().split())
A=[]
for i in range(n):
  A.append(int(input()))
B=[]
for i in range(n-1):
  B.append(A[i+1]-A[i])
B.append(k-A[n-1]+A[0])
print(k-max(B))

### FIXED CODE ###

k, n = map(int, input().split())
A=list(map(int, input().split()))
B=[]
for i in range(n-1):
  B.append(A[i+1]-A[i])
B.append(k-A[n-1]+A[0])
print(k-max(B))
s = input()

cnt = 0

while '01' in s or '10' in s:
    if '01' in s:
        s = s.replace('01','', 1)
        print(s,cnt)
        cnt += 1
        continue
    if '10' in s:
        s = s.replace('10','', 1)
        print(s,cnt)
        cnt += 1
        continue

print(cnt*2)


### FIXED CODE ###

s = input()
leng = len(s)
zero = s.count('0')
one = s.count('1')
print(2*min(zero, one))
import sys;

def init(n_):
    length = 1;
    while(length < n_):
        length*=2
    length2 = (2*length-1)
    if(length2 == 0):
        length2 = 1
    element=[0]*length2
    for i in range(length2):
        element[i] = 0
    return element,length

def update(k,a,element):
    k+=n-1
    if(n == 1):
        k = 0
    element[k]+=a
    while(k > 0):
        k = (int)((k-1)/2)
        element[k] = element[k*2+1]+element[k*2+2]

def findmin(a, b):
    return findquery(a,b+1,0,0,n)

def findquery(a, b, k, l, r):
    if(r <= a or b <= l):
        return 0
    if(a <= l and r <= b):
        return element[k]

    vl = findquery(a,b,k*2+1,l,(int)((l+r)/2+0.5))
    vr = findquery(a,b,k*2+2,(int)((l+r)/2),r)
    return vl+vr

n,q = map(int, input().split());

element,n = init(n)

for i in range(q):
    query,key,value = map(int, input().split());
    if(query == 0):
        update(key,value,element)
    else :
        if(n==1):
            key = 0
        print(findmin(key,value))


### FIXED CODE ###

import sys;

def init(n_):
    length = 1;
    while(length < n_):
        length*=2
    element = [0]*(2*length-1)
    for i in range(2*length-1):
        element[i] = 0
    return element,length

def update(k,a,element):
    k+=n-1
    element[k]+=a
    while(k > 0):
        k = (int)((k-1)/2)
        element[k] = element[k*2+1]+element[k*2+2]

def findmin(a, b):
    return findquery(a,b+1,0,0,n)

def findquery(a, b, k, l, r):
    if(r <= a or b <= l):
        return 0
    if(a <= l and r <= b):
        return element[k]

    vl = findquery(a,b,k*2+1,l,(int)((l+r)/2+0.5))
    vr = findquery(a,b,k*2+2,(int)((l+r)/2),r)
    return vl+vr

n,q = map(int, input().split());

element,n = init(n)

for i in range(q):
    query,key,value = map(int, input().split());
    if(query == 0):
        update(key-1,value,element)
    else :
        print(findmin(key-1,value-1))
# -*- coding: utf-8 -*-
s = list(input())
res = "AKIHABARA"

si = 0
ri = 0
while si<len(s):
    if s[si]==res[ri]:
        si += 1
        ri += 1
    elif res[ri]=="A" and s[si]!="A":
        ri += 1
    else:
        print("NO")
        exit()
print("YES")


### FIXED CODE ###

# -*- coding: utf-8 -*-
s = input()

for s1 in ["A",""]:
    for s2 in ["A",""]:
        for s3 in ["A",""]:
            for s4 in ["A",""]:
                if s==(s1+"KIH"+s2+"B"+s3+"R"+s4):
                    print("YES")
                    exit()
print("NO")