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

n = int(input())
a = [int(input()) for i in range(n)]
x = [1]
y = 1

for i in range(n):
    y = a[y-1]
    x.append(y)
    if y == 2:
        break
    if x.count(y) == 2:
        print(-1)
        exit()

print(len(x)-1)

### FIXED CODE ###

n = int(input())
a = [int(input()) for i in range(n)] #ボタンの仕様
x = [1] #遷移
 
for i in range(n):
    y = x[-1] #今の場所
    z = a[y-1]
    x.append(z)
    if z == 2:
        print(len(x)-1)
        exit()

print(-1)
### BUGGY CODE ###

import math
N = int(input())
A = 81
result = 0
for i in range(N + 1):
    if math.sqrt(i).is_integer() is True:
        result = i

print(result)

### FIXED CODE ###

import math
N = int(input())
N_square_root = math.floor(math.sqrt(N))
result = 0
for i in range(N_square_root + 1):
    result = i * i
print(result)
### BUGGY CODE ###

def solve():
    max_fare = 99000001
    def dijkstra(start, goal):
        unvisited = [i for i in range(n)]
        fare = [max_fare] * n
        fare[start] = 0
        
        while True:
            min_fare = max_fare
            for i in unvisited:
                f = fare[i]
                if f < min_fare:
                    min_fare = f
                    u = i
                    
            if u == goal:
                return min_fare
            elif min_fare == max_fare:
                return -1
            
            unvisited.remove(u)
            
            for v, f in enumerate(adj_matrix[u]):
                if v in unvisited:
                    fare[v] = min(min_fare + f, fare[v])
        
    import sys
    file_input = sys.stdin

    while True:
        n, k = map(int, file_input.readline().split())
        if n == 0 and k == 0:
            break
        
        adj_matrix = [[max_fare] * n for i in range(n)]
        
        for i in range(k):
            line = file_input.readline()
            if line[0] == '0':
                a, b = map(int, line[2:].split())
                print(dijkstra(a - 1, b - 1))
            else:
                c, d, e = map(int, line[2:].split())
                f = min(adj_matrix[c - 1][d - 1], e)
                adj_matrix[c - 1][d - 1] = f
                adj_matrix[d - 1][c - 1] = f

solve()


### FIXED CODE ###

def solve():
    from heapq import heappush, heappop
    def dijkstra(start, goal):
        fare = [99000001] * n
        fare[start] = 0
        pq = [(0, start)]
        
        while pq:
            u_fare, u = heappop(pq)
                    
            if u == goal:
                return u_fare
            
            for f, v in adj[u]:
                new_fare = u_fare + f
                if new_fare < fare[v]:
                    fare[v] = new_fare
                    heappush(pq, (new_fare, v))
        return -1
        
    import sys
    file_input = sys.stdin
    
    while True:
        n, k = map(int, file_input.readline().split())
        if n == 0 and k == 0:
            break
        
        adj = [[] for i in range(n)]
        
        for i in range(k):
            line = file_input.readline()
            if line[0] == '0':
                a, b = map(int, line[2:].split())
                print(dijkstra(a - 1, b - 1))
            else:
                c, d, e = map(int, line[2:].split())
                adj[c - 1].append((e, d - 1))
                adj[d - 1].append((e, c - 1))

solve()
### BUGGY CODE ###

K = int(input())
a = 7
cnt = 1
for k in range(K):
    if a % K == 0:
        print(cnt)
        exit()
    else:
        cnt += 1
        a = a * 10 + 7
else:
    print("-1")


### FIXED CODE ###

K = int(input())
a = 7 % K
cnt = 1
for k in range(K):
    if a % K == 0:
        print(cnt)
        exit()
    else:
        cnt += 1
        a = (a * 10 + 7) % K
else:
    print("-1")
### BUGGY CODE ###

s = input().strip()
q = int(input())
for i in range(q):
    a = input().split()
    t = int(a[0])
    if t == 1:
        s = s[::-1]
    else:
        f = int(a[1])
        c = a[2]
        if f == 1:
            s = c+s
        else:
            s = s+c
print(s)


### FIXED CODE ###

