Harryxun/stf_run huggingface dataset:
N,A,B=map(int,input().split())
S=list(map(input().split()))
sin=0
cos=0
K=list.count("a")
G=list.count("b")
for i in range(S)
	if S.pop(i)='a'or'b':
    sin+=1
    if S.pop(i)='b':
    cos+=1
    print("Yes" if S.pop(i)='a' and sin<K+G:
"Yes" elif s.pop(i)='b' and G<=cos and sin<K+G:
    else "No")
    
    

### FIXED CODE ###

N,h,u=map(int,input().split())
S = input()
kaigai=0
goukei=0
for i in range(0,N):
  if S[i]=='a' and goukei<h+u:
    print("Yes")
    goukei+=1
  elif S[i]=='b'and goukei<h+u and kaigai<u:
    print("Yes")
    goukei+=1
    kaigai+=1
  else:
    print("No")
cards = input()
shuffle = input()

while shuffle != '-':
	n = int(shuffle)
	cards = cards[n:] + cards[:n]
	shuffle = input()
	
print(cards)

### FIXED CODE ###

while True:
	cards = input()
	if cards == '-':
		break
	n = int(input())
	
	for _ in range(n):
		shuffle = int(input())
		cards = cards[shuffle:] + cards[:shuffle]
		
	print(cards)
N,M=map(int, input().split())

outgoing=dict()
incoming=dict()
for i in range(M):
  x,y,z=map(int, input().split())
  if x in outgoing: outgoing[x].add(y)
  else: outgoing[x]={y}
  if y in incoming: incoming[y].add(x)
  else: incoming[y]={x}
#print(outgoing)
#print(incoming)

V=set()
def dfs(v):
  if v not in V:
    V.add(v)
    og=set() if v not in outgoing else outgoing[v]
    ic=set() if v not in incoming else incoming[v]
    for u in og.union(ic):
      dfs(u)

cnt=0
for v in range(1, N+1):
  if v not in V:
    cnt += 1
    dfs(v)
print(cnt)

### FIXED CODE ###

import sys
mod = 10**9+7
sys.setrecursionlimit(mod)
N,M=map(int, input().split())

adj={i: set() for i in range(1,N+1)}
for i in range(M):
  x,y,z=map(int, input().split())
  adj[x].add(y)
  adj[y].add(x)
V=set()
def dfs(v):
  if v not in V:
    V.add(v)
    for u in adj[v]: dfs(u)
cnt=0
for i in range(1,N+1):
  if i not in V:
    cnt += 1
    dfs(i)
print(cnt)
D = int(input())
c = list(map(int,input().split()))
s = []
for i in range(D):
    s.append(list(map(int,input().split())))

def last(d,la):
    s = 0
    for i in range(26):
        s += c[i] * (d - la[i])
    return s

lastday = [0]*26
a = 0

for d in range(D):

    eff = s[d][0] - last(d+1,lastday)
    for t in range(26):
        bef = lastday[t]
        lastday[t] = d+1

        now = s[d][t] - last(d+1,lastday)
        if eff < now:
            eff = now 
            ret = t

        lastday[t] = bef
        
    lastday[ret] = d+1
    a += eff
    print(ret+1)

### FIXED CODE ###

D = int(input())
c = list(map(int,input().split()))
s = []
for i in range(D):
    s.append(list(map(int,input().split())))

def last(d,la):
    s = 0

    for i in range(26):
        if la[i] == 0 and  i == d:
            s += c[i] * (d - la[i]-1)
        else:
            s += c[i] * (d - la[i])
    return s

lastday = [0]*26
a = 0

for d in range(D):

    eff = s[d][0] - last(d+1,lastday)
    ret = 0
    for t in range(26):
        bef = lastday[t]
        #lastday[t] = d+1
        
        now = s[d][t] - last(d+1,lastday)
        if eff < now:
            eff = now 
            ret = t

        lastday[t] = bef
        
    lastday[ret] = d+1
    a += eff
    print(ret+1)
a,b,c=sorted(map(int,input().split()))
if("c" a==b else "a")

### FIXED CODE ###

