Harryxun/stf_run huggingface dataset:
from collection import deque

def bfs(loc):
    global tem_ans
    d = [[float('inf')] * w for i in range(h)]

    dx = [1,0,-1,0]
    dy = [0,1,0,-1]

    que = deque([])
    que.append(loc)
    d[loc[0]][loc[1]] = 0

    while que:
        p = popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]

            if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] == '.' and d[nx][ny] == float('inf'):
                d[nx][ny] = d[p[0]][p[1]] + 1
                que.append([nx,ny])

                if tem_ans < d[nx][ny]:
                    tem_ans = d[nx][ny]
    return tem_ans

h,w = map(int,input().split())
maze = [list(input()) for i in range(h)]
ans = 0
tem_ans = 0

loc = []
for i in range(h):
    for j in range(w):
        if maze[i][j] != '#':
            loc = [i,j]
        else:
            continue
        ans = max(ans,bfs(loc))

print(ans)


### FIXED CODE ###

from collections import deque

def bfs(loc):
    global tem_ans
    d = [[float('inf')] * w for i in range(h)]
    dx = [1,0,-1,0]
    dy = [0,1,0,-1]
    que = deque([])
    que.append(loc)
    d[loc[0]][loc[1]] = 0
    while que:
        p = que.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < h and 0 <= ny < w and maze[nx][ny] == '.' and d[nx][ny] == float('inf'):
                d[nx][ny] = d[p[0]][p[1]] + 1
                que.append([nx,ny])
                if tem_ans < d[nx][ny]:
                    tem_ans = d[nx][ny]
    return tem_ans

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

maze = [list(input()) for i in range(h)]


ans = 0
tem_ans = 0

loc = []
for i in range(h):
    for j in range(w):
        if maze[i][j] != '#':
            loc = [i,j]
        else:
            continue
        ans = max(ans,bfs(loc))

print(ans)
n,k = map(int,input().split())
if k > (n-1)*(n-2)/2:
  print(-1)
else:
  p = (n-1)*(n-2)/2 - k
  for i in range(2,n+1):
    print(1,i)
  x = 2
  y = 3
  for _ in range(p):
    print(x,y)
    y = y + 1
    if y == n:
      x = x + 1
      y = x + 1

### FIXED CODE ###

n,k = map(int,input().split())
if k > (n-1)*(n-2)/2:
  print(-1)
else:
  p = (n-1)*(n-2)/2 - k
  print(n-1+int(p))
  for i in range(2,n+1):
    print(1,i)
  x = 2
  y = 3
  for _ in range(int(p)):
    print(x,y)
    y = y + 1
    if y == n + 1:
      x = x + 1
      y = x + 1
from collections import deque

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()], maxlen=200001)
desk_b = deque([int(n) for n in input().split()], maxlen=200001)

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
    else:
        count_a = count
    if len(desk_b) != 0:
        book_b = desk_b.popleft()
        count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
    else:
        count_b = count
    return max(count_a, count_b)

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)


### FIXED CODE ###

N, M, K = map(int, input().split())
desk_a = list(map(int, input().split()))
desk_b = list(map(int, input().split()))

sum_a = [0]
sum_b = [0]

for i in range(N):
    sum_a.append(sum_a[-1] + desk_a[i])
for i in range(M):
    sum_b.append(sum_b[-1] + desk_b[i])

ans = 0
j = M
for i in range(N+1): 
    a = sum_a[i]
    if K - a < 0:
        break
    while sum_b[j] > K - a: 
        j -= 1
    ans = max(ans, i+j)

print(ans)
params = input().split(' ')
n = params[1]

acfoundfor = []

penalties = 0
points = 0

for i in range(n):
    submission = input().split(' ')
    p = eval(submission[0])
    status = submission[1]
    
    if p in acfoundfor:
        continue

    if status == 'AC':
        points += 1
        acfoundfor.append(p)
    else:
        penalties += 1


### FIXED CODE ###

params = input().split(' ')
m = eval(params[0])
n = eval(params[1])

penaltyCount = []

for i in range(m):
    penaltyCount.append(0)

penalties = 0
points = 0

