Harryxun/stf_run huggingface dataset:
H, W = map(int, input().split())
lis=[["."]*(W+2)]
for i in range(H):
    lis+=[["."]+list(input())+["."]]
lis += [["."]*(W+2)]
for w in range(1, H+1):
    for h in range(1, W+1):
        x=0
        if lis[h][w] == ".":
            if lis[h+1][w-1] == "#":
                x += 1
            if lis[h+1][w] == "#":
                x += 1
            if lis[h+1][w+1] == "#":
                x += 1
            if lis[h][w-1] == "#":
                x += 1
            if lis[h][w+1] == "#":
                x += 1
            if lis[h-1][w-1] == "#":
                x += 1
            if lis[h-1][w] == "#":
                x += 1
            if lis[h-1][w+1] == "#":
                x += 1
            lis[h][w] = x
lis=lis[1:-1]
for i in lis:
    print(*i[1:-1], sep="")

### FIXED CODE ###

h, w = map(int, input().split())
S=[]
S.append(["."] * (w + 2))
for i in range(h):
  S.append(["."] + list(input()) + ["."])
S.append(["."] * (w + 2))
 
 
for i in range(1, h+1):
  for j in range(1, w+1):
    counter = 0
    if S[i][j] == ".":
      if S[i-1][j-1] == "#":
        counter += 1
      if S[i-1][j] == "#":
        counter += 1
      if S[i-1][j+1] == "#":
        counter += 1
      if S[i][j-1] == "#":
        counter += 1
      if S[i][j+1] == "#":
        counter += 1
      if S[i+1][j-1] == "#":
        counter += 1
      if S[i+1][j] == "#":
        counter += 1
      if S[i+1][j+1] == "#":
        counter += 1
      S[i][j] = counter
 
for i in range(1,h+1):
  for j in range(1, w+1):
    print(S[i][j], end="")
  print()
N = int(input())
l1 = input()
l2 = input()
result_f=[3,6]
result_g=[3,6]

def f(N, l1, l2):
    if N==1:
        return 3
    if N==2:
        return 6
    else:
        if l1[len(l1)-1]==l2[len(l2)-1]:
            if l1[len(l1)-2]==l2[len(l2)-2]:
                l1 = l1[:len(l1)-3]
                l2 = l2[:len(l2)-3]
                return f(N-1, l1, l2)*2
            else:
                l1 = l1[:len(l1)-2]
                l2 = l2[:len(l2)-2]
                return g(N-1, l1, l2)
        else:
            return g(N, l1, l2)

def g(N, l1, l2):
    if N==1:
        return 3
    if N==2:
        return 6
    if N==3:
        return 6
    else:
        if l1[len(l1)-1]!=l2[len(l2)-1]:
            if l1[len(l1)-3]==l2[len(l2)-3]:
                l1 = l1[:len(l1)-3]
                l2 = l2[:len(l2)-3]
                return f(N-2, l1, l2)*2
            else:
                l1 = l1[:len(l1)-3]
                l2 = l2[:len(l2)-3]
                return g(N-2, l1, l2)*3
        else:
            return f(N, l1, l2)

print(f(N, l1, l2)%1000000007)


### FIXED CODE ###

N = int(input())
s1 = input()
s2 = input()
sum = 1
mul = 1
flag = 0
i = 0

while True:
    if i >= N:
        print(sum%1000000007)
        break

    elif s1[i]==s2[i] and flag==0:
        sum = 3
        i += 1
        flag = 1
    elif s1[i]!=s2[i] and flag==0:
        sum = 6
        i += 2
        flag = 2
    elif s1[i]==s2[i] and flag==1:
        mul = 2
        i += 1
        flag = 1
    elif s1[i]!=s2[i] and flag==1:
        mul = 2
        i += 2
        flag = 2
    elif s1[i]==s2[i] and flag==2:
        mul = 1
        i += 1
        flag = 1
    elif s1[i]!=s2[i] and flag==2:
        mul = 3
        i += 2
        flag = 2
    sum = sum*mul
from math import sqrt, log, pow
num = [i**5 for i in range(-1, 150)]
c = 0
def solve(X):
    for i in range(len(num)):
        a = num[i]
        for j in range(i+1):
            if a - num[j] == X:
                x, y = i-1, j-1
                # print(i-1, j-1)
                assert x**5-y**5 == X
                return x, y
print(*solve(int(input())))


### FIXED CODE ###

