Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import numpy as np
N = int(input())
H = list(map(int, input().split()))

fl = True
for i in range(1,N):
    if H[i]-H[i-1]<0:
        H[i-1] -= 1
        tmp = np.array(H[i:])
        if all(x-1<H[i-1] for x in tmp):
            fl = False
            break
print('Yes') if fl else print('No')

### FIXED CODE ###

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

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

for i in range(1,N):
    if H[i]-H[i-1]<0:
        fl = False
        break

print('Yes') if fl else print('No')
### BUGGY CODE ###

import numpy as np
import heapq

INF=10**12
def daik(s,g,d,adj):
    used=np.array([])
    heap=[]
    table=np.array([INF for i in range(N)])
    table[s]=0
    heapq.heappush(heap,(table[s],s))
    used=np.append(used,s)
                
    while heap and not(g in used):
        q=heapq.heappop(heap)
        a=q[1]
        used=np.append(used,a)
        for i in adj[a]:
            if not(i in used):
                table[i]=min(table[i],table[a]+d[a,i] )
                heapq.heappush(heap,(table[i],i))
    return table[g]

N,M=map(int,input().split())
LRC=[]
for i in range(M):
    L,R,C=map(int,input().split())
    LRC.append([L-1,R-1,C])
LRC=np.array(LRC)
LRC=LRC[np.argsort(LRC[:,2])][::-1]

d=np.array([[INF for j in range(N)] for i in range(N)])
adj=[[] for i in range(N)]
for i in range(N-1):
    d[i+1,i]=0
    adj[i+1].append(i)
    adj[i].append(i+1)
for i in range(M):
    C=LRC[i,2]
    d[LRC[i,0],LRC[i,1]]=C
    d[LRC[i,1],LRC[i,0]]=C
    adj[LRC[i,0]].append(LRC[i,1])
    adj[LRC[i,1]].append(LRC[i,0])

ans=daik(0,N-1,d,adj)
if ans==INF:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

import numpy as np
import heapq

INF=10**15
N,M=map(int,input().split())
adj=[[] for i in range(N)]
for i in range(M):
    L,R,C=map(int,input().split())
    L-=1
    R-=1
    adj[L].append((R,C))
    adj[R].append((L,C))
for i in range(N-1):
    adj[i+1].append((i,0))
    
s=0
g=N-1
heap=[]
table=np.array([INF for i in range(N)])
table[s]=0
heapq.heappush(heap,(table[s],s))
                
while heap:
    q=heapq.heappop(heap)
    a=q[1]
    if q[0]>table[a]: continue
    for ne in adj[a]:
        p=ne[0]
        co=ne[1]
        if table[p]>table[a]+co:
            table[p]=table[a]+co
            heapq.heappush(heap,(table[p],p))
ans=table[g]
if ans==INF:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

import collections
n = int(input())
x = []
for _ in range(n):
    x.append(input())
c = collections.Counter(x)
a = c.most_common()[0][1]
y = []
if len(c) == 1:
    print(x[0])
    exit()
for i in range(n):
    if c.most_common()[i][1] == a:
        y.append(c.most_common()[i][0])
    else:
        break
for i in sorted(y):
    print(i)


### FIXED CODE ###

import collections
n = int(input())
s = [input() for _ in range(n)]
c = collections.Counter(s)
if len(c) == 1:
    print(s[0])
    exit()
a = c.most_common()[0][1]
b = c.most_common()
d = collections.deque()
for i in range(n):
    if b[i][1] == a:
        d.append(b[i][0])
    else:
        break
for i in sorted(list(d)):
    print(i)
### BUGGY CODE ###

S = input()

dp = [[0 for _ in range(4)]for _ in range(len(S)+1)]
dp[0][0] = 1

for ind,i in enumerate(S):
    if(i!='?'):
        dp[ind+1][0] += dp[ind][0]
        dp[ind+1][1] += dp[ind][1]
        dp[ind+1][2] += dp[ind][2]
        dp[ind+1][3] += dp[ind][3]
    else:
        dp[ind+1][0] += dp[ind][0]*3
        dp[ind+1][1] += dp[ind][1]*3
        dp[ind+1][2] += dp[ind][2]*3
        dp[ind+1][3] += dp[ind][3]*3

    if(i=='A'):
        dp[ind+1][1] += dp[ind][0]
    elif(i=='B'):
        dp[ind+1][2] += dp[ind][1]
    elif(i=='C'):
        dp[ind+1][3] += dp[ind][2]
    else:
        dp[ind+1][3] += dp[ind][2]
        dp[ind+1][2] += dp[ind][1]
        dp[ind+1][1] += dp[ind][0]
