Harryxun/stf_run huggingface dataset:
a=input()
b=input()
c=input()

l=a+b+c

n=a[0]
a=a.lstrip(n)

for i in range(len(l)-1):
    if n=='a':
        if len(a)==0:
            print('A')
            break
        n=a[0]
        a=a.lstrip(n)
    elif x=='b':
        if len(b)==0:
            print('B')
            break
        n=b[0]
        b=b.lstrip(n)
    else:
        if len(c)==0:
            print('C')
            break
        n=c[0]
        c=c.lstrip(n)



### FIXED CODE ###

a=input()
b=input()
c=input()

#l=a+b+c

#n=a[0]
#a=a.lstrip(n)
n='a'
while True: 
    if n=='a':
        if len(a)==0:
            print('A')
            exit()
            
        n=a[0]
        #a=a.lstrip(n)
        a=a[1:]
        
    elif n=='b':
        if len(b)==0:
            print('B')
            exit()
            
        n=b[0]
        #b=b.lstrip(n)
        b=b[1:]
        
    else:
        if len(c)==0:
            print('C')
            exit()
            
        n=c[0]
        #c=c.lstrip(n)
        c=c[1:]
def abc166_d():
  x = int(input())
  for k in range(1, 56):
    cand = (x + k**5) ** 0.2
    if cand.is_integer():
      print(int(cand), k)
      return
    cand = (x - k**5) ** 0.2
    if cand.is_integer():
      print(int(cand), -k)
      return

abc166_d()

### FIXED CODE ###

def abc166_d():
  x = int(input())
  for i in range(-126, 127):
    for j in range(-126, 127):
      if i**5 - j**5 == x:
        print('{} {}'.format(i, j))
        return

abc166_d()
# -*- coding: utf-8 -*-
a, b = map(int, raw_input().split())
s = raw_input()
ok = False
if len(s) == (a+b+1):
  x,y = map(str, s.split('-'))
  if len(x) == a:
    if len(y) == b:
      print ok

### FIXED CODE ###

# -*- coding: utf-8 -*-
a, b = map(int, raw_input().split())
s = raw_input()
ok = False
if len(s) == (a+b+1):
  n = s.count('-')
  if n == 1:
    x,y = map(str, s.split('-'))
    if len(x) == a:
      if len(y) == b:
        ok = True

if ok:
  print 'Yes'
else:
  print 'No'
from functools import reduce
from operator import xor
a, b = (int(i) for i in input().split())  
print(reduce(xor, list(range(a, b+1))))

### FIXED CODE ###

A, B = map(int, input().split())
 