a,b,c=sorted(map(int,input().split()))
print(c if a==b else a)
N,R = map(int,input().split())

if N <= 10:
    R = R + (10 - N) * 100
    
print(R)py

### FIXED CODE ###

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

if N <= 10:
    R = R + (10 - N) * 100
    
print(R)
from collections import deque
H, W, M = map(int, input().split())
bomb = []
counth = [0 for k in range(H)]
countw = [0 for k in range(W)]
for k in range(M):
  h, w = map(int, input().split())
  h -= 1
  w -= 1
  bomb.append(h+ w*H)
  counth[h] += 1 
  countw[w] += 1

counth = deque(counth)
countw = deque(countw)

maxh = max(counth)
maxw = max(countw)
index_h = deque([])
index_w = []
for k in range(H):
  h = counth.popleft()
  if h == maxh:
    index_h.append(k)
for k in range(W):
  w = countw.popleft()
  if w == maxw:
    index_w.append(k)

ans = maxh + maxw - 1
lenh = len(index_h)
lenw = len(index_w)

if lenh*lenw > M:
  ans += 1
else:
  bomb.sort()
  kouho = []
  for i in range(lenh):
    h = index_h.pop()
    for j in range(lenw):
      w = index_w[j]
      kouho.append(h+ H*w)
  B = bomb.popleft()
  K = kouho.popleft()
  while True:
    if B > K:
      ans += 1
      break
    elif B == K:
      if len(kouho) == 0:
        break
      else:
        K = kouho.popleft()
    else:
      if len(bomb) == 0:
        ans += 1
        break
      else:
        B = bomb.popleft()
print(ans)


### FIXED CODE ###

from collections import deque
H, W, M = map(int, input().split())
bomb = []
counth = [0 for k in range(H)]
countw = [0 for k in range(W)]
for k in range(M):
  h, w = map(int, input().split())
  h -= 1
  w -= 1
  bomb.append(h+ w*H)
  counth[h] += 1 
  countw[w] += 1
counth = deque(counth)
countw = deque(countw)

def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            #return mid
            return True
        if guess > item:
            high = mid -1
        else:
            low = mid + 1

    #return None
    return False


maxh = max(counth)
maxw = max(countw)
index_h = deque([])
index_w = []
for k in range(H):
  h = counth.popleft()
  if h == maxh:
    index_h.append(k)

for k in range(W):
  w = countw.popleft()
  if w == maxw:
    index_w.append(k)

ans = maxh + maxw - 1
lenh = len(index_h)
lenw = len(index_w)


if lenh*lenw > M:
  ans += 1
else:
  bomb.sort()
  kouho = []
  for i in range(lenh):
    h = index_h.pop()
    for j in range(lenw):
      w = index_w[j]
      kouho.append(h+ H*w)
  for K in kouho:
    if binary_search(bomb, K):
      continue
    else:
      ans += 1
      break
    
print(ans)
a = input().split(" ")
W = int(a[0])
H = int(a[1])
x = int(a[2])
y = int([3])
r = int(a[4])

if x>=r and W-x>=r and y>=r and H-y>=r:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

W,H,x,y,r = [int(i) for i in input().split(" ")]

print("No" if x < r or y < r or x + r > W or y + r > H else "Yes" )
import math
n = int(input())
if n == 1:
    print(0)
    exit()
def makeprime(value):
    flag  = [True for _ in range(value)]
    ans = []
    for i in range(1,len(flag)):
        if flag[i]:
            ans.append(i+1)
            for j in range(i,len(flag),i+1):
                flag[j] = False
    return ans
for i in range(2,int(math.sqrt(n)+1)):
    if n%i == 0:
        flag = 1
        break
else:
    flag = 0
if flag:
    u = []
    r = n
    ans = 0
    rem = makeprime(int(math.sqrt(n)))
    for i in rem:
        o = 1
        while (i**o <= n):
            u.append(i**o)
            o += 1
    u.sort()
    for i in u:
        if n%i == 0:
            ans += 1
            n //= i
    print(ans)
else:
    print(1)

### FIXED CODE ###