s = input().strip()
q = int(input())
l, r = "", ""
rev = 0
for i in range(q):
    a = input().split()
    t = int(a[0])
    if t == 1:
        rev += 1
    else:
        f = int(a[1])
        c = a[2]
        if f == 1:
            if rev % 2 == 0:
                l = c+l
            else:
                r = r+c
        else:
            if rev % 2 == 0:
                r = r+c
            else:
                l = c+l

if rev % 2 == 0:
    print(l+s+r)
else:
    print(r[::-1]+s[::-1]+l[::-1])
### BUGGY CODE ###

from collections import deque
n, m = map(int, input().split())
q = deque()
t = {i: set() for i in range(1, n + 1)}
v = [-1] * n

for _ in range(m):
    a, b = map(int, input().split())
    t[a].add(b)
    t[b].add(a)
q.append(1)
v[0] = 1
while q:
    next = q.popleft()
    for i in t[next]:
        if v[i - 1] == -1 and i not in q:
            q.append(i)
            v[i - 1] = next
print('Yes')
print(*v[1:], sep='\n')

### FIXED CODE ###

from collections import deque
n, m = map(int, input().split())
q = deque()
t = {i: set() for i in range(1, n + 1)}
v = [-1] * n

for _ in range(m):
    a, b = map(int, input().split())
    t[a].add(b)
    t[b].add(a)
q.append(1)
v[0] = 1
while q:
    next = q.popleft()
    for i in t[next]:
        if v[i - 1] == -1:
            q.append(i)
            v[i - 1] = next
print('Yes')
print(*v[1:], sep='\n')
### BUGGY CODE ###

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

n = s[0]
blue = s[1]
red = s[2]

temp = []

while n >= 0:
    for i in range(blue):
        temp.append(1)
    for i in range(red):
        temp.append(0)
    n -= (blue + red)

print(sum(temp[:n]))

### FIXED CODE ###

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

ans = N // (A + B) * A
rem = N % (A + B)
ans += min(rem, A)
print(ans)
### BUGGY CODE ###

v,e,r = map(int,input().split())
d = [float('INF')]*v
d[r] = 0
edges=[[] for i in range(v)]
visited = [False]*v

for i in range(e):
  s,t,c = map(int,input().split())
  edges[s].append([t,c])

while not all (visited):
  dmin = float('INF')
  for i, (du,v) in enumerate(zip(d,visited)):
    if dmin > du and not v:
      dmin, u = du, i
  visited[u] = True
  for v,c in edges[u]:
    if d[v] > d[u]+ c:
      d[v] = d[u]+c

for i in d:
  if i == float('inf'):
    print('INF')
  else:
    print(i)


### FIXED CODE ###

from heapq import heappush, heappop
v,e,r = map(int,input().split())
edges=[[] for i in range(v)]
d = [float('INF')]*v

for i in range(e):
  s,t,c = map(int,input().split())
  edges[s].append([t,c])

que = []
heappush(que,(0,r))
d[r] = 0

while que:
  c, u = heappop(que)
  for v, s in edges[u]:
    if d[v] > s + c:
      d[v] = s + c
      heappush(que,(d[v],v))
for i in d:
  if i == float('inf'):
    print('INF')
  else:
    print(i)
### BUGGY CODE ###

def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    
    left = [[-1]*W for _ in range(H)]
    right = [[-1]*W for _ in range(H)]
    up = [[-1]*W for _ in range(H)]
    down = [[-1]*W for _ in range(H)]

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if j == 0:
                    left[i][j] = 0
                else:
                    left[i][j] = left[i][j-1] + 1
                if i == 0:
                    up[i][j] = 0
                else:
                    up[i][j] = up[i-1][j] + 1

            if S[-1-i][-1-j] == '.':
                if j == 0:
                    right[-1-i][-1-j] = 0
                else:
                    right[-1-i][-1-j] = right[-1-i][-1-(j-1)] + 1
                if i == 0:
                    down[-1-i][-1-j] = 0
                else:
                    down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1

    ans = 0
    temp = [0] * W
    for i in range(H):
        for j in range(W):
            temp[j] = left[i][j] + right[i][j] + down[i][j] + up[i][j] + 1
        ans = max(ans, max(temp))
    print(ans)