print(dp[-1][3]%(10**9+7))


### FIXED CODE ###

S = input()

MOD = 10**9+7
dp = [[0 for _ in range(4)]for _ in range(len(S)+1)]
dp[0][0] = 1

for ind,i in enumerate(S):
    if(i=='A'):
        dp[ind+1][0] = dp[ind][0]
        dp[ind+1][1] = dp[ind][1] + dp[ind][0]
        dp[ind+1][2] = dp[ind][2]
        dp[ind+1][3] = dp[ind][3]
    elif(i=='B'):
        dp[ind+1][0] = dp[ind][0]
        dp[ind+1][1] = dp[ind][1]
        dp[ind+1][2] = dp[ind][2] + dp[ind][1]
        dp[ind+1][3] = dp[ind][3]
    elif(i=='C'):
        dp[ind+1][0] = dp[ind][0]
        dp[ind+1][1] = dp[ind][1]
        dp[ind+1][2] = dp[ind][2]
        dp[ind+1][3] = dp[ind][3] + dp[ind][2]
    else:
        dp[ind+1][0] = dp[ind][0]*3
        dp[ind+1][1] = dp[ind][1]*3 + dp[ind][0]
        dp[ind+1][2] = dp[ind][2]*3 + dp[ind][1]
        dp[ind+1][3] = dp[ind][3]*3 + dp[ind][2]
        
    dp[ind+1][0]%=MOD
    dp[ind+1][1]%=MOD
    dp[ind+1][2]%=MOD
    dp[ind+1][3]%=MOD

print(dp[-1][3]%MOD)
### BUGGY CODE ###

from collections import defaultdict
q = int(input())
for _ in range(q):
    x = input()
    y = input()
    len_x = len(x)
    len_y = len(y)
    if len_x < len_y:
        len_x, len_y = len_y, len_x
        x, y = y, x
    c = defaultdict(list)
    for i, s in enumerate(x):
        c[s].append(i)
    li = [0] * len_x
    for s in y:
        if s in x:
            for i in c[s][::-1]:
                if i == 0:
                    li[i] = 1
                else:
                    li[i] = max(li[:i]) + 1
    print(max(li))



### FIXED CODE ###

for _ in range(int(input())):
    a = input()
    b = input()
    if len(a) < len(b):
        a, b = b, a
    indices = []
    for cb in b:
        bgn_idx = 0
        for i, cur_idx in enumerate(indices):
            chr_idx = a.find(cb, bgn_idx) + 1
            if not chr_idx:
                break
            if chr_idx < cur_idx:
                indices[i] = chr_idx
            bgn_idx = cur_idx
        else:
            chr_idx = a.find(cb, bgn_idx) + 1
            if chr_idx:
                indices.append(chr_idx)
    print(len(indices))
### BUGGY CODE ###

N = int(input())
z = [tuple(map(int,input().split())) for i in range(N)]
z.sort()
y = [(z[i][1],i) for i in range(N)]
y.sort()
cost = [[] for i in range(N)]
for i in range(N):
    j = y[i][1]
    if i != 0:
        cost[i].append((i-1,z[i][0]-z[i-1][0]))
        cost[i].append((i-1,abs(z[i][1]-z[i-1][1])))
        j_ = y[i-1][1]
        cost[j].append((j_,y[i][0]-y[i-1][0]))
        cost[j].append((j_,abs(z[j][0]-z[j_][0])))
    if i != N-1:
        cost[i].append((i+1,z[i+1][0]-z[i][0]))
        cost[i].append((i+1,abs(z[i+1][1]-z[i][1])))
        j_ = y[i+1][1]
        cost[j].append((j_,y[i+1][0]-y[i][0]))
        cost[j].append((j_,abs(z[j_][1]-z[j][1])))

import heapq

def prim(cost):
    V = len(cost)
    res = 0
    mincost = [float('inf')]*V
    used = [False]*V
    hq = []
    mincost[0] = 0
    heapq.heappush(hq,(0,0))
    done = 0
    while hq:
        weight,u = heapq.heappop(hq)
        if not used[u]:
            used[u] = True
            done += 1
            res += weight
            mincost[u] = weight
            for v, v_cost in cost[u]:
                if not used[v]:
                    heapq.heappush(hq,(v_cost,v))
            if done == V:
                break
    return res

