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

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

cost = [0] * N
cost[0] = 0
for n in range(1, N):
  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

print(cost[-1])

#def main():
#    n, k = map(int, input().split())
#    h = list(map(int, input().split()))
#    a = [0] * n
#    a[0] = 0
#    for i in range(1, n):
#        a[i] = min([a[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)])
#    print(a[-1])
 
#if __name__ == '__main__':
#    main()

### FIXED CODE ###

#  def II(): return int(input())
#def LI(): return [int(i) for i in input().split()]

#N, K = LI()
#H = LI()

#cost = [0] * N
#cost[0] = 0
#for n in range(1, N):
#  cost[n] = min([ cost[n-k]+abs(H[n-k]-H[n]) for k in range(1, min(n+1, K+1)) ])

#print(cost[-1])

def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * n
    a[0] = 0
    for i in range(1, n):
        a[i] = min([a[j] + abs(h[i] - h[j]) for j in range(max(0, i - k), i)])
    print(a[-1])
 
if __name__ == '__main__':
    main()
### BUGGY CODE ###

# coding: utf-8
# Your code here!
n,k = map(int,input().split())

s = input()

now = s[0]
tmp = 0

h = []
if s[0]=="0":
    h.append(0)

for i in s:
    if i != now:
        now = i
        h.append(tmp)
        tmp=0
    tmp+=1
h.append(tmp)

ans = 0

for i in range(0,len(h),2):
    ans = max(ans,sum(h[i:i+k*2+1]))
    
print(ans)

### FIXED CODE ###

# coding: utf-8
# Your code here!

import numpy as np

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

s = input()

now = s[0]
tmp = 0

h = []
if s[0]=="0":
    h.append(0)

for i in s:
    if i != now:
        now = i
        h.append(tmp)
        tmp=0
    tmp+=1
h.append(tmp)

h = np.array(h)

ans = 0

for i in range(0,max(len(h),len(h)-k),2):
    ans = max(ans,np.sum(h[i:i+k*2+1]))
    
print(ans)
### BUGGY CODE ###

n=int(input())
li=[]

for i in range(n):
    a=input()
    if a in li:
        li.remove(a)
    else:
        li.append(a)

print(len(li))

### FIXED CODE ###

n=int(input())
li=[]
ans=0
fl=1

for i in range(n):
    li.append(int(input()))

li.sort()

for j in range(n-1):
    if li[j]!=li[j+1]:
        if fl%2==1:
            ans+=1
            fl=1
        else:
            fl=1
    else:
        fl+=1


if fl%2==1:
    ans+=1

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

n=int(input())
a=sorted(list(map(int,input().split())))
is_a=[False for _ in range(n)]
ans=0

for i in range(n):
    if(not is_a[i]):
        ans+=1
        for j in range(i+1,n):
            if(not is_a[j] and a[j]%a[i]==0):
                is_a[j]=True

        if(i<n-1 and a[i]==a[i+1] and (i==0 or a[i]!=a[i-1])):
            ans-=1

print(ans)


### FIXED CODE ###

import numpy as np
n=int(input())
a=sorted(list(map(int,input().split())))

dp=np.array([0 for _ in range(max(a)+1)])
for i in range(n):
    ai=a[i]
    if(dp[ai]>=2):
        continue

    j=1
    while(ai*j<=a[-1]):
        dp[ai*j]+=1
        j+=1

print(sum(dp[ai]==1 for ai in a))
### BUGGY CODE ###

s = input()
n = int(input())
query = [0]*n
for i in range(n):
    query[i] = list(map(str, input().split()))
#    print(query[i])

for i in range(n):
    if int(query[i][0]) == 1:
        s = s[::-1]
    else:
        if int(query[i][1]) == 1:
            s = query[i][2] + s
        else:
            s = s + query[i][2]
#    print(s)
print(s)

### FIXED CODE ###

s = input()
n = int(input())
query = [0]*n
rev = 0
for i in range(n):
    query[i] = list(map(str, input().split()))
    if query[i][0] == '1':
        rev = rev + 1

begin = ''
end = ''
pal = 0

for i in range(n):
    if int(query[i][0]) == 1:
        pal = (pal+1)%2
    else:
        if pal == 0:
            if int(query[i][1]) == 1:
                begin = query[i][2] + begin 
            else:
                end = end + query[i][2]
        else:
            if int(query[i][1]) == 1:
                end = end + query[i][2] 
            else:
                begin = query[i][2] + begin
