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

import bisect


def count(text, s, rgb_bag):
    ans = 0
    for i in rgb_bag[text[0]]:
        for j in rgb_bag[text[1]]:
            if i > j:
                continue
            k = bisect.bisect_left(rgb_bag[text[2]], j)
            ans += len(rgb_bag[text[2]]) - k
            ng_idx = j + (j - i)
            if ng_idx >= len(s):
                continue
            if s[ng_idx] == text[2]:
                ans -= 1
    return ans


def main():
    n = int(input())
    s = input()
    rgb_bag = {'R': [], 'G': [], 'B': []}
    for i, v in enumerate(s):
        rgb_bag[v].append(i)
    ans = 0

    for r in 'RGB':
        for g in 'RGB':
            for b in 'RGB':
                if r == g or g == b or b == r:
                    continue
                ans += count(r+g+b, s, rgb_bag)
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import bisect


def count(text, s, rgb_bag):
    ans = 0
    for i in rgb_bag[text[0]]:
        for j in rgb_bag[text[1]]:
            if i > j:
                continue
            k = bisect.bisect_left(rgb_bag[text[2]], j)
            ans += len(rgb_bag[text[2]]) - k
            ng_idx = j + (j - i)
            if ng_idx >= len(s):
                continue
            if s[ng_idx] == text[2]:
                ans -= 1
    return ans


def main():
    n = int(input())
    s = input()
    rgb_bag = {'R': [], 'G': [], 'B': []}
    for i, v in enumerate(s):
        rgb_bag[v].append(i)
    ans = 0

    for r in 'RGB':
        for g in 'RGB':
            for b in 'RGB':
                if r == g or g == b or b == r:
                    continue
                ans += count(r+g+b, s, rgb_bag)
    print(ans)


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

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

d1 = [[0]*60 for _ in range(N+1)]
mod = 10**9+7

for i, n in enumerate(A, start=1):
    for j in range(60):
        d1[i][j] = d1[i-1][j] + n%2
        n//=2

ans = 0
for i, n in enumerate(A, start=1):
    for j in range(60):
        a = d1[N][j]-d1[i][j] # 1
        b = N-a-i # 0

        if n%2:
            ans += b*(2**j)
        else:
            ans += a*(2**j)
        ans %= mod
        n//=2

print(ans)

### FIXED CODE ###

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

d1 = [[0]*60 for _ in range(N+1)]
mod = 10**9+7

for i, n in enumerate(A, start=1):
    for j in range(60):
        d1[i][j] = d1[i-1][j] + ((n>>j)&1)

ans = 0
for i, n in enumerate(A, start=1):
    for j in range(60):
        a = d1[N][j]-d1[i][j] # 1
        if (n>>j)&1:
            a = N-a-i # 0

        ans += a*(1<<j)
    ans %= mod

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

n, k = map(int, input().split())
import itertools
ans = 0
for a, b, c in itertools.product(range(1,n+1), repeat=3):
  if (a+b)%k == 0 and (b+c)%k == 0 and (c+a)%k == 0:
    ans += 1
print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
ans = 0
temp = n // k
ans += temp ** 3

if k % 2 == 0:
  n += k // 2
  temp = n // k
  ans += temp ** 3
  
print(ans)
### BUGGY CODE ###

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

lenums = int(input())
nums = [int(i) for i in input().split()]
answer = 0
lenums1 = lenums + 1

ans = [sum([1 for j in range(i + 1, lenums1) if sum(nums[i:j]) == 0]) for i in range(lenums)]
answer = sum(ans)

print(answer)


### FIXED CODE ###

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

lenums = int(input())
nums = [int(i) for i in input().split()]
answer = 0

dp = [0]

for i in range(lenums):
    dp.append(dp[i] + nums[i])

count_dict = collections.Counter(dp)
for i in count_dict.values():
    if i <= 1:
        continue
    answer = answer + i * (i - 1) // 2 # xC2

print(answer)
### BUGGY CODE ###

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

dp = [[0] * (N+1) for _ in range(N+1)]

for i in range(N-1, -1, -1):
    for j in range(N-1, -1, -1):
        if S[i] == S[j]:
            dp[i][j] = dp[i+1][j+1] + 1

