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


def calcMax(i):
  now = numbers[i] 

  future_max = max(numbers[i+1:])
  #print(numbers[i+1:])
  t = numbers[i+1:]
  #print((max(t)))
  return future_max - now

n = int(input())

numbers = []
for i in range(n):
  numbers.append(int(input()))

m = -1000000001
for i in range(len(numbers) - 1):
    if i == 0 or i == len(numbers) - 1 or (numbers[i-1] >= numbers[i] and numbers[i] < numbers[i+1]) or (numbers[i-1] > numbers[i] and numbers[i] <= numbers[i+1]):
      temp = calcMax(i)
      #print("temp: " + str(temp))
      if temp > m:
          m = temp

print (m)



### FIXED CODE ###

def calcMax(i):
  now = numbers[i]

  future_max = max(numbers[i+1:])
  #print(numbers[i+1:])
  t = numbers[i+1:]
  #print((max(t)))
  return future_max - now

n = int(input())

numbers = []
for i in range(n):
  numbers.append(int(input()))

m = -1000000001
ti = 1000000001
for i in range(len(numbers) - 1):
    if numbers[i] < ti:
      if (i == 0 or i == len(numbers) - 1 or (numbers[i-1] >= numbers[i] and numbers[i] <= numbers[i+1])):
        temp = calcMax(i)
        #print("temp: " + str(temp))
        if temp > m:
            m = temp
            ti = numbers[i]

print (m)
### BUGGY CODE ###

from collections import deque
H,W=map(int,input().split())
stack=deque()
c=[input() for i in range(H)]
ans=0
reached=[[-1]*W for i in range(H)]
for i in range(H):
    for j in range(W):
        if c[i][j]=="#":
            stack.append((i,j))
            reached[i][j]=0
dydx=[(1,0),(-1,0),(0,1),(0,-1)]
while(stack):
    Y,X=stack.popleft()
    for dy,dx in dydx:
        y=Y+dy
        x=X+dx
        if y<0 or y>=H or x<0 or x>=W or c[y][x]=="#":
            continue
        if reached[y][x]!=-1:
            continue
        stack.append((y,x))
        reached[y][x]=reached[Y][X]+1
        ans=max(ans,reached[y][x])
print(ans)


### FIXED CODE ###

from collections import deque
H,W=map(int,input().split())
stack=deque()
c=[input() for i in range(H)]
ans=0
reached=[[-1]*W for i in range(H)]
for i in range(H):
    for j in range(W):
        if c[i][j]=="#":
            stack.append((i,j))
            reached[i][j]=0
dydx=[(1,0),(-1,0),(0,1),(0,-1)]
while(stack):
    Y,X=stack.popleft()
    for dy,dx in dydx:
        y=Y+dy
        x=X+dx
        if y<0 or y>=H or x<0 or x>=W or c[y][x]=="#":
            continue
        if reached[y][x]!=-1:
            continue
        stack.append((y,x))
        reached[y][x]=reached[Y][X]+1
        ans=max(ans,reached[y][x])
print(ans)
### BUGGY CODE ###

n,k,c=map(int,input().split())
s=list(input())
for i in range(len(s)):
	if s[i]=="x":
		s[i]=False
	else:
		s[i]=True
i=0
work=[]
while len(work)<k:
	if s[i]:
		work.append(i)
		i+=c+1
	else:
		i+=1
#print(work)

for day in work:
	s0=s[:]
	s0[day]=False
	i=0
	cnt=0
	while i<n:
		if s0[i]:
			i+=c+1
			cnt+=1
		else:
			i+=1
	if cnt<k:
		print(day+1)

### FIXED CODE ###

n,k,c=map(int,input().split())
s=list(input())
for i in range(len(s)):
	if s[i]=="o":
		s[i]=True
	else:
		s[i]=False
i=0
work1=[]
while len(work1)<k:
	if s[i]:
		work1.append(i)
		i+=c+1
	else:
		i+=1
