Harryxun/stf_run huggingface dataset:
from itertools import accumulate
N, K = map(int, input().split())
As = list(map(int, input().split()))

csum = list(accumulate(As, initial = 0))
csum_of_positives = list(accumulate([max(A, 0) for A in As], initial = 0))

#[i, i+K) will be all white/black.
max_score = 0
for i in range(N-K+1):
    score = 0
    all_black = csum[i+K] - csum[i]
    if all_black > 0: # if [i, i+K) is worth painting with black 
        score += all_black
    score += csum_of_positives[i] #[0, i)
    score += csum_of_positives[N] - csum_of_positives[i+K] #[i+K, N)    
    max_score = max(max_score, score)

print(max_score)


### FIXED CODE ###

from itertools import accumulate
N, K = map(int, input().split())
As = list(map(int, input().split()))

csum = list(accumulate(As, initial = 0))
csum_of_positives = list(accumulate([max(A, 0) for A in As], initial = 0))

#[i, i+K) will be all white/black.
max_score = 0
for i in range(N-K+1):
    score = 0
    all_black = csum[i+K] - csum[i]
    if all_black > 0: # if [i, i+K) is worth painting with black 
        score += all_black
    score += csum_of_positives[i] #[0, i)
    score += csum_of_positives[N] - csum_of_positives[i+K] #[i+K, N)    
    max_score = max(max_score, score)

print(max_score)
Copy
Copy
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _i in range(m)]
 
visit = [-1 for _ in range(n)]
visit[0] = 0
tree = [[] for _ in range(n)]
for a, b in ab:
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
 
from collections import deque
q = deque([0])
while q:
    p = q.popleft()
    for i in tree[p]:
        if visit[i] < 0:
            visit[i] = p
            q.append(i)
if all(i >= 0 for i in visit):
    print("Yes")
    for i in visit[1:]:
        print(i+1)
else:
    print("No")

### FIXED CODE ###

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _i in range(m)]
 
visit = [-1 for _ in range(n)]
visit[0] = 0
tree = [[] for _ in range(n)]
for a, b in ab:
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
 
from collections import deque
q = deque([0])
while q:
    p = q.popleft()
    for i in tree[p]:
        if visit[i] < 0:
            visit[i] = p
            q.append(i)
if all(i >= 0 for i in visit):
    print("Yes")
    for i in visit[1:]:
        print(i+1)
else:
    print("No")