main()

### FIXED CODE ###

def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]

    left = [[-1]*W for _ in range(H)]
    right = [[-1]*W for _ in range(H)]
    up = [[-1]*W for _ in range(H)]
    down = [[-1]*W for _ in range(H)]

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if j == 0:
                    left[i][j] = 0
                else:
                    left[i][j] = left[i][j-1] + 1

    for i in range(H):
        for j in range(W):
            if S[-1-i][-1-j] == '.':        
                if j == 0:
                    right[-1-i][-1-j] = 0
                else:
                    right[-1-i][-1-j] = right[-1-i][-1-(j-1)] + 1

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if i == 0:
                    up[i][j] = 0
                else:
                    up[i][j] = up[i-1][j] + 1

    for i in range(H):
        for j in range(W):
            if S[-1-i][-1-j] == '.':
                if i == 0:
                    down[-1-i][-1-j] = 0
                else:
                    down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1
            
    ans = 0
    temp = [0] * W
    for i in range(H):
        for j in range(W):
            temp[j] = left[i][j] + right[i][j] + down[i][j] + up[i][j] + 1
        ans = max(ans, max(temp))
    print(ans)

main()
### BUGGY CODE ###

if __name__ == '__main__':
    N = int(input())
    print(sum([i for i in range(N)]))

### FIXED CODE ###

