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

n = int(input())

for i in range(1, n+1):
    cnt = 0
    for x in range(1, 50):
        for y in range(1, 50):
            for z in range(1, 50):
                
                if i == ((x+y+z)**2 - z*(x+y) - (x*y)):
                    cnt += 1

    print(cnt)

### FIXED CODE ###

n = int(input())

ANS = [0] * (n+1)
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            tmp = (x + y + z)**2 - z*(x + y) - (x*y)
            if tmp > n: continue
            ANS[tmp] += 1

for ans in ANS[1:]:
    print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main():
    N = II()
    a_mat = []
    for i in range(N):
        a_mat.append(LI())

    cnt = 0
    first_list = [a_list.pop() for a_list in a_mat]
    while True:
        # この日に試合できる可能性リスト
        # 試合する人リスト
        match_list = []
        for i, a in enumerate(first_list):
            ind = i+1
            # 試合をするペアの要素を入れていく
            if first_list[a-1] == ind:
                match_list.append(i)

        if len(match_list) == 0:
            print(-1)
            return

        # 試合をしたことを反映
        for i in match_list:
            if len(a_mat[i]) == 0:
                first_list[i] = 0
            else:
                first_list[i] = a_mat[i].pop()

        # 一日経過
        cnt += 1

        # 終了判定
        if sum(first_list) == 0:
            break

    print(cnt)


main()

### FIXED CODE ###

import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())


from collections import deque

from copy import copy
#debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)
def main():
    N = II()
    a_mat = []
    for i in range(N):
        a_mat.append(deque(LI()))

    cnt = 0
    first_list = [a_list.popleft() for a_list in a_mat]
    nend = 0
    previous_match_list = list(range(N))
    while True:
        # この日に試合できる可能性リスト
        # 試合する人リスト
        match_list = []
        for i in previous_match_list:
            a_no = first_list[i]
            a = a_no-1
            no = i+1
            # 試合をするペアの要素を入れていく
            if first_list[a] == no:
                match_list.append(i)

        dprint(first_list, match_list)

        if len(match_list) == 0:
            print(-1)
            return

        previous_match_list = copy(match_list)

        # 試合をしたことを反映
        for i in match_list:
            if len(a_mat[i]) == 0:
                first_list[i] = 0
                nend += 1 # 終わった人
            else:
                next_no = a_mat[i].popleft()
                next = next_no - 1
                first_list[i] = next_no
                previous_match_list.append(next)

        previous_match_list = list(set(previous_match_list))

        dprint(match_list, previous_match_list)
        dprint("")
        # 一日経過
        cnt += 1

        # 終了判定
        if nend == N:
            break


    print(cnt)


main()
### BUGGY CODE ###

a,b,x = map(int,input().split())
def find(n):
    cnt = 0
    for i in range(n+1):
        if i%x == 0:
            cnt += 1
    return cnt
print(find(b) if a == 0 else find(b)-find(a-1))

### FIXED CODE ###

a,b,x = map(int,input().split())
if a==0 and b==0:
    print(1)