ans = 0
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        now = min(dp[i][j], j-i)
        ans = max(ans, now)

print(ans)

### FIXED CODE ###

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

dp = [[0] * (N+1) for _ in range(N+1)]

for i in range(N-1, -1, -1):
    for j in range(N-1, -1, -1):
        if S[i] == S[j]:
            dp[i][j] = dp[i+1][j+1] + 1

ans = 0
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        now = min(dp[i][j], j-i)
        ans = max(ans, now)

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

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,m=MI()
lis=[LI() for i in range(m)]
pas=[]
for i in range(m):
    if lis[i][0]==1:
        pas.append(lis[i][1])
for i in range(m):
    if lis[i][1]==n:
        if lis[i][0] in pas:
            print("POSSIBLE")
            sys.exit()
print("IMPOSSIBLE")

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,m=MI()
lis=[LI() for i in range(m)]
nums=[]
for i in range(m):
    if lis[i][0]==1:
        nums.append(lis[i][1])
    if lis[i][1]==n:
        nums.append(lis[i][0])
#print(nums)
if len(nums)>len(list(set(nums))):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
### BUGGY CODE ###

H, W = map(int,input().split())
# C = [list(input()) for _ in range(H)]
C = []
pre = 0
for i in range(H):
    c = list(input())
    pre += c.count("#")
    C.append(c)

list = [(0, 0)]
count = 1
 
while C[H-1][W-1] == '.':
    count += 1
    next_list = []
    for y,x in list:
        for i,j in ((1,0),(0,1),):
            if x+j < W and y+i < H:
                if C[y+i][x+j] == '.':
                    C[y+i][x+j] = count
                    next_list.append((y+i,x+j))
    list = next_list
print(H*W-pre-count)

### FIXED CODE ###

H, W = map(int, input().split())
C = [list(input()) for _ in range(H)]

# bfs 
C[0][0] = 0
pre_list = [(0,0)]
count = 0
 
while C[H-1][W-1] == '.' and len(pre_list) > 0:
    count += 1
    next_list = []
    for y,x in pre_list:
        for i,j in ((1,0),(0,-1),(0,1),(-1,0)):
            if y+i < 0 or x+j < 0 or y+i >= H or x+j >= W:
                continue
            if C[y+i][x+j] == '.':
                C[y+i][x+j] = count
                next_list.append((y+i,x+j))
    pre_list = next_list

if C[H-1][W-1] == '.':
    print(-1)
else:
    black = 0
    for h in C:
        for v in h:
            if v == "#":
                black += 1
    print(H*W-black-count-1)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(1,n+1):
    b.append(a.index(i)+1)
print(*b)

### FIXED CODE ###

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

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

tmp = []
cnt = 1
s += '-'
for i in range(n):
    if s[i] == s[i + 1]:
        cnt += 1
    else:
        tmp.append(cnt)
        cnt = 1

for i in range(k):
    if len(tmp) == 1:
        break
    elif len(tmp) == 2:
        tmp = [tmp[0] + tmp[1]]
    else:
        tmp = [tmp[0] + tmp[1] + tmp[2]] + tmp[3:]
# print(tmp)

if len(tmp) == 1:
    print(tmp[0] - 1)
else:
    total = 0
    for j in tmp:
        if j > 1:
            total += j - 1
    print(total)


### FIXED CODE ###

from collections import deque


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

tmp = deque()
cnt = 1
s += '-'
for i in range(n):
    if s[i] == s[i + 1]:
        cnt += 1
    else:
        tmp.append(cnt)
        cnt = 1

for i in range(k):
    if len(tmp) == 1:
        break
    elif len(tmp) == 2:
        tmp = [tmp[0] + tmp[1]]
    else:
        hoge = tmp[0] + tmp[1] + tmp[2]
        tmp.popleft()
        tmp.popleft()
        tmp.popleft()
        tmp.appendleft(hoge)

if len(tmp) == 1:
    print(tmp[0] - 1)
else:
    total = 0
    for j in tmp:
        if j > 1:
            total += j - 1
    print(total)
### BUGGY CODE ###