num = [i**5 for i in range(-121, 121)]
X = int(input())
for i in range(len(num)):
    a = num[i]
    for j in range(i+1):
        if a - num[j] == X:
            print(i-121, j-121)
            exit()
N=int(input())
A=map(str,input().split())
if P in N and W in N and Y in N and G in N:
  print("Four")
else:
  print("Three")

### FIXED CODE ###

input()
A=map(str,input().split())
if len(set(A))==4:
  print("Four")
else:
  print("Three")
def m():
    a, b, n = map(int, input().split())

    def calc(x):
        return int((a * x) / b) - (a * int(x / b))

    if calc(1) < calc(n // 2):
        return max([calc(i) for i in range(n // 2, n + 1)])
    else:
        return max([calc(i) for i in range(1, n // 2 + 1)])


print(m())


### FIXED CODE ###

def m():
    a, b, n = map(int, input().split())

    def calc(x):
        return int((a * x) / b) - (a * int(x / b))

    return calc(min(n, b-1))

print(m())
S = list(map(int, list(input())))
N = len(S)

dp = [[0]*N for i in range(N)]
if N < 4:
    print(0)
    exit(0)

D = [[0]*N for i in range(9)]
for i in range(9):
    D[i][i] = (i+1)
    for j in range(i+1, N):
        D[i][j] = D[i][j-1]*10 % 2019


print(D)
ans = 0

dp[0] = S[0]
for i in range(1, N):
    dp[i] = (dp[i-1]*10 + S[i]) % 2019
    if dp[i] == 0:
        ans += 1

for i in range(1, N):
    for j in range(i+1, N):
        dp[i] -= D[S[i-1]][j]
        dp[i] %= 2019
        if dp[i] == 0:
            ans += 1

# print(N)
# print(*dp, sep='\n')
print(ans)


### FIXED CODE ###

import collections
S = list(map(int, list(input())))
N = len(S)

dp = [0]*N
if N < 4:
    print(0)
    exit(0)

ans = 0

D = [0]*N
D[0] = 1
for i in range(1, N):
    D[i] = D[i-1]*10 % 2019
t = collections.defaultdict(int)
tmp = 0

t[0] += 1
for i in range(N):
    tmp += S[N-1-i]*D[i]
    tmp %= 2019
    t[tmp] += 1

for x in t:
    ans += t[x]*(t[x]-1) // 2

# print(N)
# print(*dp, sep='\n')

print(ans)
length0 = input()
#print(length0)
length = length0.split()
a = int(length[0])
b = int(length[1])
#print(str(a)+" "+str(b))
area = a*b
per = 2*a+2*b
print(str(area)+" "+str(per))


### FIXED CODE ###

length0 = input()
#print(length0)
length = length0.split()
a = int(length[0])
b = int(length[1])
#print(str(a)+" "+str(b))
area = a*b
per = 2*a+2*b
print(str(area)+" "+str(per))
import sys
sys.setrecursionlimit(1000000000000)



def create_field(H, W):
    field = []
    for i in xrange(H):
        raw = []
        for j in xrange(W):
            raw.append(1)
        field.append(raw)
    return field


print 0

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000000)


def main():
    solve()


def solve():
    for data in get_dataset():
        print search(data)


def search(data):
    count = 0
    H = len(data)
    W = len(data[0])
    for i in xrange(H):
        for j in xrange(W):
            if data[i][j] == '.':
                continue
            _search(i, j, H, W, data[i][j], data)
            count += 1
    return count


def _search(i, j, H, W, cell, data):
    data[i][j] = '.'
    for a in xrange(i-1, i+2):
        if not -1 < a < H:
            continue
        for b in xrange(j-1, j+2):
            if not -1 < b < W:
                continue

            if a != i and b != j:
                continue

            if data[a][b] == '.':
                continue

            if cell == data[a][b]:
                _search(a, b, H, W, cell, data)
    return


def get_dataset():
    dataset = []
    while True:
        line = raw_input().rstrip().split()
        H = int(line[0])
        if H == 0:
            break

        data = []
        for i in xrange(H):
            data.append(list(raw_input().rstrip()))
        dataset.append(data)
    return dataset


if __name__ == '__main__':
    main()
N = int(input())
ans = 0
for i in range(N):
  a, b = input().split()
  if b = 'JPY':
    ans += int(a)
  else:
    ans += int(a)*380000
print(ans)

### FIXED CODE ###

N = int(input())
ans = 0.0
for i in range(N):
  a, b = input().split()
  if b == 'JPY':
    ans += float(a)
  else:
    ans += float(a)*380000
print(ans)
X=int(input())
li=[x**p for x in range(2,32) for p in range(2,35) if x**p<=X]
print(max(li))

### FIXED CODE ###

X=int(input())
li=[x**p for x in range(1,32) for p in range(2,35) if x**p<=X]
print(max(li))
from itertools import product


def makelist(BIT):
    LIST, tmp = [], s[0]
    for i, bi in enumerate(BIT, 1):
        if bi == 1:
            LIST.append(tmp)
            tmp = s[i]
        elif bi == 0:
            tmp = [p + q for p, q in zip(tmp, s[i])]
    else:
        LIST.append(tmp)
    return LIST


def solve(LIST):
    CNT, tmp = 0, [l[0] for l in LIST]
    for i in range(1, w):
        cal = [tmp[j] + LIST[j][i] for j in range(len(LIST))]
        if any(num > k for num in cal):
            CNT += 1
            tmp = [l[i] for l in LIST]
        else:
            tmp = cal
    return CNT


h, w, k = map(int, input().split())
s = [[int(sij) for sij in input()] for _ in range(h)]

for bit in product([0, 1], repeat=(h - 1)):
    numlist = makelist(bit)
    ans = min(ans, solve(numlist) + sum(bit))
print(ans)


### FIXED CODE ###

from itertools import product


def makelist(BIT):
    LIST, tmp = [], s[0]
    for i, bi in enumerate(BIT, 1):
        if bi == 1:
            LIST.append(tmp)
            tmp = s[i]
        elif bi == 0:
            tmp = [p + q for p, q in zip(tmp, s[i])]
    else:
        LIST.append(tmp)
    return LIST


def solve(LIST):
    CNT, tmp = 0, [l[0] for l in LIST]
    if any(num > k for num in tmp):
        return h * w
    for i in range(1, w):
        cal = [tmp[j] + LIST[j][i] for j in range(len(LIST))]
        if any(num > k for num in cal):
            CNT += 1
            tmp = [l[i] for l in LIST]
        else:
            tmp = cal
    return CNT


h, w, k = map(int, input().split())
s = [[int(sij) for sij in input()] for _ in range(h)]

ans = h * w
for bit in product([0, 1], repeat=(h - 1)):
    numlist = makelist(bit)
    ans = min(ans, solve(numlist) + sum(bit))
print(ans)
import numpy as np

n = int(input())
a = [int(input()) for _ in range(n)]

cnt = 0
while sum(a%2) == 0:
    cnt += 1
    a = a//2
print(cnt)

### FIXED CODE ###

import numpy as np

n = int(input())
a = np.array([int(x) for x in input().split()])

cnt = 0
while sum(a%2) == 0:
    cnt += 1
    a = a//2
print(cnt)
import math as m
from functools import reduce

n=int(input())
l=set([])
def f(a,b):
    return int(a*b/m.gcd(a,b))
for i in range(n):
    l.add(int(input()))
print(reduce(f,l))










### FIXED CODE ###

import math as m
from functools import reduce
n,T= int(input()),[]
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
for i in range(n):
    T.append(int(input()))
tmp = max(T)
for i in range(n):
    if tmp % T[i] != 0:
        tmp = T[i]//gcd(tmp, T[i])*tmp

print(tmp)
N,M = map(int, input().split())
X = [ [int(j) for j in input().split()] for _ in range(N)]
ans = 0
for i in range(1<<3):
    if M=0:
        break
    dp = [ [0] * (M+1) for _ in range(N+1)]
 
    for n in range(0,N):
        x,y,z = X[n]
        s = (x if (i & (1<<2)) else -x) \
            + (y if (i & (1<<1)) else -y) \
            + (z if (i & (1<<0)) else -z) \
 
        for m in range(min(n,M-1), -1, -1 ):
            dp[n+1][m+1] =  max(dp[n+1][m+1], s + dp[n][m] )
            dp[n+1][m]   =  max(dp[n+1][m], dp[n][m])
 
        dp[n+1][M] = max(dp[n+1][M], dp[n][M])
    ans = max(ans, dp[N][M])
print(ans)

### FIXED CODE ###

N,M = map(int, input().split())
X = [ [int(j) for j in input().split()] for _ in range(N)]
ans = 0
for i in range(1<<3):
    if M==0:
        break
    ss = [None]*N

    for n in range(0,N):
        x,y,z = X[n]
        s = (x if (i & (1<<2)) else -x) \
            + (y if (i & (1<<1)) else -y) \
            + (z if (i & (1<<0)) else -z)
        ss[n] = s
    ss.sort()
    ans = max(ans, sum(ss[N-M:]))
print(ans)
s, t = input().strip().split()
if s == t[:-1]:
  print("Yes")
else:
  print("No")


### FIXED CODE ###

s = input().strip()
t = input().strip()
if s == t[:-1]:
  print("Yes")
else:
  print("No")
N = int(input())
s = [int(input()) for i in range(N)]
sums = sum(s)
others = filter(lambda x: x% 10, s)
if sums % 10:
    print(sums)
elif others:
    print(sums-min(others))
else:
    print(0)

### FIXED CODE ###

N = int(input())
s = [int(input()) for i in range(N)]
sums = sum(s)
others = list(filter(lambda x: x % 10, s))
if sums % 10:
    print(sums)
elif others != []:
    print(sums-min(others))
else:
    print(0)
import math

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

A, B = list(map(int, input().split(' ')))
maxKouyaku = math.gcd(A, B)
#print(maxKouyaku)
if maxKouyaku == 1:
    print(1)
else:
    print(len(factorization(maxKouyaku)) + 1)

### FIXED CODE ###

import fractions

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

A, B = list(map(int, input().split(' ')))
maxKouyaku = fractions.gcd(A, B)
#print(maxKouyaku)
#print(*factorization(maxKouyaku))
if maxKouyaku == 1:
    print(1)
else:
    print(len(factorization(maxKouyaku)) + 1)
n = int(input())

table = [0] * 1001

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            k = (x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x)
            if k < 1001:
                table[k] += 1

for i in range(1, n + 1):
    print(table[i])


### FIXED CODE ###

import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def checker():
    ans = [0] * 10001
    for a in range(1, 101):
        for b in range(1, 101):
            for c in range(1, 101):
                n = a * a + b * b + c * c + a * b + b * c + c * a
                if n > 10000:
                    continue
                else:
                    ans[n] += 1
    return ans


def main():
    N = int(input().strip())
    ans = checker()
    for n in range(1, N + 1):
        print(ans[n])
    return


if __name__ == "__main__":
    main()
H,W = map(int, input().split())
A = [input() for _ in range(H)]
HMANY = [ [10**9] * W for _ in range(H)]


def dfs(h,w,A,HMANY, num,H,W):
    if not ( 0<= h < H and 0 <= w < W) : 
        return

    if HMANY[h][w] > num:
        HMANY[h][w] = num  

        if 0 <= h-1 :
            dfs(h-1,w,A,HMANY,num+1 ,H,W)
        if h+1 < H:
            dfs(h+1,w,A,HMANY,num+1 ,H,W)
        if w+1 < W:
            dfs(h,w+1,A,HMANY,num+1 ,H,W)
        if 0<=w-1:
            dfs(h,w-1,A,HMANY,num+1 ,H,W)

for h in range(H):
    for w in range(W):
        if A[h][w] == "#":
            dfs(h,w, A,HMANY, 0, H,W)

ans = 0
for h in range(H):
    ans = max(ans, max(HMANY[h]))
    # ans = max(ans, HMANY[h][w])
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
from collections import deque
from heapq import heappush, heappop
def solve():
    H,W = map(int, input().split())
    A = [ list(input()) for _ in range(H)]
    HMANY = [ [10**9] * W for _ in range(H)]

    
    
    # q = deque()
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#" :
                HMANY[h][w] = 0
    for w in range(W):
        for h in range(H-1):
            if HMANY[h][w]+1 < HMANY[h+1][w]:
                HMANY[h+1][w] = HMANY[h][w] + 1
        for h in range(H-1, 0, -1):
            if HMANY[h][w]+1 < HMANY[h-1][w]:
                HMANY[h-1][w] = HMANY[h][w] + 1
    
    for h in range(H):
        for w in range(W-1):
            if HMANY[h][w]+1 < HMANY[h][w+1]:
                HMANY[h][w+1] = HMANY[h][w] + 1
        for w in range(W-1, 0, -1):
            if HMANY[h][w]+1 < HMANY[h][w-1]:
                HMANY[h][w-1] = HMANY[h][w] + 1        
    #             q.append((h,w))
    #             A[h][w] = "."
    # ans = 0
    # while q:
    #     nextQ = deque()
    #     for h,w in q:
    #         A[h][w] = "#"
    #         if h+1 <H and A[h+1][w] == ".":
    #             nextQ.append( (h+1,w))
    #         if w+1 <W and A[h][w+1] == ".":
    #             nextQ.append((h,w+1))
    #         if 0<=h-1 and A[h-1][w] == ".":
    #             nextQ.append((h-1,w))
    #         if 0<=w-1 and A[h][w-1] == ".":
    #             nextQ.append((h,w-1))        
    #     ans += 1
    #     q = nextQ
        # num,h,w = q.popleft()        
        # if HMANY[h][w] > num and A[h][w] == ".":
        #     HMANY[h][w] = num
        #     A[h][w] = "#"
        #     if h+1 <H and A[h+1][w] == ".":
        #         q.append( (num+1,h+1,w))
        #     if w+1 <W and A[h][w+1] == ".":
        #         q.append((num+1,h,w+1))
        #     if 0<=h-1 and A[h-1][w] == ".":
        #         q.append((num+1,h-1,w))
        #     if 0<=w-1 and A[h][w-1] == ".":
        #         q.append((num+1,h,w-1))

    ans = 0
    for h in range(H):
        ans = max(ans, max(HMANY[h]))
    # print(ans-1)
    print(ans)

if __name__ == "__main__":
    solve()
import sys
input = sys.stdin.readline
from scipy.optimize import linear_sum_assignment
import numpy as np

N = int(input())
AB = [[int(x) for x in input().split()] for _ in range(N)]
CD = [[int(x) for x in input().split()] for _ in range(N)]

mat = np.zeros((N,N),dtype=np.int32)

for i,(a,b) in enumerate(AB):
    for j,(c,d) in enumerate(CD):
        if a<c and b<d:
            mat[i,j] -= 1


I,J = linear_sum_assignment(mat)

answer = -mat[I,J].sum()
print(answer)

### FIXED CODE ###

from scipy.sparse.csgraph import dijkstra
# 二部グラフ完全マッチング
# 最大フロー
N = int(input())
NN = N * 2
XY = [[int(x) for x in input().split()] for _ in range(NN)]
graph = [[0] * (NN+2) for _ in range(NN+2)]
start = NN
goal = NN+1

for i,(a,b) in enumerate(XY[:N]):
  for j,(c,d) in enumerate(XY[N:], N):
    if a < c and b < d:
      graph[i][j] = 1

for i in range(N):
  graph[start][i] = 1
for i in range(N,NN):
  graph[i][goal] = 1
  
INF = 10 ** 9

def max_flow(graph):
  dist, pred = dijkstra(graph, indices = start, return_predecessors = True)
  if dist[goal] > INF:
    return 0
  y = goal
  while y != start:
    x = pred[y]
    graph[x][y] -= 1
    graph[y][x] += 1
    y = x
  return 1 + max_flow(graph)

answer = max_flow(graph)
print(answer)
K,N = map(int,input().split())
A = list(map(int,input().split()))

B = [K]*N
for i in range(N):
    B[i] += A[i]
    
C = A+B

for i in range(2*N):
    ans = 2*K
    l = 0
    if i<N:
        for j in range(N-1):
            l += C[i+j+1]-C[i+j]
        if l<ans:
            ans = l
    else:
        for j in range(N-1):
            l += C[i-j]-C[i-j-1]
        if l<ans:
            ans = l
            
print(ans)

### FIXED CODE ###

S = input()

if S[2]==S[3] and S[4]==S[5]:
    print("Yes")
else:
    print("No")
import numpy as np

N, M = map(int, input().split())
P = [None] * (N+1)
Y = [None] * (N+1)
for i in range(M):
    p, y = map(int, input().split())
    P[i] = p
    Y[i] = y
P = np.array(P)
Y = np.array(Y)
PY = np.c_[P, Y]
sort_ind = np.argsort(Y)
PY_sort = PY[sort_ind]
count = [0] * (N+1)
id_list = [None] * (N+1)
for i, py in enumerate(PY_sort):
    count[py[0]] += 1
    id_list[i] = (str(py[0]).zfill(6) + str(count[py[0]]).zfill(6))
id_list = np.array(id_list)
id_list = id_list[np.argsort(sort_ind)]
for city_id in id_list:
    print(city_id)


### FIXED CODE ###

import numpy as np

N, M = map(int, input().split())
P = []
Y = []
for _ in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
P = np.array(P)
Y = np.array(Y)
PY = np.c_[P, Y]
sort_ind = np.argsort(Y)

PY_sort = PY[sort_ind]
count = [0] * (int(1e+5) + 1)
id_list = []
for p, y in PY_sort:
    count[p] += 1
    id_list.append(str(p).zfill(6) + str(count[p]).zfill(6))

id_list = np.array(id_list)
id_list = id_list[np.argsort(sort_ind)]
for city_id in id_list:
    print(city_id)
import sys
from io import StringIO
import unittest

sys.setrecursionlimit(10**5)
def search(n, step, rec, seq, k):
	if rec[n] != -1:
		c = step - rec[n]
		sim = (k - rec[n]) % c
		v = n
		for i in range(sim):
			v = seq[v] - 1
		print(v+1)
		return
	rec[n] = step
	search(seq[n] - 1, step + 1, rec, seq, k)

def resolve():
	n, k = map(int, input().split())
	seq = list(map(int, input().split()))
	rec = [-1]*n
	search(0, 0, rec, seq, k)
resolve()

### FIXED CODE ###

import sys
from io import StringIO
import unittest

sys.setrecursionlimit(10**5*2)

def search(u, n, g, disc, k):
    if disc[u] != None:
        circles = n - disc[u]
        v = (k - disc[u]) % circles
        ans = u
        if n > k:
            ans = 0
            for _ in range(k):
                ans = g[ans]
            return ans + 1
        for i in range(v):
            ans = g[ans]
        return ans + 1
    disc[u] = n
    return search(g[u], n+1, g, disc, k)

def resolve():
    n, k = map(int, input().split())
    g = list(map(lambda x: int(x) - 1, input().split()))
    disc = [None]*n
    v = search(0, 0, g, disc, k)
    print(v)
resolve()
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(i-k,0)
  dp[i] = np.min(dp[s:i]+ np.abs(h[s:i] - h[i]))
  
print(dp[-1])
    

### FIXED CODE ###

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(i-K,0)
  dp[i] = np.min(dp[s:i]+ np.abs(h[s:i] - h[i]))
  
print(dp[-1])
N = int(input())
h_arr = list(map(int, input().split(" ")))
dp = [9999999 for _ in range(N)]
dp[0] = 0

for i in range(1, N):
	if i - 2 >= 0:
    	dp[i] = min(abs(h_arr[i]-h_arr[i-1]) + dp[i-1], abs(h_arr[i]-h_arr[i-2]) + dp[i-2], dp[i])
    elif i - 2 < 0:
    	dp[i] = min(abs(h_arr[i]-h_arr[i-1]) + dp[i-1], dp[i])

print(dp[-1])

### FIXED CODE ###

N = int(input())
h_arr = list(map(int, input().split(" ")))
dp = [9999999 for _ in range(N)]
dp[0] = 0
dp[1] = abs(h_arr[1]-h_arr[0])

for i in range(2, N):
	dp[i] = min(abs(h_arr[i]-h_arr[i-1]) + dp[i-1], abs(h_arr[i]-h_arr[i-2]) + dp[i-2])
		
print(dp[-1])
N , Q = map(int,input().split())

D = [0]*Q
Input = []
length = [-1]*Q

for i in range(N):
    Input.append(list(map(int,input().split())))

# 距離順でソート
dist = lambda A : A[2]
Input.sort(key=dist)

for i in range(Q):
    D[i] = [i,int(input())]

# 出発時刻でソート
time = lambda A : A[1]
D.sort(key=time)

# i番目の人の座標を計算
skip = 0
for start in D:
    for j in range(N):
        if(Input[j][1] <= start[1]): # 工事終了時刻 <= 出発時刻
            Input.pop(j)
            continue

        stopTime = Input[j][2] + start[1] # 出発時刻 + 距離/速度

        if(stopTime >= Input[j][0] - 0.5 and stopTime <= Input[j][1] - 0.5): # 工事期間内
            length[start[0]] = Input[j][2]
            break

for i in range(Q):
    print(length[i])


### FIXED CODE ###

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

N, Q = map(int, input().split())
INF = float('inf')

events = []
for i in range(N):
    S, T, X = map(int, input().split())
    events.append((S - X, 0, X))
    events.append((T - X, 1, X))

for _ in range(Q):
    events.append((int(input()), 2, 0))

events.sort()

cnt = defaultdict(int)
cnt[INF] += 1
que = [INF]

for t, flag, x in events:
    if flag == 0:
        if cnt[x] == 0:
            heappush(que, x)
        cnt[x] += 1
    elif flag == 1:
        cnt[x] -= 1
    else:
        while cnt[que[0]] == 0:
            heappop(que)
        print(que[0] if que[0] != INF else -1)