for i in range(n):
    submission = input().split(' ')
    p = eval(submission[0])-1
    status = submission[1]
    
    if penaltyCount[p] == -1:
        continue

    if status == 'AC':
        penalties += penaltyCount[p]
        penaltyCount[p] = -1
        points += 1
    else:
        penaltyCount[p] += 1


print(points, penalties)
N=int(input())
H=list(map(int,input().split()))

def cost(n):
    if n==1:
        return 0
    if n==2:
        return abs(H[1]-H[0])
    else:
        ans=min(cost(n-2)+abs(H[n-1]-H[n-3]),cost(n-1)+abs(H[n-1]-H[n-2]))
    return ans

print(cost(N))

### FIXED CODE ###

N=int(input())
H=list(map(int,input().split()))
dp=[0]*N
dp[0]=0
dp[1]=abs(H[1]-H[0])

for i in range(2,N):
    dp[i]=min(dp[i-2]+abs(H[i]-H[i-2]),dp[i-1]+abs(H[i]-H[i-1]))

print(dp[N-1])
def solve(A, n, i, m):
    if m == 0:
        return True
    if i >= n:
        return False
    res = solve(A, n, i+1, m) or solve(A, n, i+1, m-A[i])
    return res

n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))

for m in M:
    if solve(A, len(A), 0, m):
        print("yes")
    else:
        print("no")


### FIXED CODE ###

import itertools as itl

n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))
S = []

for i in range(n):
    cmb = list(itl.combinations(A, i+1))
    for j in cmb:
        S.append(sum(j))

for m in M:
    flg = False
    for s in S:
        if s == m:
            flg = True
            break
    if flg:
        print("yes")
    else:
        print("no")
N = int(input())

if N=10*i for i in range(1,5+1):
    print("10")