N,Q = map(int,input().split())
S = input()
lr = [list(map(int,input().split())) for _ in range(Q)]
q_lis = [S[lr[x][0]-1:lr[x][1]:] for x in range(Q)]
for q in range(Q):
    print(q_lis[q].count('AC'))

### FIXED CODE ###

N,Q = map(int,input().split())
S = input()
ansers = [0] * (N+1)
for i in range(N):
    ansers[i+1] = ansers[i] + (1 if S[i:i+2] == 'AC' else 0)
for q in range(Q):
    l,r = map(int,input().split())
    print(ansers[r-1] - ansers[l-1])
### BUGGY CODE ###

from bisect import bisect_left, bisect, insort
def main():
    n = int(input())
    s = list(input())
    q = int(input())
    _is = {chr(i):[] for i in range(ord("a"), ord("a")+27)}
    for i, si in enumerate(s, 1):
        _is[si].append(i)
    for _ in range(q):
        t, i, c = input().split()
        i = int(i)
        if t == "1":
            index = bisect_left(_is[s[i-1]], i)
            del _is[s[i-1]][index]
            insort(_is[c], i)
            s[i-1] = c
        else:
            c = int(c)
            cnt = 0
            for _isi in _is.values():
                if _isi:
                    is_in = bisect(_isi, c)-bisect_left(_isi, i)
                    if is_in:
                        cnt += 1
            print(cnt)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n = int(input())
    a = ord("a")
    orda = lambda x: ord(x)-a
    s = list(map(orda, list(input())))
    q = int(input())
    bits = [BIT(n) for _ in range(26)]
    for i, si in enumerate(s, 1):
        bits[si].add(i, 1)
    for _ in range(q):
        t, i, c = input().split()
        i = int(i)
        if t == "1":
            bits[s[i-1]].add(i, -1)
            bits[ord(c)-a].add(i, 1)
            s[i-1] = ord(c)-a
        else:
            c = int(c)
            cnt = 0
            for bit in bits:
                is_in = bit.sum_(c) - bit.sum_(i-1)
                if is_in:
                    cnt += 1
            print(cnt)
            
            
class BIT:
    __slots__ = ["length", "data"]
    def __init__(self, length):
        self.data = [0]*(length+1)
        self.length = length
    
    def add(self, i, x):
        while i < self.length+1:
            self.data[i] += x
            i += i&-i
    
    def sum_(self, i):
        x = 0
        while i > 0:
            x += self.data[i]
            i -= i&-i
        return x


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

# [時間、変数、処理の種類]をイベントに追加。処理の種類は1：工事開始、2：工事終了、3：判定
from heapq import *
n, q = map(int, input().split())
events = []
ans = [-1] * q
koji = []
for _ in range(n):
    s, t, x = map(int, input().split())
    events += [[s - x - 0.3, x, 1]]
    events += [[t - x - 0.7, x, 2]]
for i in range(q):
    d = int(input())
    events += [[d, i, 3]]
events.sort()
for j, h, s in events:
    if s == 1:
        heappush(koji,h)
    elif s == 2:
        koji.remove(h)
        heapify(koji)
    else:
        if koji:
            ans[h] = koji[0]
print(*ans, sep="\n")


### FIXED CODE ###

import sys
from bisect import *

input = sys.stdin.readline

def f(n, q):
    xst = []
    for i in range(n):
        s, t, x = map(int, input().split())
        xst.append([x, s - x, t - x])
    xst.sort()

    ds = []
    for i in range(q):
        d = int(input())
        ds.append(d)

    ans = [-1] * q
    jump = [-1] * q

    for x, s, t in xst:
        i = bisect_left(ds, s)
        fi = bisect_left(ds, t)
        while i < fi:
            if jump[i] != -1:
                i = jump[i]
            else:
                ans[i] = x
                jump[i] = fi
                i += 1

    print(*ans, sep="\n")

n, q = map(int, input().split())
f(n, q)
### BUGGY CODE ###

w=input()
n=int(input())
import itertools as it
s={w}
for i,j in it.product(range(len(w)),repeat=2):
  if i<=j: s.add(w[i:j+1])