print(prim(cost))

### FIXED CODE ###

N = int(input())
z = [tuple(map(int,input().split())) for i in range(N)]
z.sort()
y = [(z[i][1],i) for i in range(N)]
y.sort()
cost = [[] for i in range(N)]
for i in range(N-1):
    j = y[i][1]
    cost[i].append((i-1,min(abs(z[i][0]-z[i-1][0]),abs(z[i][1]-z[i-1][1]))))
    j_ = y[i-1][1]
    cost[j].append((j_,min(abs(y[i][0]-y[i-1][0]),abs(z[j][0]-z[j_][0]))))
    cost[i].append((i+1,min(abs(z[i+1][0]-z[i][0]),abs(z[i+1][1]-z[i][1]))))
    j_ = y[i+1][1]
    cost[j].append((j_,min(abs(y[i+1][0]-y[i][0]),abs(z[j_][1]-z[j][1]))))

i = N-1
j = y[i][1]
cost[i].append((i-1,min(abs(z[i][0]-z[i-1][0]),abs(z[i][1]-z[i-1][1]))))
j_ = y[i-1][1]
cost[j].append((j_,min(abs(y[i][0]-y[i-1][0]),abs(z[j][0]-z[j_][0]))))


import heapq

def prim(cost):
    V = len(cost)
    res = 0
    mincost = [float('inf')]*V
    used = [False]*V
    hq = []
    mincost[0] = 0
    heapq.heappush(hq,(0,0))
    done = 0
    while hq:
        weight,u = heapq.heappop(hq)
        if not used[u]:
            used[u] = True
            done += 1
            res += weight
            mincost[u] = weight
            for v, v_cost in cost[u]:
                if not used[v]:
                    heapq.heappush(hq,(v_cost,v))
            if done == V:
                break
    return res

print(prim(cost))
### BUGGY CODE ###

# coding: utf-8
# Your code here!

N,K = map(int,input().split())
h = list(map(int,input().split()))

costs = [0]*N

for i in range(1,N):
    tmp = costs[i-1]+abs(h[i]-h[i-1])
    for j in range(2,min(K+1,i+1)):
        tmp = min(tmp,costs[i-j]+abs(h[i]-h[i-j]))
    # print(tmp)
    costs[i] = tmp
    
print(costs[N-1])

### FIXED CODE ###

# coding: utf-8
# Your code here!

N,K = map(int,input().split())
h = list(map(int,input().split()))

costs = [0]*N

for i in range(1,N):
    tmp = costs[i-1]+abs(h[i]-h[i-1])
    for j in range(2,min(K+1,i+1)):
        tmp = min(tmp,costs[i-j]+abs(h[i]-h[i-j]))
    # print(tmp)
    costs[i] = tmp
    
print(costs[N-1])
### BUGGY CODE ###

N = int(input())
P_list = list(map(int,input().split()))
i_num = 0
for i in range(N):
    now_num = P_list[i]
    new_list = P_list[0:i+1]
    if now_num <= min(new_list):
        i_num += 1
    elif now_num > min(new_list):
        pass
print(i_num)

### FIXED CODE ###

N = int(input())
P_list = list(map(int,input().split()))
i_num = 0
min_P = P_list[0]
for p in P_list:
    if p <= min_P:
        min_P = p
        i_num += 1
print(i_num)
### BUGGY CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
for i in range(n):
    num = a.pop(i)
    print(max(a))
    a = [num]+a


### FIXED CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a)
max_a = max(a)
max_cnt = a.count(max_a)
for i in range(n):

    if max_a > a[i]:
        print(max_a)
    else:
        if max_cnt > 1:
            print(a[i])
        else:
            print(b[-2])
### BUGGY CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = input()
S = input()

s = set([""])
for n in S[::-1]:
	s |= set(x+n for x in s if len(x) != 3)

print(len([x for x in s if len(x) == 3]))


### FIXED CODE ###

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = input()
S = input()

s = set([""])
for n in S[::-1]:
	s |= set(x+n for x in s if len(x) != 3)

print(len([x for x in s if len(x) == 3]))
### BUGGY CODE ###

from operator import itemgetter
import heapq
n, m = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
heap_a = [i for i in a]
heapq.heapify(heap_a)
b = []
c = []
for i in range(m):
    bi, ci = list(map(int, input().split()))
    b.append(bi)
    c.append(ci)

