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

# -*- coding: utf-8 -*-
import math

p = set([2])


def isPrime(x):
    if x < 2:
        return False
    elif x in p:
        return True
    elif x % 2 == 0:
        return False

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

    p.add(x)
    return True


q = int(input())
pairs = []
for i in range(q):
    s, e = map(int, input().split())
    pairs.append((s, e))

for i in range(q):
    s, e = pairs[i]
    r = 0
    for j in range(s, e+1):
        if isPrime(j) and isPrime((j + 1) / 2):
            r += 1
    print(str(r))

### FIXED CODE ###

# -*- coding: utf-8 -*-
u = 100000

f = [False]*(u+1)
for i in range(2, u+1):
    if not f[i]:
        for j in range(i+i, u+1, i):
            f[j] = True

c = [0]*(u+2)
for i in range(3, u+1, 2):
    if not f[i] and not f[int((i+1)/2)]:
        c[i] += 1
for i in range(3, u+1):
    c[i] += c[i-1]

q = int(input())
for i in range(q):
    s, e = map(int, input().split())
    print(c[e] - c[s-1])
### BUGGY CODE ###

# coding: utf-8
# Your code here!
s=input()
t=input()

dp=[["" for i in range(len(t)+1)] for j in range(len(s)+1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i]==t[j]:
            if len(dp[i][j]+s[i])>len(dp[i+1][j+1]):
                dp[i+1][j+1]=dp[i][j]+s[i]
        else:
            #print(i,j)
            if len(dp[i][j])>len(dp[i][j+1]):
                dp[i][j+1]=dp[i][j]
            if len(dp[i][j])>len(dp[i+1][j]):
                dp[i+1][j]=dp[i][j]

ans=""
for item in dp[-1]:
    if len(item)>len(ans):
        ans=item
print(ans)

### FIXED CODE ###

# coding: utf-8
# Your code here!
s=list(input())
t=list(input())

dp=[[0]*(len(t)+1) for i in range(len(s)+1)]

for i in range(1,len(s)+1):
    for j in range(1,len(t)+1):
        if s[i-1]==t[j-1]:
            dp[i][j]=dp[i-1][j-1]+1
        else:
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])
            
#print(dp)

ans=""
ns=len(s)
nt=len(t)

while ns>0 and nt>0:
    #print(ns,nt,ans)
    if s[ns-1]==t[nt-1]:
        ans+=s[ns-1]
        ns-=1
        nt-=1
    elif dp[ns][nt]==dp[ns-1][nt]:
        ns-=1
    else:
        nt-=1
        
print(ans[::-1])
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
B=[]
for k in range(N):
    B.append([A[k],k+1])
B.sort(key=lambda x: x[0], reverse=True)
dp=[[0 for k in range(N+1)]for k in range(N+1)]
dp[1][0]=dp[0][0]+B[0][0]*(B[0][1]-1)
dp[0][1]=dp[0][0]+B[0][0]*(N-B[0][1])
for k in range(1,N):
    #j=0
    dp[0][k+1]=dp[0][k]+B[k][0]*(N-k-B[k][1])
    dp[1][k]=max(dp[0][k]+B[k][0]*(B[k][1]-1), dp[1][k-1]+B[k][0]*(N-k+1-B[k][1]))
    #j=k
    dp[k+1][0]=dp[k][0]+B[k][0]*(B[k][1]-k-1)
    dp[k][1]=max(dp[k-1][+1]+B[k][0]*(B[k][1]-k), dp[k][0]+B[k][0]*(N-B[k][1]))
    for j in range(1,k):
        dp[j+1][k-j]=max(dp[j][k-j]+B[k][0]*(B[k][1]-j-1), dp[j+1][k-j-1]+B[k][0]*(N-k+j+1-B[k][1]))
        dp[j][k-j+1]=max(dp[j-1][k-j+1]+B[k][0]*(B[k][1]-j), dp[j][k-j]+B[k][0]*(N-k+j-B[k][1]))