print(sorted(s)[n-1])

### FIXED CODE ###

w=input();n=int(input())
print(sorted({w[j:j+i+1] for i in range(n) for j in range(len(w)-i)})[n-1])
### BUGGY CODE ###

s = input().strip()
k = int(input())

ss = set()
for i in range(len(s)):
    for j in range(i, len(s)):
        ss.add(s[i:j+1])

print(sorted(list(ss))[k-1])

### FIXED CODE ###

def all_index(s, c):
    ins = []
    for i in range(len(s)):
        if s[i] == c:
            ins.append(i)

    return ins


s = input().strip()
k = int(input())

ss = set()
alphabets = sorted(list(set(s)))
for c in alphabets:
    ins = all_index(s, c)
    for i in ins:
        for j in range(i, len(s)):
            if (j+1 - i) > k:
                break

            ss.add(s[i:j+1])

    if len(ss) >= k:
        break

print(sorted(list(ss))[k-1])
### BUGGY CODE ###

N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[[0 for i in range(N)] for j in range(N)] 
P=[0 for i in range(N)]
for i in range(M):
  A,B=map(int,input().split())
  P[A-1]+=1
  P[B-1]+=1
  if H[A-1]>H[B-1]:
    L[A-1][B-1]+=1
  if H[B-1]>H[A-1]:  
    L[B-1][A-1]+=1

count=0 
for i in range(N):
  if P[i]==sum(L[i]):
    count+=1
print(count)

### FIXED CODE ###

N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[0 for i in range(N)] 
P=[0 for i in range(N)]
for i in range(M):
  A,B=map(int,input().split())
  P[A-1]+=1
  P[B-1]+=1
  if H[A-1]>H[B-1]:
    L[A-1]+=1
  if H[B-1]>H[A-1]:  
    L[B-1]+=1

count=0 
for i in range(N):
  if P[i]==L[i]:
    count+=1
print(count)
### BUGGY CODE ###

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

biggest = 0
humidai = 0

result = 0


for i in range(N-1):
    for j in range(i+1,N):
        result += A[i]*A[j]
        if result>10**9+7:
            result = result%(10**9+7)

result = result%(10**9+7)

print(result)

### FIXED CODE ###

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

biggest = 0
humidai = 0

result = 0

tmp_list = []

tmp=sum(A)

for i in range(N-1):

    # for j in range(i+1,N):
        # tmp += A[j]
    tmp -= A[i]
    
    result += A[i]*tmp

    if result>10**9+7:
        result = result%(10**9+7)

result = result%(10**9+7)

print(result)
### BUGGY CODE ###

h, w = map(int, input().split())
s = [input() for i in range(h)]
isCase = True
count = 1

while (count != 0):
    count = 0
    for i in range(h):
        for j in range(w):
            count = s[i][j].count('#')
            if (s[i][j] == '#'):
                s[i][j].replace('#', '.')
                if (s[max(i-1,0)][j] == '#'):
                    s[max(i-1,0)][j].replace('#', '.')
                elif (s[i][max(j-1,0)] == '#'):
                    s[i][max(j-1,0)].replace('#', '.')
                elif (s[i][min(j+1,w-1)] == '#'):
                    s[i][min(j+1,w-1)].replace('#', '.')
                elif (s[min(i+1,h-1)][j] == '#'):
                    s[min(i+1,h-1)][j].replace('#', '.')
                else:
                    isCase = False
                    break
    if (isCase == False):
        break

if (isCase):
    print('Yes')
else:
    print('No')

### FIXED CODE ###

h, w = map(int, input().split())
s = [list(map(str, input())) for i in range(h)]
isCase = True
count = 1

def isBlack(i, j, h, w):
    if ((i-1>0 and s[max(i-1,0)][j] == 'B') or (j-1>0 and s[i][max(j-1,0)] == 'B') or (j+1<w-1 and s[i][min(j+1,w-1)] == 'B') or (i+1<h-1 and s[min(i+1,h-1)][j] == 'B')):
        return True
    else:
        return False