def xor(A):
  ans = ((A+1)//2)%2
  if A%2==0:
    ans ^= A
  return ans
 
print(xor(B)^xor(A-1))
N = input()
if N < 10:
  print(N)
else:
  if 9 < N < 100:
    print("9")
  else:
    if 99 < N < 1000:
      print(N - 90)
    else:
      if 999 < N < 10000:
        print("909")
      else:
        if 9999 < N < 100000:
          print(909 +  N - 9999)
        else:
          if N = 100000:
            print("90909")


### FIXED CODE ###

N = int(input())
if N < 10:
  print(N)
else:
  if 9 < N < 100:
    print("9")
  else:
    if 99 < N < 1000:
      print(N - 90)
    else:
      if 999 < N < 10000:
        print("909")
      else:
        if 9999 < N < 100000:
          print(909 +  N - 9999)
        else:
          if N == 100000:
            print("90909")
h, w = map(int, input().split())
s = []
for i in range(h):
    s_ = input()
    s.append(s_)

for i in range(w):
    for j in range(h):
        if s[j][i] == '#':
            if j + 1 < w and s[j+1][i] == '#':
                continue
            if j - 1 >= 0 and s[j-1][i] == '#':
                continue
            if i + 1 < h and s[j][i+1] == '#':
                continue
            if i - 1 >= 0 and s[j][i-1] == '#':
                continue
            print('No')
            exit()

print('Yes')

### FIXED CODE ###

h, w = map(int, input().split())
s = []
for i in range(h):
    s_ = input()
    s.append(s_)

for i in range(w):
    for j in range(h):
        if s[j][i] == '#':
            if j + 1 < h and s[j+1][i] == '#':
                continue
            if j - 1 >= 0 and s[j-1][i] == '#':
                continue
            if i + 1 < w and s[j][i+1] == '#':
                continue
            if i - 1 >= 0 and s[j][i-1] == '#':
                continue
            print('No')
            exit()

print('Yes')
a,p=map(int, input().split())
print((3a+p)//2)

### FIXED CODE ###

a,p=map(int, input().split())
print((3*a+p)//2)
def solve():
    S = input()
    if S == "Sunny":
        ans = "Cloudy"
    elif S == "Cloudy":
        ans = "Rainy"
    else S == "Rainy":
        ans == "Sunny"
    
    print(ans)
solve()

### FIXED CODE ###

def solve():
    S = input()
    if S == "Sunny":
        ans = "Cloudy"
    elif S == "Cloudy":
        ans = "Rainy"
    elif S == "Rainy":
        ans = "Sunny"
    
    print(ans)
solve()
n=input()
graph=[[] for i in range(n+1)]
for i in range(n-1):
    v,u=list(map(int,raw_input().split()))
    graph[v].append(u)
    graph[u].append(v)

dist= [-1 for i in range(n+1)]
dist[1]=0
son=[[] for i in range(n+1)]
queue=[1]
father=[0 for i in range(n+1)]
def bfs(u):
    for v in graph[u]:
        if dist[v]==-1:
            dist[v]=dist[u]+1
            son[u].append(v)
            father[v]=u
            queue.append(v)
    queue.pop(0)
    if len(queue)!=0:
        bfs(queue[0])

bfs(1)
road=[n]
tempfather=n
for i in range(dist[n]):
    road.append(father[tempfather])
    tempfather=father[tempfather]

di=len(road)
k=road[(di-2)/2]

def countson(u):
  count=0
  if len(son[u])==0:return 1
  for v in son[u]:
      count+=countson(v)
  return count+1

cs=countson(k)
cf=n-cs

if cs>=cf:print 'Snuke'
else:
    print 'Fennec'


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
n=input()
graph=[[] for i in range(n+1)]
for i in range(n-1):
    v,u=list(map(int,raw_input().split()))
    graph[v].append(u)
    graph[u].append(v)

dist= [-1 for i in range(n+1)]
dist[1]=0
son=[[] for i in range(n+1)]
queue=[1]
father=[0 for i in range(n+1)]
def bfs(u):
    for v in graph[u]:
        if dist[v]==-1:
            dist[v]=dist[u]+1
            son[u].append(v)
            father[v]=u
            queue.append(v)
    queue.pop(0)
    if len(queue)!=0:
        bfs(queue[0])

bfs(1)
road=[n]
tempfather=n
for i in range(dist[n]):
    road.append(father[tempfather])
    tempfather=father[tempfather]

di=len(road)
k=road[(di-2)/2]

def countson(u):
  count=0
  if len(son[u])==0:return 1
  for v in son[u]:
      count+=countson(v)
  return count+1

cs=countson(k)
cf=n-cs

if cs>=cf:print 'Snuke'
else:
    print 'Fennec'
from bisect import bisect
    n,k=map(int,input().split())
    x=list(map(int,input().split()))
    g=bisect(x,0)
    if x[n-1]<=0 or x[0]>=0:
        print(max(abs(x[k-1]),abs(x[0])))
    else:
        if g>=k:
            s=g-k
        else:
            s=0
        t=0
        while s<=n-k:
            if x[s]<0 and x[s+k-1]>0:
                if t==0:
                    t=min(2*abs(x[s])+x[s+k-1],abs(x[s])+2*x[s+k-1])
                else:
                    t=min(t,2*abs(x[s])+x[s+k-1],abs(x[s])+2*x[s+k-1])
            else:
                t=min(t,max(abs(x[s]),abs(x[s+k-1])))
            s+=1
        print(t)

### FIXED CODE ###

def resolve():
    from bisect import bisect
    n,k=map(int,input().split())
    x=list(map(int,input().split()))
    g=bisect(x,0)
    if x[n-1]<=0:
        print(abs(x[n-k]))
    elif x[0]>=0:
        print(x[k-1])
    else:
        if g>=k:
            s=g-k
        else:
            s=0
        t=0
        while s<=n-k:
            if x[s]<0 and x[s+k-1]>0:
                if t==0:
                    t=min(2*abs(x[s])+x[s+k-1],abs(x[s])+2*x[s+k-1])
                else:
                    t=min(t,2*abs(x[s])+x[s+k-1],abs(x[s])+2*x[s+k-1])
            else:
                t=min(t,max(abs(x[s]),abs(x[s+k-1])))
            s+=1
        print(t)
resolve()
import math;
a,b,c,d=map(int,input().split())
print(math.max(a*b,c*d))

### FIXED CODE ###

import math;
a,b,c,d=map(int,input().split())
print(max(a*b,c*d))
def intersect_list(lst1, lst2):
    arr = []
    lst = lst1.copy()
    for element in lst2:
        try:
            lst.remove(element)
        except ValueError:
            pass
        else:
            arr.append(element)
    return len(arr)

n=int(input())
a=[input() for i in range(n)]
a=list(map(lambda x:list(x),a))
count=0
for i in range(len(a)):
    for j in range(i+1,len(a)):
        if intersect_list(a[i],a[j])==len(len(a[i])):
            count+=1
print(count)

### FIXED CODE ###

x,y = map(int,input().split())
a=x+y
b=x-y
c=x*y
print(max([a,b,c]))
from math import factorial

def cases(idx_start, idx_end):
  cases = 0
  for r in range((idx_end - idx_start)//2+1):
    n = idx_end - idx_start - r
    cases += factorial(n) / factorial(r) / factorial(n - r)
  return cases

n, m  = map(int, input().split())
alist = [int(input()) for i in range(m)]
div_num = 1000000007

ans = cases(1,alist[0])
for i in range(1,m):
  if alist[i] - alist[i-1] <= 1:
    print(0)
    exit()
  ans *= cases(alist[i-1]+1, alist[i])
ans *= cases(alist[-1]+1, n+1)
print(int(ans%div_num))

### FIXED CODE ###

n, m  = map(int, input().split())

if n == 1:
  print(1)
  exit()

f = [0 for i in range(n)]
f[-2:] = [1, 1]
for i in range(m):
  f[int(input())-1] = -1

div_num = 1000000007

for i in range(n-2)[::-1]:
  if f[i] == -1:
    continue
  if f[i+1] == -1 and f[i+2] == -1:
    print(0)
    exit()
  elif f[i+1] == -1 and f[i+2] != -1:
    f[i] = f[i+2]
  elif f[i+1] != -1 and f[i+2] == -1:
    f[i] = f[i+1]
  else:
    f[i] = f[i+1]+f[i+2]

if f[0] != -1 and f[1] != -1:
  print(int((f[0]+f[1])%div_num))
elif f[0] == -1 and f[1] != -1:
  print(int(f[1]%div_num))
elif f[0] != -1 and f[1] == -1:
  print(int(f[0]%div_num))
else:
  print(0)
N = int(input())

a = list(range(1, N+1))
sc = 0
print((a[-2]+a[0])*(N-1)//2)


### FIXED CODE ###

N = int(input())

a = list(range(1, N+1))

if N ==1:
    sc = 0
else:
    sc = int((N**2-N)/2)
print(sc)
N, K = map(int, input().split())
 
tmp = [0] * N
 
for i in range(K):
  input()
  for j in set(map(int, input().split())):
 	tmp[j] |= 1 
print(sum(tmp))

### FIXED CODE ###

N, K = map(int, input().split())
 
tmp = set()
 
for i in range(K):
  input()
  tmp |= set(map(int, input().split()))
 
print(len(set(range(1, N+1)) - tmp))
from scipy.special import comb
list = input().rstrip().split(" ")
gusu = int(list[0])
kisu = int(list[1])
#奇数奇数の場合
kiki = int(comb(kisu, 2, exact=True))
#偶数偶数の場合
gugu = int(comb(gusu, 2, exact=True))
print(kiki + gugu)

### FIXED CODE ###

n, m = map(int, input().split())
print((n * ~-n // 2) + (m* ~-m // 2))#n * ~-n == n*(n-1)
s = input().split()
num = int(s)

if num % 4 == 0:
  print('YES')
else:
  print('NO')

### FIXED CODE ###

a, b, c = input().split()
num = int(a+b+c)

if num % 4 == 0:
    print('YES')
else:
    print('NO')
x=input()
x=int(x)
t=input()
t=int(t)
if(x>t):
  print(x-t)
else:
  print("0")

### FIXED CODE ###

x, t = map(int, input().split())
if(x>t):
    print(x-t)
else:
  print("0")
n, k = map(int, input().split())

pow2 = [1]
for i in range(1, k):
    pow2.append(pow2[i-1]*2)
win = 0
for i in range(1, n+1):
    for j, x in enumerate(pow2):
        if x > k/i:
            index = j
            break
    bunbo = pow(2, index)
    win += 1/bunbo
print(win/n)

### FIXED CODE ###

n, k = map(int, input().split())
win = 0
for i in range(1, n+1):
    index = 0
    while pow(2, index) < k/i:
        index += 1
    win += pow(0.5, index)/n
print(win)
import sys
a=1
for b in sys.stdin:b=b.strip()
    if b=="0":break
    print("Case %d: %s"%(a,b))
    a+=1

### FIXED CODE ###

x=int(input())
i=1
while x!=0:
    print("Case %d: %s" %(i,x))
    x=int(input())
    i+=1
A, B, C = map(input().split())

l = [5, 5, 7]
if A in l:
    l.remove(A)
    if B in l:
        if C in l:
            print('YES')
            break
    print('NO')

### FIXED CODE ###

args = []
args = input()

count_5 = 0
count_7 = 0

for i in args:
    if i == '5':
        count_5+=1
    if i == '7':
        count_7+=1

if count_5 == 2 and count_7 == 1:
    print('YES')
else:
    print('NO')
n, m, l = map(int, input().split())
A = []
B = []
C = [[0] * l for i in range(n)]
for x in range(n):
	A[x].append(list(map(int, input().split())))

for x in range(m):
	B[x].append(list(map(int, input().split())))

for x in range(n):
	for y in range(l):
		sum = 0
		for z in range(m):
			sum += A[x][z] * B[z][y]
		C[x][y] = sum

for x in range(n):
	for y in range(l-1):
		print("{0} ".format(C[x][y]), end = '')
	print(C[x][l-1])

		

### FIXED CODE ###

n, m, l = map(int, input().split())
A = []
B = []
C = [[0] * l for i in range(n)]
for x in range(n):
	A.append(list(map(int, input().split())))

for x in range(m):
	B.append(list(map(int, input().split())))

for x in range(n):
	for y in range(l):
		sum = 0
		for z in range(m):
			sum += A[x][z] * B[z][y]
		C[x][y] = sum

for x in range(n):
	for y in range(l-1):
		print("{0} ".format(C[x][y]), end = '')
	print(C[x][l-1])
import sys
sys.setrecursionlimit(10**5)
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [-1 for i in range(N)]
def rec(n):
    if dp[n] == -1:
        if n == 0:
            dp[n] = 0
        elif n == 1:
            dp[n] = abs(h[1]-h[0])
        else:
            work = []
            for i in range(1, K+1):
                if n-i >= 0:
                    work.append(rec(n-i)+abs(h[n-i]-h[n]))
            dp[n] = min(work)
    return dp[n]
rec(N-1)
print(dp[N-1])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
import numpy as np
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))
dp = np.zeros(N,dtype=int)
for i in range(1, N):
    s=max(0, i-K)
    dp[i] = min(dp[s:i]+abs(h[s:i]-h[i]))
print(dp[-1])
a = int(input())
print(a)

### FIXED CODE ###

S = input()
if S == "Sunny":
    print("Cloudy")
elif S == "Cloudy":
    print("Rainy")
else:
    print("Sunny")
N = input();
  
if N[0] == "7" or N[1] == "7" or N[2] == "7":
    print("Yes");
  else:
    print("No");


### FIXED CODE ###

num = input();

if num[0] == "7" or num[1] == "7" or num[2] == "7" :
  print("Yes");
else:
  print("No");
H, W = map(int, input().split())
a = []
for i in range(H):
  b = list(map(int, input().split()))
  a.append(b)
c = []
for i in range(2*H):
  d = []
  for j in range(W):
    d.append(a[(i + 1)//2][j])
  c.append(d)
print(c)

### FIXED CODE ###

H, W = map(int, input().split())
a = []
for i in range(H):
  b = list(input())
  a.append(b)
for i in range(2*H):
  for j in range(W):
    if j != W - 1:
      print(a[i//2][j],end="")
    else:
      print(a[i//2][j])
import math
a,b,c,d = map(int, input().split())
cnt=0
num_c = b//c - (a-1)//c
num_d = b//d - (a-1)//d
num_c_d = b//((c*d)/math.gcd(c,d))- (a-1)//((c*d)/math.gcd(c,d))
total = num_c + num_d - num_c_d
print(int((b-a+1) - total))

### FIXED CODE ###

import fractions
a,b,c,d = map(int, input().split())
cnt=0
num_c = b//c - (a-1)//c
num_d = b//d - (a-1)//d
num_c_d = b//((c*d)//fractions.gcd(c,d))- (a-1)//((c*d)//fractions.gcd(c,d))
total = num_c + num_d - num_c_d
print(int((b-a+1) - total))
S=str(input())
s=list(S)
x,y=map(int,input().split())
fora=0
side=[]
updw=[]
while s[0]=="F":
  fora+=1
  s.pop(0)
flag=1#1のとき横向き、-1のときたて向き
step=0
while s:
  if s[0]=="T":
    s.pop(0)
    if step:
      if flag==-1: updw+=[step]
      else: side+=[step]
    flag=flag*(-1)
    step=0
  else:
    s.pop(0)
    step+=1
    if len(s)==0:
      if flag==-1: updw+=[step]
      else: side+=[step]
ypossi=len(side)
tpossi=len(updw)
X=sum(side)+fora+x
Y=sum(updw)+y
xdp=[[0 for i in range(2*X+1)] for j in range(ypossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
xdp[0][fora+X]=1 
for i in range(ypossi):
  for j in range(2*X+1):
    if j-side[i]>=0:
      if xdp[i][j-side[i]]==1:xdp[i+1][j]=1
    if j+side[i]<2*X+1:
      if xdp[i][j+side[i]]==1:xdp[i+1][j]=1

ydp=[[0 for i in range(2*Y+1)] for j in range(tpossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
ydp[0][Y]=1 
for i in range(tpossi):
  for j in range(2*Y+1):
    if j-updw[i]>=0:
      if ydp[i][j-updw[i]]==1:ydp[i+1][j]=1
    if j+updw[i]<2*Y+1:
      if ydp[i][j+updw[i]]==1:ydp[i+1][j]=1
if xdp[ypossi][x+X]==1 and ydp[tpossi][y+Y]==1:
  print("Yes")
else: print("No")

### FIXED CODE ###

S=str(input())
s=list(S)
x,y=map(int,input().split())
fora=0
side=[]
updw=[]
while s[0]=="F":
  fora+=1
  s.pop(0)
  if len(s)==0:break
flag=1#1のとき横向き、-1のときたて向き
step=0
while s:
  if s[0]=="T":
    s.pop(0)
    if step:
      if flag==-1: updw+=[step]
      else: side+=[step]
    flag=flag*(-1)
    step=0
  elif s[0]=="F":
    s.pop(0)
    step+=1
    if len(s)==0:
      if flag==-1: updw+=[step]
      else: side+=[step]
  else: break
ypossi=len(side)
tpossi=len(updw)
X=sum(side)+fora+abs(x)
Y=sum(updw)+abs(y)
xdp=[[0 for i in range(2*X+1)] for j in range(ypossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
xdp[0][fora+X]=1 
for i in range(ypossi):
  for j in range(2*X+1):
    if j-side[i]>=0:
      if xdp[i][j-side[i]]==1:xdp[i+1][j]=1
    if j+side[i]<2*X+1:
      if xdp[i][j+side[i]]==1:xdp[i+1][j]=1

ydp=[[0 for i in range(2*Y+1)] for j in range(tpossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
ydp[0][Y]=1 
for i in range(tpossi):
  for j in range(2*Y+1):
    if j-updw[i]>=0:
      if ydp[i][j-updw[i]]==1:ydp[i+1][j]=1
    if j+updw[i]<2*Y+1:
      if ydp[i][j+updw[i]]==1:ydp[i+1][j]=1
if xdp[ypossi][x+X]==1 and ydp[tpossi][y+Y]==1:
  print("Yes")
else: print("No")
"""
"""

from math import factorial


def int_as_array(num): return list(map(int, [y for y in str(num)]))


def array_as_int(arr): return int(''.join(map(str, arr)))


def read_int(): return int(input())


def read_array(): return list(map(int, input().split(' ')))


def array_to_string(arr, sep=' '): return sep.join(map(str, arr))


def matrix_to_string(arr, sep=' '): return '[\n' + '\n'.join(
    [sep.join(map(str, row)) for row in arr]) + '\n]'


def combine(n, r):
    return (factorial(n) / factorial(n - r)) * (1 / r)


def solve(N, M):
    choose_evens = combine(N, 2)
    choose_odds = combine(M, 2)
    return choose_evens + choose_odds


print('input()', input())
N, M = read_array()
print('N, M', N, M)
solve(N, M)


### FIXED CODE ###

"""
"""

from math import factorial


def int_as_array(num): return list(map(int, [y for y in str(num)]))


def array_as_int(arr): return int(''.join(map(str, arr)))


def read_int(): return int(input())


def read_array(): return list(map(int, input().split(' ')))


def array_to_string(arr, sep=' '): return sep.join(map(str, arr))


def matrix_to_string(arr, sep=' '): return '[\n' + '\n'.join(
    [sep.join(map(str, row)) for row in arr]) + '\n]'


def combine(n, r):
    try:
        return (factorial(n) / factorial(n - r)) * (1 / r)
    except:
        return 0


def solve(N, M):
    choose_evens = combine(N, 2)
    choose_odds = combine(M, 2)
    return int(choose_evens + choose_odds)


N, M = read_array()
print(solve(N, M))
from collections import Counter
n,k=map(int,input().split())
cnt=list(sorted(Counter(map(int,input().split().values()))))
num=len(cnt)
ans=0
for v in cnt:
    if num<=k:
        break
    ans+=v
    num-=1
print(ans)


### FIXED CODE ###

from collections import Counter
n,k=map(int,input().split())
a=list(map(int,input().split()))
counter=Counter(a)
ans=[]
for i in counter.values():
    ans.append(i)
ans.sort()
ans.reverse()
v=sum(ans[0:k])
print(n-v)
a, b, t=map(int.input().split())
print(b*(t//a))

### FIXED CODE ###

a, b, t=map(int, input().split())
print(b*(t//a))
h,n=map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
maxAi= max(a for a,b in AB)
dp=[0]*(H+maxAi)
i=1
try:
    dp[i]=min(dp[i-a]+b for a,b in AB)
    i+=1
else:
    print(min(dp[H:]))

### FIXED CODE ###

H,n=map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(n)]
maxAi= max(a for a,b in AB)
dp=[0]*(H+maxAi)
i=1
while True:
  try:
    dp[i]=min(dp[i-a]+b for a,b in AB)
    i+=1
  except:
    print(min(dp[H:]))
    break
N = int(input())
S = str(input())

if N % 2 ==1:
  print("No")
else:
  if S[:int(N/2)]==S[int(N/2):]:
    print("Yes")
  else:
    print("No")
 
　　

### FIXED CODE ###

N = int(input())
S = input()

if N % 2 ==1:
    print("No")
else:
    if S[:int(N/2)]==S[int(N/2):]:
        print("Yes")
    else:
        print("No")
w = input()
c = ""
for i in w:
  if i == "9":
    i = 1
    c += i
  elif i == "1":
    i == 9
    c += i
  else:
    c += i
print(i)

### FIXED CODE ###

w = input()
c = ""
for i in w:
  if i == "9":
    i = "1"
    c += i
  elif i == "1":
    i = "9"
    c += i
print(c)
N, K = map(int, input().split())
H = list(map(int, input().split()))
H = [0] + H
dp = [0] * (N + 1)
dp[1] = 0
dp[2] = abs(H[2] - H[1])

for i in range(3, N+1):
    dp[i] = 1000000000
    for j in range(max(1, i - j), K + 1):
        dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]))
print(dp[N])

### FIXED CODE ###

N, K = map(int, input().split())
H = list(map(int, input().split()))
H = [0] + H
dp = [0] * (N + 1)
dp[1] = 0
dp[2] = abs(H[2] - H[1])

for i in range(3, N+1):
    dp[i] = dp[i - 1] + abs(H[i] - H[i - 1])
    for j in range(1, K + 1):
        if i - j <= 0:
            break
        dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]))
print(dp[N])
N=list(map(int,input().splti()))]
print(15-n[01]-n[1]-n[2]-n[3]-n[4])
     

### FIXED CODE ###

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

for i in range(len(n)):
  if n[i]==0:
    print(i+1)
S = input()
N = len('S')
if S == S[::-1] and S[0:(N-3)/2] == S[0:(N-3)/2:-1]:
    print ('Yes')
else:
    print ('No')

### FIXED CODE ###

S = input()
N = len(S)
K = (N-3)//2
if S == S[::-1] and S[0:K] == S[K:0:-1]:
    print ('Yes')
else:
    print ('No')
k,n=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for x in range(n-1):
  b=a[x+1]-a[x]
  ans=max(ans,b)
  
c=k-a[n-1]+a[0]

print(k-max(ans,c))



### FIXED CODE ###

s=list(input())

if s[2]==s[3] and s[4]==s[5]:
  print('Yes')
  
else:
  print('No')
N = int(input())
A = list(map(int, input()))
S = [0]
ans = 0
for i in range(len(A)):
  S.append(S[i] + A[i])
S.sort()
count = 1
for i in range(1, len(S)):
  if S[i-1] == S[i]:
    count += 1
  else:
    ans += count * (count-1) / 2
    count = 1
ans += count * (count-1) / 2
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
S = [0]
ans = 0
for i in range(len(A)):
	S.append(S[i] + A[i])
S.sort()
count = 1
for i in range(1, len(S)):
	if S[i-1] == S[i]:
		count += 1
	else:
		ans += (count * (count - 1)) / 2
		count = 1
ans += (count * (count - 1)) / 2
print(int(ans))
L, R = (int(x) for x in input().split())
L = L % 2019
R = R % 2019
if(L > R):
    print(0)
elif(L == 0):
    print(0)
N = R - L
A = []
if(N == 1):
    print(L * R % 2019)
else:
    for i in range(N):
        for j in range(i):
            A.append((L + i) * (L + j) % 2019)
    print(min(A))

### FIXED CODE ###

L, R = map(int, input().split())
ans = 10000
 
for i in range(L, min(R + 1, L + 2020)):
  for j in range(i,  min(R + 1, L + 2020)):
    if i < j:
      ans = min(ans, (i * j)%2019)
 
print(ans)
n = int(input())
 s = input()
cnt = 1
 for i in range(1, n):
     if s[i] != s[i-1]:
         cnt += 1
print(cnt)

### FIXED CODE ###

n = int(input())
s = input()
cnt = 1
for i in range(1, n):
    if s[i] != s[i-1]:
        cnt += 1
print(cnt)
N=int(input())
P=list(map(int,input().split()))

c=[]
for i in range(N):
    if P[i]==i+1:
        c.append(i+1)

import sys
if c==[]:
    print(0)
    sys.exit()

d=[]
for i in range(1,len(c)):
    d.append(c[i]-c[i-1])

if len(c)==2:
    print(c[1]-c[0])
elif len(c)%2==0:
    print(sum(d)-max(d))
else:
    print(sum(d)-max(d)+1)

### FIXED CODE ###

N=int(input())
P=list(map(int,input().split()))
Q=P[::-1]
c=0
for i in range(N-1):
    if P[i]==i+1:
        P[i],P[i+1]=P[i+1],P[i]
        c+=1
if P[N-1]==N:
    c+=1
print(c)
import bisect
n = int(input())
length = list(map(int, input().split()))
length = sorted(length)
count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        insert_index = bisect.bisect_left(length, length[i]+length[j])
                   count += insert_index-j               
print(count)

### FIXED CODE ###

import bisect
n = int(input())
length = list(map(int, input().split()))
length = sorted(length)
count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        insert_index = bisect.bisect_left(length, length[i]+length[j])
        count += insert_index-j-1               
print(count)