#    print('--------'+str(i+1)+'th try-----')
#    print('begin:'+begin)
#    print('end:'+end)
#    print('pal:'+str(pal))
if rev%2 == 1:
    print(end[::-1]+s[::-1]+begin[::-1])
else:
    print(begin+s+end)
### BUGGY CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
BC=list(list(map(int,input().split())) for  _ in range(M))
BC.sort(key=lambda x: x[1],reverse=True)

for b,c in BC:
    A.extend([c]*b)
    if len(A)>N*N:
        break
A.sort(reverse=True)
print(sum(A[:N]))

### FIXED CODE ###

N, M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]
BC.sort(key = lambda x: -x[1])

for B, C in BC:
  A.extend([C]*B)
  if len(A) > N*2:
    break
A.sort(reverse = True)
print(sum(A[:N]))
### BUGGY CODE ###

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

data = [0]*N
for i, item in enumerate(S):
    data[i] = [item, i]
data.sort(reverse=True)

dp = [[0]*(N+1) for _ in range(N+1)]
# dp[i][j] i+j-1番目までの幼児がi人0から、j人N-1から並んだ時の最大値

for i in range(N):
    for j in range(N):
        if i+j >= N:
            break
        dp[i+1][j] = max(dp[i+1][j], dp[i][j]+data[i+j][0]*(data[i+j][1]-(i)))
        dp[i][j+1] = max(dp[i][j+1], dp[i][j]+data[i+j][0]*((N-1-j)-data[i+j][1]))

ans = 0
for i in range(N+1):
    ans = max(ans, dp[i][N-i])

print(ans)

### FIXED CODE ###

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

data = [0]*N
for i, item in enumerate(S):
    data[i] = [item, i]
data.sort(reverse=True)

dp = [[0]*(N+1) for _ in range(N+1)]
# dp[i][j] i+j-1番目までの幼児がi人0から、j人N-1から並んだ時の最大値

for i in range(N):
    for j in range(N):
        if i+j >= N:
            break
        dp[i+1][j] = max(dp[i+1][j], dp[i][j]+data[i+j][0]*(data[i+j][1]-(i)))
        dp[i][j+1] = max(dp[i][j+1], dp[i][j]+data[i+j][0]*((N-1-j)-data[i+j][1]))

ans = 0
for i in range(N+1):
    ans = max(ans, dp[i][N-i])

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

from fractions import gcd
from functools import reduce
from collections import deque

N = int(input())

line = [int(a) for a in input().split()]
line = deque(line)

def check(inf):
  return reduce(gcd, inf)
m=0
for i in range(N):
  x = line.pop()
  g = check(line)
  if g>m:
    m = g
  line.appendleft(x)

print(m)


### FIXED CODE ###

from fractions import gcd
from collections import deque

N = int(input())
A = [int(a) for a in input().split()]
L = deque([0])
R = deque([0])

for i in range(N):
  L.append(gcd(L[i],A[i]))
for i in range(N)[::-1]:
  R.appendleft(gcd(R[0],A[i]))

ans = []
for i in range(N):
  ans += [gcd(L[i], R[i+1])]
print(max(ans))
### BUGGY CODE ###

n, m = map(int, input().split())
p = list(map(int, input().split()))
xys = [list(map(int, input().split())) for _ in range(m)]
lsxy = {}
stxy = {}
maxi = 0
allst = set()
for xy in xys:
    xin = True if xy[0] in lsxy else False
    yin = True if xy[1] in lsxy else False
    allst.add(xy[0])
    allst.add(xy[1])
    if xin and yin:
        xidx = lsxy[xy[0]]
        yidx = lsxy[xy[1]]
        stx = stxy[xidx]
        sty = stxy[yidx]
        if len(stx) > len(sty):
            stxy[xidx] |= stxy.pop(yidx)
            for i in sty:
                lsxy[i] = xidx
        else:
            stxy[yidx] |= stxy.pop(xidx)
            for i in stx:
                lsxy[i] = yidx
    elif xin:
        lsxy[xy[1]] = lsxy[xy[0]]
        stxy[lsxy[xy[0]]].add(xy[1])
    elif yin:
        lsxy[xy[0]] = lsxy[xy[1]]
        stxy[lsxy[xy[1]]].add(xy[0])
    else:
        stxy[maxi] = set(xy)
        lsxy[xy[0]] = maxi
        lsxy[xy[1]] = maxi
        maxi += 1