bc = zip(b, c)
bc = sorted(bc, key=itemgetter(1))
b, c = zip(*bc)

for i in range(m):
    for j in range(b[i]):
        min_a = heapq.heappop(heap_a)
        if min_a < c[i]:
            heapq.heappush(heap_a, c[i])
        else:
            heapq.heappush(heap_a, min_a)
            break
print(sum(heap_a))


### FIXED CODE ###

from operator import itemgetter
import heapq
n, m = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
heap_a = [i for i in a]
heapq.heapify(heap_a)
b = []
c = []
for i in range(m):
    bi, ci = list(map(int, input().split()))
    b.append(bi)
    c.append(ci)

bc = zip(b, c)
bc = sorted(bc, key=itemgetter(1), reverse=True)
b, c = zip(*bc)

flag = False

for i in range(m):
    if flag:
        break
    for j in range(b[i]):
        min_a = heapq.heappop(heap_a)
        if min_a < c[i]:
            heapq.heappush(heap_a, c[i])
        else:
            heapq.heappush(heap_a, min_a)
            flag = True
            break
print(sum(heap_a))
### BUGGY CODE ###

a,b,k = map(int,input().split())
klist = [i for i in range(a,b+1)]
hidari = klist[:k]
migi = klist[-k:]
for i in migi:
    if i not in hidari:
        hidari.append(i)
hidari.sort()
for j in hidari:
    print(j)

### FIXED CODE ###

a,b,k = map(int,input().split())
if b-a+1 >= k:
    hidari = [i for i in range(a,a+k)]
    migi = [j for j in range(b,b-k,-1)]
    for i in migi:
        if i not in hidari:
            hidari.append(i)
    hidari.sort()
    for k in hidari:
        print(k)
else:
    for h in range(a,b+1):
        print(h)
### BUGGY CODE ###

#!/mnt/c/Users/moiki/bash/env/bin/python
N,K = list(map(int, input().split()))
h = list(map(int, input().split()))

suml = [1e9 for i in range(N)]
suml[0] = 0

for e in range(1,N):
    for k in range(1,K+1):
        if not ((e-k) >= 0):
            continue
        suml[e] = min(suml[e],
                abs(h[e]-h[e-k]) + suml[e-k]
        )

print(suml[N-1])
        



### FIXED CODE ###

#!/mnt/c/Users/moiki/bash/env/bin/python
# N,K = list(map(int, input().split()))
# h = list(map(int, input().split()))

# (N,K), h = map(int, input().split()), list(map(int, input().split()))
N,K,*h = map(int, "\n".join([input(), input()]).split())

# suml = [1e9 for i in range(N)]
# suml[0] = 0


suml = [0]*N

# for i in range(1,N):
for i,e_h in enumerate(h):
    if i == 0:
        continue

    start = max(0, i-K)
    cost  = min(cst + abs( e_h - hgh) for cst, hgh in 
                   zip(suml[start:i], h[start:i]))
    # cost  = min(cst + abs( h[i] - hgh ) for cst, hgh in 
    #               zip(suml[start:i], h[start:i]))
    suml[i] = cost

print(suml[-1])
### BUGGY CODE ###

def main():
  H,W,K = map(int,input().split())
  import numpy as np
  from collections import deque
  ans = 10000
  S = np.array([list(map(int,list(input()))) for _ in range(H)])
  cum = [[0]*W for _ in range(H+1)]
  for j in range(W):
    for i in range(1,H+1):
      cum[i][j] = cum[i-1][j]+S[i-1][j]

  cum = np.array(cum)
  for i in range(2**(H-1)):
    q = deque([0])
    for h in range(H):
      if (i>>h)&1:
        q.append(h+1)
    q.append(H)
    p = deque()
    judge = False
    for a in range(len(q)-1):
      x = cum[q[a+1]]-cum[q[a]]
      if (x>K).any():
        judge = True
        break
      else:
        p.append(list(x))

    if judge:
      continue
    t_a = len(q)-2
    n = len(p)
    l = [0]*n
    for w in range(W):
      y = [l[j]+p[j][w] for j in range(n)]
      if max(y)>K:
        t_a+=1
        l = [p[j][w] for j in range(n)]
      else:
        l = y
    ans = min(ans,t_a)

  print(ans)
  
main()

### FIXED CODE ###