while (count != 0 and isCase):
    count = 0
    for i in range(h):
        for j in range(w):
            if (s[i][j] == '#'):
                s[i][j] = 'B'
                count += 1
                if (s[max(i-1,0)][j] == '#'): #上
                    s[max(i-1,0)][j] = 'B'
                elif (s[i][max(j-1,0)] == '#'): #左
                    s[i][max(j-1,0)] = 'B'
                elif (s[i][min(j+1,w-1)] == '#'): #右
                    s[i][min(j+1,w-1)] = 'B'
                elif (s[min(i+1,h-1)][j] == '#'): #下
                    s[min(i+1,h-1)][j] = "B"
                elif (isBlack(i, j, h ,w)):
                    pass
                else:
                    isCase = False
                    break
        if (isCase == False):
            break

if (isCase):
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

a, b = map(int, input().split())
y = []
p = 0
w = []
for i in range(1, 1000):
    p += i
    y.append(p)
    w.append(1)

"""z = []
for i in range(499500):
    z.append([])
for i in range(499500):
    z[i] = list(map(lambda k: k - i - 1, y))"""

for h in range(1, 499501):
    y = [y1 - w1 for (y1, w1) in zip(y, w)]
    for i in range(999):
        if i != 0:
            if b == y[i] and a == y[i - 1]:
                print(h)
                break
    else:  # 内側のforのelse節は内側ループが全部まわり切ったら実行される、つまり前の行のbreakで抜けた場合ここは実行されない
        continue  # 外側のforに対応するcontinue文、ここが実行されたら次の行のbreakには処理がいかず、外側のforの次のループにジャンプする
    break  # 外側のforを抜ける

### FIXED CODE ###

a, b = map(int, input().split())
y = []
p = 0

for i in range(1, 1000):
    p += i
    y.append(p)
    
c = b - a
for i in range(1, 999):
    if y[i] - y[i - 1] == c:
        print(y[i] - b)
        break
### BUGGY CODE ###

from collections import deque


class Tree:
    def __init__(self, n, init_list, root=1):
        self.num = (n + 1)
        self.parents = [-1] * self.num
        self.first_child = [-1] * self.num
        self.next_child = [-1] * self.num
        self.check = [-1] * self.num
        self.g = {i: [] for i in range(1, self.num)}
        self.make_g(init_list, root)

    def make_g(self, con, root):
        m = len(con)
        for i in range(m):
            self.g[con[i][0]].append(con[i][1])
            self.g[con[i][1]].append(con[i][0])
        q = deque([root])
        while q != deque():
            node = q.pop()
            self.check[node] = 1
            cnt = 0
            for i, sub_node in enumerate(self.g[node]):
                if self.check[sub_node] != -1:
                    continue
                if cnt == 0:
                    self.first_child[node] = sub_node
                self.parents[sub_node] = node
                if i != len(self.g[node])-1:
                    self.next_child[sub_node] = self.g[node][i+1]
                q.append(sub_node)
                cnt += 1

    def childs(self, node):
        child_list = []
        if self.first_child[node] != -1:
            child_list.append(self.first_child[node])
            node = self.first_child[node]
            while 1:
                if self.next_child[node] == -1:
                    break
                else:
                    child_list.append(self.next_child[node])
                node = self.next_child[node]
        return child_list

    def parent(self, n):
        return self.parents[n]


N, Q = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N-1)]
P = [0] * Q
X = [0] * Q
V = [0] * (N + 1)
for i in range(Q):
    P, X = map(int, input().split())
    V[P] += X

tr = Tree(N, AB)

q = deque()
q.extend(tr.childs(1))
while q != deque():
    node = q.pop()
    V[node] += V[tr.parent(node)]
    if tr.childs(node) != []:
        q.extend(tr.childs(node))

print(*V[1:])

### FIXED CODE ###

from collections import deque

N, Q = map(int, input().split())
AB = {i: set() for i in range(1, N+1)}
for i in range(N - 1):
    tmpA, tmpB = map(int, input().split())
    AB[tmpA].add(tmpB)
    AB[tmpB].add(tmpA)
P = [0] * Q
X = [0] * Q
V = [0] * (N + 1)
for i in range(Q):
    P, X = map(int, input().split())
    V[P] += X