i=n-1
work2=[]
while len(work2)<k:
	if s[i]:
		work2.append(i)
		i-=c+1
	else:
		i-=1
work2.sort()
for i in range(k):
	if work1[i]==work2[i]:
		print(work1[i]+1)
### BUGGY CODE ###

# encoding:utf-8

def main():
	N = int(input())
	cards = list(map(int, input().split()))

	if N == 2:
		print(abs(cards[0] - cards[1]))
	else:
		print(min([abs(calcDif(cards, x)) for x in range(1, N - 1)]))


def calcDif(cards, k):
	# k >= 1
	#print(k)
	x = cards[:k]
	y = cards[k:len(cards)]
	return(sum(x) - sum(y))

if __name__ == '__main__':
	main()

### FIXED CODE ###

# encoding:utf-8

def main():
	N = int(input())
	cards = list(map(int, input().split()))

	x = cards[0]
	y = sum(cards[1:])
	i = 1
	val = abs(x - y)

	while i < len(cards) - 1:
		x += cards[i]
		y += -cards[i]
		temp = abs(x - y)
		
		if temp == 0:
			val = 0
			break
		if temp < val:
			val = temp

		i += 1

	print(val)

if __name__ == '__main__':
	main()
### BUGGY CODE ###

n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 0
i = 1
for _ in range(60):
    b = sum(map(lambda x: x & i != 0, a))
    c = n - b
    ans += b * c * i % mod
    i <<= 1
print(ans%mod)


### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
ans = 0
i = 1
for _ in range(60):
    b = 0
    c = 0
    for j in a:
        if j & i != 0:
            b += 1
        else:
            c += 1
    ans += b * c * i % mod
    i *= 2
print(ans%mod)
### BUGGY CODE ###

n = int(raw_input())
 
def f(c):

	cumul = 0
	step = 1
	cc = 0
	while(cumul < c):
		cc +=1
		cumul += step
		step += 1
	if cumul > c: cc -=1
	return cc

d = 2
count = 0
on = n
while(n != 1):
	if n%d==0:
		c = 0
		while(n%d == 0): 
			c += 1
			n /= d
		count += f(c)
	d+=1
print count

### FIXED CODE ###

def f(exponent):
	#reurns how many times a prime raised to exponent can be used
	step = 1
	cumul = 0
	count = 0
	while( cumul <= exponent):
		cumul += step
		count +=1
		step +=1
	return count - (1 if cumul > exponent else 0)

def answer(n):
	if n == 1: return 0
	res = 0
	on = n
	p = True
	for d in range(2, int(on ** 0.5) + 2):
		if n % d == 0:
			p = False
			e = 0
			while(n%d == 0): 
				e +=1
				n/=d
			res+= f(e)
	if n > 1: res += 1
	return res

print answer(int(raw_input()))
### BUGGY CODE ###

import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


def bg(n:int):
    
    if n == 0:
        yield 'P'
        
    else:
        yield 'B'
        
        gen = bg(n-1)
        while True:
            try:
                yield next(gen)
            except:
                break

        
        yield 'P'
        
        gen = bg(n-1)
        while True:
            try:
                yield next(gen)
            except:
                break
        
        yield 'B'
        

n,x = li()

cnt = 0
ans = 0

s = bg(n)
while True:
    try:
        char = next(s)
        if char == 'P' and cnt < x:
            ans += 1
            
        cnt += 1
    except:
        break
            
print(ans)

### FIXED CODE ###

import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

a = [1]
p = [1]
for _ in range(51):
    a.append(3 + 2*a[-1])
    p.append(1 + 2*p[-1])

def burger(level: int, x: int):
    if level == 0:
        if x <= 0:
            return 0
        else:
            return 1
    
    if x == 1:
        return 0
    
    elif 1 < x <= 1+a[level-1]:
        return burger(level-1, x-1)
    
    elif x == 2+a[level-1]:
        return p[level-1] + 1
    
    elif 2+a[level-1] < x <= 2+2*a[level-1]:
        return p[level-1] + 1 + burger(level-1, x-1-a[level-1]-1)
    
    elif x == 3+2*a[level-1]:
        return 2*p[level-1] + 1
    