elif a == 0:
    print(b//x+1)
else:
    print(b//x - (a-1)//x)
### BUGGY CODE ###

h,w,m=map(int,input().split())
s=[0]*m
t=[0]*m
temp=[0]*m
for i in range(m):
  sm,tm=map(int,input().split())
  s[i]=sm
  t[i]=tm
  temp[i]=[s[i],t[i]]
st=[0]*h
tt=[0]*w
for i in range(m):
  st[s[i]-1]=st[s[i]-1]+1
  tt[t[i]-1]=tt[t[i]-1]+1
smax=max(st)
tmax=max(tt)
ans=smax+tmax
maxs=[]
maxt=[]
for i in range(h):
  if st[i]==smax:
    maxs.append(i)
for i in range(w):
  if tt[i]==tmax:
    maxt.append(i)

if len(maxs)*len(maxt)>m:
  print(ans)
else:
  for i in range(len(maxs)):
    for j in range(len(maxt)):
      if [maxs[i]+1,maxt[j]+1] not in temp:
        print(ans)
        exit()
  else:
    print(ans-1)

### FIXED CODE ###

h,w,m=map(int,input().split())
s=[0]*m
t=[0]*m
temp=set()
for i in range(m):
  sm,tm=map(int,input().split())
  s[i]=sm
  t[i]=tm
  temp.add((s[i],t[i]))
st=[0]*h
tt=[0]*w
for i in range(m):
  st[s[i]-1]=st[s[i]-1]+1
  tt[t[i]-1]=tt[t[i]-1]+1
smax=max(st)
tmax=max(tt)
ans=smax+tmax
maxs=[]
maxt=[]
for i in range(h):
  if st[i]==smax:
    maxs.append(i)
for i in range(w):
  if tt[i]==tmax:
    maxt.append(i)

if len(maxs)*len(maxt)>m:
  print(ans)
else:
  for i in range(len(maxs)):
    for j in range(len(maxt)):
      if (maxs[i]+1,maxt[j]+1) not in temp:
        print(ans)
        exit()
  else:
    print(ans-1)
### BUGGY CODE ###

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

ans = float('inf')
for i in range(len(S)):
    cnt = 0
    Right = S[i+1:]
    Left = S[:i]
    cnt += Right.count('E')  #右にいて東を向いている人の数
    cnt += Left.count('W')  #左にいて西を向いている人の数
    
    ans = min(ans, cnt)

print(ans)

### FIXED CODE ###

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

cnt_right = S[1:].count('E')
cnt_left = 0
ans = cnt_right + cnt_left

for ichi in range(len(S)-1):
    if S[ichi] == 'W':
        cnt_left += 1
    if S[ichi+1] == 'E':
        cnt_right -= 1
    ans = min(ans, cnt_right + cnt_left)
    
print(ans)
### BUGGY CODE ###

n=int(input())
A=[int(i) for i in input().split()]
  
if 1 not in A:
  ans=-1
else:
  ans=0
  for i in range(1,n+1):
    if i in A:
      k=A.index(i)
      ans+=k
      A=A[k+1:]
    else:
      ans+=len(A)
      break
print(ans)

### FIXED CODE ###

n=int(input())
A=[int(i) for i in input().split()]

k=1
cnt=0
for i in range(n):
  if A[i]!=k:
    cnt+=1
  else:
    k+=1
if cnt==n:
  print(-1)
else:
  print(cnt)
### BUGGY CODE ###

import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

X = int(read())

for a in range(pow(10, 9)):
    B_ = pow(a, 5) - X
    B = pow(B_, -5)
    if B_ == pow(B, 5):
        print(a, int(B))
        sys.exit()


### FIXED CODE ###

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

X = int(read())
A = np.array([pow(i, 5) for i in range(7000)])

for i, B_f in enumerate(A):
    for sig in [1, -1]:
        diff = A - (sig * B_f)
        if (diff == X).any():
            A_f = X + (sig * B_f)
            AA = A.tolist().index(A_f)
            B = A.tolist().index(B_f)
            print(AA, sig * B)
            sys.exit()
### BUGGY CODE ###

N, W = map(int, input().split())

dp = [0] + [-1] * W
for i in range(1, N + 1):
    w, v = map(int, input().split())
    for sum_w in range(W - w, -1, -1):
        if dp[sum_w] >= 0:
            dp[sum_w + w] = max(dp[sum_w + w], dp[sum_w] + v)
    # print(dp)
print(max(dp))


### FIXED CODE ###

import numpy as np

N, _W = map(int, input().split())

W, V = [0], [0]
for _ in range(N):
    w, v = map(int, input().split())
    W.append(w)
    V.append(v)
# dp[i][sum_w] := i-1 番目までの品物から重さが sum_w を超えないように選んだときの、価値の総和の最大値
# dp[i + 1][sum_w], dp[i][sum_w - w[i]] + v[i]

dp = np.array([0] * (_W + 1))
for i in range(1, N + 1):
    w, v = W[i], V[i]
    np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])
    # print(dp)

# print('dp')
print(dp.max())
### BUGGY CODE ###

from collections import deque

N,X,Y = map(int,input().split())

L= [[1]]+[[i-1,i+1] for i in range(1,N-1)]+ [[N-2]]
L[X-1].append(Y-1)
L[Y-1].append(X-1)