ans=[]
for k in range(N+1):
    ans.append(dp[k][N-k])
print(max(ans))               

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
B=[]
for k in range(N):
    B.append([A[k],k+1])
B.sort(key=lambda x: x[0], reverse=True)
dp=[[0 for k in range(N+1)]for k in range(N+1)]
dp[1][0]=dp[0][0]+B[0][0]*(B[0][1]-1)
dp[0][1]=dp[0][0]+B[0][0]*(N-B[0][1])
for k in range(1,N):
    #j=0
    dp[0][k+1]=dp[0][k]+B[k][0]*(N-k-B[k][1])
    dp[1][k]=max(dp[0][k]+B[k][0]*(B[k][1]-1), dp[1][k-1]+B[k][0]*(N-k+1-B[k][1]))
    #j=k
    dp[k+1][0]=dp[k][0]+B[k][0]*(B[k][1]-k-1)
    dp[k][1]=max(dp[k-1][+1]+B[k][0]*(B[k][1]-k), dp[k][0]+B[k][0]*(N-B[k][1]))
    for j in range(1,k):
        dp[j+1][k-j]=max(dp[j][k-j]+B[k][0]*(B[k][1]-j-1), dp[j+1][k-j-1]+B[k][0]*(N-k+j+1-B[k][1]))
        dp[j][k-j+1]=max(dp[j-1][k-j+1]+B[k][0]*(B[k][1]-j), dp[j][k-j]+B[k][0]*(N-k+j-B[k][1]))
ans=[]
for k in range(N+1):
    ans.append(dp[k][N-k])
print(max(ans))
### BUGGY CODE ###

def main():
    n = int(input())
    primelist = []
    for _ in range(n):
        x = int(input())
        if isprime(x) == 1:
            primelist.append(x)
    print(len(primelist))

def isprime(x: int):    
    if x == 2:
        return 1
    elif x % 2 == 0:
        return 0
    else:        
        yesno = 1
        for y in range(3, x, 2):
            # 偶数は最初に除外するので、奇数で割れるかだけ見ていく
            if x % y == 0:
                yesno = 0
                break
    return yesno

if __name__ == '__main__':
    main()



### FIXED CODE ###

def main():
    A = set()
    n_prime = 0
    while True:
        try:
            x = int(input())
            A.add(x)
        except:
            break

    for x in A:
        n_prime += is_prime(x)

    print(n_prime)


def is_prime(x):  
    if x == 2:
        return 1
    elif x % 2 == 0:
        return 0
    else:
        return pow(2, x - 1, x) == 1   

main()
### BUGGY CODE ###

import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
X = list(map(int, sys.stdin.readline().split()))
L = int(sys.stdin.readline())
Q = int(sys.stdin.readline())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]

N += 2
X = [X[0]] + X + [X[-1]]
X = np.array(X, dtype=int)
# dp[d][i]: i番のホテルから(2^d)日で何個右までいけるか
dp = np.zeros((N.bit_length() + 1, N), dtype=int)
dp[0] = np.searchsorted(X, X + L, side="right") - 1
for d in range(1, N.bit_length() + 1):
    dp[d] = dp[d - 1][dp[d - 1]]
dp = dp.T


def solve(l, r):
    ret = 0
    d = len(dp[0]) - 1
    while l + 1 < r:
        while d > 0 and dp[l, d] >= r:
            d -= 1
        ret += pow(2, d)
        l = dp[l, d]
    if l < r:
        ret += 1
    return ret


ans = []
for a, b in AB:
    ans.append(solve(min(a, b), max(a, b)))
print(*ans, sep='\n')


### FIXED CODE ###

import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
X = list(map(int, sys.stdin.readline().split()))
L = int(sys.stdin.readline())
Q = int(sys.stdin.readline())
AB = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]