n,x = li()    
print(burger(n,x))
### BUGGY CODE ###

from fractions import gcd
MOD = 10 ** 9 + 7


def lcm(a, b):
    """
    aとbの最小公倍数を計算します。
    """
    return a * b // gcd(a, b)


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

l = A[0]
for i in range(1, N):
    l = lcm(l, A[i])

ans = 0
for a in A:
    Bi = l // a
    ans += Bi
    ans %= MOD
print(ans)

### FIXED CODE ###

from fractions import gcd
import sys
input = sys.stdin.readline
MOD = 10 ** 9 + 7


def main():
    N = int(input())
    A = list(map(int, input().split()))

    l = A[0]
    for i in range(1, N):
        l = l * A[i] // gcd(l, A[i])

    print(sum([l // a for a in A]) % MOD)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

from heapq import heappush, heappop
import sys
input = sys.stdin.readline

h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
x1 -= 1
y1 -= 1
x2 -= 1
y2 -= 1
c = [tuple(input()) for _ in range(h)]
# print(x1, y1)
# print(x2, y2)

dx = [+1, 0, -1, 0]
dy = [0, +1, 0, -1]
MAX = 10**7


def convert(x, y, d):
    return (x * w + y) * 4 + d


# dp = [[[(MAX, MAX)] * 4 for _ in range(w)] for _ in range(h)]
dp = [(MAX, MAX)] * (h * w * 4)

# q = [((1, 0, x1, y1, i)) for i in range(4)]
q = [((1, 0, convert(x1, y1, i))) for i in range(4)]

while q:
    c1, c2, xyd = heappop(q)
    # print(x, y, d, c1, c2)
    d = xyd % 4
    y = (xyd // 4) % w
    x = (xyd // 4) // w
    if c1 > dp[xyd][0]:
        continue
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        nxyi = convert(nx, ny, i)
        if nx < 0 or nx >= h or ny < 0 or ny >= w:
            continue
        if c[nx][ny] == '@':
            continue
        if i == d and c2 < k:
            if dp[nxyi] > (c1, c2 + 1):
                dp[nxyi] = (c1, c2 + 1)
                heappush(q, (c1, c2 + 1, nxyi))
        else:
            if dp[nxyi] > (c1 + 1, 1):
                dp[nxyi] = (c1 + 1, 1)
                heappush(q, (c1 + 1, 1, nxyi))

ans = min(dp[convert(x2, y2, i)][0] for i in range(4))
if ans == MAX:
    ans = -1
print(ans)


### FIXED CODE ###

from heapq import heappush, heappop
import sys
input = sys.stdin.readline

h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
x1 -= 1
y1 -= 1
x2 -= 1
y2 -= 1
c_ = [tuple(input()) for _ in range(h)]
c = [[False] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if c_[i][j] == '@':
            c[i][j] = True
# print(x1, y1)
# print(x2, y2)

dx = [+1, 0, -1, 0]
dy = [0, +1, 0, -1]
MAX = 10**7


def convert(x, y, d):
    return (x * w + y) * 4 + d


# dp = [[[(MAX, MAX)] * 4 for _ in range(w)] for _ in range(h)]
dp = [MAX * (k + 1) + k] * (h * w * 4)

# q = [((1, 0, x1, y1, i)) for i in range(4)]
q = [((k + 1, convert(x1, y1, i))) for i in range(4)]

while q:
    c0, xyd = heappop(q)
    c1 = c0 // (k + 1)
    c2 = c0 % (k + 1)
    # print(x, y, d, c1, c2)
    d = xyd % 4
    y = (xyd // 4) % w
    x = (xyd // 4) // w
    if c1 > dp[xyd] // (k + 1):
        continue
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        nxyi = convert(nx, ny, i)
        if nx < 0 or nx >= h or ny < 0 or ny >= w:
            continue
        if c[nx][ny]:
            continue
        if i == d and c2 < k:
            if dp[nxyi] > c1 * (k + 1) + c2 + 1:
                dp[nxyi] = c1 * (k + 1) + c2 + 1
                heappush(q, (dp[nxyi], nxyi))
        else:
            if dp[nxyi] > (c1 + 1) * (k + 1) + 1:
                dp[nxyi] = (c1 + 1) * (k + 1) + 1
                heappush(q, (dp[nxyi], nxyi))

ans = min(dp[convert(x2, y2, i)] // (k + 1) for i in range(4))
if ans == MAX:
    ans = -1
print(ans)
### BUGGY CODE ###

import bisect
n,m = map(int,input().split())
A = [-int(i)for i in input().split()]
A.sort()
for _ in range(m):
    a = -((-A.pop(0)) //2)
    A.insert(bisect.bisect_left(A,a),a)
print(-sum(A))

### FIXED CODE ###

import heapq

N , M = map(int,input().split())
A = [-int(i) for i in input().split()]
heapq.heapify(A)
for _ in range(M):
    a = -heapq.heappop(A) >> 1
    heapq.heappush(A,-a)
print(-sum(A))
### BUGGY CODE ###

import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
from collections import defaultdict

MOD = 10 ** 9 + 7

N,K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

C = []

s = 0
ma = 0
for i in range(0,N-1):
    for j in range(i, N):
        if j==i:
            C.append(A[i])
        else:
            C.append(C[-1] + A[j])
    ma = max(ma, max(C))

IDX = 0
while ((1 << IDX) < ma):
    IDX += 1


def filterList(list, i):
    retList = []
    for l in list:
        if l & (1 << i):
            retList.append(l)
    return retList

D = C
for i in range(IDX,-1,-1):
    newD = filterList(D,i)
    if len(newD) < K:
        break
    else:
        D = newD


EE = list(itertools.combinations(D, K))

ret = 0
for E in EE:
    r = E[0]
    for e in E:
        r = r & e
    ret = max(ret, r)


print(ret)

sys.exit(0)


### FIXED CODE ###

import sys

N,K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

C = []

for i in range(0,N-1):
    for j in range(i, N):
        if j==i:
            C.append(A[i])
        else:
            C.append(C[-1] + A[j])

D = C
ans = 0
for i in range(40,-1,-1):
    yes = []
    no = []
    for l in D:
        if l & (1 << i):
            yes.append(l)
        else:
            no.append(l)

    if len(yes) >= K:
        ans += 1 << i
        D = yes

print(ans)

sys.exit(0)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
sum = 0
mod = 10**9+7
for i in range(n):
  for j in range(i+1, n):
    sum += a[i]*a[j]
print(sum%mod)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
S = sum(a)
S2 = sum(map(lambda x:x*x, a))
print((S*S-S2)//2%mod)
### BUGGY CODE ###

K,S = map(int,input().split())
print(sum([i+j+k==S  for i in range(0,K+1) for j in range(0,K+1) for k in range(0,K+1)]))

    

    

### FIXED CODE ###

k, s = map(int, input().split())
count = 0
for x in range(k + 1):
    for y in range(k + 1):
        z = s - x - y
        if 0 <= z <= k:
            count += 1
print(count)
### BUGGY CODE ###

from collections import deque

import sys
input = sys.stdin.readline


n = int(input())
a_list = {i:None for i in range(n)}
num = 0
day = 0
for i in range(n):
    a_list[i] = deque([int(i) - 1 for i in input().split()])

for kkk in range(n * (n - 1) // 2):
    visit = set([])
    day += 1
    for j in range(n):
        if j not in visit:
            if len(a_list[j]) > 0:
                k = a_list[j][0]
                if k > j:
                    if k not in visit:
                        if a_list[k][0] == j:
                            num += 1
                            visit.add(a_list[j].popleft())
                            visit.add(a_list[k].popleft())
                        if num >= n * (n - 1) // 2:
                            print(day)
                            exit()
    if (len(visit) == 0):
        print(-1)
        exit()
    if num >= n * (n - 1) // 2:
        print(day)
        exit()


### FIXED CODE ###

from collections import deque
n = int(input())
a_list = []
for i in range(n):
    a_list.append(deque([int(aa) - 1 for aa in input().split()]))
day = 0
battle = 0
for _ in range(n * (n - 1) // 2):
    if battle == n * (n - 1) // 2:
        break
    day += 1
    battle_today = 0
    tomorrow = set([])
    if (day == 1):
        player = set([i for i in range(n)])
    for i in player:
        if len(a_list[i]) == 0:
            continue
        j = a_list[i][0]
        if (i == a_list[j][0]) & (j not in tomorrow) & (len(a_list[j]) > 0) & (i not in tomorrow):
            tomorrow.add(i)
            tomorrow.add(a_list[i][0])
            battle += 1
            battle_today += 1
            a_list[i].popleft()
            a_list[j].popleft()
    player = tomorrow
    if battle_today == 0:
        day = -1
        break
print(day)
### BUGGY CODE ###

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

li = [0]*(n+2)
lis = []
lis2 =[0]*(3*n)
lis2[1]=1

for i in range(k):
    l,r = map(int, input().split())
    for j in range(l,r+1):
        lis.append(j)

for i in range(1,n+1):
    for j in lis:
        lis2[i]%=998244353
        lis2[i+j]+=lis2[i]

print(lis2[n])


### FIXED CODE ###

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

li = [0]*(n+2)
lis = []
lr=[]
lis2 =[0]*(3*n)
lis2[1]=1
lis2[2]=-1

for i in range(k):
    l,r = map(int, input().split())
    lr.append((l,r))

for i in range(1,n+1):
    lis2[i]+=lis2[i-1]
    lis2[i]%=998244353

    for j,k in lr:
        lis2[i+j]+=lis2[i]
        lis2[i+k+1]-=lis2[i]

print(lis2[n]%998244353)
### BUGGY CODE ###

import itertools
import numpy as np
import math

def main():
    N = int(input())

    coordinate = []
    for _ in range(N):
        x, y = map(int, input().split())
        coordinate.append((x, y))

    path = [i for i in range(N)]
    sum = 0

    for i in itertools.permutations(path):
        v_1 = np.array(coordinate[i[0]])
        for j in range(1, len(i)):
            v_2 = np.array(coordinate[i[j]])
            sum += np.linalg.norm(v_1 - v_2)
            #print(np.linalg.norm(v_1 - v_2))
            v_1 = v_2


    print(sum/math.factorial(N))
    return 0
if __name__ == '__main__':
    main()

### FIXED CODE ###

import itertools
import numpy as np
import math

def main():
    N = int(input())

    coordinate = []
    for _ in range(N):
        coordinate.append(tuple(map(int, input().split())))

    distance = [[None]*N for _ in range(N)]

    for i in range(N):
        x1, y1 = coordinate[i]
        for j in range(N):
            x2, y2 = coordinate[j]
            distance[i][j] = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)

    C = [i for i in range(N)]

    sum = 0
    for c in itertools.permutations(C):
        c_1 = c[0]
        for j in range(1, len(c)):
            c_2 = c[j]
            sum += distance[c_1][c_2]
            c_1 = c_2
    print(sum/math.factorial(N))

    return 0
if __name__ == '__main__':
    main()
### BUGGY CODE ###

from collections import Counter

def main():
    s = list(map(int,input()[::-1]))

    t = []
    m = 0
    for i,s_i in enumerate(s):
        m = m+s_i*10**i
        t.append(m%2019)
    
    c = Counter(t)
    ans = c[0]
    for i in c.values():

        ans += i*(i-1)//2
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

from collections import Counter

def main():
    s = list(map(int,input()[::-1]))

    t = []
    m = 0
    for i,s_i in enumerate(s):
        m = m+s_i*pow(10,i,2019)
        t.append(m%2019)
    
    c = Counter(t)
    ans = c[0]
    for i in c.values():

        ans += i*(i-1)//2
    print(ans)

if __name__ == "__main__":
    main()
### BUGGY CODE ###

import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    R, C, K = read_values()
    V2 = [0] * (R * C)
    for _ in range(K):
        r, c, v = read_values()
        r -= 1
        c -= 1
        V2[r * C + c] = v
    
    dp = [[V(max, 0) for _ in range(4)] for _ in range(R * C)]
    for i in range(R * C):
        r = i // C
        c = i % C
        if c + 1 < C:
            # not take
            for k in range(4):
                dp[i + 1][k].ud(dp[i][k].v)

            # take 
            for k in range(3):
                dp[i + 1][k + 1].ud(dp[i][k].v + V2[i])

        # next r
        if r + 1 < R:
            for k in range(3):
                dp[i + C][0].ud(dp[i][k].v + V2[i])
            dp[i + C][0].ud(dp[i][3].v)

    print(max(k.v + (V2[-1] if i  < 3 else 0) for i, k in enumerate(dp[-1])))


if __name__ == "__main__":
    main()



### FIXED CODE ###

import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    R, C, K = read_values()
    V = [0] * (R * C)
    for _ in range(K):
        r, c, v = read_values()
        r -= 1
        c -= 1
        V[r * C + c] = v
    
    dp = [0 for _ in range(R * C * 4)]
    for i in range(R * C):
        r = i // C
        c = i % C
        if c + 1 < C:
            # not take
            for k in range(4):
                dp[4 * (i + 1) + k] = max(dp[4 * (i + 1) + k], dp[4 * i + k])

            # take 
            for k in range(3):
                dp[4 * (i + 1) + k + 1] = max(dp[4 * (i + 1) + k + 1], dp[4 * i + k] + V[i])

        # next r
        if r + 1 < R:
            for k in range(4):
                dp[4 * (i + C)] = max(dp[4 * (i + C)], dp[4 * i + k] + (V[i] if k < 3 else 0))

    res = 0
    for k in range(4):
        res = max(res, dp[4 * (R * C - 1) + k] + (V[-1] if k < 3 else 0))

    print(res)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

S = int(input())
#S = 3600
count = 0

for i in range(S):
    ss = [int(x) for x in list(str(i+1))]
    
    if list(set(ss)) == [3,5,7]:
        count = count + 1

print(count)


### FIXED CODE ###

import numpy as np

S = int(input())
count = 0

dim = len(str(S))

box = np.zeros(([4]*dim),dtype='int64')

for j in range(dim):
    for i in range(4):
        I = [slice(None)]*box.ndim
        I[j] = i
        if i == 0:
            None
        else:
            box[tuple(I)]+= (i*2+1)*10**j

box = box.reshape(4**dim)

for i in np.sort(box).tolist():
    ss = [int(x) for x in list(str(i))]

    if i > S:
        break

    if list(set(ss)) == [3, 5, 7]:

        count = count + 1
print(count)
### BUGGY CODE ###

n = int(input())

result_num = 0
words = []
for i in range(n):
  word = sorted(str(input()))
  for word_ in words:
    if word == word_:
      result_num += 1
  words.append(word)
  
print(result_num)

### FIXED CODE ###

n = int(input())

result_num = 0
count_dict = {''.join(sorted(str(input()))): 1}

for i in range(n-1):
  word = ''.join(sorted(str(input())))

  if word in count_dict.keys():
    result_num += count_dict[word]
    count_dict[word] += 1
  else:
    count_dict[word] = 1

print(result_num)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
ans = 1
for i in range(n):
    ans *= a[i]
if ans > 10**18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
#print(a)
ans = 1
if a.count(0):
    print(0)
    exit()
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)
### BUGGY CODE ###

N,K=map(int,input().split())
if(N<K):
  K=N
h=list(map(int,input().split()))
dp=[10000000000 for i in range(N)]
dp[0]=0
for i in range(1,N):
  for j in range(K+1):
    dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[N-1])                      
                      
                      
                  

### FIXED CODE ###

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