def main():
  H,W,K = map(int,input().split())
  import numpy as np
  from collections import deque
  ans = 10000
  S = np.array([list(map(int,list(input()))) for _ in range(H)])
  cum = [[0]*W for _ in range(H+1)]
  for j in range(W):
    for i in range(1,H+1):
      cum[i][j] = cum[i-1][j]+S[i-1][j]

  cum = np.array(cum)
  for i in range(2**(H-1)):
    j = 0
    q = deque([0])
    for h in range(H):
      if (i>>h)&1:
        q.append(h+1)
    q.append(H)
    t_a = len(q)-2
    if t_a>=ans:
      continue
    p = deque()
    judge = False
    for a in range(len(q)-1):
      x = cum[q[a+1]]-cum[q[a]]
      if (x>K).any():
        judge = True
        break
      else:
        p.append(list(x))

    if judge:
      continue
    n = len(p)
    l = [0]*n
    for w in range(W):
      y = [l[j]+p[j][w] for j in range(n)]
      if max(y)>K:
        t_a+=1
        l = [p[j][w] for j in range(n)]
        if t_a>=ans:
          judge = True
          break
      else:
        l = y
    if judge:
      continue
    ans = min(ans,t_a)

  print(ans)
  
main()
### BUGGY CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(N-K):
  a=1
  b=1
  for j in range(K):
    a=a*A[(i+j)]
    ##print(A[(i+j)],end=" ")
  ##print("")
  for j in range(K):
    b=b*A[(i+j+1)]
    ##print(A[(i+j+1)],end=" ")
  ##print("")
  ##print(a,b)
  if a<b:
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
V=list()
for i in range(N-K):
  if A[i]<A[K+i]:
    print("Yes")
  else:
    print("No")
### BUGGY CODE ###

from collections import defaultdict
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())

cnt_dic = defaultdict(lambda: 0)

for _ in range(n):
    s = list(input())
    s.sort()
    cnt_dic[str(s)] +=1


ans = 0
for i in cnt_dic.values():
    if 1 < i:
        ans += combinations_count(i,2)

print(ans)


### FIXED CODE ###

from collections import defaultdict
from collections import Counter
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())

cnt_dic = defaultdict(lambda: 0)

for _ in range(n):
    s = list(input())
    cnt_s = [0] * 52
    for c in s:
        cnt_s[ord(c)- ord('a')] += 1
    cnt_dic[tuple(cnt_s)] +=1

ans = 0
for i in cnt_dic.values():
    if 1 < i:
        ans += combinations_count(i,2)

print(ans)
### BUGGY CODE ###

from math import floor
from fractions import gcd
N,M = map(int,input().split())

def prime_decomposition(n):
  i = 2
  d = {2:0}
  while i * i <= n:
    while n % i == 0:
      n //= i
      if i not in d:
          d[i] = 0
      d[i] += 1
    i += 1
  if n > 1:
    if n not in d:
        d[n] = 1
  return d
A = list(map(int,input().split()))
for i in range(N):
    A[i] //= 2

l = A[0]
for i in range(1,N):
    l = (l*A[i])//gcd(l,A[i])
ans = floor((M/l+1)/2)
n = prime_decomposition(l)[2]
p2 = 2**n
for i in range(N):
    if A[i]%p2 != 0:
        ans = 0
        break
print(ans)


### FIXED CODE ###

from math import floor
from fractions import gcd
N,M = map(int,input().split())

def prime_decomposition(n):
  i = 2
  d = {2:0}
  while i * i <= n:
    while n % i == 0:
      n //= i
      if i not in d:
          d[i] = 0
      d[i] += 1
    i += 1
  if n > 1:
    if n not in d:
        d[n] = 1
  return d
A = list(map(int,input().split()))
for i in range(N):
    A[i] //= 2

l = A[0]
for i in range(1,N):
    l = (l*A[i])//gcd(l,A[i])
    if l>M:
        break
ans = floor((M/l+1)/2)
n = prime_decomposition(l)[2]
p2 = 2**n
for i in range(N):
    if A[i]%p2 != 0:
        ans = 0
        break
print(ans)
### BUGGY CODE ###

n = int(input().strip())
arr = list(map(int, input().strip().split()))

ans = 1

for num in arr:
	ans *= num
	
if ans > 10**18:
	print(-1)
else:
	print(ans)


### FIXED CODE ###


n = int(input().strip())
arr = list(map(int, input().strip().split()))
arr.sort()

ans = 1

for num in arr:
    ans *= num

    if ans > 10**18:
        print(-1)
        exit(0)