N += 2
X = [X[0]] + X + [X[-1]]
X = np.array(X, dtype=int)
# dp[d][i]: i番のホテルから(2^d)日で何個右までいけるか
dp = np.zeros((N.bit_length() + 1, N), dtype=int)
dp[0] = np.searchsorted(X, X + L, side="right") - 1
for d in range(1, N.bit_length() + 1):
    dp[d] = dp[d - 1][dp[d - 1]]
dp = dp.tolist()


def solve(l, r):
    ret = 0
    d = len(dp) - 1
    while l + 1 < r:
        while d > 0 and dp[d][l] >= r:
            d -= 1
        ret += 1 << d
        l = dp[d][l]
    if l < r:
        ret += 1
    return ret


ans = []
for a, b in AB:
    ans.append(solve(min(a, b), max(a, b)))
print(*ans, sep='\n')
### BUGGY CODE ###

import sys
import numpy as np



def main(N,dp):
    dp[0, 0] = min(N[0], 11 - N[0])
    dp[0, 1] = min(N[0] + 1, 10 - N[0])
    for i in range(1, len(N)):
        dp[i, 0] = min(dp[i - 1, 0] + N[i], dp[i - 1, 1] + 10 - N[i])
        dp[i, 1] = min(dp[i - 1, 0] + N[i] + 1, dp[i - 1, 1] + 9 - N[i])
    print(dp[-1][0])


if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', '(i8,i8[:],)')(main)
    # b1: bool, i4: int32, i8: int64, double: f8, [:], [:, :]
    cc.compile()
else:
    #from my_module import main
    N = np.array([int(_) for _ in input()])
    dp = np.array([[0, 0] for _ in range(len(N))])
    main(N, dp)


### FIXED CODE ###

N = [int(_) for _ in input()]
dp = [[0, 0] for _ in range(len(N))]
dp[0][0] = min(N[0], 11 - N[0])
dp[0][1] = min(N[0] + 1, 10 - N[0])
for i in range(1, len(N)):
    dp[i][0] = min(dp[i - 1][0] + N[i], dp[i - 1][1] + 10 - N[i])
    dp[i][1] = min(dp[i - 1][0] + N[i] + 1, dp[i - 1][1] + 9 - N[i])
print(dp[-1][0])
### BUGGY CODE ###

n,m = map(int,input().split())
li = list(map(int,input().split()))
tmp_li = []
for _ in range(m):
    b,c = map(int,input().split())
    tmp_li.append((c,b))
tmp_li.sort(reverse=True)
#print(tmp_li)
count = 0
for t in tmp_li:
    kazu = min(t[1],n-count+1)
    li += [t[0]]*kazu
    if count>=n:
        break
li.sort(reverse=True)
print(sum(li[:n]))

### FIXED CODE ###

n,m = map(int,input().split())
li = list(map(int,input().split()))
tmp_li = []
for _ in range(m):
    b,c = map(int,input().split())
    tmp_li.append((c,b))
tmp_li.sort(reverse=True)
#print(tmp_li)
for c,b in tmp_li:
    li.extend([c]*b)
    if len(li)>= 2*n:
        break
li.sort(reverse=True)
print(sum(li[:n]))
### BUGGY CODE ###

S = input()
Q = int(input())

reversing = False

for i in range(Q):
    query = list(input().split())
    if int(query[0]) == 1:
        reversing = not reversing
    else:
        if int(query[1]) == 1:
            if not reversing:
                S = query[2] + S
            else:
                S += query[2]
        else:
            if reversing:
                S = query[2] + S
            else:
                S += query[2]

print(S) if not reversing else print(S[::-1])

### FIXED CODE ###

from collections import deque

S = deque(input())
Q = int(input())

reversing = False

for i in range(Q):
    query = list(input().split())
    if query[0] == '1':
        reversing = not reversing
    else:
        if query[1] == '1':
            if not reversing:
                S.appendleft(query[2])
            else:
                S.append(query[2])
        else:
            if reversing:
                S.appendleft(query[2])
            else:
                S.append(query[2])

