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

import math
import sys
N,K=map(int,input().split())
pi=list(map(int,input().split()))
dice=[0]*N
for i in range(N):
    dice[i]=pi[i]*(pi[i]+1)/2/(pi[i])
#print(dice)
a = sum(dice[0:K-1])
max=a
for i in range(N-K+1):
    a=sum(dice[i:i+K])
    #print(dice[i:i+K])
    if a>max:
        max=a

print(max)



### FIXED CODE ###

import math
import sys
N,K=map(int,input().split())
pi=list(map(int,input().split()))
dice=[0]*N
for i in range(N):
    dice[i]=pi[i]*(pi[i]+1)/2/(pi[i])
#print(dice)
a = sum(dice[0:K])
max=a
for i in range(1,N-K+1):
    a=a-dice[i-1]+dice[K+i-1]
    #print(dice[i:i+K])
    if a>max:
        max=a

print(max)
### BUGGY CODE ###

def gcd(a,b):
  while b > 0:
    a, b = b, a % b
  return a

n = int(input())
arr = list(map(int , input().split()))
lcm = arr[0]
for i in range(1,n):
  hcf = gcd(lcm, arr[i])
  lcm = (lcm*arr[i])//hcf
sum =0
for i in range(0,n):
  sum = sum +(lcm//arr[i])
sum =sum%1000000007
print(int(sum))
  


### FIXED CODE ###

def gcd(a,b):
  while b > 0:
    a, b = b, a % b
  return a

n = int(input())
arr = list(map(int , input().split()))
lcm = arr[0]
for i in range(1,n):
  hcf = gcd(lcm, arr[i])
  lcm = (lcm*arr[i])//hcf
sum =0
for i in range(0,n):
  sum = sum +(lcm//arr[i])
sum =sum%1000000007
print(int(sum))
### BUGGY CODE ###

N, Q = map(int,input().split())
S = input()
T = [0]*N

for n in range(N-1):
  if S[n] == "A" and S[n+1] =="C":
    T[n] += 1

for q in range(Q):
  l, r = map(int,input().split())
  print(sum(T[l-1:r-1]))


### FIXED CODE ###

N, Q = map(int,input().split())
S = input()
T = [0]*N

for n in range(1,N):
  T[n] = T[n-1]
  if S[n-1] == "A" and S[n] =="C":T[n] += 1

for q in range(Q):
  l, r = map(int,input().split())
  print(T[r-1]-T[l-1])
### BUGGY CODE ###

#!/usr/bin/env python
# coding: utf-8

# In[28]:


N = int(input())
L = sorted(list(map(int, input().split())))


# In[29]:


count = 0
for i in range(N):
    for j in range(i+1, N):
        #print(i, j)
        #print(L[i], L[j], L[i]+L[j])
        for k in range(j+1, N):
            #print(L[i], L[j], L[k], L[i]+L[j] > L[k])
            if L[i]+L[j] > L[k]:
                count += 1
            else:
                break
print(count)


# In[ ]:






### FIXED CODE ###

#!/usr/bin/env python
# coding: utf-8

# In[9]:


import bisect


# In[10]:


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


# In[11]:


s_L = sorted(L)
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ans += bisect.bisect_left(s_L,s_L[i]+s_L[j])-j-1
print(ans)


# In[ ]:
### BUGGY CODE ###

N,K=map(int,input().split())
Array=[]
for n in range(0,N):
    a,b=input().split()
    Array+=((a+" ")*int(b)).split()
    Array.sort()
print(int(Array[K-1]))


### FIXED CODE ###

N,K=map(int,input().split())
Array={}
for n in range(0,N):
    a,b=map(int,input().split())
    if a in Array:
        Array[a]+=b
    else:
        Array[a]=b
numbers=sorted(list(Array.keys()))
n=0
k=0
while True:
    k+=Array[numbers[n]]
    if k>=K:
        break
    n+=1
print(numbers[n])
### BUGGY CODE ###

n = int(input())
S = list(input())
min_people = int(1e+6)

for i in range(n):
    if i == n-1:
        min_people = min(min_people,S[:i].count("W"))
    else:
        min_people = min(min_people,S[:i].count("W")+S[i+1:].count("E"))
    
print(min_people)


### FIXED CODE ###

n = int(input())
S = list(input())
dp = [0 for i in range(n)]
dp[0] = S[1:].count("E")

for i in range(n-1):
    if S[i] == S[i+1] == "E":
        dp[i+1] = dp[i]-1
    elif S[i] == S[i+1] == "W":
        dp[i+1] = dp[i]+ 1
    else:
        dp[i+1] = dp[i]

print(min(dp))
### BUGGY CODE ###

import queue

h, w = map(int, input().split(" "))

s = list()
for l in range(0, h):
    line = input()
    s.append(line)

dx = {(1, 0), (-1, 0), (0, 1), (0, -1)}


def search(start_h, start_w):
    if s[start_h][start_w] == "#":
        return -1

    cost = [[10000000 for i in range(0, w)] for j in range(0, h)]

    q = queue.Queue()
    q.put((start_h, start_w, 0))
    while not q.empty():
        current_h, current_w, current_c = q.get()
        if cost[current_h][current_w] < 10000000:
            continue
        else:
            cost[current_h][current_w] = current_c

        # print("pos_w:%d, pos_h:%d, cost:%d" % (current_w, current_h, current_c))
        for dw, dh in dx:
            next_h = current_h + dh
            next_w = current_w + dw
            next_c = current_c + 1

            if next_h < 0 or next_h >= h or next_w < 0 or next_w >= w:
                continue

            if s[next_h][next_w] == "#" or cost[next_h][next_w] < next_c:
                continue
            else:
                q.put((next_h, next_w, next_c))

    tmp = 0
    for a in range(0, w):
        for b in range(0, h):
            if cost[b][a] > 1000:
                continue
            else:
                tmp = max(tmp, cost[b][a])

    return tmp


ans = 0
for i in range(0, w):
    for j in range(0, h):
        # print("start_h:%d, start_w:%d" % (j, i))
        cost_tmp = search(j, i)
        ans = max(ans, cost_tmp)
        # print("start_h:%d, start_w:%d cost:%d" % (j, i, cost_tmp))


print(ans)


### FIXED CODE ###

import queue

h, w = map(int, input().split(" "))

s = list()
for l in range(0, h):
    line = input()
    s.append(line)

dx = {(1, 0), (-1, 0), (0, 1), (0, -1)}


def search(start_h, start_w):
    if s[start_h][start_w] == "#":
        return -1

    cost = [[10000000 for i in range(0, w)] for j in range(0, h)]

    q = queue.Queue()
    q.put((start_h, start_w, 0))
    cost[start_h][start_w] = 0
    while not q.empty():
        current_h, current_w, current_c = q.get()
        # print("(%d, %d, %d)" % (current_h, current_w, current_c))

        # print("pos_w:%d, pos_h:%d, cost:%d" % (current_w, current_h, current_c))
        for dw, dh in dx:
            next_h = current_h + dh
            next_w = current_w + dw
            next_c = current_c + 1

            if next_h < 0 or next_h >= h or next_w < 0 or next_w >= w:
                continue

            if s[next_h][next_w] == "#" or cost[next_h][next_w] <= next_c:
                continue
            else:
                q.put((next_h, next_w, next_c))
                cost[next_h][next_w] = next_c

    tmp = 0
    for a in range(0, w):
        for b in range(0, h):
            if cost[b][a] > 1000:
                continue
            else:
                tmp = max(tmp, cost[b][a])

    return tmp


ans = 0
for i in range(0, w):
    for j in range(0, h):
        # print("start_h:%d, start_w:%d" % (j, i))
        cost_tmp = search(j, i)
        ans = max(ans, cost_tmp)
        # print("start_h:%d, start_w:%d cost:%d" % (j, i, cost_tmp))


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

def gcd(p, q):
    while (q != 0):
        r = p % q
        p = q
        q = r
    return p


def sum_of_gcd_tuples():
    K = int(input())
    total = 0
    for a in range(1, K + 1):
        for b in range(1, K + 1):
            for c in range(1, K + 1):
                total += gcd(gcd(a, b), c)

    print(total)


sum_of_gcd_tuples()

### FIXED CODE ###

def sum_of_gcd_tuples():
    from math import gcd
    K = int(input())
    total = 0

    for a in range(1, K + 1):
        for b in range(1, K + 1):
            for c in range(1, K + 1):
                total += gcd(gcd(a, b), c)

    print(total)


sum_of_gcd_tuples()
### BUGGY CODE ###

s=input()+'E'
q=int(input())
for i in range(q):
  que=input().split()
  if que[0]==str(1):
    if s[-1]=='E':
      s='E'+s[:-1]
    else:
      s=s[1:]+'E'
  else:
    if que[1]==str(1):
      if s[-1]=='E':
        s=que[2]+s
      else:
        s='E'+s[1:]+que[2]
    else:
      if s[-1]=='E':
        s=s[:-1]+que[2]+'E'
      else:
        s='E'+que[2]+s[1:]
if s[-1]=='E':
  print(s[:-1])
else:
  s=s[::-1]
  print(s[:-1])



### FIXED CODE ###

from collections import deque
s=deque(input())
q=int(input())
cnt=0
for i in range(q):
  t=input().split()
  if t[0]=="1":
    cnt+=1
  else:
    if (int(t[1])+cnt)%2==1:
      s.appendleft(t[2])
    else:
      s.append(t[2])
      
if cnt%2==1:
  s.reverse()
print("".join(s))
### BUGGY CODE ###

import re

def solve():
    N = int(input())
    S = input()
    searched = [False]*999
    
    # 愚直にやると↓だが、まあ間に合わないだろう
    # ret = len(set(for s in combination(S, 3)))
    ret = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                regex = '.*{0}.*{1}.*{2}.*'.format(i,j,k)
                if re.search(regex,S):
                    ret += 1
                    
    print(ret)
    
solve()

### FIXED CODE ###

def search_substr(S, subs):
    idx = 0
    ret = False
    for s in S:
        if s == subs[idx]:
            idx += 1
            if idx == len(subs):
                ret = True
                break
                
    return ret

def solve():
    N = int(input())
    S = input()
    
    # 愚直にやると↓だが、まあ間に合わないだろう
    # ret = len(set(for s in combination(S, 3)))
    ret = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                subs = '{0}{1}{2}'.format(i,j,k)
                if search_substr(S, subs):
                    ret += 1
                    
    print(ret)
    
solve()
### BUGGY CODE ###

def inv(s):
    t = ''
    for i in range(len(s)):
        t += s[-1 * (i + 1)]
    return t

s = input()
q = int(input())
ans = s
parity = 0
for i in range(q):
    qi = input()
    if qi[0] == '1':
        parity += 1
    else:
        if qi[2] == '1' and parity % 2 == 0:
            ans = qi[4] + ans
        elif qi[2] == '2' and parity % 2 == 0:
            ans = ans + qi[4]
        if qi[2] == '1' and parity % 2 == 1:
            ans = ans + qi[4]
        elif qi[2] == '2' and parity % 2 == 1:
            ans = qi[4] + ans
if parity % 2:
    print(ans[::-1])
else:
    print(ans)

### FIXED CODE ###

from collections import deque
s = input()
q = int(input())
ans = deque(s)
rev = 0
for i in range(q):
    qi = input()
    if qi[0] == '1':
        rev += 1
    else:
        if qi[2] == '1' and rev % 2 == 0:
            ans.appendleft(qi[4])
        elif qi[2] == '2' and rev % 2 == 0:
            ans.append(qi[4])
        if qi[2] == '1' and rev % 2 == 1:
            ans.append(qi[4])
        elif qi[2] == '2' and rev % 2 == 1:
            ans.appendleft(qi[4])

parity = rev % 2
if parity:
    ans.reverse()
    for i in ans:
        print(i, end='')
else:
    for i in ans:
        print(i, end='')
### BUGGY CODE ###

import bisect

x,y,z,k = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
cc = list(map(int, input().split()))

# A,Bでソート
score_ab = []
for a in aa:
    for b in bb:
        # bisect.insort_right(score_ab, a+b)
        score_ab.append(a+b)
score_ab = sorted(score_ab)[::-1][:k]
# print(score_ab[::-1])
# A,B合計値の上位K個とCでソート
score = []
for s in score_ab:
    for c in cc:
        # bisect.insort_right(score, s+c)
        score.append(s+c)
score = sorted(score)[::-1][:k]
for s in score:
    print(s)

### FIXED CODE ###

x,y,z,k = map(int, input().split())
aa = sorted(list(map(int, input().split())))
bb = sorted(list(map(int, input().split())))
cc = sorted(list(map(int, input().split())))

ab = sorted(a+b for a in aa for b in bb)[:-k-1:-1]
abc = sorted(s+c for s in ab[:k] for c in cc)[:-k-1:-1]
print(*abc, sep='\n')
### BUGGY CODE ###

def main():
    import numpy as np
    h, w, K = map(int, input().split())
    grid = np.array([list(map(int, list(input())))
                     for _ in [0]*h], dtype=np.int16)
    m = 10**9
    for i in range(2**(h-1)):
        i = (("0"*h)+bin(i)[2:])[-h:]
        memo = [0]+[j for j in range(1, h) if i[j-1] != i[j]]+[h]
        ans = len(memo)-1
        ans2 = [0]
        aa = ans2.append
        memo2 = [0]*ans
        j = 0
        flag = False
        while j < w:
            if flag:
                break
            p, l = memo[0], ans2[-1]
            for k, q in enumerate(memo[1:ans+1]):
                memo2[k] += np.sum(grid[p:q, j])
                p = q
                if memo2[k] > K:
                    aa(j)
                    memo2 = [0]*ans
                    if j == l:
                        flag = True
                    l = j
                    break
            else:
                j += 1
        if not flag:
            m = min(m, ans+(len(ans2)-2))
    print(m)


main()


### FIXED CODE ###

def main():
    from itertools import product
    h, w, K = map(int, input().split())
    grid = [list(input()) for _ in [0]*h]
    m = 10**9
    for i in range(2**h):
        i = (("0"*h)+bin(i)[2:])[-h:]+"2"
        memo = [0]
        for j in range(h):
            if i[j] == i[j+1]:
                pass
            else:
                memo.append(j+1)
        ans = len(memo)-1
        ans2 = [0]
        memo2 = [0]*ans
        j = 0
        flag = False
        while j < w:
            if flag:
                break
            for k in range(ans):
                memo2[k] += [grid[l][j]
                             for l in range(memo[k], memo[k+1])].count("1")
                if memo2[k] > K:
                    ans2.append(j)
                    memo2 = [0]*ans
                    if ans2[-1] == ans2[-2]:
                        flag = True
                    break
            else:
                j += 1
        if flag == False:
            m = min(m, ans+(len(ans2)-2))
    print(m)


main()
### BUGGY CODE ###

from sys import stdin
data = stdin.readlines()

x = int(data[0].split()[0])
a = [int(s) for s in data[1].split()]
a = sorted(a, reverse = True)

counter = 0
for i in range(len(a)):
    for j in range(len(a)):
        if i != j and a[i] % a[j] == 0:
            break
    else:
        counter += 1
print(counter)

### FIXED CODE ###

from sys import stdin
data = stdin.readlines()

n = int(data[0].split()[0])
a = [int(s) for s in data[1].split()]
a = sorted(a)

max = a[-1]

l = [0]*(max+1)

for i in a:
    l[i] += 1
    if l[i] == 1:
        for j in range(i*2,max+1,i):
            l[j] = 2
print(l.count(1))
### BUGGY CODE ###

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


def ex(list):
    ans = 0
    for i in list:
        ans += (i+1)/2
    return(float(ans))


ans = 0
for i in range(N-K+1):
    p = pn[i:i+K]
    if ans < sum(p):
        maxlist = p
        ans = sum(p)

print('{:.12f}'.format(ex(maxlist)))

### FIXED CODE ###

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

pn_t = [0]
for i in range(N):
    pn_t.append(pn[i]+pn_t[i])

l = 0
for i in range(N-K+1):
    l = max(l, pn_t[K+i]-pn_t[i])
ans = (l+K)/2
print(ans)
### BUGGY CODE ###

from collections import defaultdict
from heapq import heappop, heappush

class Graph(object):

    def __init__(self):
        self.graph = defaultdict(list)

    def add_edge(self, a, b, w):
        self.graph[a].append((b, w))


class Dijkstra(object):
    def __init__(self, graph, s):
        self.g = graph.graph
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[s] = 0

        self.Q = []
        heappush(self.Q, (self.dist[s], s))
        while self.Q:
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, w in self.g[u]:
                alt = dist_u + w
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    heappush(self.Q, (alt, v))

    def s_d(self, goal):
        return self.dist[goal]



xs, ys, xg, yg = list(map(int, input().split()))
xyr = []
xyr.append([xs, ys, 0])
N = int(input())

for i in range(N):
    xyr.append(list(map(int, input().split())))
xyr.append([xg, yg, 0])

g_a = Graph()
for i in range(N + 1):
    for j in range(i + 1, N + 2):
        a, b = i, j
        x1 = xyr[i][0]
        y1 = xyr[i][1]
        x2 = xyr[j][0]
        y2 = xyr[j][1]
        R = ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) ** 0.5
        r1 = xyr[i][2]
        r2 = xyr[j][2]
        if R > r1 + r2:
            r = R - r1 - r2
        else:
            r = 0
        g_a.add_edge(a, b, r)
        g_a.add_edge(b, a, r)

d_a = Dijkstra(g_a, 0)
print(d_a.s_d(N + 1))

### FIXED CODE ###

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

class Graph(object):

    def __init__(self):
        self.graph = defaultdict(list)

    def add_edge(self, a, b, w):
        self.graph[a].append((b, w))


class Dijkstra(object):
    def __init__(self, graph, s):
        self.g = graph.graph
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[s] = 0

        self.Q = []
        heappush(self.Q, (self.dist[s], s))
        while self.Q:
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, w in self.g[u]:
                alt = dist_u + w
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    heappush(self.Q, (alt, v))

    def s_d(self, goal):
        return self.dist[goal]


xs, ys, xg, yg = list(map(int, input().split()))
xyr = []
xyr.append([xs, ys, 0])
N = int(input())

for i in range(N):
    xyr.append(list(map(int, input().split())))
xyr.append([xg, yg, 0])

g_a = Graph()
for i in range(N + 1):
    for j in range(i + 1, N + 2):
        R = ((xyr[i][0] - xyr[j][0]) * (xyr[i][0] - xyr[j][0]) + (xyr[i][1] - xyr[j][1]) * (xyr[i][1] - xyr[j][1]))
        R = R ** 0.5
        if R > xyr[i][2] + xyr[j][2]:
            r = R - xyr[i][2] - xyr[j][2]
        else:
            r = 0
        g_a.add_edge(i, j, r)
        g_a.add_edge(j, i, r)

d_a = Dijkstra(g_a, 0)
print(d_a.s_d(N + 1))
### BUGGY CODE ###

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

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


alphabet = "abcdefghijklmnopqrstuvwxyz"

bag = { l:[] for l in alphabet}

for i in range(N):
  bag[S[i]].append(i+1)


import bisect

for _ in range(Q):
  t,a,b = input().split()
  a = int(a)
  if int(t) == 1:
    bag[S[a-1]].remove(a)
    S[a-1] = b
    bisect.insort(bag[b],a)
  else:
    count = 0
    b = int(b)
    for l in alphabet:
      left = bisect.bisect_left(bag[l],a)
      right = bisect.bisect_right(bag[l],b)
      if left !=  right:
        count += 1
    print(count)

### FIXED CODE ###

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

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


alphabet = "abcdefghijklmnopqrstuvwxyz"

bag = { l:[] for l in alphabet}

for i in range(N):
  bag[S[i]].append(i+1)


import bisect

for _ in range(Q):
  t,a,b = input().split()
  a = int(a)
  if int(t) == 1:
    if S[a-1]!=b:
      bag[S[a-1]].remove(a)
      S[a-1] = b
      bisect.insort(bag[b],a)
  else:
    count = 0
    b = int(b)
    for l in alphabet:
      if len(bag[l])>0:
        left = bisect.bisect_left(bag[l],a)
        if left != len(bag[l]):
          if bag[l][left] <= b:
            count += 1
    print(count)
### BUGGY CODE ###

n = int(input())

Li = [0] * 2 + [2] * (n -1)

uvws = [list(map(int, input().split())) for _ in range(n - 1)]

while 2 in Li:
    for u, v, w in uvws:
        if w % 2:
            if Li[u] != 2 and Li[v] == 2:
                Li[v] = 1 - Li[u]
            elif Li[u] == 2 and Li[v] != 2:
                Li[u] = 1 - Li[v]
        else:
            if Li[u] != 2 and Li[v] == 2:
                Li[v] = Li[u]
            elif Li[u] == 2 and Li[v] != 2:
                Li[u] = Li[v]

for item in Li[1:]:
    print(item)

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

def tree_path():
    # 辺と長さが与えられる
    # 頂点1からの各点の距離を計算する
    # 距離が偶数か奇数かで色分け
    sys.setrecursionlimit(100000)
    n = int(input())
    path = [[] for _ in range(n + 1)]
    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        # 無向グラフ
        path[u].append((v, w))
        path[v].append((u, w))
    # d[0]は使わない
    d = [-1] * (n + 1)

    def walk(i, c):
        if d[i] == -1:
            d[i] = c
            for x, w in path[i]:
                walk(x, c + w)

    walk(1, 0)
    for i in d[1:]:
        print(i % 2)

        
tree_path()
### BUGGY CODE ###

import  fractions
from functools import reduce
import sys
input = sys.stdin.readline
def main():
    n=int(input())
    a=list(map(int,input().split()))
    # tmp = lcm(*a)
    mod=pow(10,9) + 7
    m=0
    ans=0
    tmp = a[0]
    for i in range(1,len(a)):
        tmp = (tmp*a[i]) // fractions.gcd(tmp,a[i])
    
    for i,v in enumerate(a):
        m=tmp//v
        ans+=m%mod
    ans = ans % mod
    print(ans)


if __name__=='__main__':
    main()


### FIXED CODE ###

import  fractions
from functools import reduce
import sys
input = sys.stdin.readline
def main():
    n=int(input())
    a=list(map(int,input().split()))
    # tmp = lcm(*a)
    mod=pow(10,9) + 7
    m=0
    ans=0
    tmp = a[0]
    for i in range(1,len(a)):
        tmp = (tmp*a[i]) // fractions.gcd(tmp,a[i])
    
    for i,v in enumerate(a):
        m=tmp//v
        ans+=m
    ans = ans % mod
    print(ans)


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

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

scores = []

for i in range(k, n+1):
    score = 1
    for j in range(i-1, i-k-1, -1):
        score *= a[j]
    scores.append(score)
    if len(scores) > 1:
        if scores[-1] > scores[-2]:
            print('Yes')
        else:
            print('No')



### FIXED CODE ###

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

for i in range(k, n):
    if a[i] > a[i-k]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

N, K = map(int, input().split())
height = list(map(int,input().split()))
min_jump = [0,abs(height[0]-height[1])]

for num in range(2,N): #num is index of stone
  jump = 10**9
  if num < K:
    for n in range(num): # n is number of passed stones
      jump = min(jump, min_jump[num-n-1] + abs(height[num-n-1] - height[num]))
    min_jump.append(jump)
  else:
    for n in range(K): # n is number of passed stones
      jump = min(jump, min_jump[num-n-1] + abs(height[num-n-1] - height[num]))
    min_jump.append(jump)
print(min_jump[N-1])

### FIXED CODE ###

N, K = map(int, input().split())
height = list(map(int,input().split()))
min_jump = [0,abs(height[0]-height[1])]

for num in range(2,N): #num is index of stone
  jump = 10**9
  if num < K:
    for n in range(num): # n is number of passed stones
      jump = min(jump, min_jump[num-n-1] + abs(height[num-n-1] - height[num]))
    min_jump.append(jump)
  else:
    for n in range(K): # n is number of passed stones
      jump = min(jump, min_jump[num-n-1] + abs(height[num-n-1] - height[num]))
    min_jump.append(jump)
print(min_jump[N-1])
### BUGGY CODE ###

n = int(input())
s = input()
c = 0
for i in range(n):
    s1 = s[i]
    for j in range(i,n):
        s2 = s[j]
        for k in range(j,n):
            s3 = s[k]
            if (s1==s2) or (s1==s3) or (s2 == s3):
                pass
            elif (j-i)==((k-j)):
                pass
            else:
                c+=1

print(c)

### FIXED CODE ###

n = int(input())
s = input()

R=[]
G=[]
B=[]

for i in range(n):
    if s[i] == "R":
        R.append(i)
    elif s[i] == "G":
        G.append(i)
    else:
        B.append(i)

ans = len(R)*len(G)*len(B)
for i in range(n-2):
    for j in range(i+1,n-1):
        k  = 2*j-i
        if k<n:
            if (s[i]!=s[j]) and (s[i]!=s[k]) and (s[j]!=s[k]):
                ans-=1
print(ans)
### BUGGY CODE ###

import numpy as np

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

X = []
for i in range(N):
    x = [0 for _ in range(N)]
    for j in range(i, i+2):
        if j >= N:
            continue
        x[j] = 1
    if i == N - 1:
        x[0] = 1
    X.append(x)

Y = A
X = np.matrix(X)
Y = np.matrix(Y).reshape(-1, 1)
ans = np.linalg.solve(X,Y) * 2
ans = list(map(lambda x: str(int(x)), ans))
print(' '.join(ans).strip())


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
X = []
for i in range(N):
    X.append(sum(A) - 2 * sum([x for j, x in enumerate(A) if j % 2 != 0]) if i == 0 else 2 * A[i-1] - X[i-1])
print(' '.join(list(map(str, X))).strip())