check = [0]*(N + 1)
q = deque()
q.append(1)
check[1] = 1
while q != deque():
    node = q.pop()
    for i in AB[node]:
        if check[i] == 1:
            continue
        V[i] += V[node]
        check[i] = 1
        q.appendleft(i)
print(*V[1:])
### BUGGY CODE ###

N = int(input())
P_list = list(map(int, input().split()))
cnt = 0
for i, P in enumerate(P_list):
    for tmp_P in P_list[:i+1]:
        if P > tmp_P:
            break
    else:
        cnt += 1
print(cnt)

### FIXED CODE ###

N = int(input())
P_list = list(map(int, input().split()))
cnt = 0
min_num = P_list[0]
for P in P_list:
    if min_num >= P:
        cnt += 1
        min_num = P
print(cnt)
### BUGGY CODE ###

import sys
big=10**9+7

def modsum(a,b):
  return a%big + b%big

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

a = [0]*m
for i in range(m):
  a[i] = int(input())
  
#連続こわれ
for i in range(m-1):
  if a[i]+1 == a[i+1]:
    print(0)
    sys.exit(0)

#選択肢計算
cho = [1]*n
if 1 in a:
  cho[1]=0

for i in range(2,n):
  if i in a:
    cho[i] = 0
  elif i-1 in a:
    cho[i] = cho[i-2]
  else:
    cho[i] = modsum(cho[i-1], cho[i-2])


print(cho[-1]%big)


### FIXED CODE ###


big=10**9+7

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

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

cho = [0]*(n+1)
if 0 not in a:
  cho[0] = 1
if 1 not in a:
  cho[1] = 1

for i in range(2,n+1):
  if i not in a:
    cho[i] = (cho[i-1]+cho[i-2])%big


print(cho[-1])
### BUGGY CODE ###

import math
import bisect
import heapq
from collections import deque

def main():
    n, k = map(int, input().split())

    h = list(map(int, input().split()))

    d = [float('inf')] * n
    d[0] = 0

    for j in range(1, n):
        p = [d[i] + abs(h[j] - h[i]) for i in range(max(0, j - k), j)]

        d[j] = min(p)

    print(d[-1])

if __name__ == "__main__":
    main()

### FIXED CODE ###

# import math
# import bisect
# import heapq
# from collections import deque

def main():
    n, k = map(int, input().split())

    h = list(map(int, input().split()))
    inf = 10**7
    d = [inf] * n
    d[0] = 0

    for j in range(1, n):
        p = [d[i] + abs(h[j] - h[i]) for i in range(max(0, j - k), j)]

        d[j] = min(p)

    print(d[-1])

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

from math import gcd
from functools import reduce

def gcd3(*numbers):
    return reduce(gcd, numbers)

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

  ans = 0

  for i in range(K):
    for j in range(K):
      for k in range(K):
        ans += gcd3(i+1,j+1,k+1)

  print(ans)



if __name__ == "__main__":
  main()

### FIXED CODE ###

def gcd(a, b):
  if a%b == 0:
    return(b)
  else:
    return(gcd(b, a%b))

def gcd3(a,b,c):
  d = gcd(a,b)
  ans = gcd(d,c)
  return ans

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

  ans = 0

  for i in range(K):
    for j in range(K):
      for k in range(K):
        ans += gcd3(i+1,j+1,k+1)

  print(ans)

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

n,m = map(int,input().split())
o = [int(input()) for _ in range(m)]
#print(o)
mod = (10**9)+7
dp = [1]+[0]*(n)
flag1 = False
 
for i in range(n):
  if i+1 not in o:
    dp[i+1] = dp[i] + dp[i-1]
  else:
    dp[i+1] = 0
  #print(i,dp)
#print(dp)
print(dp[-1]%mod)

### FIXED CODE ###

n,m = map(int,input().split())
o = set(int(input()) for _ in range(m))
#print(o)
mod = (10**9)+7
dp = [0]*(n+1)
dp[0] = 1

for i in range(1,n+1):
  dp[i] = (dp[i-1]+dp[i-2])%mod
  if i in o:
    dp[i] = 0
  #print(i,dp)
#print(dp)
print(dp[-1])