count = 0
for i in range(n):
    if i + 1 == p[i]:
        count += 1
    elif i + 1 in lsxy and p[i] in stxy[lsxy[i + 1]]:
        count += 1
print(count)


### FIXED CODE ###

n, m = map(int, input().split())
p = list(map(int, input().split()))
xys = [list(map(int, input().split())) for _ in range(m)]
mapp = [[] for _ in range(n + 1)]
for xy in xys:
    mapp[xy[0]].append(xy[1])
    mapp[xy[1]].append(xy[0])

bfs = [0] * (n + 1)
count = 0
for i in range(1, n + 1):
    nexts = mapp[i]
    if not(bfs[i]):
        bfs[i] = i
    for j in nexts:
        if bfs[j]:
            continue
        bfs[j] = i
        nexts += mapp[j]
    if bfs[i] == bfs[p[i - 1]]:
        count += 1
print(count)
### BUGGY CODE ###

import bisect
import sys
import math
input = sys.stdin.readline
import functools

from collections import defaultdict

############ ---- Input Functions ---- ############

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

############ ---- Solution ---- ############

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

def solve():
    N = inp()
    AA = inlt()
    
    mult = AA[0]
    gcd_cum = AA[0]
    pairwise = True

    for i in range(1, N):
        if i == 1 or (gcd_cum == 1 and pairwise):
            g = gcd(mult, AA[i])
            if g != 1:
                pairwise = False
            mult = mult * (AA[i] // g)
        gcd_cum = gcd(gcd_cum, AA[i])
    
    if gcd_cum == 1 and pairwise:
        return "pairwise coprime"

    if gcd_cum == 1:
        return "setwise coprime"
    
    return "not coprime"

    

if len(sys.argv) > 1 and sys.argv[1].startswith("input"):
    f = open("./" + sys.argv[1], 'r')
    input = f.readline

res = solve()
print(str(res))


### FIXED CODE ###

import bisect
import sys
import math
input = sys.stdin.readline
import functools

from collections import defaultdict

############ ---- Input Functions ---- ############

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

############ ---- Solution ---- ############


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

def solve():
    N = inp()
    AA = inlt()

    MAX = 10 ** 6 + 5
    freq = [0 for i in range(MAX)]
    cnt = [0 for i in range(MAX)]
    
    gcd_cum = AA[0]

    for i in range(N):
        freq[AA[i]] += 1
        gcd_cum = gcd(gcd_cum, AA[i])

    for i in range(2, MAX):
        for j in range(i, MAX, i):
            cnt[i] += freq[j]

    pairwise = True
    for i in range(2, MAX):
        if cnt[i] > 1:
            pairwise = False
            break
    
    if gcd_cum == 1 and pairwise:
        return "pairwise coprime"

    if gcd_cum == 1:
        return "setwise coprime"
    
    return "not coprime"
    

if len(sys.argv) > 1 and sys.argv[1].startswith("input"):
    f = open("./" + sys.argv[1], 'r')
    input = f.readline

res = solve()
print(str(res))
### BUGGY CODE ###

N = int(input())

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

res = 1
overflow = False

for a in A:
  res *= a
  if res > 10**18:
    overflow = True

if overflow == True and res != 0:
  print(-1)
else:
  print(res)
    

### FIXED CODE ###

import sys
N = int(input())

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

res = 1
overflow = False

if 0 in A:
  print(0)
  sys.exit()

i = 0
while i < len(A) and res <= 10**18:
  res *= A[i]
  i += 1


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

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

S=input()

for q in range(Q):
	L,R=map(int,input().split())
	tmp=S[L-1:R]
	print(tmp.count("AC"))


### FIXED CODE ###

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

S=input()

# 最初からNまでに何個ACがあったか
cnt=[0 for _ in range(N)]

prev=""

for i in range(N):
	if S[i]=="C":
		if prev=="A":
			cnt[i]+=1
	if i!=0:
		cnt[i]+=cnt[i-1]
	prev = S[i]

for q in range(Q):
 	L,R=map(int,input().split())
 	ans = cnt[R-1]-cnt[L-1]
 	print(ans)
### BUGGY CODE ###

from collections import Counter
N = int(input())
S = input()
ans = 0
D = Counter(S)
id = 0
dic = {}
for k in D.keys():
    dic[k] = id
    id += 1
m = 0
OB = [-1]*N
for i in range(N):
    if D[S[i]]<=1:
        pass
    else:
        OB[i] = dic[S[i]]
        m = max(m,dic[S[i]])
SSS = [[] for i in range(m+1)]
for i in range(N):
    SSS[OB[i]].append(i)

for n in range(len(SSS)):
    lss = len(SSS[n])
    for i in range(lss):
        for j in range(i,lss):
            ni = SSS[n][i]
            nj = SSS[n][j]
            if i==j or ans>nj-ni or ans>N-nj:
                continue
            id = 0
            while True:
                if nj+id>=N or ni+id>=nj:
                    break
                if S[ni+id]==S[nj+id]:
                    id += 1
                else:
                    break
            ans = max(ans,id)
print(ans)

### FIXED CODE ###

N = int(input())
S = input()
ans = 0
right = 0
for left in range(N):
    while S[left:right + 1] in S[right + 1:]:
        ans = max(ans, right + 1 - left)
        right += 1
print(ans)
### BUGGY CODE ###

N = int(input())
S = input()
res = []
for i, n_ban in enumerate(S):
    # Westからn_ban目の人をリーダーとしたときに何人を変える必要があるか
    # n_banについて全探索
    # 自分よりEast側かつEastを向いてる人の人数と
    # 自分よりWest側かつWestを向いてる人の人数の合計
    E_cnt = 0
    W_cnt = 0

    for ii, target in enumerate(S):
        if i < ii:
            if target == "E":
                E_cnt += 1
        elif ii < i:
            if target == "W":
                W_cnt += 1
    
    res.append(E_cnt+W_cnt)

print(min(res))

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Mon Aug  6 17:34:40 2018

@author: Yuki
"""

N = int(input())
S = input()
res = []

res.append(S[1:].count('E'))
for i in range(1, len(S)):
    if S[i] == 'E':
        tmp = res[-1]-1
        if S[i-1] == 'W':
            tmp += 1
        
    elif S[i] == 'W':
        tmp = res[-1]
        if S[i-1] == 'W':
            tmp += 1
    res.append(tmp)
    

print(min(res))
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
total = 0
for i in range(N - 1):
  for j in range(i + 1, N):
    total += A[i] * A[j]
  total %= (10 ** 9 + 7)
print(total)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
T = sum(A)
ans = 0
for i in range(N):
  T -= A[i]
  ans += A[i] * T
  ans %= 10 ** 9 + 7
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Wed Feb 12 16:01:34 2020

@author: matsui
"""

N=int(input())
A=input().split()

ans='YES'
for i in range(1,N):
    if A[i] in A[:i]:
        ans='NO'
        break
    
print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Wed Feb 12 16:01:34 2020

@author: matsui
"""

N=int(input())
A=input().split()
A=[int(a) for a in A]
A.sort()

ans='YES'
for i in range(1,N):
    if A[i]==A[i-1]:
        ans='NO'
        break
    
print(ans)
### BUGGY CODE ###

N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))
A.sort()
ans = 0
idx = 0
while idx < N:
    sub = 0
    while idx + sub < N and A[idx] == A[idx + sub]:
        sub = sub + 1
    if sub % 2 == 1:
        ans = ans + 1
print(ans)

### FIXED CODE ###

N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))
A.sort()
ans = 0
idx = 0
while idx < N:
    sub = 0
    while idx + sub < N and A[idx] == A[idx + sub]:
        sub = sub + 1
    if sub % 2 == 1:
        ans = ans + 1
    idx = idx + sub
print(ans)
### BUGGY CODE ###

def main():
    N, T, *AB = map(int, open(0).read().split())

    dp = [0] * (T + max(AB[::2]))
    for w, v in sorted(zip(*[iter(AB)] * 2)):
        for i in reversed(range(T)):
            if dp[i + w] < dp[i] + v:
                dp[i + w] = dp[i] + v

    print(max(dp))

main()

### FIXED CODE ###

N, T, *AB = map(int, open(0).read().split())

dp = [0] * (T + max(AB[::2]))
for w, v in sorted(zip(*[iter(AB)] * 2)):
    for i in reversed(range(T)):
        dp[i + w] = max(dp[i + w], dp[i] + v)

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

# coding: utf-8

n, q = map(int, input().split())
s = input()
lst = []
for i in range(q):
    l = list(map(int, input().split()))
    lst.append(l)

for i in range(q):
    f,e = lst[i][0]-1,lst[i][1]
    st = s[f:e]
    print(st.count('AC'))



### FIXED CODE ###

# coding: utf-8

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

t = [0]*(n+1)
for i in range(n):
    if s[i:i+2] == 'AC':
        t[i+1] = t[i] + 1
    else:
        t[i+1] = t[i]

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

import sys
import copy
def input():
	return sys.stdin.readline().rstrip()
def main():
	N = int(input())
	A = [int(input()) for _ in range(N)]
	for i in range(N):
		B = copy.deepcopy(A)
		B.pop(i)
		print(max(B))
if __name__ == '__main__':
	main()

### FIXED CODE ###

import sys
import copy
def input():
	return sys.stdin.readline().rstrip()
def main():
	N = int(input())
	A = [int(input()) for _ in range(N)]
	B = list(set(A))
	if (len(B) == 1) or (A.count(B[-1]) > 1):
		for i in range(N):
			print(B[-1])
	else :
		for i in range(N):
			if A[i] == B[-1]:
				print(B[-2])
			else:
				print(B[-1])
if __name__ == '__main__':
	main()
### BUGGY CODE ###

import numpy as np
sitei = input().split()
H, W, D = int(sitei[0]), int(sitei[1]), int(sitei[2])
_masume = np.zeros([H, W])
for i in range(H):
    _masume[i] = np.array(input().split())
masume = _masume.astype(int)

Q = int(input())

_settei = np.zeros([Q, 2])

for i in range(Q):
    _settei[i] = np.array(input().split())

settei = _settei.astype(int)
maryoku = 0

zahyou = [np.where(masume==l) for l in range(1, H*W+1)]

for l in range(Q):
    atai = settei[l][0]
    while (atai != settei[l][1]):
        maryoku += abs((zahyou[atai+D-1])[0]-(zahyou[atai-1])[0]) + abs((zahyou[atai+D-1])[1]-(zahyou[atai-1])[1])
        atai += D
    if maryoku != 0:
        maryoku, = maryoku
    print(maryoku)
    maryoku = 0

### FIXED CODE ###

import numpy as np
H, W, D = list(map(int, input().split()))

px, py = [None for i in range(H*W+1)], [None for i in range(H*W+1)]
for i in range(H):
    A = list(map(int, input().split()))
    for j in range(W):
        px[A[j]] = i
        py[A[j]] = j

d = [0 for i in range(H*W+1)]
for i in range(D+1, H*W+1):
    d[i]= d[i-D]+abs(px[i]-px[i-D])+abs(py[i]-py[i-D])

Q = int(input())

for i in range(Q):
    L, R = list(map(int, input().split()))
    print(d[R]-d[L])
### BUGGY CODE ###

from collections import deque
import copy
def bfs():
  H, W = map(int, input().split())
  maze = [list(input()) for i in range(H)]
  S = []
  for i in range(H):
    for j in range(W):
      if maze[i][j] == ".":
        maze[i][j] = float("inf")
        S.append([i, j])
      else:
        maze[i][j] = -1
  ans = 0
  for k in range(len(S)):
    maze1 = copy.deepcopy(maze)
    maze1[S[k][0]][S[k][1]] = 0
    q = deque([[S[k][0],S[k][1]]])
    while q:
      y, x = q.popleft()
      for i, j in [(1, 0), (0, 1), (0, -1), (-1, 0)]:
        nexty, nextx = y+i, x+j
        if nexty < 0 or nexty>=H or nextx < 0 or nextx>=W:
          continue
        dist1 = maze1[nexty][nextx]
        if dist1 != -1:
          if dist1 > maze1[y][x]:
            maze1[nexty][nextx] = maze1[y][x] + 1
            q.append([nexty, nextx])
            ans = max(ans, maze1[nexty][nextx])
  print(ans)
bfs()

### FIXED CODE ###

from collections import deque
import copy
def bfs():
    h,w = map(int, input().split())
    maze = [list(input()) for i in range(h)]
    S, G = [], []
    for y in range(h):
        for x in range(w):
            if maze[y][x]=='.':
                S.append([y,x])
                G.append([y,x])
                maze[y][x]=float("inf")
            else:
                maze[y][x]=-1
    l = []
    ans = 0
    for i in range(len(S)):
        maze1 = copy.deepcopy(maze)
        maze1[S[i][0]][S[i][1]]=0
        que=deque([[S[i][0],S[i][1]]])
        while que:
          y,x=que.popleft()
          for k,m in [(1,0),(0,1),(-1,0),(0,-1)]:
            nexty,nextx=y+k,x+m
            if nexty < 0 or nexty >= h or nextx < 0 or nextx >= w:
                continue
            dist=maze1[nexty][nextx]
            if dist!=-1:
              if dist>maze1[y][x]+1:
                maze1[nexty][nextx]=maze1[y][x]+1
                que.append([nexty,nextx])
            ans = max(ans, maze1[nexty][nextx])
    print(ans)
bfs()
### BUGGY CODE ###

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


def is_valid():
    if n % 2 == 1 and A.count(0) != 1:
        return False

    for a in A:
        if n % 2 == a % 2:
            return False
        if a != 0 and A.count(a) != 2:
            return False
    return True


if not is_valid():
    print(0)
    exit()

print((2**(n//2)) % (10**9+7))


### FIXED CODE ###

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

Bi = []
if n % 2 == 0:
    half_Bi = list(range(1, n, 2))
    Bi = half_Bi + half_Bi
else:
    half_Bi = list(range(2, n, 2))
    Bi = half_Bi + half_Bi
    Bi.append(0)

A.sort()
Bi.sort()
if A != Bi:
    print(0)
    exit()

print((2**(n//2)) % (10**9+7))
### BUGGY CODE ###

from heapq import heappop, heappush, heapify

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


A.sort(reverse=False)
F.sort(reverse=True)

h = [(-1 * a * f, a, f) for (a, f) in zip(A, F)]
heapify(h)

for k in range(K):
    if h[0][1] == 0:
        break
    a = heappop(h)
    heappush(h, (-1 * (a[1] - 1) * a[2], a[1] - 1, a[2]))

print(-1 * heappop(h)[0])



### FIXED CODE ###

import numpy as np
from math import ceil

N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
F = np.array(list(map(int, input().split())))

A.sort()
F.sort()

if np.sum(A) <= K:
    print(0)
else:
    st = 0
    ed = 10 ** 12
    md = ceil((st + ed) / 2)
    while True:
        if np.sum(A - np.minimum(A, md // F[::-1])) <= K:
            ed = md
        else:
            st = md
        md = ceil((st + ed) / 2)

        if md == ed:
            break

    print(md)
### BUGGY CODE ###

n = int(input())

sum = 0

while(n >= 1):
  sum += n % 10
  n //= 10

if(sum % 9 == 0):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

n = int(input())

# sum = 0

# while(n >= 1):
#   sum += n % 10
#   n //= 10

if(n % 9 == 0):
  print("Yes")
else:
  print("No")
### BUGGY CODE ###

import sys
import bisect

def main():
    input = sys.stdin.readline

    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    bc = []
    for _ in range(m):
        bc.append(list(map(int,input().split())))

    a.sort()

    bc.sort(key=lambda x: x[1], reverse=True)
    num = 0
    ans = 0
    for i in range(m):
        index = bisect.bisect_left(a[num:],bc[i][1])
        if index == 0:
            break
        elif index > bc[i][0]:
            ans += bc[i][1] * bc[i][0]
        else:
            ans += bc[i][1] * index
            ans += sum(a[num+index:num+bc[i][0]])

        num += bc[i][0]
        if num >= n:
            break
    if num < n:
        print(ans + sum(a[num:]))
    else:
        print(ans)

if __name__ == '__main__':
  main()

### FIXED CODE ###

import sys

def main():
    input = sys.stdin.readline

    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    bc = []
    for _ in range(m):
        bc.append(list(map(int,input().split())))

    a.sort()
    a = tuple(a)

    bc.sort(key=lambda x: x[1], reverse=True)

    num = 0
    ans = 0

    for i in range(m):
        b = bc[i][0]
        c = bc[i][1]
        for j in range(num,min(num+b,n)):
            if c > a[j]:
                ans += c
            else:
                ans += a[j]

        num += b
        if num >= n:
            break

    if num < n:
        print(ans + sum(a[num:]))
    else:
        print(ans)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

S = raw_input()
N = len(S)

count = 0
tmp  = 1
dst = S
while True:
    dst1 = dst.replace('01', '')
    dst2 = dst1.replace('10', '')
    if len(dst) - len(dst2) <= 0: break
    count += len(dst) - len(dst2)
    dst = dst2

print count

### FIXED CODE ###

S = raw_input()
print(min(S.count('1'), S.count('0')) * 2)