print(''.join(S)) if not reversing else print(''.join(reversed(S)))
### BUGGY CODE ###

def main():
    n=int(input())
    s=input()
    r,g,b=[],[],[]
    if n<=3:
        print(0)
    else:
        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(len(r)):
            for j in range(len(g)):
                if (r[i]+g[j])%2==0 and (r[i]+g[j])//2 in b:
                        ans-=1
        for i in range(len(g)):
            for j in range(len(b)):
                if (g[i]+b[j])%2==0 and (g[i]+b[j])//2 in r:
                        ans-=1
        for i in range(len(r)):
            for j in range(len(b)):
                if (r[i]+b[j])%2==0 and (r[i]+b[j])//2 in g:
                        ans-=1
        print(ans)
if __name__=="__main__":
    main()

### FIXED CODE ###

def main():
    n=int(input())
    s=input()
    r,g,b=[],[],[]
    if n<=3:
        print(0)
    else:
        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(len(r)):
            for j in range(len(g)):
                if (r[i]+g[j])%2==0 and s[(r[i]+g[j])//2]=="B":
                        ans-=1
        for i in range(len(g)):
            for j in range(len(b)):
                if (g[i]+b[j])%2==0 and s[(g[i]+b[j])//2]=="R":
                        ans-=1
        for i in range(len(r)):
            for j in range(len(b)):
                if (r[i]+b[j])%2==0 and s[(r[i]+b[j])//2]=="G":
                        ans-=1
        print(ans)
if __name__=="__main__":
    main()
### BUGGY CODE ###

N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
xy.sort()
xy = [list(x) for x in zip(*xy)]
import copy
ans = 0
for i in range(N-1):
    w = xy.copy()
    x = list(map(lambda x: abs(x-xy[0][i]),w[0]))
    y = list(map(lambda y: abs(y-xy[1][i]),w[1]))
    z = [i+j for i,j in zip(x,y)]
    ans = max(ans,max(z))
print(ans)

### FIXED CODE ###

N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
xy = [list(x) for x in zip(*xy)]
a = [i+j for i,j in zip(xy[0],xy[1])]
b = [i-j for i,j in zip(xy[0],xy[1])]
aa = max(a) - min(a)
ba = max(b) - min(b)
print(max(aa,ba))
### BUGGY CODE ###

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

def main():
    scores = []
    score = 1
    for i in range(k-1, -1, -1):
        score *= a[i]

    scores.append(score)

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

            
if __name__ == '__main__':
    main()

### 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 = int(input())
a = list(map(int,input().split()))
i = 0
j = 1
ans = 0
p = 0
nextj = 0
while True:
    if j == n:
        i += 1
        j = min(n-1,i+a[i]+1)

    
    if a[i] + a[j] == j-i:
        ans += 1

    j += 1
    
    if i == n-1:
        print(ans)
        exit()

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
mae = {}
ans = 0
for i in range(n):
    mae[i+a[i]]=mae.get(i+a[i],0)+1
    ans += mae.get(i-a[i],0)
print(ans)
### BUGGY CODE ###

from collections import deque
N = int(input())
C = []
M = {}
for i in range(N):
    *c, = map(int, input().split())
    c = tuple(min(c[j:] + c[:j] for j in range(1, 5)))
    C.append(c)
    if c not in M:
        M[c] = deque([i])
    else:
        M[c].append(i)
def count(p, q, r, s):
    if p == q == r == s:
        return 4
    if p == r and q == s:
        return 2
    return 1
def solve(ci, cj, k):
    R = {}
    for l in range(4):
        #  [l]   [l-1]
        # [l+k] [l+k+1]
        c = ci[l], ci[l-1], cj[k-l], cj[k-l-1]
        c = tuple(min(c[j:] + c[:j] for j in range(1, 5)))
        if c not in M:
            return 0
        R[c] = R.get(c, 0) + 1
    res = 1
    for c in R:
        m = M[c]
        cnt = len(m)
        if c == cj:
            cnt -= 1
        if cnt < R[c]:
            return 0
        k = count(*c)
        for p in range(cnt-R[c]+1, cnt+1):
            res *= p * k
    return res

ans = 0
for i in range(N):
    ci = C[i]
    q = M[ci]; q.popleft()
    if not q:
        del M[ci]
    for j in range(i+1, N):
        cj = C[j]
        for k in range(4):
            ans += solve(ci, cj, k)
print(ans)


### FIXED CODE ###

from collections import deque
N = int(input())
C = []
M = {}
for i in range(N):
    *c, = map(int, input().split())
    c = tuple(min(c[j:] + c[:j] for j in range(1, 5)))
    C.append(c)
    if c not in M:
        M[c] = deque([i])
    else:
        M[c].append(i)
def count(p, q, r, s):
    if p == q == r == s:
        return 4
    if p == r and q == s:
        return 2
    return 1
def solve(ci, cj, k):
    R = {}
    for l in range(4):
        #  [l]   [l-1]
        # [l+k] [l+k+1]
        c = ci[l], ci[l-1], cj[k-l], cj[k-l-1]
        c = tuple(min(c[j:] + c[:j] for j in range(1, 5)))
        if c not in M:
            return 0
        R[c] = R.get(c, 0) + 1
    res = 1
    for c in R:
        m = M[c]
        cnt = len(m)
        if c == cj:
            cnt -= 1
        if cnt < R[c]:
            return 0
        k = count(*c)
        for p in range(cnt-R[c]+1, cnt+1):
            res *= p * k
    return res

ans = 0
for i in range(N):
    ci = C[i]
    q = M[ci]; q.popleft()
    if not q:
        del M[ci]
    for j in range(i+1, N):
        cj = C[j]
        for k in range(4):
            ans += solve(ci, cj, k)
print(ans)
### BUGGY CODE ###

#python3
from copy import copy
MOD = int(1e9)+7

def main():
    s = input()
    n = len(s)
    dp = [0 for _ in range(13)]
    dp[0] = 1 
    mul = 1
    for i in reversed(range(n)):
        nextDP = [0 for _ in range(13)]
        if s[i] == '?':
            for j in range(13):
                for k in range(10):
                    nextDP[(k*mul + j)%13] += dp[j]
                    nextDP[(k*mul + j)%13] %= MOD
        else:
            x = ord(s[i]) - ord('0')
            for j in range(13):
                nextDP[(x*mul + j)%13] += dp[j]
                nextDP[(x*mul + j)%13] %= MOD
        dp = copy(nextDP)
        mul *= 10
    print(dp[5])
main()

### FIXED CODE ###

from copy import copy
MOD = int(1e9)+7

def main():
    s = input()
    n = len(s)
    dp = [0 for _ in range(13)]
    dp[0] = 1 
    mul = 1
    for i in reversed(range(n)):
        nextDP = [0 for _ in range(13)]
        if s[i] == '?':
            for j in range(13):
                for k in range(10):
                    nextDP[(k*mul + j)%13] += dp[j]
                    nextDP[(k*mul + j)%13] %= MOD
        else:
            x = ord(s[i]) - ord('0')
            for j in range(13):
                nextDP[(x*mul + j)%13] += dp[j]
                nextDP[(x*mul + j)%13] %= MOD
        dp = copy(nextDP)
        mul *= 10
        mul %= 13
    print(dp[5])
main()
### BUGGY CODE ###

N = int(input())
A=[]
B=[]
for i in range(N):
    a,b = map(int,input().split())
    c = 0
    A.append(a)
    B.append(b)
def merge_sort(arr,b):
    if len(arr) <= 1:
        return (arr,b)

    mid = len(arr) // 2
    # ここで分割を行う
    left = arr[:mid]
    right = arr[mid:]
    leftt =b[:mid]
    rightt = b[mid:]

    # 再帰的に分割を行う
    left,leftt = merge_sort(left,leftt)
    right,rightt = merge_sort(right,rightt)

    # returnが返ってきたら、結合を行い、結合したものを次に渡す
    return merge(left, right,leftt,rightt)


def merge(left, right,leftt,rightt):
    merged = []
    mergedd = []
    l_i, r_i = 0, 0

    # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
    while l_i < len(left) and r_i < len(right):
        # ここで=をつけることで安定性を保っている
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            mergedd.append(leftt[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            mergedd.append(rightt[r_i])
            r_i += 1

    # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
    if l_i < len(left):
        merged.extend(left[l_i:])
        mergedd.extend(leftt[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
        mergedd.extend(rightt[r_i:])
    return (merged,mergedd)
B,A = merge_sort(B,A)
found = True
SUM = 0
for i in range(N):
    SUM = SUM + A[i]
    if B[i] < SUM:
        found = False
if found:
    print("Yes")
else:
    print("No")
    



### FIXED CODE ###

N = int(input())
A=[]
B=[]
for i in range(N):
    a,b = map(int,input().split())
    c = 0
    A.append(a)
    B.append(b)
def merge_sort(arr,b):
    if len(arr) <= 1:
        return (arr,b)

    mid = len(arr) // 2
    # ここで分割を行う
    left = arr[:mid]
    right = arr[mid:]
    leftt =b[:mid]
    rightt = b[mid:]

    # 再帰的に分割を行う
    left,leftt = merge_sort(left,leftt)
    right,rightt = merge_sort(right,rightt)

    # returnが返ってきたら、結合を行い、結合したものを次に渡す
    return merge(left, right,leftt,rightt)


def merge(left, right,leftt,rightt):
    merged = []
    mergedd = []
    l_i, r_i = 0, 0

    # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
    while l_i < len(left) and r_i < len(right):
        # ここで=をつけることで安定性を保っている
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            mergedd.append(leftt[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            mergedd.append(rightt[r_i])
            r_i += 1

    # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
    if l_i < len(left):
        merged.extend(left[l_i:])
        mergedd.extend(leftt[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
        mergedd.extend(rightt[r_i:])
    return (merged,mergedd)
B,A = merge_sort(B,A)
found = True
SUM = 0
for i in range(N):
    SUM = SUM + A[i]
    if B[i] < SUM:
        found = False
if found:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

n,k = map(int,input().split())
li = list(map(int,input().split()))
ans = [0]*n
tmp = [0]*n
#print(ans)
#[0, 0, 0, 0, 0]
for kkk in range(k):
    for i,l in enumerate(li):
        for xx in range(n):
            sa = abs(xx - i)
            #print(sa,l,'sa',i)
            if sa<=l:
                tmp[xx]+=1
    ans = tmp
    li = tmp
    tmp = [0]*n
    if len(set(ans)) == 1:
        break
print(*ans)

### FIXED CODE ###

n,k = map(int,input().split())
li = list(map(int,input().split()))
ans = [0]*(n+1)
tmp = [0]*(n+1)
tmp_sum = []
#print(ans)
#[0, 0, 0, 0, 0]
k = min(k,100)

for kkk in range(k):
    #print(li,'li')
    for i,l in enumerate(li):
        if l != 0:
            start = max(0,i-l)
            end = min(n,i+l+1)
            #print(start,'start',end,'end')
            tmp[start] += 1
            #print(end,len(tmp),'aaa')
            tmp[end] -= 1
    #print(tmp,'tmp')
    last = 0
    for t in tmp:
        last = t+last
        tmp_sum.append(last)
    for i,l in enumerate(li):
        if l == 0:
            tmp_sum[i] += 1
    ans = tmp_sum[:n]
    li = tmp_sum[:n]
    tmp = [0]*(n+1)
    tmp_sum = []
    #if len(set(ans)) == 1:
    #    break
print(*ans)
### BUGGY CODE ###

n=int(input())
a=list()
for i in range (n):
    a.append(int(input()))
for i in range(n):
    if(max(a)==a[i]):
        new_a_reverse=sorted(a,reverse=True)
        print(new_a_reverse[1])
    elif(max(a)!=a[i]):
        print(max(a))


### FIXED CODE ###

n=int(input())
a=list()
for i in range (n):
    a.append(int(input()))
new_a_reverse=sorted(a,reverse=True)
max=new_a_reverse[0]
max2=new_a_reverse[1]
for i in a:
    if(i==max):
        print(max2)
    else:
        print(max)
### BUGGY CODE ###

import math
import operator as op
from functools import reduce
from fractions import Fraction as frac

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer / denom
"""
int(input())
map(int,input().split())
list(map(int,input().split()))
"""
# t=int(input())
t=1
for term in range(t):
    n,k=map(int,input().split())
    A=list(map(int,input().split()))
    B=[0 for i in range(n)]
    for i in range(1,n):
        B[i]=min(    (B[max(i-j,0)]+abs(A[max(i-j,0)]-A[i]) )   for j in range(1,k+1))
    print(B[n-1])

### FIXED CODE ###

import sys
def input():
    return sys.stdin.readline().strip()
 
def main():
    nk=list(map(int,input().split()))
    h=list(map(int,input().split()))
    n=nk[0]
    k=nk[1]
    dp=[10**9]*n
    dp[0]=0
    dp[1]=abs(h[1]-h[0])
    for i in range(2,n):
        dp[i]=min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i))
        # for j in range(max(0,i-k),i):
        #     dp[i]=min(dp[j]+abs(h[i]-h[j]),dp[i])
 
    print (dp[-1])
 
if __name__ == "__main__":
    main()
### BUGGY CODE ###

k = int(input())
a =7
for i in range(20000):
  if a%k ==0:
    print(i+1)
    break
  i +=1
  a = a + 7*10**(i)
else:
  print("-1")

 

### FIXED CODE ###

k = int(input())
if k % 2 == 0 or k%5==0:
    print(-1)
    exit()
a = 7
ans = 1
while True:
    if a % k == 0:
        print(ans)
        exit()
    a = (a*10+7) % k
    ans += 1
### BUGGY CODE ###

N = int(input())
T,A = (int(T) for T in input().split())
for TN in range(1,N):
    TNext,ANext = (int(T) for T in input().split())
    Cnt = 1
    while TNext*Cnt<T or ANext*Cnt<A:
        Cnt += 1
    T = TNext*Cnt
    A = ANext*Cnt
print(A+T)

### FIXED CODE ###

N = int(input())
TNow,ANow = (int(T) for T in input().split())
for TN in range(1,N):
    TNext,ANext = (int(T) for T in input().split())
    Magn = max(TNow//TNext+(TNow%TNext!=0),ANow//ANext+(ANow%ANext!=0))
    TNow,ANow = TNext*Magn,ANext*Magn
print(TNow+ANow)
### BUGGY CODE ###

n,x,y=map(int,input().split())
ans=[0]*(n-1)
for i in range(n):
  for j in range(i+1,n):
    nagasa=min(abs(j-i),(abs(x-(i+1))+1+abs((j+1)-y)),(abs(y-(i+1))+1+abs((j+1)-x)))
    #print(i,j,nagasa)
    ans[nagasa-1]+=1
for i in range(n-1):
  print(ans[i])

### FIXED CODE ###

n,x,y=map(int,input().split())
ans=[0]*(n-1)
for i in range(n):
  for j in range(i+1,n):
    nagasa=min(abs(j-i),(abs(x-(i+1))+1+abs((j+1)-y)),(abs(y-(i+1))+1+abs((j+1)-x)))
    #print(i,j,nagasa)
    ans[nagasa-1]+=1
for i in range(n-1):
  print(ans[i])