if __name__ == '__main__':
    N = int(input())
    print((N)*(N-1)//2)
### BUGGY CODE ###

from collections import deque
from math import ceil
import sys
def input():
	return sys.stdin.readline()[:-1]

H, W, k = map(int, input().split())
m = [input() for _ in range(H)]
q = deque()
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

step = [[10**10 for _ in range(W)] for _ in range(H)]

for h in range(1, H-1):
	for w in range(1, W-1):
		if m[h][w] == "S":
			q.appendleft([h, w])
			sx, sy = h, w

step[sx][sy] = 0
while q:
	label = q.pop()
	if step[label[0]][label[1]] == k:
		continue
	for i in range(4):
		h, w = label[0] + dx[i], label[1] + dy[i]
		if 0 <= h < H and 0 <= w < W:
			if m[h][w] == "." and step[h][w] > step[label[0]][label[1]] + 1:
				q.appendleft([h, w])
				step[h][w] = step[label[0]][label[1]] + 1

min_dis = max(H, W)
for h in range(H):
	for w in range(W):
		if step[h][w] <= k:
			min_dis = min(min_dis, h, w, H-h-1, W-w-1)

print(1+ceil(min_dis/k))

### FIXED CODE ###

from collections import deque
from math import ceil
import sys
def input():
	return sys.stdin.readline()[:-1]

H, W, k = map(int, input().split())
m = [input() for _ in range(H)]
q = deque()
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

step = [[10**10 for _ in range(W)] for _ in range(H)]

for h in range(1, H-1):
	for w in range(1, W-1):
		if m[h][w] == "S":
			q.appendleft([h, w])
			sx, sy = h, w

step[sx][sy] = 0
while q:
	label = q.pop()
	if step[label[0]][label[1]] == k:
		continue
	for i in range(4):
		h, w = label[0] + dx[i], label[1] + dy[i]
		if 0 <= h < H and 0 <= w < W:
			if m[h][w] == "." and step[h][w] > step[label[0]][label[1]] + 1:
				q.appendleft([h, w])
				step[h][w] = step[label[0]][label[1]] + 1

min_dis = max(H, W)
for h in range(H):
	for w in range(W):
		if step[h][w] <= k:
			min_dis = min(min_dis, h, w, H-h-1, W-w-1)

print(1+ceil(min_dis/k))
### BUGGY CODE ###


import sys
input = sys.stdin.readline
#区間の管理は　[a, b)で管理していることに注意

# INT_MIN = -10 ** 18
MAX_N = 4 * 10 ** 5
# MAX_N = 20


def init(n_):
    #簡単にするために2のべき乗に揃える
    n = 1
    while n < n_:
        n *= 2
    return n

#初期化
N = int(input())
n = init(N)
data = [0] * (2 * MAX_N - 1)

def update(k, a):
    k += n - 1
    data[k] = a
    while k > 0:
        k = (k - 1) // 2
        data[k] = max(data[2 * k + 1], data[2 * k + 2])

def query(a, b, k = 0, l = 0, r = n):
    if r <= a or b <= l:
        return 0
    if a <= l and r <= b:
        return data[k]
    else:
        v1 = query(a, b, 2 * k + 1, l, (l + r)//2)
        v2 = query(a, b, 2 * k + 2, (l + r)//2, r)
        return max(v1, v2)

H = tuple(map(int, input().split()))
A = tuple(map(int, input().split()))

ans = 0
for i in range(N):
    # h = int(input())
    # a = int(input())
    h = H[i]
    a = A[i]
    tmp = query(1, h + 1) #[1, h)での最大値
    # print (h, tmp)
    update(h, tmp + a)
    ans = max(ans, tmp + a)
    # print (data)

print (ans)

# print (update(1, 1))
# print (update(2, 5))
# print (query(1, 2))



### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    #区間の管理は　[a, b)で管理していることに注意

    # INT_MIN = -10 ** 18
    # MAX_N = 4 * 10 ** 5
    # MAX_N = 20


    # def init(n_):
    #     #簡単にするために2のべき乗に揃える
    #     n = 1
    #     while n <= n_:
    #         n *= 2
    #     return n

    #初期化
    N = int(input())
    # n = 1
    # while n <= N:
    #     n *= 2

    n = 262144
    data = [0] * (2 * n - 1)

    def update(k, a):
        k = k + n - 1
        # data[k] = a
        while k >= 0:
            data[k] = max(a, data[k])
            k = (k - 1) // 2
            # data[k] = max(data[2 * k + 1], data[2 * k + 2])

    def query(a, b, k, l, r):
        if r <= a or b <= l:
            return 0
        elif a <= l and r <= b:
            return data[k]
        else:
            return max(query(a, b, 2 * k + 1, l, (l + r)//2), query(a, b, 2 * k + 2, (l + r)//2, r))

    H = tuple(map(int, input().split()))
    A = tuple(map(int, input().split()))

    # ans = 0

    dp = [A[0]] + [0] * (N - 1)
    update(H[0] - 1, A[0])
    for i in range(1, N):
        # h = int(input())
        # a = int(input())
        dp[i] = query(0, H[i] - 1, 0, 0, n) + A[i]
        # h = H[i]
        # a = A[i]
        # tmp = query(1, h + 1) #[1, h)での最大値
        # print (h, tmp)
        update(H[i] - 1, dp[i])
        # ans = max(ans, tmp + a)
        # print (data)

    print (query(0, N, 0, 0, n))

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

n,m = map(int,input().split())
card = [ set() for i in range(n+1) ]
for i in range(m):
    l,r = map(int,input().split())
    for j in range(l,r+1):
        card[j].add(i)

ans = 0
for i in card:
    if len(i) == m:
        ans += 1
print(ans)


### FIXED CODE ###

n,m = map(int,input().split())
card = [ 0 for i in range(n+5) ]
for i in range(m):
    l , r = map(int,input().split())
    card[l] += 1
    card[r+1] -= 1

for i in range(1,n+1):
    card[i] += card[i-1]
ans = 0
for i in card:
    if i == m:
        ans += 1
print(ans)
### BUGGY CODE ###

from collections import deque

N, K = list(map(int, input().split()))
K -= 1
A = list(map(lambda x: int(x) - 1, input().split()))
seen = deque()
now = 0
for i in range(N):
    seen.append(now)
    to = A[now]
    now = to
    if now in seen:
        seen.append(now)
        break
loop_s = seen.index(now)
loop_end = seen.index(now, loop_s + 1)
size = loop_end - loop_s
if K <= loop_s:
    print(seen[K+1] + 1)
else:
    K -= loop_s
    print(seen[loop_s + 1 + K % size] + 1)

### FIXED CODE ###

N, K = list(map(int, input().split()))
K -= 1
A = list(map(lambda x: int(x) - 1, input().split()))
seen = [None]*N
seen_set = set()
now = 0
for i in range(N):
    seen[i] = now
    seen_set.add(now)
    to = A[now]
    now = to
    if now in seen_set:
        seen[i+1] = now
        loop_s = seen.index(now)
        loop_end = i + 1
        size = loop_end - loop_s
        break
if K <= loop_s:
    print(seen[K+1] + 1)
else:
    K -= loop_s
    print(seen[loop_s + 1 + K % size] + 1)
### BUGGY CODE ###

import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""
n,k,q =  map(int, sys.stdin.readline().split())
l=[k]*n
p=[1]*n
def penalty(b):
    return b - 1

for i in range(q):
    a =  int(sys.stdin.readline())
    l=list(map(penalty, l))
    l[a-1]+=1

for e in l:
    if e <=0:
        print("No")
    else:
        print("Yes")

### FIXED CODE ###

import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""
import numpy as np
n,k,q =  map(int, sys.stdin.readline().split())
l=[0]*n
l = np.array(l)
l+=q

# a=[l[i-1]-1 for i in  list(map(int,sys.stdin.readlines()))]
# print(a)
for i in range(q):
    a =  int(sys.stdin.readline())
    l[a-1]-=1

for e in l:
    if e >=k:
        print("No")
    else:
        print("Yes")
### BUGGY CODE ###

n = int(input())
R = [0]*n

for i in range(n):
    R[i] = int(input())

maximum_profit = -10**9
for i in range(1, n):
    profit = max(R[i:n]) - min(R[0:i])
    maximum_profit = profit if profit > maximum_profit else maximum_profit

print(maximum_profit)

### FIXED CODE ###

n = int(input())
maximum_profit = -10**9

r0 = int(input())
r_min = r0
for i in range(1, n):
    r1 = int(input())
    r_min = min(r0, r_min)
    maximum_profit = max(maximum_profit, r1 - r_min)
    r0 = r1
print(maximum_profit)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()

    dp = [[0] * (n + 1) for _ in range(n + 1)]
    for i in reversed(range(n)):
        for j in reversed(range(n)):
            if s[i] == s[j]:
                dp[i][j] = dp[i + 1][j + 1] + 1

    res = 0
    for i in range(n):
        for j in range(n):
            if i < j:
                now = min(dp[i][j], j - i)
                res = max(res, now)
    print(res)


if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    s = input()

    dp = [[0] * (n + 1) for _ in range(n + 1)]
    for i in reversed(range(n)):
        for j in reversed(range(n)):
            if s[i] == s[j]:
                dp[i][j] = dp[i + 1][j + 1] + 1

    res = 0
    for i in range(n):
        for j in range(n):
            if i < j:
                now = min(dp[i][j], j - i)
                res = max(res, now)
    print(res)


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

from functools import reduce

def main():
    n,k = map(int,input().split()) #学期は1-indexed
    scores = [0] + list(map(int,input().split()))
    seiseki = []
    for i in range(k,n+1):
        seiseki.append(reduce(lambda a,b:a*b,scores[i-k+1:i+1]))
    for i,_ in enumerate(seiseki):
        if i == 0:
            continue
        if seiseki[i] > seiseki[i-1]:
            print("Yes")
        else:
            print("No")






if __name__ == '__main__':
    main()


### FIXED CODE ###

#尺取り法的な……
#

def main():
    n,k = map(int,input().split())
    scores = [0] + list(map(int,input().split()))
    for i in range(k+1,n+1):
        if scores[i] > scores[i-k]:
            print("Yes")
        else:
            print("No")

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

R, G, B, N = map(int, input().split())

ans = 0
for i in range(int(N / R) + 1):
    for j in range(int((N - i * R) / G) + 1):
        if (N - (i * R + j * G)) % B == 0 and (N - (i * R + j * G)) >= 0:
            ans += 1
print(ans)


### FIXED CODE ###

R, G, B, N = map(int, input().split())

ans = 0
for i in range(int(N / R) + 1):
    for j in range(int((N - i * R) / G) + 1):
        if ((N - (i * R + j * G)) % B == 0):
            ans += 1
print(ans)
### BUGGY CODE ###

N = int(input())
a = list(map(int,input().split()))
buka_num=[]
for i in range(1,len(a)+1):
  buka_num.append(str(a.count(i)))
buka_num.append("0")
joined = "\n".join(buka_num)
print(joined)

### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
buka_num=[0 for _ in range(N+1)]

for i in a:
  buka_num[i]+=1
buka_num.pop(0)
for j in buka_num:
  print(j)
### BUGGY CODE ###

S = input()
K = int(input())

N = len(S)
substr = []
for i in range(N):
    for j in range(i, N):
        tmp_substr = S[i:j+1]
        
        if tmp_substr in substr:
            continue

        if len(substr) <= 4:
            substr.append(tmp_substr)
            substr.sort()
        else:
            substr.append(tmp_substr)
            substr.sort()
            del substr[-1]

print(substr[K-1])

### FIXED CODE ###

s = input()
K = int(input())
subs = []
for i in range(len(s)):
  subs += [s[i:i+j] for j in range(1,min(len(s)-i+1,K+1))]

subs = list(set(subs))
subs.sort()
print(subs[K-1])
### BUGGY CODE ###

import sys
import numpy as np

sys.setrecursionlimit(10**7)

def get_cost(arr, n, k, dp):
  if dp[n] != 0:
    return dp[n]
  elif n-k <= 0:
    dp[n] = abs(arr[n] - arr[0])
    return dp[n]
  elif n == 0:
    dp[0] = 0
    return dp[0]
  elif n == 1:
    dp[1] = abs(arr[1] - arr[0])
    return dp[1]
  else:
    dp[n] = min(((np.abs(arr[n] - arr[n-i]) + get_cost(arr, n-i, k, dp)) for i in range(1, k+1)))
    return dp[n]

N, K = input().split()
N = int(N)
K = int(K)
arr = np.array(input().split(), dtype=np.int64)

dp = np.zeros(N, dtype=np.int64)
print(get_cost(arr, N-1, K, dp))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

def get_cost(arr, n, k, dp):
  min_ = -1
  for i in range(2, n):
    dp[i] = min([(abs(arr[s] - arr[i]) + dp[s]) for s in range(max(0, i-k), i)])
  return dp[-1]
    

N, K = input().split()
N = int(N)
K = int(K)
arr = [int(num) for num in input().split()]

dp = [0]*N
dp[1] = abs(arr[1] - arr[0])
print(get_cost(arr, N, K, dp))
### BUGGY CODE ###

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

p = list(map(int, input().split()))
hope_list = []
max = 0
index = 0
for j in range(n-k+1):
    goukei = sum(p[j:j+k])
    if goukei > max:
        max = goukei
        index = j

ans = 0
for i in range(index, index+k):
    ans += ((p[i]+1)*0.5)

print(ans)

### FIXED CODE ###

import numpy as np

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

p = np.array(list(map(int, input().split())))


index = 0
goukei = sum(p[0:k])
max = goukei
for j in range(n-k):
    goukei = (goukei - p[j] + p[j+k])
    if goukei > max:
        max = goukei
        index = j+1

ans = 0
for i in range(index, index+k):
    ans += ((p[i]+1)*0.5)

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

def lucas(N):
    if N == 0:
        return 2
    elif N == 1:
        return 1
    else:
        return lucas(N-1) + lucas(N-2)

N = int(input())
print(lucas(N))


### FIXED CODE ###

N = int(input())
L = [0] * 87  # 制約から
L[0] = 2
L[1] = 1
if N >= 2:
	for i in range(2, N + 1):
		L[i] = L[i - 1] + L[i - 2]
print(L[N])
### BUGGY CODE ###

S = input()
N = len(S)
cnt = 0
used = [0] * N
l , r = -1,-1
while True:
    flg = False
    for i in range(N):
        if used[i] == 0:
            if l == -1:
                l = i
            else:
                r = i
                if S[l] != S[r]:
                    used[l] = 1
                    used[r] = 1
                    l,r = -1,-1
                    flg = True
                    cnt += 1
                else:
                    l = r
    if not flg:
        break

print(cnt*2)

### FIXED CODE ###

S = list(input())
a = S.count('0')
print(min(a,len(S)-a)*2)