print(ans)
### BUGGY CODE ###

l,r = map(int,input().split())
li = []
for i in range(l,r):
    for j in range(i+1,r+1):
        li.append((i*j)%2019)
print(min(li))

### FIXED CODE ###

l,r = map(int,input().split())
value = 2019
if r - l > 2019:
    print(0)
else:
    l1 = l%2019
    r1 = r%2019
    ans = 100000000
    if r1>l1:
        for i in range(l,r):
            for j in range(i+1,r+1):
                if ans>(i*j)%2019:
                    ans = (i*j)%2019
        print(ans)
    else:
        print(0)
### BUGGY CODE ###

number = list(map(int,input().split()))
line = list(map(int,input().split()))
 
num = number[0]
K = number[1]
dp = [0]* num


for i in range(1, num):
  dp[i] = min([dp[i - k] + abs(line[i] - line[i - k]) for k in range(1 , min(i + 1 , K + 1))])
  #kの範囲: k = 1,2,3...K 無理なときは k = 1,2..i
  
print(dp[-1])

### FIXED CODE ###

def ans():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j , i)])
    print(dp[n-1])
 
ans()
### BUGGY CODE ###

n=int(input())
s=input()
k=n
for i in range(n):
    a=s[:i]
    b=s[i+1:]
    l=a.count("W")+b.count("E")
    if l<k:
        k=l
print(k)

### FIXED CODE ###

n=int(input())
s=input()
k=0
l=[]
for i in range(n):
    if s[i]=="W":
        k+=1
    l.append(k)
#print(l)
#既に追加されたものまで変更されはしなかった
w=n
for i in range(n):
    if i==0:
        #if s[i]=="W":
        #    v=n-l[n-1]+1
        #else:
        #    v=n-l[n-1]
        #下のようにすれば分ける必要はない
        v=n-1-l[n-1]+l[0]
    else:
        v=l[i-1]+n-1-i-(l[n-1]-l[i])


    if v<w:
        w=v
print(w)
### BUGGY CODE ###

n=int(input())
s=[]
for i in range(n):
    s.append("".join(sorted(input())))

S=set(s)
"""
import math

def cmb(n,r):
    return math.factorial(n) // (math.factorial(n-r)*math.factorial(r))
"""
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

ans=0
for x in S:
    a=s.count(x)
    if a<2:
        continue
    else:
        ans+=cmb(a,2)
print(ans)



### FIXED CODE ###

n=int(input())
s=[]
for i in range(n):
    s.append("".join(sorted(input())))

S=set(s)

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

from collections import Counter

ans=0
l=Counter(s)
for x in S:
    a=l[x]
    if a<2:
        continue
    else:
        ans+=cmb(a,2)
print(ans)
### BUGGY CODE ###

N,Q=map(int,input().split())
S=input()
for i in range(Q):
    count=0
    l,r=map(int,input().split())
    for j in range(r-l):
        if S[l-1+j]=="A" and S[l+j]=="C":
            count+=1
    print(count)

### FIXED CODE ###

N,Q=map(int,input().split())
S=input()
list1=[list(map(int,input().split())) for _ in range(Q)]
list2=[0]*(N+1)
count=0
for i in range(N):
    if i>0:
        list2[i+1]=list2[i]
    if i==N-1:
        continue
    elif S[i:i+2]=="AC":
        list2[i+1]+=1
for tmp in list1:
    print(list2[tmp[1]-1]-list2[tmp[0]-1])
### BUGGY CODE ###

num = list(map(int, input().split()))

loop = [0]

for i in loop:
  if num[0] < num[1]:
    difference = abs(num[0] - num[1])
    if difference > num[0]:
      break
    else:
      num[0] = difference
      break
  elif num[1] == 1:
    num[0] = 0
    break
  elif num[1] == 0:
    break
  num[0] = abs(num[0] - num[1])
  loop.append(i+1)

print(num[0])

### FIXED CODE ###

num = list(map(int, input().split()))

loop = [0]

for i in loop:
  if num[0] < num[1]:
    difference = abs(num[0] - num[1])
    if difference > num[0]:
      break
    else:
      num[0] = difference
      break
  elif num[1] == 1:
    num[0] = 0
    break
  elif num[1] == 0:
    break
  if i == 0:
    num[0] = num[0] % num[1]
  num[0] = abs(num[0] - num[1])
  loop.append(i+1)

print(num[0])