import math
import decimal
a,b = map(decimal.Decimal,input().split())
ans = a*b
print(math.floor(ans))
from math import gcd
A, B, C, D = map(int,input().split())
total = B - A + 1
divC = B//C - (A-1)//C
divD = B//D - (A-1)//D
lcm = int(C * D / gcd(C, D))
divCD = B//lcm - (A-1)//lcm
print(total - divC - divD + divCD)


### FIXED CODE ###

from fractions import gcd

def get_num(div):
  num = (B)//div - (A-1)//div
  return num

A,B,C,D = map(int,input().split())
print(B-A+1-get_num(C)-get_num(D)+get_num(C*D//gcd(C,D)))
while True:
	m,f,r=map(int,input().split())
	if m==f==r==-1: break
	if m==-1 or f==-1:
		sum=0
	elif r!=-1:
		if r>49:
			sum=50	
		else :
			sum=r
		
	elif sum<30 :
		print('F')
	elif 30<=sum<50:
		print('D')
	elif 50<=sum<65:
		print('C')
	elif 65<=sum<=79:
		print('B')
	elif 80<=sum:
		print('A')
		
	

### FIXED CODE ###

while True:
	data=list(map(int,input().split()))
	if data[0]==data[1]==data[2]==-1: break
	
	if data[0]!=-1 and data[1]!=-1:
		sum=data[0]+data[1]
	if data[2]!=-1 and sum<data[2]:
		if data[2]>=50:
			sum=50
		
	if data[0]==-1 or data[1]==-1:
		print('F')
	elif sum<30 :
		print('F')
	elif 30<=sum<50:
		print('D')
	elif 50<=sum<65:
		print('C')
	elif 65<=sum<=79:
		print('B')
	elif 80<=sum:
		print('A')
vdef judge(A, B, C, M):
	result = C
	for i in range(M):
		result += A[i] * A[j]

	return result > 0

def main():
	N, M, C = map(int, input().split())
	B = map(int, input().split())
	count = 0

	for i in N:
		A = map(int, input().split())

		if judge(A, B, C, M):
			count += 1

	print(count)



if __name__ == '__main__':
	main()

### FIXED CODE ###

def judge(A, B, C, M):
	result = C
	for i in range(M):
		result += A[i] * B[i]

	return result > 0

def main():
	N, M, C = map(int, input().split())
	B = [int(x) for x in input().split()]
	count = 0

	for i in range(N):
		A = [int(x) for x in input().split()]

		if judge(A, B, C, M):
			count += 1

	print(count)



if __name__ == '__main__':
	main()
length = raw_input().split()
print length[0] * length[1], 2 * (length[0] + length[1])

### FIXED CODE ###

length = raw_input().split(" ")
length[0] = int(length[0])
length[1] = int(length[1])
print length[0] * length[1], 2 * (length[0] + length[1])
[a,b] = int(input().split())
 if a < b:
   print(" a < b ")
 elif a > b:
   print(" b < a ")
 else:
   print(" a == b ")

### FIXED CODE ###

a,b = map(int,input().split())

if a < b:
    print("a < b")
elif a > b:
    print("a > b")
else:
    print("a == b")
n,a,b=map(int,input().split())
x=list(map(int,input().split()))
if a>=b:
  print(b*n)
else:
  d=b//a
  ans=0
  for i in range(n-1):
    if x[i+1]-x[i]>d:
      ans+=b
    else:
      ans+=(x[i+1]-x[i])*a
print(ans)

### FIXED CODE ###

n,a,b=map(int,input().split())
x=list(map(int,input().split()))
ans=0
if a>=b:
  print(b*(n-1))
else:
  d=b//a
  
  for i in range(n-1):
    if x[i+1]-x[i]>d:
      ans+=b
    else:
      ans+=(x[i+1]-x[i])*a
  print(ans)
a = int(input())
b = int(input())
if a*b % 2 == 1:
  print(a*b // 2+1)
else:
  print(a*b // 2)

### FIXED CODE ###

h,w=map(int,input().split())
if h==1 or w==1:
  print(1)
else:
  print((h*w+1)//2)
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
def fibo(i):
    if i == 0 :
        return 1
    elif i == 1:
        return 1
    else :
        return fibo(i - 1) + fibo(i - 2)
m = a[0] + 1
num = fibo(m - 2)
for i in range(M - 1):
    m = a[i + 1] - a[i]
    num = num * fibo(m - 2)
    if m == 1:
        num = 0
        break
num = num * fibo(N - a[M - 1] - 1)
print(num % 1000000007)


### FIXED CODE ###

N, M = map(int, input().split())
kaidan = [0] * (N + 1)
for i in range(M):
    tmp = int(input())
    kaidan[tmp] = -1
kaidan[0] = 1
for i in range(1,N + 1):
    if i == 1:
        if kaidan[i] != -1:
            kaidan[i] = 1
        else:
            kaidan[i] = 0
    else:
        if kaidan[i] != -1:
            kaidan[i] = kaidan[i -1] + kaidan[i - 2]
        else:
            kaidan[i] = 0
print(kaidan[N] % (10 ** 9 + 7))
moji=str(input()) #文字列の入力
ListNum=[] #suuの各値を入れる
suu=0
for i in range(0,len(moji),1):
  if moji[i]=="A":
    suu+=1
  elif moji[i]=="T":
    suu+=1
  elif moji[i]=="G":
    suu+=1
  elif moji[i]=="C":
    suu+=1
  else:
    ListNum.append(suu)
    suu=0
print(max(ListNum))

### FIXED CODE ###

S=str(input())  #文字列の入力
S=S.replace("A","x")
S=S.replace("T","x")
S=S.replace("G","x")
S=S.replace("C","x")
for i in range(0,2,1):
  if S.count("xxxxxxxxxx")!=0:
    print(10)
    break
  elif S.count("xxxxxxxxx")!=0:
    print(9)
    break
  elif S.count("xxxxxxxx")!=0:
    print(8)
    break
  elif S.count("xxxxxxx")!=0:
    print(7)
    break
  elif S.count("xxxxxx")!=0:
    print(6)
    break
  elif S.count("xxxxx")!=0:
    print(5)
    break
  elif S.count("xxxx")!=0:
    print(4)
    break
  elif S.count("xxx")!=0:
    print(3)
    break
  elif S.count("xx")!=0:
    print(2)
    break
  elif S.count("x")!=0:
    print(1)
    break
  else:
    print(0)
    break
a,b,c=map(int,intput().split())
z=(a*b)/2
print(int(z))

### FIXED CODE ###

a,b,c=map(int,input().split())
print((a*b)//2)
x, y = map(int, input().split())
a = y - 2*x
if a < 0:
    print("No")
elif a > x:
    print("No")
elif a % 2 == 0:
    print("Yes")
elif a == 0:
    print("Yes")

### FIXED CODE ###

a, b, c, d, e = map(int, input().split())
if a == 0:
    print(1)
elif b == 0:
    print(2)
elif c == 0:
    print(3)
elif d == 0:
    print(4)
else:
    print(5)
s = input()
t = input()
print("Yes" if s == t[:-1] "No")

### FIXED CODE ###

s = input()
t = input()
print("Yes" if s == t[:len(t) - 1] else "No")
s=input();print(min(abs(int(s[i:i+3])-753)for i in range(9)))

### FIXED CODE ###

s=input();print(min(abs(int(s[i:i+3])-753)for i in range(len(s)-2)))
import math
a, b = map(int, input().split())
print(math.floor(a*b/math.gcd(a, b)))

### FIXED CODE ###

import math
def gcd(m, n):
    x = max(m,n)
    y = min(m,n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z
def lcm(m, n):
    return int(m*n/gcd(m,n))
a, b = map(int, input().split())
print(lcm(a,b))
A, B = map(int, input().split())
S = input()
if S[A] == '-' and A+B+1 == len(S):
    S = a[:A]+a[A+1:]
    try:
        S = int(S)
        print('Yes')
    except:
        print('No')
else:
    print('No')

### FIXED CODE ###

A, B = map(int, input().split())
S = list(input())

if len(S) == A+B+1 and S[A] == '-' and S.count('-') == 1:
    print('Yes')

else:
    print('No')
from collections import deque
n, m = map(int, input().split())
A = [0] * m
B = [0] * m
for i in range(m):
    A[i], B[i] = map(int, input().split())

next_queue = deque()
sign = [-1] * n

next_queue.append(1)

while next_queue:
    current_number = next_queue.popleft()
    for i, _ in enumerate(A):
        if A[i] == current_number:
            if sign[B[i] - 1] == -1:
                sign[B[i] - 1] = current_number
                if B[i] != 1:
                    next_queue.append(B[i])
                A.pop(i)
                B.pop(i)
        if B[i] == current_number:
            if sign[A[i] - 1] == -1:
                sign[A[i] - 1] = current_number
                if A[i] != 1:
                    next_queue.append(A[i])
                A.pop(i)
                B.pop(i)
print("Yes")
for i in range(1, n):
    print(sign[i])




### FIXED CODE ###

from collections import deque
n, m = map(int, input().split())
route = [[] for i in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    route[a-1].append(b - 1)
    route[b-1].append(a - 1)

next_queue = deque()
sign = [-1 for i in range(n)]
sign[0] = 999

next_queue.append(0)

while next_queue:
    current_number = next_queue.popleft()
    for room in route[current_number]:
        if sign[room] == -1:
            sign[room] = current_number
            next_queue.append(room)
print("Yes")
for i in range(1, n):
    print(sign[i] + 1)
n = int(input())

sum_list = []
for i in range(2, int((n + 1) / 2)):
    a = i
    b = n - i
    sum_a = 0
    for a_i in range(len(str(a))):
        sum_a += int(str(a)[a_i])
    sum_b = 0
    for b_i in range(len(str(b))):
        sum_b += int(str(b)[b_i])
    sum_list.append(sum_a + sum_b)

print(min(sum_list))

### FIXED CODE ###

n = int(input())

sum_list = []
for i in range(1, int(n / 2) + 1):
    a = i
    b = n - i
    sum_a = 0
    for a_i in range(len(str(a))):
        sum_a += int(str(a)[a_i])
    sum_b = 0
    for b_i in range(len(str(b))):
        sum_b += int(str(b)[b_i])
    sum_list.append(sum_a + sum_b)

print(min(sum_list))
import math
n, k = map(int, input().split())
data = list(map(int, input().split()))
print(math.ceil((n-1)/(k-1)))


### FIXED CODE ###

s = input()
ans = 0
for i in s:
    if i == '+':
        ans += 1
    else:
        ans -= 1
print(ans)
N = int(input())
A = list(map(int, input().split()))
import numpy as np
if 0 in A:
    print(0)
    exit(0)

ans = np.prod(A)
if ans<= 10**18:
    print(ans)
    exit(0)
if 10**18 < ans:
    print(-1)


### FIXED CODE ###

A, B = map(int,input().split())
print(A*B)
n,m = map(int,input().split())
student = []
check = []
for i in range(n):
    ab = [int(i) for i in input().split()]
    student.append(ab)
for j in range(m):
    cd = [int(i) for i in input().split()]
    check.append(cd)
mn = 10**8
for ax,by in student:
    for i in range(m):
        dist = abs(ax-check[i][0]) + abs(by-check[i][1])
        if mn > dist:
            ans = i+1
            mn = dist
    print(ans)
    mn = 10**8

### FIXED CODE ###

n,m = map(int,input().split())
student = []
check = []
for i in range(n):
    ab = [int(i) for i in input().split()]
    student.append(ab)
for j in range(m):
    cd = [int(i) for i in input().split()]
    check.append(cd)
mn = 10**13
for ax,by in student:
    for i in range(m):
        dist = abs(ax-check[i][0]) + abs(by-check[i][1])
        if mn > dist:
            ans = i+1
            mn = dist
    print(ans)
    mn = 10**13
from collections import Counter

n = int(input())
v = input().split()

v1 = v[::2]
v2 = v[1::2]
c1 = Counter(v1).most_common(2)
c2 = Counter(v2).most_common(2)

if c1[0][0] != c2[0][0]:
    print(n - c1[0][1] - c2[0][1])
else:
    print(min(n - c1[0][1] - c2[1][1], n - c1[1][1] - c2[0][1]))


### FIXED CODE ###

from collections import Counter

n = int(input())
v = input().split()

v1 = v[::2]
v2 = v[1::2]
c1 = Counter(v1).most_common(2)
c2 = Counter(v2).most_common(2)

if len(set(v)) == 1:
    print(len(v) // 2)
elif c1[0][0] != c2[0][0]:
    print(n - c1[0][1] - c2[0][1])
else:
    print(min(n - c1[0][1] - c2[1][1], n - c1[1][1] - c2[0][1]))
import math

h = float(input())

count = 1
while(h > 1) {
  h = round(h / 2)
  count+=1
}
print(count)


### FIXED CODE ###

import math

h = int(input())

count = 0
while h > 1:
  h = math.floor(h/2)
  count += 1

print(2**count*2-1)
n, m = map(int,input().split())

g = [[] for i in range(n)]

for _ in range(m):
  v1 , v2 = map(int,input().split())
  v1 -=1; v2 -=1
  g[v1].append(v2)

# longest path from vertice i
def dfs(i):
  temp = 0
  for nv in g[i]:
    temp = max(temp,dfs(nv)+1)
  return temp

# iterate over all vertices

res = 0
for i in range(n):
  res = max(res, dfs(i))
  
print(res)

### FIXED CODE ###

import sys

sys.setrecursionlimit(10**9)

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

g = [[] for i in range(n)]

dp = [-1] *n
for _ in range(m):
  v1 , v2 = map(int,input().split())
  v1 -=1; v2 -=1
  g[v1].append(v2)
  
# finding longest path for vertice i
def dfs(i):
  if dp[i]!=-1:
    return dp[i]
  temp = 0
  for nv in g[i]:
    temp = max(temp, dfs(nv)+1)
  
  dp[i]=temp
  return temp
  
# finding overall longest path  
res = 0  
for i in range(n):
  res = max(res, dfs(i))
  
print(res)
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N,H,W = map(int,readline().split())
RCA = [tuple(int(x) for x in line.split()) for line in readlines()]

RCA.sort(key = lambda x: -x[2])

RCA

root = list(range(H+W))
size = [0] * (H+W)
no_cycle = [True] * (H+W)

def find_root(x):
    y = root[x]
    if x == y:
        return y
    z = find_root(y)
    root[x] = z
    return z

def merge(x,y):
    x,y = find_root(x),find_root(y)
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    no_cycle[x] = no_cycle[x] and no_cycle[y]

answer = 0
for R,C,A in RCA:
    x,y = R-1,H+C-1
    rx,ry = find_root(x),find_root(y)
    if rx == ry:
        if not no_cycle[rx]:
            continue
        no_cycle[rx] = False
    else:
        if (not no_cycle[rx]) and (not no_cycle[ry]):
            continue
        merge(rx,ry)
    answer += A

print(answer)



### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

M,D = map(int,input().split())

answer = 0
for d in range(10,D+1):
    a,b = divmod(d,10)
    if a >= 2 and b >= 2 and 1<=a*b<=M:
        answer += 1

print(answer)
c = a*b
if c%2 == 0:
    print("Even")
else:
    print("Odd")

### FIXED CODE ###

a, b= (int(i) for i in input().split())  
c = a*b
if c%2 == 0:
    print("Even")
else:
    print("Odd")
def f(i,ans,l,t):
  if (i+1) == (len(l)-1):
    if (ans+l[i]) > l[i+1]:
      ans = ans + l[i]-l[i+1]
      return t+ans
    else:
      return t
  else:
    if (ans+l[i]) > l[i+1]:
      ans = ans + l[i]-l[i+1]
      return f(i+1,ans,l,t+ans)
    else:
      return f(i+1,0,l,t)
n = input("")
an = input("").split(" ")
ani = []
for b in an:
  if b != "" and b != " ":
    ani.append(int(b))
if len(ani) == 1:
  print("0")
else:
  print(f(0,0,ani,0))

### FIXED CODE ###

import sys
sys.setrecursionlimit(2000000)
def f(i,ans,l,t):
  if (i+1) == (len(l)-1):
    if (ans+l[i]) > l[i+1]:
      ans = ans + l[i]-l[i+1]
      return t+ans
    else:
      return t
  else:
    if (ans+l[i]) > l[i+1]:
      ans = ans + l[i]-l[i+1]
      return f(i+1,ans,l,t+ans)
    else:
      return f(i+1,0,l,t)
n = input("")
an = input("").split(" ")
ani = [int(a) for a in an]
if len(ani) == 1:
  print("0")
else:
  print(str(f(0,0,ani,0)))
from numpy.linalg import solve
N = int(input())
A = list(map(int, input().split()))

left = [[0 for _ in range(N)] for _ in range(N)]
right = []
for i in range(N):
  right.append(2 * A[i] + 2 * A[(i + 1) % N])
  for j in range(N):
    if j == i or j == (i + 2) % N:
      left[i][j] = 1
    if j == (i + 1) % N:
      left[i][j] = 2

ans = solve(left, right)
for i in range(N):
  print(int(round(ans[i])), end = "")
  if i == N - 1:
    print()
  else:
    print(" ", end = "")

### FIXED CODE ###

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

ans = 0
for i in range(N):
  tmp = ans
  if i == 0:
    for j in range(N):
      if j % 2 == 0:
        ans += A[j]
      else:
        ans -= A[j]
  else:
    ans = 2 * A[i - 1] - tmp

  tmp = ans
  print(ans, end = "")
  if i != N - 1:
    print(" ", end = "")
  else:
    print()
import collections

n = int(input())
x = input()

x_list = list(x)

num_dict = dict(collections.Counter(x_list))

num_of_1 = num_dict["1"]

first_temp = int(x, 2)

for i in range(n):
    temp_num_of_1 = num_of_1 + 1 if x_list[i] == "0" else num_of_1 - 1

    ans = 0

    if temp_num_of_1 > 0:
        a = first_temp + 2 ** (n - i - 1) if x_list[i] == "0" else first_temp - 2 ** (n - i - 1)

        a = a % temp_num_of_1

        temp = list(bin(a)[2:])

        ans += 1
    
        while temp.count("1") != 0:
            a = int("".join(temp), 2)

            a = a % temp.count("1")

            temp = list(bin(a)[2:])

            ans += 1

    print(ans)

### FIXED CODE ###

n = int(input())
x = input()

num_of_1 = x.count("1")

first = int(x, 2)

def f(x):
    if x == 0:
        return 0
    return 1 + f(x % bin(x).count('1'))

if num_of_1 == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        elif i == n-1:
            print(2)
        else:
            print(1)
    exit()

first_one, first_zero = first % (num_of_1 - 1), first % (num_of_1 + 1)

for i in range(n):
    if x[i] == "0":
        print(1 + f((first_zero + pow(2, n-i-1, num_of_1 + 1)) % (num_of_1 + 1)))
    else:
        print(1 + f((first_one - pow(2, n-i-1, num_of_1 - 1)) % (num_of_1 - 1)))
import sys
n=sys.argv[1]
print(n*n*n)

### FIXED CODE ###

n=input()
num=int(n)
print(num*num*num)
s = input()
cha = list(s)
answer = []
for hoge in int_cha:
  if hoge == '1':
    answer.append('9')
  else:
    answer.append('1')
print(''.join(answer))

### FIXED CODE ###

s = input()
cha = list(s)
answer = []
for hoge in cha:
  if hoge == '1':
    answer.append('9')
  else:
    answer.append('1')
print(''.join(answer))
n,k = list(map(int,input().split()))
h = list(map(int,input().split()))

dp = [10**9]*n
dp[0] = 0

for i in range(n):
    for j in range(1,k+1):
        if i+j>=n:
            break
        dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
    print(dp)

### FIXED CODE ###

def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,k = MAP()
h = MAP()

dp = [MOD]*n
dp[0]=0

for i in range(n-1):
    for j in range(i+1,min(i+k+1,n)):
        dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]))
print(dp[n-1])