def BFS(x,L,k):
  d=[-1 for _ in range(N)] #距離
  d[x]=0
  v=deque([x])
  
  while len(v)>0:
    a=v.popleft()
    for num in L[a]:
      if d[num]==-1:
        d[num]=d[a]+1
        v.append(num)
  else:
    ret=0
    for num in d:
      if num==k:
        ret+=1
    return ret

for k in range(1,N):
  ans=0
  for j in range(N):
    ans+=BFS(j,L,k)
  print(ans//2)

### FIXED CODE ###

N,X,Y=map(int,input().split())
cost=[[] for _ in range(N)]

for i in range(N-1):
  cost[i].append(i+1)
for j in range(1,N):
  cost[j].append(j-1)

cost[X-1].append(Y-1)
cost[Y-1].append(X-1)
#print(cost)

def bfs(v):
    d=[-1]*N
    d[v]=0
    q=[v]
    c=1
    while q:
        q1=[]
        for i in q:
            for j in cost[i]:
                if d[j]==-1:
                    d[j]=c
                    q1.append(j)
        q=q1
        c+=1
        #print(d,q)
    return d

d=dict()
for m in range(N):
  tmp=bfs(m)
  #print(tmp)
  for num in tmp:
    if num not in d:
      d[num]=1
    else:
      d[num] += 1
#print(d)

for z in range(1,N):
  if z in d:
    print(d[z]//2)
  else:
    print(0)
### BUGGY CODE ###

import numpy as np

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

count_sum = np.sum([A.count(i)*(A.count(i)-1)/2 for i in A_set])
    
for i in A:
    print(int(count_sum-(A.count(i)-1)))

### FIXED CODE ###


from collections import Counter
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
A_set = np.unique(A)
count_dict= Counter(A)
count_sum = np.sum([count_dict[i]*(count_dict[i]-1)/2 for i in A_set])

out = [int(count_sum-count_dict[i]+1) for i in A]
for i in out:
    print(i)
### BUGGY CODE ###

import numpy as np

N = int(input())
A_vec = [int(_) for _ in input().split()]

matrix = [0] * N

for n in range(N - 1):
    matrix[n] = [0] * (n) + [0.5, 0.5] + [0] * (N - n - 2)
matrix[N - 1] = [0.5] + [0] * (N - 2) + [0.5]

X_vec = map(int, np.dot(np.linalg.inv(np.array(matrix)), A_vec))
print(' '.join(map(str, X_vec)))

### FIXED CODE ###

n = int(input())
r_list = list(map(int, input().split()))
ans_list = []

for i in range(len(r_list)):
    if i == 0:
        a = sum(r_list)
        for j in range(1, len(r_list)):
            if j % 2 == 1:
                a -= r_list[j] * 2
    else:
        a = (2 * r_list[i-1]) - ans_list[i-1]
    ans_list.append(a)

print(' '.join(map(str, ans_list)))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N, K = ZZ()
    A = sorted(ZZ(), reverse=True)
    F = sorted(ZZ())

    if sum(A) <= K:
        print(0)
        return

    cost = list()
    for a, f in zip(A, F): cost.append(a*f)

    ok = 10 ** 12
    ng = -1

    for _ in range(100):
        mid = (ok+ng)//2
        cc = 0
        for i in range(N): cc += max(0, (cost[i]-mid+F[i]-1)//F[i])
        if cc <= K: ok = mid
        else: ng = mid
    print(ok)

    return

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N, K = ZZ()
    A = sorted(ZZ(), reverse=True)
    F = sorted(ZZ())

    if sum(A) <= K:
        print(0)
        return

    cost = list()
    for a, f in zip(A, F): cost.append(a*f)

    ok = 10 ** 12
    ng = -1

    for _ in range(45):
        mid = (ok+ng)//2
        cc = 0
        for i in range(N): cc += max(0, (cost[i]-mid+F[i]-1)//F[i])
        if cc <= K: ok = mid
        else: ng = mid
    print(ok)

    return

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

S = input().strip()
Q = int(input().strip())
flag = 1
for i in range(Q):
  line = input().strip()
  if len(line) == 1:
    flag = 1 - flag
  else:
    _, F, C = line.strip().split()
    if flag:
      if int(F) == 1:
        S = C + S
      else:
        S = S + C
    else:
      if int(F) == 1:
        S = S + C
      else:
        S = C + S

if flag:
  print(S)
else:
  print(S[::-1])
    

### FIXED CODE ###

from collections import deque
S = deque(list(input().strip()))
Q = int(input().strip())
flag = 1
for i in range(Q):
  line = input().strip()
  if len(line) == 1:
    flag = 1 - flag
  else:
    _, F, C = line.strip().split()
    if flag:
      if int(F) == 1:
        S.appendleft(C)
      else:
        S.append(C)
    else:
      if int(F) == 1:
        S.append(C)
      else:
        S.appendleft(C)

if flag:
  print(''.join(S))
else:
  print(''.join(list(reversed(S))))
### BUGGY CODE ###

import math
k = int(input())
s = 0
a = []
b = []
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            p = [i,j,l]
            p.sort()
            if (p in a):
                s += b[a.index(p)]
            else:
                a.append(p)
                t = math.gcd(i,j)
                q = math.gcd(t,l)
                s += q
                b.append(q)
print(s)


### FIXED CODE ###

import math
k = int(input())
s = 0
b = []
for i in range(1,k+1):
    for j in range(i,k+1):
        for l in range(j,k+1):
            p = len(set([i,j,l]))
            if p ==1:
                t = math.gcd(i,j)
                q = math.gcd(t,l)
                s += q
                b.append(q)
            elif p ==2:
                t = math.gcd(i,j)
                q = math.gcd(t,l)
                s += q*3
                b.append(q)
            else:
                t = math.gcd(i,j)
                q = math.gcd(t,l)
                s += q*6
                b.append(q)
print(s)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
number = [a.count(i) for i in range(1,n)]
for j in range(n-1):
  print(number[j])
print(0)

### FIXED CODE ###

import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
for i in range(1,n+1):
  print(c[i])
### BUGGY CODE ###

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

for i in range(N):
  print(n.count(i+1))

### FIXED CODE ###

N=int(input())
a=list(map(int,input().split()))
A=[0]*N
for i in a:
  A[i-1]+=1
for i in A:
  print(i)
### BUGGY CODE ###

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

ans = 0
for i in range(N):
    ans ^= A[i]

for i in range(N):
    A[i] = (~ans)&A[i]

A = sorted([a for a in A if a != 0])
b = []

while A:
    M = A[-1]
    for i in range(len(A)-1,-1,-1):
        if len(bin(M))==len(bin(A[i])):
            A[i] ^= M
        else:
            break
    A = sorted([a for a in A if a != 0])
    b.append(M)    

b = b[::-1]
ans_ = 0
for i in range(len(b)):
    M = b[i]
    for j in range(i+1,len(b)):
        m = b[j]
        if len(bin(M))==len(bin(M&m)):
            b[j] ^= M
    ans_ ^= M

ans += ans_*2
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
ans = 0
for a in A:
    ans ^= a
M = 2**60-1
b = M^ans
for i in range(N):
    A[i] &= b
A.sort(reverse=True)
for i in range(min(60,N)):
    a = A[i]
    if a == 0:
        break
    l = len(bin(a))-3
    for j in range(N):
        if j==i:
            continue
        if A[j]//2**l%2==1:
            A[j] ^= a
        else:
            if i < j:
                break
    A.sort(reverse=True)
s = 0
for a in A:
    s ^= a
ans += 2*s
print(ans)
### BUGGY CODE ###

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

    A.sort()
    B.sort()
    C.sort()

    bb = [0 for _ in range(N)]
    for i,b in enumerate(B):
        for c in C[::-1]:
            if c > b:
                bb[i]+=1
            else: 
                break
    count = 0
    for a in A:
        for i,b in enumerate(B[::-1]):
            if b > a:
                count += bb[-i-1]
            else:
                break
    return count

print(main())


### FIXED CODE ###

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

    count = 0
    Ai = -1
    Ci = -1
    for i in range(N):
        if Ai<N-1:
            while A[Ai+1]<B[i]:
                Ai += 1
                if Ai == N-1:
                    break
        if Ci<N-1:
            while C[Ci+1]<=B[i]:
                Ci += 1
                if Ci==N-1:
                    break
        count += (Ai+1) * (N-(Ci+1))

    return count

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

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

l = [0]*100000
r = [0]*100000

for i in range(0,m):
    l[i],r[i] = map(int,input().split())

count = 0
num = 0

for key in range(1,n + 1):#鍵の番号
    for i in range(0,m):#
        if(key < l[i]):
            break
        if(key >= l[i] and key <= r[i]):
            count += 1
    if(count == m):
        num += 1
    count = 0
        
print(num)
        
    


### FIXED CODE ###

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

l = [0]*m
r = [0]*m
b = [0]*(n + 2)

count = 0

for i in range(0,m):
    l[i],r[i] = map(int,input().split())

l_max = max(l)
r_min = min(r)

for i in range(1,n+1):
        if(i >= l_max and i <= r_min ):
                count += 1
        
print(count)
### BUGGY CODE ###

def resolve():
    S = input()
    list_S = list(S)
    len_S = len(list_S)
    ans = 0

    if len(list_S) <= 3:
        print(ans)
        return

    for start_i in range(0, len_S - 3):
        for last_i in range(start_i, len_S):
            tmp = ''.join(list_S[start_i:last_i + 1])
            if tmp:
                tmp_ans = int(tmp) % 2019

                if tmp_ans == 0:
                    ans += 1
    print(ans)


resolve()

### FIXED CODE ###

from collections import defaultdict


def resolve():
    s = input()

    cnt = defaultdict(int)
    cnt[0] += 1
    tmp = 0
    for i, c in enumerate(s[::-1]):
        c = int(c)
        tmp = (tmp + c * pow(10, i, 2019)) % 2019
        cnt[tmp] += 1

    ans = sum(c * (c - 1) // 2 for c in cnt.values())
    print(ans)


resolve()
### BUGGY CODE ###

N=int(input())
S=[]
counts=[]
A=[]

for _ in range(N):
    S.append(input())
s=sorted(S)
T=set(s)
t=sorted(list(T))

for i in range(len(T)):
    counts.append(s.count(t[i]))

for j in range(len(t)):
    if counts[j]==max(counts):
        A.append(j)
for k in A:
    print(t[k])

### FIXED CODE ###

N=int(input())
S=[input() for _ in range(N)]

S_d={}
A=[]

for i in range(N):
    if S[i] not in S_d.keys():
        S_d[S[i]]=1
    else:
        S_d[S[i]]+=1

max_co=max(S_d.values())

for j in S_d.keys():
    if S_d[j]==max_co:
        A.append(j)

B=sorted(A)

for k in B:
    print(k)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

#整数値入力 1文字の入力
def input_one_number():
    return int(input())

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

#整数値龍力　複数の入力(配列)
def input_multiple_number_as_list():
    return list(map(int, input().split()))



#複数の最小公倍数
def calc_lcm_list(l):
    lcm = l[0]
    for i in l:
        lcm = lcm * i // fractions.gcd(lcm, i)
    return lcm


import fractions
N = input_one_number()
lstA = input_multiple_number_as_list()

lcm = calc_lcm_list(lstA)

ans = 0
for a in lstA:
    ans += (lcm // a)

print(ans % 1000000007)


### FIXED CODE ###

# -*- coding: utf-8 -*-

#整数値入力 1文字の入力
def input_one_number():
    return int(input())

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

#整数値龍力　複数の入力(配列)
def input_multiple_number_as_list():
    return list(map(int, input().split()))

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
def lcm(a,b):
    return a*b//gcd(a,b)

def calc_gcd_list(l):
    gcd = l[0]
    for i in range(1, N):
        gcd = gcd(gcd, l[i])
    return gcd

def calc_lcm_list(l):
    lcm = 1
    for i in l:
        lcm = lcm * i // gcd(lcm, i)
    return lcm


N = input_one_number()
lstA = input_multiple_number_as_list()
lcm = calc_lcm_list(lstA)
pow = 10**9 +7
print(sum(lcm//a for a in lstA)%pow)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
res = 1
for a_i in a:
    res *= a_i

print(-1 if res > 10 ** 18 else res)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
res = 1
for a_i in a:
    if 0 == a_i:
        print(0)
        exit(0)
    elif res > 10 ** 18:
        continue
    else:
        res *= a_i

print(-1 if res > 10 ** 18 else res)
### BUGGY CODE ###

# C - GeT AC
n, q = list(map(int, input().split()))
s = input()
q_range = [ list(map(int, input().split())) for i in range(q)]
for i in q_range:
	s_ = s[i[0]-1:i[1]]
	r= 0
	for i in range(len(s_)-1):
		if s_[i] == "A" and s_[i+1] == "C":
			r += 1
	print(r)

### FIXED CODE ###

# C - GeT AC
n, q = map(int, input().split())
s = input()
t = [0] * (n + 1)
for i in range(n):
	t[i + 1] = t[i] + (1 if s[i : i + 2] == 'AC' else 0)
for i in range(q):
	l, r = map(int, input().split())
	print(t[r-1] - t[l-1])
### BUGGY CODE ###

n,m=map(int,input().split())
x=[]
y=[]
for i in range(m):
  a,b=map(int,input().split())
  if a==1:
    x.append(b)
  elif b==n:
    y.append(a)

ans="IMPOSSIBLE"

for i in range(len(x)):
  if x[i] in y:
    ans="POSSIBLE"

print(ans)

### FIXED CODE ###

n,m=map(int,input().split())
data=[0]*n
for i in range(m):
  a,b=map(int,input().split())
  if a==1:
    data[b-1]+=1
    if data[b-1]==2:
      print('POSSIBLE')
      exit()
  if b==n:
    data[a-1]+=1
    if data[a-1]==2:
      print('POSSIBLE')
      exit()

print('IMPOSSIBLE')
### BUGGY CODE ###

import math

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

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

    return True


l=[]
r=[]
q=int(input())
for i in range(q):
    ll,rr=map(int,input().split())
    l.append(ll)
    r.append(rr)

n=0
x_cnt=0
for i in range(q):
    for j in range(l[i],r[i]+1,2):
        if is_prime(j) == True:
            n=(j+1)/2
            if is_prime(n) == True:
                x_cnt+=1
    print(x_cnt)
    x_cnt=0


### FIXED CODE ###

import math

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

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

    return True

q=int(input())
l=[]
r=[]
for i in range(q):
    ll,rr=map(int,input().split())
    l.append(ll)
    r.append(rr)

similar=[]
cnt=0
for i in range(10**5+2):
    if i<=2:
        similar.append(0)
    else:
        if is_prime(i)==True and (is_prime((i+1)/2))==True:
            cnt+=1
        similar.append(cnt)

for i in range(q):
    print(similar[r[i]]-similar[l[i]-1])
### BUGGY CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LS()

  s=l[0]
  if n%2==0:
    for i in range(1,len(l)):
      if i%2==0:
        s=s+' '+l[i]
      else:
        s=l[i]+' '+s
  else:
    for i in range(1,len(l)):
      if i%2==1:
        s=s+' '+l[i]
      else:
        s=l[i]+' '+s

  return s

print(main())


### FIXED CODE ###

n=int(input())
l=[0]*n
ind=n//2
l0=list(map(int,input().split()))
f=1
if n%2==0:
  f=-1
for i in range(n):
  if f==1:
    l[ind-i]=l0[i]
    f=-1
    ind-=i
  else:
    l[ind+i]=l0[i]
    f=1
    ind+=i
print(*l)
### BUGGY CODE ###

N, K = map(int, input().split())
h = [int(i) for i in input().split()]


dp = [float("inf") for i in range(N)]
dp[0] = 0

for i in range(1, N):
    for k in range(1, min(i+1, K+1)):


        dp[i] = min(dp[i], dp[i-k]+abs(h[i]-h[i-k]))


print(dp[N-1])

### FIXED CODE ###

def main():
	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[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
		)
	print(dp[N-1])
main()