#ABC083
import math
X, Y=map(int,input().split())
print(int(math.log(Y/X, 2)//1+1))

### FIXED CODE ###

#ABC082C
N=int(input())
a_sorted=sorted(list(map(int,input().split())))
#必要な変数の作成
Allowable_original=0
Allowable_count=0
Delete_count=0
#aが要素1個のみの場合
if N==1:
    if a_sorted[0]==1:
        print(0)
    else:
        print(1)
    exit()
#順番にチェック
for i in range(N):
    #開始処理
    if i==0:
        #許容個数カウントとその元値を作成
        Allowable_original=a_sorted[0]
        Allowable_count=Allowable_original-1
        continue

    #前の数字と同じか否か
    # 同じなら、
    if a_sorted[i]==a_sorted[i-1]:
        #許容個数カウントを一つ減らす
        Allowable_count-=1
    # 違うなら、または末尾なら、
    if a_sorted[i]!=a_sorted[i-1]:
        # 許容個数カウントの現在値が正か0か負かチェック
        # 正なら、
        if Allowable_count>0:
            #カウントしてきた許容個数（許容個数カウントの元値-現在値）を削除対象カウントに追加
            Delete_count+=Allowable_original-Allowable_count
        #0以下なら、
        else:
            # -1をかけた値を削除対象カウントに追加
            Delete_count-=Allowable_count
        # 許容個数カウントとその元値を新規作成
        Allowable_original = a_sorted[i]
        Allowable_count = Allowable_original - 1
    #末尾なら、
    if i==N-1:
        # 許容個数カウントの現在値が正か0か負かチェック
        # 正なら、
        if Allowable_count>0:
            #カウントしてきた許容個数（許容個数カウントの元値-現在値）を削除対象カウントに追加
            Delete_count+=Allowable_original-Allowable_count
        #0以下なら、
        else:
            # -1をかけた値を削除対象カウントに追加
            Delete_count-=Allowable_count
#結果出力
print(Delete_count)
A=int(input())
B=int(input())
C=B/2
if A >= 13 :
  print( '%d' % B )
elif A<=12 and A>=6 :
  print( '%d' % C )
else:
  print( '0')

### FIXED CODE ###

A,B = (int(i) for i in input().split()) 
C=B/2
if A >= 13 :
  print( '%d' % B )
elif A<=12 and A>=6 :
  print( '%d' % C )
else:
  print( '0')
# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())
a = int(input())
# スペース区切りの整数の入力
# b, c = map(int, input().split())
# 文字列の入力
# s = input()
# # 出力
# print("{} {}".format(a+b+c, s))

amari = n%500

if amari =< a:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

# -*- coding: utf-8 -*-
# 整数の入力
n = int(input())
a = int(input())


if n < 500:
    if n <= a:
        print('Yes')
    else:
        print('No')
else:    
    amari = n%500
    if amari <= a:
        print('Yes')
    else:
        print('No')
while 1:
    a,op,b=raw_input().split()
    if(a==b=='0' and op=='?'): break
    a,b=map(int,[a,b])
    ans=0
    if op=='+':
        ans=a+b
    elif op=='-':
        ans=a-b
    elif op=='*':
        ans=a*b
    elif op=='/':
        ans=a/b
    print ans

### FIXED CODE ###

while 1:
    a,op,b=raw_input().split()
    if(op=='?'): break
    a,b=map(int,[a,b])
    ans=0
    if op=='+':
        ans=a+b
    elif op=='-':
        ans=a-b
    elif op=='*':
        ans=a*b
    elif op=='/':
        ans=a/b
    print ans
N = int(input())
C = {0:0,1:0,2:0}
cnt = 0
for _ in range(N):
    s = input().strip()
    if s[0]=="B" and s[-1]!="A":
        C[0] += 1
    elif s[0]!=B and s[-1]=="A":
        C[1] += 1
    elif s[0]=="B" and s[-1]=="A":
        C[2] += 1
    for i in range(len(s)-1):
        if s[i:i+2]=="AB":
            cnt += 1
if C[2]>0:
    cnt += C[2]-1
    if C[0]>0:
        cnt += 1
        C[0] -= 1
    if C[1]>0:
        cnt += 1
        C[1] -= 1
cnt += min(C[0],C[1])
print(cnt)


### FIXED CODE ###

N = int(input())
C = {0:0,1:0,2:0}
cnt = 0
for _ in range(N):
    s = input().strip()
    if s[0]=="B" and s[-1]!="A":
        C[0] += 1
    elif s[0]!="B" and s[-1]=="A":
        C[1] += 1
    elif s[0]=="B" and s[-1]=="A":
        C[2] += 1
    for i in range(len(s)-1):
        if s[i:i+2]=="AB":
            cnt += 1
if C[2]>0:
    cnt += C[2]-1
    if C[0]>0:
        cnt += 1
        C[0] -= 1
    if C[1]>0:
        cnt += 1
        C[1] -= 1
cnt += min(C[0],C[1])
print(cnt)
#N = int(input())
#a = list(map(int, input().split()))

ans=0

if N%2==0:
    for i in range(N//2):
      if a[a[i]-1]==i+1:
        ans += 1
            
else:
    for i in range(N//2 +1):
        if a[a[i]-1]==i+1:
          ans+=1

print(ans)

### FIXED CODE ###

N = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(N):
    if a[a[i]-1] == i+1:
        ans += 1
print(ans//2)
ns=0
right=0
left=0
for i in range(n):
    left=min(a[i],b[i])
    ans+=left
    a[i]-=left
    b[i]-=left
    
    right=min(a[i+1],b[i])
    ans+=right
    a[i+1]-=right
    b[i]-=right
print(ans)

### FIXED CODE ###

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

ans=0
right=0
left=0
for i in range(n):
    left=min(a[i],b[i])
    ans+=left
    a[i]-=left
    b[i]-=left
    
    right=min(a[i+1],b[i])
    ans+=right
    a[i+1]-=right
    b[i]-=right
print(ans)
D,N=map(int,input().split())
if N=100 :
    print((N+1)*100**D)
else :
    print(N*100**D)

### FIXED CODE ###

D,N=map(int,input().split())
if N<100 :
    print(N*100**D)
else :
    print((N+1)*100**D)
a,b = map(int, input().split())
result = a+b if a+b < 10 else ‘Error’ 
print(result)

### FIXED CODE ###

A, B = map(int, input().split())
if A + B < 10:
  print(A+B)
else:
  print("error")
def extgcd(a,b):
  r=[1,0,a]
  w=[0,1,b]
  while w[2]!=1:
    q=r[2]//w[2]
    r2=w
    w2=[r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
    r=r2
    w=w2
  return [w[0],w[1]]
def mod_inv(a,m):
  x=extgcd(a,m)[0]
  return (m+x%m)%m

def primes(n):
  is_prime=[True]*(n+1)
  is_prime[0]=False
  is_prime[1]=False
  for i in range(2,int(n**0.5)+1):
    if not is_prime[i]:
      continue
    for j in range(i*2,n+1,i):
      is_prime[j]=False
  return [i for i in range(n+1) if is_prime[i]]

prime=primes(int(10**3)+1)

def fact2(n):
  l=prime
  L=[]
  for i in range(len(l)):
    ct=0
    while n%l[i]==0:
      n=n//l[i]
      ct+=1
    L.append((l[i],ct))
    if n==1:
      break
  if n!=1:
    L.append(n)
  return L

print(fact2(12))
n=int(input())
a=list(map(int,input().split()))
l=[0 for i in range(10**6)]
mod=10**9+7
for i in range(n):
  x=fact2(a[i])
  for j in range(len(x)):
    l[x[j][0]]=max(l[x[j][0]],x[j][1])
lcm=1
for i in range(2,10**6):
  lcm*=(i**l[i])
  lcm%=mod
ans=0
for i in range(n):
  ans+=lcm*mod_inv(a[i],mod)
  ans%=mod
print(ans)

### FIXED CODE ###

from fractions import gcd
import collections

def lcm(x, y):
  return (x*y)//gcd(x, y)
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

n=int(input())
a=list(map(int,input().split()))
l=[0 for i in range(10**6)]
mod=10**9+7
for i in range(n):
  x=factorize(a[i])
  for j in range(len(x)):
    l[x[j][0]]=max(l[x[j][0]],x[j][1])
lcm=1
for i in range(2,10**6):
  lcm*=(i**l[i])
  lcm%=mod
ans=0
for i in range(n):
  ans+=lcm*mod_inv(a[i],mod)
  ans%=mod
print(ans)
import numpy as np


if __name__ == '__main__':
    List = [list(map(int, input().split())) for i in range(2)]
    N = List[0][0]
    buka = np.array(List[1][:])


    l_out = np.zeros(N,dtype=int)

    for i in range(N):
        l_out[buka[i]-1] += 1

    for i in range(N):
        print(l_out[i])



### FIXED CODE ###

import numpy as np
 
 
if __name__ == '__main__':
    List = [list(map(int, input().split())) for i in range(2)]
    N = List[0][0]
    buka = np.array(List[1][:])
 
 
    l_out = np.zeros(N,dtype=int)
 
    for i in range(N-1):
        l_out[buka[i]-1] += 1
 
    for i in range(N):
        print(l_out[i])
import math
a,b,c = list(map(int,input().split()))
print(math.sqrt(a))
print(math.sqrt(b))
print()
print(math.sqrt(a)+math.sqrt(b))
print(math.sqrt(c))

if c-a-b>0 and 4*a*b<(c-a-b)^2:
  print("Yes")
else:print("No")


### FIXED CODE ###

# coding: utf-8
word=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
]
n = int(input())
print(word[n-1])
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, K = LI()
    S = SS()

    # 1の塊の長さと位置を調べる
    l = []
    if S[0] == '1':
        l.append(0)
    for i in range(N - 1):
        if S[i] == '0' and S[i+1] == '1':
            l.append(i + 1)
        elif S[i] == '1' and S[i+1] == '0':
            l.append(i + 1)
    if S[-1] == '1':
        l.append(N)
    # print(S)
    # print(l)

    # 1の塊をK+1個くっつけた場合の長さを調べる
    ans = 0
    for i in range(len(l) // 2 - K):
        ans = max(l[2*i+2*K+1] - l[2*i], ans)

    # 端の0を逆立ちさせた場合
    if S[0] == '0':
        ans = max(l[2*K-1], ans)
    # if S[-1] == '0':
    #     ans = max(N - l[len(l)-2*K], ans)
    
    # 全部1だった場合(塊の間も無いし端の0もない)
    if l == [0, N]:
        ans = N

    print(ans)

if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, K = LI()
    S = SS()

    # 1の塊の長さと位置を調べる
    l = []
    if S[0] == '1':
        l.append(0)
    else:
        l.append(0)
        l.append(0)
    for i in range(N - 1):
        if S[i] == '0' and S[i+1] == '1':
            l.append(i + 1)
        elif S[i] == '1' and S[i+1] == '0':
            l.append(i + 1)
    if S[-1] == '1':
        l.append(N)
    else:
        l.append(N)
        l.append(N)
    # print(S)
    # print(l)

    # 1の塊をK+1個くっつけた場合の長さを調べる
    ans = 0
    if len(l) // 2 - 1 < K:
        ans = N
    else:
        for i in range(len(l) // 2 - K):
            ans = max(l[2*i+2*K+1] - l[2*i], ans)

    # 端の0を逆立ちさせた場合
    # if S[0] == '0':
    #     ans = max(l[2*K-1], ans)
    # if S[-1] == '0':
    #     ans = max(N - l[len(l)-2*K], ans)
    
    # 全部1だった場合(塊の間も無いし端の0もない)
    # if l == [0, N]:
    #     ans = N

    print(ans)

if __name__ == '__main__':
    resolve()
import sys
input = sys.stdin.readline


def main():

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

    A = []
    B = []
    for _ in range(n):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)

    dp = [0] * 10**4
    for a, b in zip(A, B):
        dp[a] = b
    for i in range(10**4):
        for a, b in zip(A, B):
            # if i + a < 10**4:
            # print(i + a)
            # print(dp[i], dp[i + a], b, i + a)
            if i + a < 10**4 and dp[i] > 0:
                if dp[i + a] > 0:
                    dp[i + a] = min(dp[i + a], dp[i] + b)
                else:
                    dp[i + a] = dp[i] + b
    k = h
    flag = 1
    ans = 0
    # print(dp[:20])
    while (flag):
        # print(k)
        if dp[k] > 0:
            ans = dp[k]
            flag = 0
        k += 1
    print(ans)


main()


### FIXED CODE ###

#import numpy as np
import sys
input = sys.stdin.readline


def main():
    h, n = map(int, input().split())
    # A = []
    # B = []
    # for _ in range(n):
    #     A.append(a)
    #     B.append(b)
        
    m = 2 * 10**4 + 10
    dp = [float("inf")] * (h+1)
    dp[0] = 0
    # for a, b in zip(A, B):
    #     dp[a] = b
    for _ in range(n):
        a, b = map(int, input().split())
        for i in range(h):
            # for a, b in zip(A, B):
            if i + a < m :
                j = min(i+a, h)
                if dp[j] > 0:
                    dp[j] = min(dp[j], dp[i] + b)
                else:
                    dp[j] = dp[i] + b
    k = h
    # print(dp[:20])
    # while (flag):
    #     if dp[k] > 0:
    #         ans = dp[k]
    #         flag = 0
    #     k += 1
    # d = np.array(dp[k:])
    # print(np.min(d[d.nonzero()]))
    print(dp[h])
    
    
main()
x ** 3

### FIXED CODE ###

x = input()
print x ** 3
a, b = map(int, input().split())
count = 0
for i in range(a, b+1):
    s = str(i)
    if(s[0]==s[-1] and s[1]==s[-2]):
        count += 1
print(count)

### FIXED CODE ###

a = input()
b = input()
c = input()

print(a[0]+b[1]+c[2])
import sys

H, W, M = map(int,input().split())
R = [0] * H
C = [0] * W
S = set()
for _ in range(M):
    h, w = map(int,input().split())
    S.add((h-1, w-1))
for i in range(M):
    h, w = S[i]
    R[h] += 1
    C[w] += 1

r = max(R)
c = max(C)

for h in [i for i in range(H) if R[i] == r]:
    for w in [i for i in range(W) if C[i] == c]:
        if not (h, w) in S:
            print(r + c)
            sys.exit()

print(r + c - 1)

### FIXED CODE ###

import sys

H, W, M = map(int,input().split())
R = [0] * H
C = [0] * W
S = set()
for _ in range(M):
    h, w = map(int,input().split())
    S.add((h-1, w-1))
    R[h-1] += 1
    C[w-1] += 1

r = max(R)
c = max(C)

HL = [i for i in range(H) if R[i] == r]
WL = [i for i in range(W) if C[i] == c]

for h in HL:
    for w in WL:
        if not (h, w) in S:
            print(r + c)
            sys.exit()

print(r + c - 1)
N=int(input())
A=list(map(int,input().split()))
for i in range(1,N+1):
    ans=A.count(i)
    print(ans)


### FIXED CODE ###

A=int(input())
print(A*2*3.141)
n=int(input())
X=[]
Y=[]
A=[]
for i in range(n):
  A=int(input())
  x=[]
  y=[]
  for j in range(A[i]):
    x,y=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
c=0
#for i in range(n):
 # l=[1]*n
  #for j in range(i, n-i):
   # if l[j]==0:continue
    #for k in range(A[j]):
   # 　　l[X[j][k]] *= Y[j][k]
#if c<l.count(1):
 # c=l.count(1) 
  
        
  
print(c)  
   

### FIXED CODE ###

n=int(input())
X=[]
Y=[]
A=[0]*n
for i in range(n):
  A[i]=int(input())
  a=A[i]
  x=[0]*a
  y=[0]*a
  for j in range(a):
    x[j],y[j]=[int(s) for s in input().split()]
  X.append(x)
  Y.append(y)
  
s=0
for i in range(2**n):
  c=0
  d=0
  B=[0]*n
  for j in range(n):
    if((i >> j) & 1):
      c=c+1
      B[j]=1
  for k in range(n):
    if B[k]==1:
      for j in range(A[k]):
        if Y[k][j]!=B[X[k][j]-1]:
          d=-1
          break
    if d<0:
      break
  if s<c and d==0:
    s=c
      
      
print(s)
N = input()
S = (N[-3])
A = int(S) - 10
print (abs(A) * 100)

### FIXED CODE ###

N = int(input())
S = divmod(N, 1000)
if S[1] == 0:
  print (S[1])
else:
  print (1000 - S[1])
n = int(input())
a = list(map(int,input().split()))

x = a[-1]
i = -1

for j in range(len(a)-1):
    if a[j] <= x:
        i += 1
        a[i], a[j] = a[j], a[i]

a[i + 1], a[n] = "[" + str(a[n]) + "]", a[i + 1]

print(*a)

### FIXED CODE ###

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

x = a[-1]
i = -1

for j in range(len(a)-1):
    if a[j] <= x:
        i += 1
        a[i], a[j] = a[j], a[i]

a[i + 1], a[n - 1] = "[" + str(a[n - 1]) + "]", a[i + 1]

print(*a)
S=input()
N=len(S)
S1=S[:((N+1)/2)]
S2=S[((N+3)/2):]
if S == S[::-1] and S1 == S1[::-1] and S2 == S2[::-1]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

S=input()
N=len(S)
S1=S[:int((N-1)/2)]
S2=S[int((N+1)/2):]
if S == S[::-1] and S1 == S1[::-1] and S2 == S2[::-1]:
  print("Yes")
else:
  print("No")
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = -10**18
P = list(map(lambda x: x-1, P))

for i in range(N):
    visit = [False]*N
    now = i
    l = []
    visit[now] = True
    
    for j in range(N+10):
        nex = P[now]
        l.append(C[nex])
        
        if visit[nex]:
            break
        
        visit[nex] = True
        now = nex
    
    su = sum(l)
    
    if su>=0:
        if K>=len(l):
            now = su*(K//len(l))
            rem = K%len(l)
            ans = max(ans, now)
        
            for j in range(rem):
                now += l[j]
                ans = max(ans, now)
                
            now = l[0]
            ans = max(ans, now)
            
            for j in range(1, len(l)):
                now += l[i]
                ans = max(ans, now)
        else:
            now = l[0]
            ans = max(ans, now)
            
            for j in range(1, K):
                now += l[j]
                ans = max(ans, now)
    else:
        now = l[0]
        ans = max(ans, now)
        
        if K<len(l):
            for j in range(1, K):
                now += l[j]
                ans = max(ans, now)
        else:
            for j in range(1, len(l)):
                now += l[j];
                ans = max(ans, now)

print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline

N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = -10**18

for i in range(N):
    now = i
    visit = [False]*N
    visit[now] = True
    l = []
    
    for _ in range(N+10):
        nex = P[now]-1
        l.append(C[nex])
        
        if visit[nex]:
            break
        
        visit[nex] = True
        now = nex
    
    s = sum(l)
    now = 0
    
    for i in range(min(K, len(l))):
        now += l[i]
        ans = max(ans, now+(K-i-1)//len(l)*max(0, s))
    
print(ans)
from functools import lru_cache

H,N = map(int,input().split())
atk=[]
MP=[]
for i in range(N):
  n,a=input().split()
  atk.append(int(n))
  MP.append(int(a))

@lru_cache(maxsize=1000)
def fx(H):
  if H <= 0:
    return 0
  arr = []
  for i in range(len(atk)):
    b = fx(H - atk[i]) + MP[i]
    arr.append(b)   
  return min(arr)

a = fx(H)
print(a)

### FIXED CODE ###

def knapsack(N,W,weight,value):
  #初期化
  inf=float("inf")
  dp=[[inf for i in range(W+1)] for j in range(N+1)]
  dp[0][0]= 0
  #DP
  for i in range(N):
    for w in range(W+1):
      if 0 <= w-weight[i]: #dp[i][w-weight[i]の状態にi番目の荷物が入る可能性がある
        dp[i+1][w]=min(dp[i+1][w-weight[i]]+value[i], dp[i][w])
      else:
        dp[i+1][w]=dp[i][w]
  return dp
 
H,N = map(int,input().split())
 
weight=[]
value=[]
for i in range(N):
    n,a=input().split()
    weight.append(int(n))
    value.append(int(a))
MAX = max(weight)
dp = knapsack(N,H+MAX,weight,value)
 
print(min(dp[N][H:H+MAX]))
for i in range(100000):
  g = N -i
  a=sum(map(int,list(str(g))))
  b=sum(map(int,list(str(i))))
  ans =  a + b
  if ans == 0:
    num = ans
  elif num >= ans:
    num = ans
  else:
    continue

### FIXED CODE ###

N =input()
list = [int(i) for i in N]

ans = sum(list)
if ans ==1:
  print(10)
else:
  print(ans)
n,x,m=map(int,input().split())
i=int(2)
a=[x]
while (i <= n):
	x=(x**2)%m
	if x in a:
		goto .abc
	else:
		a.append(x)
label .abc
if len(a) == n:
	print(sum(a))	
else:
	j=a.index(x)
	b=a[0:j]
	c=a[j:]
	lb=len(b)
	lc=len(c)
	k=(n-lb)%lc
	l=(n-lb)//lc
	d=c[0:k]
	print(sum(b)+sum(c)*l+sum(d))

### FIXED CODE ###

n,x,m=map(int,input().split())
i=int(2)
a=[x]
q=int(0)
while (i <= n) and (q == 0):
	x=(x**2)%m
	if x in a:
		q=1
	else:
		a.append(x)
	i=i+1

if len(a) == n:
	print(sum(a))	
else:
	j=a.index(x)
	b=a[0:j]
	c=a[j:]
	lb=len(b)
	lc=len(c)
	k=(n-lb)%lc
	l=(n-lb)//lc
	d=c[0:k]
	print(sum(b)+sum(c)*l+sum(d))
print("A%sC",%input()[8])

### FIXED CODE ###

print("A%sC"%input()[8])
array = [0 for i in range(11)]
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

for a in A:
    array[a] += 1
souwa = sum(A)

B = []
C = []
for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

for i in range(Q):
    souwa = souwa + (C[i]-B[i])*array[B[i]]
    array[C[i]] += array[B[i]]
    array[B[i]] = 0
    print(souwa)


### FIXED CODE ###

array = [0 for i in range(100001)]
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

for a in A:
    array[a] += 1
souwa = sum(A)

B = []
C = []
for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

for i in range(Q):
    souwa = souwa + (C[i]-B[i])*array[B[i]]
    array[C[i]] += array[B[i]]
    array[B[i]] = 0
    print(souwa)
inport math
n = int(input())
b = math.ceil(n/2)
print(b/n)

### FIXED CODE ###

import math
n = int(input())
print(math.ceil(n/2)/n)
def dfs(G,v,p):
    for nv in G[v]:
        if(nv==p):
            continue
        point[nv]+=point[v]
        dfs(G,nv,v)

N,Q=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
point=[0]*N
for i in range(Q):
    p,x=map(int,input().split())
    point[p-1]+=x
dfs(G,0,-1)
print(*point)

### FIXED CODE ###

import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
def dfs(G,s,p):
    for nv in G[s]:
        if(nv==p):
            continue
        Count[nv]+=Count[s]
        dfs(G,nv,s)
    
N,Q=map(int,input().split())
Count=[0]*N
G=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(lambda x:int(x)-1,input().split())
    G[a].append(b)
    G[b].append(a)
for i in range(Q):
    p,x=map(int,input().split())
    Count[p-1]+=x
dfs(G,0,-1)
print(*Count)
N, K = map(int, input().split())

if K == 1:
    print(0)

else:
    shou, N_min_1 = divmod(N, abs(N-K))
    N_min_2 = abs(N_min_1 - abs(N-K))
    print(min(N_min_1, N_min_2))

### FIXED CODE ###


N, K = map(int, input().split())
amari=N%K

print(min(amari,abs(amari-K)))