else
    print(sum(int(str(N)))

### FIXED CODE ###

N = int(input())
a = 0

for i in str(N):
    a += int(i)
if a == 1:
    print(10)
else:
    print(a)
str_len,input_str = input().split('\n')
half = int(int(str_len)/2)
if(str_len % 2 == 0 and input_str[0:half] == input_str[half:str_len]):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

str_len = int(input())
input_str = str(input())
half = int(int(str_len)/2)
if(str_len % 2 == 0 and input_str[0:half] == input_str[half:str_len]):
  print("Yes")
else:
  print("No")
import math

A = int(A)
B = int(B)
X = int(X)
Y = int(Y)
Z = int(Z)

Y = X - A

Y % B = Z



print("手元に残っている金額は" + str(Y) + "円です")

### FIXED CODE ###

x=int(input())
a=int(input())
b=int(input())
print((x-a)%b)
h,w=map(int,input().split())
c=0
for i in range(h):
  c=input().count("#")
print("Possible" if c=h+w-1: "Impossible")

### FIXED CODE ###

h,w=map(int,input().split())
c=0
for i in range(h):
  c+=input().count("#")
print("Possible" if c==h+w-1 else "Impossible")
import sys
bingo = [[],[],[]]
 
for i in range(3):
  a, b, c = map(int,input().split())
  bingo[i].append(a)
  bingo[i].append(b)
  bingo[i].append(c)
  
N = int(input())
  
for i in range(N):
  S = int(input())
  for j in range(3):
    if S in bingo[j]:
      for k in range(3):
        if S == bingo[j][k]:
          bingo[j][k] = 'ok'
          
ANS = 0
 
for i in range(3):
  for j in range(3):
    if bingo[i][j] == 'ok':
      ANS += 1
      if ANS == 3:
        print("Yes")
        sys.exit()
  ANS = 0
 
for i in range(3):
  for j in range(3):
    if bingo[j][i] == 'ok':
      ANS += 1
      if ANS == 3:
        print("Yes")
        sys.exit()
  ANS = 0
 
if bingo[1][1] == 'ok':
  if bingo[0][0] == 'ok' and bingo[2][2] == 'ok':
    print("Yse")
    sys.exit()
  elif bingo[0][2] == 'ok' and bingo[2][0] == 'ok':
    print("Yse")
    sys.exit()
  else:
    print("No")
    sys.exit()
 

### FIXED CODE ###

N = int(input())
print(int((N+1)/2))
for t in range(int(input())):
	s=input()
	freq=[0]*(26)
	ct=0
	for i in range(len(s)):
		freq[ord(s[i])-ord('a')]+=1
		if freq[ord(s[i])-ord('a')]==1:
			ct+=1
	ans=1
	for i in range(26):
		if freq[i]>0:
			ans=(ans*(freq[i]+1))
	print((ans-1)%1000000007)



### FIXED CODE ###

for t in range(1):
	n=input()
	s=input()
	freq=[0]*(26)
	ct=0
	for i in range(len(s)):
		freq[ord(s[i])-ord('a')]+=1
		if freq[ord(s[i])-ord('a')]==1:
			ct+=1
	ans=1
	for i in range(26):
		if freq[i]>0:
			ans=(ans*(freq[i]+1))
	print((ans-1)%1000000007)
a,b,c=map(int,input())
print(a*b/2)

### FIXED CODE ###

a,b,c=map(int,input().split())
print(a*b//2)
from math import pi
r=import()
print("{0:.5f} {1:.5f}".format(pi*r*r, 2*pi*r))

### FIXED CODE ###

from math import pi
r=float(input())
print("{0:.5f} {1:.5f}".format(pi*r*r, 2*pi*r))
a, b = map(int, input())
def f(i):
    x = a>>i
    y = b>>i
    r = 0
    if x==y:
        if x&1:
            r^=(y-x+1)%2
        return r
    if x&1:
        r^=(a-x+1)%2
    if y&1:
        r^=(b-y)%2
    return r
print(int(''.join([str(f(i)) for i in range(len(bin(b))-2)])[::-1],2))

### FIXED CODE ###

a,b=map(int,input().split())
r=0
if a%2==1:
    r=a
    a+=1
if a<=b:
    x,y=divmod(b-a+1,2)
    r^=x%2^b*y
print(r)
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
l=[A,B,C,D,E]
l0=[i%10 for i in l]
x=[]
for i in range(5):
    if l0[i]!=0:
        l[i]=(1+l[i]//10)*10 
        x.append(l0[i])
ans=sum(l)-10+min(x)
print(ans)

### FIXED CODE ###

A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
l=[A,B,C,D,E]
l0=[i%10 for i in l]
x=[]
for i in range(5):
    if l0[i]!=0:
        l[i]=(1+l[i]//10)*10 
        x.append(l0[i])
if x==[]:
    ans=sum(l)
else:
    ans=sum(l)-10+min(x)
print(ans)
# グラフ木累積和
n, q = map(int, input().split())
tree = [[] for _ in range(n)]
ans = [0] * n

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

for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x

def dfs(v, p=-1):
    for u in tree[v]:
        # 親には戻らないようにする
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)

dfs(0)
print(*ans)



### FIXED CODE ###

import collections

n, q = map(int, input().split())
cnt = [0] * (n + 1)

# adjacency list for tree graph
g = [[] for _ in range(n + 1)]
for _ in range(n-1):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

# calc cnt
for _ in range(q):
    v, val = map(int, input().split())
    cnt[v] += val

q = collections.deque()
q.append(1)
checked = [0] * (n + 1)

while q:
    v = q.pop()
    checked[v] = 1
    for u in g[v]:
        if checked[u] == 1:
            continue
        cnt[u] += cnt[v]
        q.append(u)
print(*cnt[1:])
a,b= map(int,raw_input().split())
d=a/b
r=a%b
f=float(a/b)
print %d,%d,%f,%(d,r,f)

### FIXED CODE ###

a,b= map(int,raw_input().split())
d=a/b
r=a%b
f=float(a)/float(b)
print "%d %d %f" % (d,r,f)
S=str(input())
k = 0
for i in Range(S):
  if S[i] == '+':
    k = k + 1
  else:
    k = k - 1
print(k)

### FIXED CODE ###

S=str(input())
k = 0
for i in range(4):
  if S[i] == '+':
    k = k + 1
  else:
    k = k - 1
print(k)
i = int(input()) 
s = input()
if i >= 1 and 100 >= i and i % 2 == 0 and i == len(s) and s.isalpha() and s.islower():
  t_0 = s[0]
  t_1 = s[i/2]
    for j in range(1, i/2):
      t_0 += s[j]
    for k in range(i/2 + 1, i):
      t_1 += s[k]
    if t_0 == t_1:
      print("Yes")
    else:
      print("No")


### FIXED CODE ###

i = int(input()) 
s = input()
if i >= 1 and 100 >= i and i % 2 == 0 and i == len(s) and s.isalpha() and s.islower():
  n = (int)(i/2)
  t_0 = s[0]
  t_1 = s[n]
  for j in range(1, n):
    t_0 += s[j]
  for k in range(n + 1, i):
    t_1 += s[k]
  if t_0 == t_1:
    print("Yes")
  else:
    print("No")
else:
  print("No")
A, B, K = map(int, input().split())

s = 0
def sp(R):
  if R == 1:
    return {1:1}
  dic = {}
  I = int(R)
  s=0
  while s==0:
    for i in range(2, R+1):
      if I%i==0:
        I=I/i
        if I==1:
          s=1
        if i not in dic:
          dic[i] = 0
        dic[i] += 1
        break
  return dic

a = sp(A)
b = sp(B)

c = []
for i in range(0, max(max(a.keys()), max(b.keys()))+1):
  if (i in a) and (i in b):
    t = min(a[i], b[i])
    c.append([i**j for j in range(t+1)])

arr = []
import itertools
from functools import reduce
for i in itertools.product(*c):
  v = reduce(lambda x,y:x*y,i)
  if v not in arr:
    arr.append(v)

arr.sort(reverse=True)

print(arr[K-1])

### FIXED CODE ###

import sys
A,B,K = map(int, input().split())

for i in range(min(A,B), 0, -1):
  if (A % i == 0) and (B%i == 0):
    K-=1
  if K == 0:
    print(i)
    sys.exit()
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b.reverse()
p = 1
c = 0
d = 0
for i in range(n):
    if a[i] == b[i]:
        v = a[i]
        h = i
        p = 0
        break
if p == 1:
    print('Yes')
    for i in range(n):
        print(b[i],end = ' ')
else:
    for i in range(n):
        if a[i] != v and b[i] != v:
            c += 1
        if b[i] == a[i] :
            d += 1
    if c < d:
        print('No')
    else:
        print('Yes')
        o = 0
        for i in range(n):
            if a[i] != v and b[i] != v:
                b[i],b[i+h] = b[i+h],b[i]
                0 += 1
                if o == d:
                    break
        for i in range(n):
            print(b[i],end = ' ')

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b.reverse()
p = 1
c = 0
d = 0
for i in range(n):
    if a[i] == b[i]:
        v = a[i]
        h = i
        p = 0
        break
if p == 1:
    print('Yes')
    for i in range(n):
        print(b[i],end = ' ')
else:
    for i in range(n):
        if a[i] != v and b[i] != v:
            c += 1
        if b[i] == a[i] :
            d += 1
    if c < d:
        print('No')
    else:
        print('Yes')
        o = 0
        for i in range(n):
            if a[i] != v and b[i] != v:
                b[i],b[h+o] = b[o+h],b[i]
                o += 1
                if o == d:
                    break
        for i in range(n):
            print(b[i],end = ' ')
N=int(input())
l=list(map(int,input().split()))
if N==1:
    print("Yes")
elif N==2:
    if l[1]-l[0]<-2:
        print("No")
    else:
        print("Yes")
else:
    for i in range(N-1):
        if l[i+1]-l[i]<-2 or l[i]>l[i+1]>l[i+2]:
            print("No")
            break
        else:
            continue
    else:
        print("Yes")
    

### FIXED CODE ###

N=int(input())
l=list(map(int,input().split()))
l[0]-=1

if N==1:
    print("Yes")
else:
    for i in range(N-1):
        if l[i]<l[i+1]:
            l[i+1]-=1
            continue
        elif l[i]>l[i+1]:
            print("No")
            break
        else:
            pass
    else:
        print("Yes")
N = int(input())
max1 = 1
cnt = 0
for i in range(N):
  b = int(input())
  if max1 <= b:
   	cnt += 1
    max1 = b
print(cnt)

### FIXED CODE ###

N = int(input())
max_num = 1
cnt = 0
list_num = [int(x) for x in input().split()]
for i in range(len(list_num)):
	if max_num <= list_num[i]:
		cnt += 1
		max_num = list_num[i]
print(cnt)
import numpy as np
n, m = map(int, raw_input().split())
a = np.array(map(int, raw_input().split()))
for i in xrange(n-1):
	a = np.c_[a, (map(int, raw_input().split()))]

### FIXED CODE ###

n, m = map(int, raw_input().split())
 
a = [[0]*m for i in xrange(n)]
 
b = [0]*m
 
for i in xrange(n):
    tmp = map(int, raw_input().split())
    for j in xrange(m):
        a[i][j] = tmp[j]
for i in xrange(m):
    b[i] = input()
for i in xrange(n):
    tmp = 0
    for j in xrange(m):
        tmp += a[i][j] * b[j]
    print tmp
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(N - 2):
  if min(p[i], p[i + 2]) < p[i + 1] < max(p[i], p[i + 2]):
    count += 1
print(count)

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(n - 2):
  if min(p[i], p[i + 2]) < p[i + 1] < max(p[i], p[i + 2]):
    count += 1
print(count)
import numpy as np
N = int(input())
a = list(map(int, input().split()))

d = np.arange(0, 3600, 400)
c = []

for i in range(N):
	for j in range(len(d)-1):
		if d[j] <= a[i] < d[j + 1]:
			c.append(j)
	if a[i] >= 3200:
		c.append(8)

import collections
c_dict=collections.Counter(c)

s_val, s_count=zip(*c_dict.most_common())
nana_ika = [x for x in s_val if x < 8]

if not 8 in s_val:
	print(len(nana_ika), len(nana_ika))

else:
	if len(nana_ika) == 0:
		print(1, c_dict[8])
	elif 8 - len(nana_ika) > c_dict[8]:
		print(len(nana_ika), len(nana_ika) + c_dict[8])
	elif 8 -len(nana_ika) <= c_dict[8]:
		print(len(nana_ika), 8)



### FIXED CODE ###

r, g, b = map(str, input().split( ))
ans = 'NO'

if int(r + g + b) % 4 ==0:
	ans = 'YES'
print(ans)
n=int(input())
a=list(map(int,input().split()))
b=0
c=0
for i in range(n):
  if a[i]%2==0:
    if a[i]%4==0:
      c+=1
    else:
      b+=1
if b==0:
  print("Yes") if n<=3*c else print("No")
else:
  print("Yes") if n<=3c+b-1 else print("No")

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=0
c=0
for i in range(n):
  if a[i]%2==0:
    if a[i]%4==0:
      c+=1
    else:
      b+=1
if c==0:
  print("Yes") if n==b else print("No")
elif b==0:
  print("Yes") if n<=2*c+1 else print("No")
else:
  print("Yes") if n<=2*c+b else print("No")
def gcd(a, b):
    if a % b == 0:
        return b
    return gcd(b, a % b)

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

n = int(input())
ans = 1
for i in range(n):
    t = int(input())
    ans = lcm(ans, t)

print(int(ans))

### FIXED CODE ###

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

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

n = int(input())
ans = 1
for i in range(n):
    t = int(input())
    ans = lcm(ans, t)

print(int(ans))
import sys
input = sys.stdin.buffer.readline

def main():
	
	# SegmentTree Class
	class SegmentTree:
		
		# 初期化
		def __init__(self, size, default):
			self.size = 2**(size-1).bit_length()
			self.default = default
			self.seg = [default]*(2*self.size)

		# function(max, min, plus, minus, etc...)
		def segfunc(self,x,y):
			return max(x,y)

		# update
		def update(self,k,x):
			k += self.size
			self.seg[k] = x
			while k:
				k = (k-1)//2
				self.seg[k] = self.segfunc(self.seg[2*k+1],self.seg[2*k+2])

		# query([p,q)のsegfunc)
		def query(self,p,q):
			if q <= p:
				return self.default
			p += self.size-1;q += self.size-2
			ret = self.default
			while q-p > 1:
				if p&1 == 0:
					ret = self.segfunc(ret,self.seg[p])
				if q&1 == 1:
					ret = self.segfunc(ret,self.seg[q])
					q -= 1
				p = p//2
				q = (q-1)//2
			ret = self.segfunc(self.segfunc(ret,self.seg[p]),self.seg[q])
			return ret

		# seg確認用
		def seg_print(self):
			print(self.seg)
		
	N = int(input())
	a = list(map(int,input().split()))
	ans=[i+1 for i in range(N)]
	left_seg = SegmentTree(N, 0)
	for i, num in enumerate(a):
	    ans[num-1] *= i + 1 - left_seg.query(0,num)
	    left_seg.update(num-1, i+1)
	right_seg = SegmentTree(N, 0)
	for i, num in enumerate(a[::-1]):
	    ans[num-1] *= i + 1 - right_seg.query(0,num)
	    right_seg.update(num-1, i+1)
	
	print(sum(ans))

if __name__ == "__main__":
	main()


### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

def main():
	
	class BinaryIndexedTree:
		
		# 初期化
		def __init__(self, size, default):
			self.size = size
			self.default = default
			self.BIT = [default]*(self.size+1)

		# function(max, min, plus, minus, etc...)
		def BIT_segfunc(self, x, y):
			return max(x, y)

		def BIT_query(self, idx):
			ret = self.default
			while idx > 0:
				ret = self.BIT_segfunc(ret, self.BIT[idx])
				idx -= idx&(-idx)
			return ret

		# update
		def BIT_update(self, idx, x):
			while idx <= self.size:
				self.BIT[idx] = self.BIT_segfunc(self.BIT[idx], x)
				idx += idx&(-idx)
			return

		def BIT_range(self, x, y):
			return self.BIT_query(y)-self.BIT_query(x)

		# seg確認用
		def BIT_print(self):
			print(self.BIT)
		
	N = int(input())
	a = list(map(int,input().split()))
	l = [0]*N;r = [0]*N
	left_bit = BinaryIndexedTree(N, 0)
	for i, num in enumerate(a):
	    l[num-1] = i + 1 - left_bit.BIT_query(num)
	    left_bit.BIT_update(num, i+1)
	right_bit = BinaryIndexedTree(N, 0)
	for i, num in enumerate(a[::-1]):
	    r[num-1] = i + 1 - right_bit.BIT_query(num)
	    right_bit.BIT_update(num, i+1)
	
	print(sum(l[i]*r[i]*(i+1) for i in range(N)))

if __name__ == "__main__":
	main()
N,K=map(int,input().split())
while (N-K)>=0:
    N=N-K

if N>=abs(N-K):
    print(int(abs(N-K)))
else:
    print(int(N))

### FIXED CODE ###

N,K=map(int,input().split())
t=N%K
print(min(t,K-t))
n = int(input())

if n % 2 >  :
  print(n // 2 + 1)
else:
  print(n // 2)

### FIXED CODE ###

n = int(input())

if n % 2 > 0 :
  print(n // 2 + 1)
else:
  print(n // 2)
import math

r = int(intput())

print(math.pi * 2 * r)

### FIXED CODE ###

import math

r = int(input())

print(r * 2 * math.pi)
# -*- coding: utf-8 -*-
import sys
from collections import deque,defaultdict

H,W,K=map(int, sys.stdin.readline().split())
ichigo=[]
tate_ichigo=set()
cnt=0
h_visit=[0 for h in range(H)]  #縦軸にイチゴがない箇所は0、ある箇所は1
L=[ [] for h in range(H) ]
for h in range(H):
    s=sys.stdin.readline().strip()
    for w,x in enumerate(s):
        if x==".":
            L[h].append(0)
        elif x=="#":
            cnt+=1
            L[h].append(cnt)
            ichigo.append((h,w))
            h_visit[h]=1
            tate_ichigo.add(h)

D=(1,-1)
for h,w in ichigo:
    num=L[h][w]
    Visit=defaultdict(lambda: 0) #訪問した頂点
    q=deque()
    q.append((h,w))
    Visit[(h,w)]=1

    while q:
        h,w=q.popleft()
        for dw in D:
            if 0<=w+dw<W:   #マスの横にはみださないように
                if L[h][w+dw]==0 and Visit[(h,w+dw)]==0:
                    Visit[(h,w+dw)]=1	#訪問済みVisitに1をセットする。4行上のpopleftの直後でVisitをセットすると同じ頂点がqに入り、TLEする
                    L[h][w+dw]=num
                    q.append((h,w+dw))

#1行全部0の行を、値ありの行で埋めるためのdfs
def dfs(h):
    if h<=0 or H-1<=h: return
    for dh in D:
        if h_visit[h+dh]==0:
            L[h+dh]=L[h]
            dfs(h+dh)

for h in tate_ichigo:
    dfs(h)

for l in L:
    for x in l:
        print x,
    print


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
from collections import deque,defaultdict
sys.setrecursionlimit(10**5)

H,W,K=map(int, sys.stdin.readline().split())
ichigo=[]
cnt=0
h_visit=[0 for h in range(H)]  #縦軸にイチゴがない箇所は0、ある箇所は1

L=[ [] for h in range(H) ]
for h in range(H):
    s=sys.stdin.readline().strip()
    for w,x in enumerate(s):
        if x==".":
            L[h].append(0)
        elif x=="#":
            cnt+=1
            L[h].append(cnt)
            ichigo.append((h,w))
            h_visit[h]=1


D=(1,-1)

def yoko_dfs(h,w):  #縦座標、横座標
    for dw in D:
        if 0<=w+dw<=W-1 and L[h][w+dw]==0:
            L[h][w+dw]=L[h][w]
            yoko_dfs(h,w+dw)
    return

for h,w in ichigo:
    yoko_dfs(h,w)


def tate_dfs(h):  #縦座標
    for dh in D:
        if 0<=h+dh<=H-1:
            if h_visit[h+dh]==1: continue
            h_visit[h+dh]=1 #訪問済みにする
            L[h+dh]=L[h]
            tate_dfs(h+dh)

for h,w in ichigo:
    tate_dfs(h)

for l in L:
    for x in l:
        print x,
    print
H,W=map(int,input().split())
G=[input()+"." for _ in range(4)]+["."*(W+1)]
p=[0,0]
while(p!=[H-1,W-1]):
    if G[p[0]+1][p[1]]==G[p[0]][p[1]+1]:
        print("Impossible")
        break
    elif G[p[0]+1][p[1]]=="#":
        p=[p[0]+1,p[1]]
    else:
        p=[p[0],p[1]+1]
else:
    print("Possible")

### FIXED CODE ###

H,W=map(int,input().split())
G=[input()+"." for _ in range(H)]+["."*(W+1)]
G_cnt=sum([g.count("#") for g in G])
p=[0,0]
i=1
while(p!=[H-1,W-1]):
    if G[p[0]+1][p[1]]==G[p[0]][p[1]+1]:
        print("Impossible")
        break
    elif G[p[0]+1][p[1]]=="#":
        p=[p[0]+1,p[1]]
        i+=1
    else:
        p=[p[0],p[1]+1]
        i+=1
else:
    if i==G_cnt:
        print("Possible")
    else:
        print("Impossible")
import numpy as np

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


ret = 0
i = 0
while i < len(a):
    j = i
    while j < n -1 and a[j] <= a[j+1]:
        j += 1
    h = i
    while h < n - i and a[h] >= a[h +1 ]:
        h += 1
        i = max(h,j) + 1
        ret += 1

print(ret)


### FIXED CODE ###


import numpy as np

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


ret = 0
i = 0
while i < len(a):
    j = i
    while j < n -1 and a[j] <= a[j+1]:
        j += 1
    h = i
    while h < n - 1 and a[h] >= a[h +1]:
        h += 1
    i = max(h,j) + 1
    ret += 1

print(ret)