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

n,k = map(int,input().split())
a = list(map(int,input().split()))
memo = {}

for i in range(k,n):
    before = 1
    after = 1

    if not(i-1 in memo):
        tmp = 0
        for j in range(k):
            tmp = before
            before *= a[i-j-1]
        memo[i-1] = [before,tmp]
    else:
        before = memo[i-1][0]

    after = memo[i-1][1] * a[i]

    # if not(i in memo):
    #     for j in range(k):
    #         after *= a[i-j]
    #     memo[i] = after
    # else:    
    #     print("memoあり！")
    #     after = memo[i]

    if after > before:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

n,k = map(int,input().split())
a = list(map(int,input().split()))
memo = {}

for i in range(k,n):
    if a[i] > a[i-k]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

from sys import stdin
import sys

(N, Y) = stdin.readline().rstrip().split()

N = int(N)
Y = int(Y)

## 1 <= N <= 2000
## 1000 <= Y <= 2 * 10**7

## x y z
## x 10000
## y 5000
## z 1000

## N == x + y + z
## Y == 10000 * x + 5000 * y + 1000 * z


#for x in range(0, N+1):
for x in range(0, N+1):
    if 10000 * x > Y:
        break
    if 10000 * x + 5000 * N-x < Y:
        continue
    for y in range(0, N+1 - x ):
        if 10000 * x + 5000 * y > Y:
            break
        for z in range(0, N+1 - x - y):
            if 10000 * x + 5000 * y > Y:
                break

            #print("total:%d 10000:%d 5000:%d 1000:%d" % (10000 * x + 5000 * y + 1000 * z, x, y, z))

            if (Y == 10000 * x + 5000 * y + 1000 * z) and (N == x + y + z):
                print("%d %d %d" % (x, y, z))
                sys.exit()
                #example = "%d %d %d" % (x, y, z)
                #break

print('-1 -1 -1')


### FIXED CODE ###

from sys import stdin
import sys

(N, Y) = stdin.readline().rstrip().split()

N = int(N)
Y = int(Y)

## 1 <= N <= 2000
## 1000 <= Y <= 2 * 10**7

## x y z
## x 10000
## y 5000
## z 1000

## N == x + y + z
## Y == 10000 * x + 5000 * y + 1000 * z


#for x in range(0, N+1):
for x in range(0, N+1):
    if 10000 * x > Y:
        break
    if 10000 * x + 5000 * N-x < Y:
        continue
    for y in range(0, N+1 - x ):
        if 10000 * x + 5000 * y > Y:
            break
        #print("total:%d 10000:%d 5000:%d 1000:%d" % (10000 * x + 5000 * y + 1000 * z, x, y, z))
        z = N - x - y
        if (Y == 10000 * x + 5000 * y + 1000 * z) and (N == x + y + z):
                print("%d %d %d" % (x, y, z))
                sys.exit()
                #example = "%d %d %d" % (x, y, z)
                #break

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

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

ans =[]

for i in range((n//(a+b)) + 1):
  for j in range(a):
    ans.append("b")
    continue
  
  for k in range(b):
    ans.append("r")
    continue
    

num =0   
for l in range(n):
  if ans[l] == "b":
    num += 1
  
  
  
print(num)

### FIXED CODE ###

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

ans = n //(a+b)

if n%(a+b) >= a:
  ans2 = a
elif n%(a+b) <a:
  ans2 = n%(a+b)
  
  
print(ans*a+ans2)
### BUGGY CODE ###

numberOfToorists = int(input())

residents = [0,0,0,0,0,0]

transportCapacity = [0,0,0,0,0]
migrants = [0,0,0,0,0]

elapsedTime = 0

for i in range(5):
	transportCapacity[i] = int(input())

residents[0] = numberOfToorists

while residents[5] < numberOfToorists:
	for i in range(5):
		if residents[i] >= transportCapacity[i]:
			migrants[i] = transportCapacity[i]
		else:
			migrants[i] = residents[i]

	for i in range(5):
		residents[i] -= migrants[i]
		residents[i+1] += migrants[i]

	elapsedTime += 1

print(elapsedTime)

### FIXED CODE ###

numberOfToorists = int(input())

minimumCapacity = 10.0**16

for i in range(5):
	vehicleCapacity = int(input())
	minimumCapacity = min(minimumCapacity, vehicleCapacity)

bottleNeckTime = int(numberOfToorists / minimumCapacity)

if numberOfToorists % minimumCapacity > 0:
	bottleNeckTime += 1

requiredTime = bottleNeckTime + 4

print(requiredTime)
### BUGGY CODE ###

n, b, r = map(int, input().split())

num = 0
count = 0
res_b = 0
res_r = 0

while num <= n:
  if count % 2 == 0:
    num += b
    if num > n:
      res_b += b - (num - n)
    else:
      res_b += b
      
  else:
    num += r
#    if num > n:
#      res_r += r - (num - n)
#    else:
#      res_r += r

  count += 1

print(res_b)

### FIXED CODE ###

n, b, r = map(int, input().split())

cnt_blk = n // (b+r)
res_b = cnt_blk*b
num = cnt_blk*(b+r) + b

if num > n:
  res_b += b - (num - n)
else:
  res_b += b
      
print(res_b)
### BUGGY CODE ###

N = int(input())
S = str(input())
ans = 0
for i in range(N):
  for j in range(N):
    for k in range(N):
      if S[i] != S[j] and S[i] != S[k] and S[k] != S[j] and j-i != k-j and i < j and j < k:
        ans += 1
print(ans)     

### FIXED CODE ###

N = int(input())
S = str(input())
r = 0
g = 0
b = 0
#S[i],S[j],S[k]が違うものはr*g*b通り
for i in range(N):
  if S[i] == 'R':
    r += 1
  elif S[i] == 'G':
    g += 1
  else:
    b += 1
tot = r*g*b
#S[i],S[j],S[k]が違うかつj-i=k-jを満たすものは引く
minus = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    if 2*j-i < N:
      
      if S[i] != S[j] and S[j] != S[2*j-i] and S[i] != S[2*j-i]:
        minus += 1
print(tot - minus)
### BUGGY CODE ###

n = int(input())
s = input()
whole = (n*(n-1)*(n-2))//6
num = n-2
cnt = 0
for i in range(n-3):
    for j in range(i+1,n-1):
        if j == i+1:
            if s[i] == s[j]:
                cnt += (n-(j+2))
                continue
            for k in range(j+2,n):
                if (j-i) == (k-j):
                    cnt += 1
                    continue
                if s[i] == s[j] or s[j] == s[k] or s[i] == s[k]:
                    cnt+= 1
        else:
            if s[i] == s[j]:
                cnt += (n-(j+1))
                continue
            for k in range(j+1,n):
                if (j-i) == (k-j):
                    cnt += 1
                    continue
                if s[i] == s[j] or s[j] == s[k] or s[i] == s[k]:
                    cnt+= 1
print(whole-num-cnt)

### FIXED CODE ###

n = int(input())
S = input()
k = 0
num = 0
r, g, b = 0, 0, 0
for s in S:
    if s == "R": r += 1
    elif s == "G": g += 1
    else: b += 1
whole = r * g * b
for i in range(n-2):
    for j in range(i+1,n-1):
        k = 2 * j - i
        if k >= n:
            continue
        if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
            num += 1
print(whole - num)
### BUGGY CODE ###

import itertools as itr
n = int(input())
a = list(map(int, input().split()))
itra = list(itr.accumulate(a))
ans_c = itra.count(0)
seta = set(itra)
for i in seta:
    tmp_c = itra.count(i)
    ans_c += tmp_c * (tmp_c - 1) // 2
print(ans_c)

### FIXED CODE ###

import itertools as itr
n = int(input())
a = list(map(int, input().split()))
itra = list(itr.accumulate(a))
ans_c = itra.count(0)
dev = {}
for i in itra:
    if i in dev:
        dev[i] += 1
    else:
        dev[i] = 1
for i in dev:
    ans_c += dev[i] * (dev[i] - 1) // 2
print(ans_c)
### BUGGY CODE ###


N, T = map(int,input().split())
a = list(map(int, input().split()))
b = []

d = set()
for i in range(N):
    d = d | set(range(a[i], a[i] + T))


print(len(d))

### FIXED CODE ###

##N T
#t1 t2 ... tN
N, T = map(int,input().split())
a = list(map(int, input().split()))
b = []
zo  = [0, T]
leng = T
"""
d = set()
for i in range(N):
    d = d | set(range(a[i], a[i] + T))
"""
for i in range(N):
    if  a[i] + T <= zo[1]:
        pass
    elif a[i] <= zo[1] and zo[1] <= a[i] + T:
        leng += a[i] + T - zo[1]
        zo[1] = a[i] + T
    elif zo[1] <= a[i]:
        zo[0] = a[i]
        zo[1] = a[i] + T
        leng += T






print(leng)
### BUGGY CODE ###

import sys,math,copy
# import numpy as np
input = sys.stdin.readline
S = [int(x) if x != '?' else -1 for x in reversed(input().strip())]
N = len(S)

# dp = np.zeros((13), dtype=int)
# dp_ = np.zeros((13), dtype=int)
dp = [0] * 13
dp_ = [0] * 13
mod13_list = [i % 13 for i in range(12 ** 2 + 1)]
divisor = 10 ** 9 + 7
dp_[0] = 1
mul = 1
for i, s in enumerate(S, start=1):
    if s == -1:
        for d in range(10):
            m = mod13_list[(d * mul)]
            for pm in range(13):
                dp[mod13_list[(pm+m)]] = dp[mod13_list[(pm+m)]] + dp_[pm]

    else:
        m = mod13_list[(s * mul)]
        for pm in range(13):
            dp[mod13_list[(pm+m)]] = dp_[pm]

    # dp_ = dp % divisor
    # dp = dp * 0 # np.zeros((13), dtype=int)
    for i in range(13):
        dp_[i] = dp[i] % divisor
        dp[i] = 0
    mul = mod13_list[(mul * 10)]
print(dp_[5] % divisor)

### FIXED CODE ###

import sys,math,copy

def main():
    # import numpy as np
    input = sys.stdin.readline
    S = ''.join(reversed(input().strip()))

    # dp = np.zeros((13), dtype=int)
    # dp_ = np.zeros((13), dtype=int)
    dp = [0] * 13
    dp_ = [0] * 13
    mod13_list = [i % 13 for i in range(12 ** 2 + 1)]
    list10 = list(range(10))
    list13 = list(range(13))
    divisor = 10 ** 9 + 7
    dp_[0] = 1
    mul = 1
    for i in range(len(S)):
        s = S[i]
        if s == '?':
            for d in list10:
                m = mod13_list[(d * mul)]
                for pm in list13:
                    dp[mod13_list[(pm+m)]] += dp_[pm]

        else:
            si = int(s)
            m = mod13_list[(si * mul)]
            for pm in list13:
                dp[mod13_list[(pm+m)]] = dp_[pm]

        # dp_ = dp % divisor
        # dp = dp * 0 # np.zeros((13), dtype=int)
        for j in list13:
            dp_[j] = dp[j] % divisor
            dp[j] = 0
        mul = mod13_list[(mul * 10)]
    print(dp_[5])

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

N,M=map(int,input().split())
list1=list(map(int,input().split()))
list2=[1]
for _ in range(M):
  B,C=map(int,input().split())
  if C>min(list2) and len(list2)>N:
    list2+=[C]*B
  else:
    list2+=[C]*B
list3=list1+list2
list3.sort(reverse=True)
list5=list3[:N]
SUM=sum(list5)
print(SUM)

### FIXED CODE ###

N,M = map(int, input().split())
listA = list(map(int, input().split()))
listA.sort()
 
listBC = [list(map(int, input().split())) for i in range(M)]
listBC = sorted(listBC, key=lambda x: x[1], reverse=True)
countB = 0
 
for i in range(M):
  B, C = listBC[i][0], listBC[i][1]
  listA += [C]*B
  countB += B
  if countB >= N:
    break

listA.sort(reverse=True)
print(sum(listA[:N]))
### BUGGY CODE ###

n = int(input())
N_str = input()
N_str = N_str.split(" ")
N = [int(s) for s in N_str]

N_before = N.copy()
del N[0]
t = []
for k in range(n):
    cnt = 0
    
    for i, j in zip(N_before[k:-1], N[k:]):
        
        if i >= j:
            cnt = cnt + 1
        else:
            break
    t.append(cnt)
print(max(t))

### FIXED CODE ###

n = int(input())
N_str = input()
N_str = N_str.split(" ")
N = [int(s) for s in N_str]

t = []
cnt = 0  
for i in range(n-1):
    t.append(N[i] - N[i+1])
    
l=[]
cnt = 0
for j in t:

    if j >= 0:
        cnt = cnt + 1
    else:
        l.append(cnt)
        cnt = 0
l.append(cnt)
print(max(l))
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
count=[]
for K in range(N):
  a=0
  for i in range(N):
    for j in range(N-1-i):
      if A[i] == A[j+1+i] and (i != K and (j+1+i) != K):
#        print("start")
#        print(i)
#        print(j+1+i)
#        print(K)
#        print(A[i] == A[j+1+i] and (i != K or (j+1+i) != K))
        a += 1
#        print(a)
  count.append(a)
for i in range(len(count)):
  print(count[i])

### FIXED CODE ###

import sys
from collections import Counter
N=int(sys.stdin.readline())
L=list(map(int,sys.stdin.readline().split()))
C=Counter(L)
x=0
for a in C.values():
  x += int(a*(a-1)/2)  
for K in range(N):
  print(x-C[L[K]]+1)
### BUGGY CODE ###

n, k, q = map(int, input().split())
participants = [k for i in range(n)]
a = []

for i in range(q):
    line = input()
    a.append(line)

for i in a:
    for j in range(n):
    	if (int(i)-1) != j:
    		participants[j] -= 1

for i in participants:
    if i <= 0:
        print("No")
    else:
        print("Yes")

### FIXED CODE ###

n, k, q = map(int, input().split())
points = [k-q for i in range(n)]

for i in range(q):
    num = int(input())
    points[num-1] += 1

for i in points:
    if i <= 0:
        print("No")
    else:
        print("Yes")
### BUGGY CODE ###

#
import sys
import math
import numpy as np
import itertools


# いくつか入力
n, p = (int(i) for i in input().split())  

f=[]
r=2
while p >= r:
    if p % r == 0:
        f.append(r)
        p = p // r
    else:
        r += 1

#print(f)
answer = 1
now = 1
k=0
for i in f:
    if now == i:
        k += 1
    else:
        answer = answer * (now ** (k // n) )
        now = i
#        print(i,k,answer)
        k=1
answer = answer * (now ** (k // n) )
print(answer)



### FIXED CODE ###

#
import sys
import math
import numpy as np
import itertools


# いくつか入力
n, p = (int(i) for i in input().split())  

f=[]
r=2
root = math.sqrt(p)
while root >= r:
    if p % r == 0:
        f.append(r)
        p = p // r
    else:
        r += 1
if p > 2:
    f.append(p)

#print(f)
answer = 1
now = 1
k=0
for i in f:
    if now == i:
        k += 1
    else:
        answer = answer * (now ** (k // n) )
        now = i
#        print(i,k,answer)
        k=1
answer = answer * (now ** (k // n) )
print(answer)
### BUGGY CODE ###

N, M  = map(int, input().split())
a  = []
for _ in range(M):
  a.append(int(input()))
sdic  = {}
nn1 = 1
nn2 = 0
for n in reversed(range(N)):
  if n in a:
    nn2 = nn1
    nn1 = 0
    continue
  t = nn1 + nn2
  if t == 0:
    print(0)
    quit()
  nn2 = nn1
  nn1 = t
  
print(nn1%1000000007)

### FIXED CODE ###

N, M  = map(int, input().split())
a  = {}
for _ in range(M):
  a[int(input())] = 1
sdic  = {}
nn1 = 1
nn2 = 0
for n in reversed(range(N)):
  if n in a:
    nn2 = nn1
    nn1 = 0
    continue
  t = nn1 + nn2
  if t == 0:
    print(0)
    quit()
  nn2 = nn1
  nn1 = t
  
print(nn1%1000000007)
### BUGGY CODE ###

s = input()
T = len(s)
st = s.split("T")
x, y = map(int, input().split())
XL = []; YL = []
for i in range(len(st)):
    if i % 2 == 0:
        XL.append(len(st[i]))
    else:
        YL.append(len(st[i]))

xx = [[False for j in range(2*T+1)] for i in range(len(XL)+1)]
yy = [[False for j in range(2*T+1)] for i in range(len(YL)+1)]
xx[0][T]=True
yy[0][T]=True
xx[1][T+XL[0]]=True
for i in range(2, len(XL)+1):
    for j in range(2*T+1):
        if j-XL[i-1] < 0:
            xx[i][j]=xx[i-1][j+XL[i-1]]
        elif j+XL[i-1] > 2*T:
            xx[i][j]=xx[i-1][j-XL[i-1]]
        else:
            xx[i][j]=xx[i-1][j-XL[i-1]] or xx[i-1][j+XL[i-1]]

for i in range(1,len(YL)+1):
    for j in range(2*T+1):
        if j-YL[i-1] < 0:
            yy[i][j]=yy[i-1][j+YL[i-1]]
        elif j+YL[i-1] > 2*T:
            yy[i][j]=yy[i-1][j-YL[i-1]]
        else:
            yy[i][j]=yy[i-1][j-YL[i-1]] or yy[i-1][j+YL[i-1]]

if xx[len(XL)][x+T] and yy[len(YL)][y+T]:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

st = input().split("T")
x, y = map(int, input().split())
XL = []; YL = []; t = 0
for i in range(len(st)):
    if i % 2 == 0:
        XL.append(len(st[i]))
    else:
        YL.append(len(st[i]))
    t += len(st[i])
if abs(x) + abs(y) > t:
    print("No")
else:
    T = max([abs(x), abs(y), t])
    xx = [[False for j in range(2*T+1)] for i in range(len(XL)+1)]
    yy = [[False for j in range(2*T+1)] for i in range(len(YL)+1)]
    xx[0][T]=True
    yy[0][T]=True
    xx[1][T+XL[0]]=True
    for i in range(2, len(XL)+1):
        for j in range(2*T+1):
            if j-XL[i-1] < 0:
                xx[i][j]=xx[i-1][j+XL[i-1]]
            elif j+XL[i-1] > 2*T:
                xx[i][j]=xx[i-1][j-XL[i-1]]
            else:
                xx[i][j]=xx[i-1][j-XL[i-1]] or xx[i-1][j+XL[i-1]]
    
    for i in range(1,len(YL)+1):
        for j in range(2*T+1):
            if j-YL[i-1] < 0:
                yy[i][j]=yy[i-1][j+YL[i-1]]
            elif j+YL[i-1] > 2*T:
                yy[i][j]=yy[i-1][j-YL[i-1]]
            else:
                yy[i][j]=yy[i-1][j-YL[i-1]] or yy[i-1][j+YL[i-1]]

    if xx[len(XL)][x+T] and yy[len(YL)][y+T]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

input()
A = map(int, input().split())
ans = 1
for a in A:
    ans *= a

if 1000000000000000000 < ans:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

input()
A = list(map(int, input().split()))
ans = 1

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

for a in A:
    ans *= a
    if 1000000000000000000 < ans:
        print(-1)
        exit()

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

# -*- coding: utf-8 -*-
import itertools


def change(val):
    # 黒なら1
    if val == '#':
        return 1

    # 白なら0
    return 0


# def calc_root(board):


def main():
    h, w = map(int, input().split())
    board = [[change(s) for s in input()] for i in range(h)]

    cnt = 200
    for move in itertools.product(range(0, 2), repeat=h + w - 2):

        if sum(move) != h - 1:
            continue

        x, y = (0, 0)
        temp_root = [(x, y, board[y][x])]
        change_cnt = 0
        if board[y][x] == 1:
            change_cnt += 1

        for hko in move:
            # 0なら横移動
            if hko == 0:
                x += 1
            else:
                y += 1

            # temp_root.append((x, y, board[y][x]))

            if board[y][x] == 1:
                change_cnt += 1

        cnt = min(cnt, change_cnt)

    print(cnt)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import itertools


def change(val):
    # 黒なら1
    if val == '#':
        return 1

    # 白なら0
    return 0


# def calc_root(board):


def main():
    h, w = map(int, input().split())
    board = [[s for s in input()] for i in range(h)]

    cnt = 200
    dp = [[200] * w for i in range(h)]

    for i_row, row in enumerate(dp):
        for i_col, col in enumerate(row):
            if i_row == 0 and i_col == 0:
                dp[i_row][i_col] = change(board[i_row][i_col])
                continue

            if i_row >= 1:
                if board[i_row][i_col] == '#' and board[i_row - 1][i_col] == '.':
                    dp[i_row][i_col] = min(dp[i_row - 1][i_col] + 1, dp[i_row][i_col])
                else:
                    dp[i_row][i_col] = min(dp[i_row - 1][i_col], dp[i_row][i_col])

            if i_col >= 1:
                if board[i_row][i_col] == '#' and board[i_row][i_col - 1] == '.':
                    dp[i_row][i_col] = min(dp[i_row][i_col - 1] + 1, dp[i_row][i_col])
                else:
                    dp[i_row][i_col] = min(dp[i_row][i_col - 1], dp[i_row][i_col])

    print(dp[-1][-1])


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

import sys
#色々とメモリ使用量には気をつける
from collections import deque

n, m=map(int, input().split())
u_list=[]
v_list=[]
for i in range(m):
    u, v=map(int, input().split())
    u_list.append(u)
    v_list.append(v)
s, t=map(int, input().split())
queue=deque()
kenken=[]
for i in range(1, n+1):
    queue.append((i, 0))
    while(len(queue))!=0:
        target=queue.popleft()
        target_pos=target[0]
        target_val=target[1]
        for j in range(m):
            if u_list[j]==target_pos:
                if target_val+1==3:
                    kenken.append((i, v_list[j]))
                else:
                    queue.append((v_list[j], target_val+1))

use_edge=[1 for i in range(len(kenken))]

queue.append((s, 0))
while(len(queue)!=0):
    target=queue.popleft()
    target_pos=target[0]
    target_val=target[1]
    for j in range(m):
        if use_edge[j]:

            if kenken[j][0]==target_pos:
                if kenken[j][1]==t:
                    print(target_val+1)
                    sys.exit()
                else:
                    queue.append((kenken[j][1], target_val+1))
                    use_edge[j]=0
print(-1)


### FIXED CODE ###

import sys
from collections import deque
n, m=map(int,input().split())
"""
頂点1~nを1~3nに3倍加する
"""
edges=[[] for i in range(3*n)]
for i in range(m):
    """
    uからvへの枝を
    uからv+n, u+nからv+2n, u+2nからv+3n
    とする
    (枝を3倍加)
    """
    u, v=map(int, input().split())
    u, v=u-1, v-1
    edges[u].append(v+n)
    edges[u+n].append(v+2*n)
    edges[u+2*n].append(v)
s, t=map(int, input().split())
s, t=s-1, t-1
q=deque()
q.append(s)
dist=[-1]*(3*n)
dist[s]=0
"""
結局求めるものは，s~tへの最短距離を3で割ったもの
"""
while len(q)!=0:
    fr=q.popleft()
    for to in edges[fr]:
        #もし行ったことがなければ
        if dist[to]==-1:
            dist[to]=dist[fr]+1
            q.append(to)
print(dist[t]//3)
### BUGGY CODE ###

from collections import defaultdict


def dfs(graph, start):
    visited, stack = set(), [start]
    while stack:
        vertex = stack.pop()
        if vertex not in visited:
            visited.add(vertex)
            stack.extend(graph[vertex] - visited)
    return visited


if __name__ == "__main__":
    n, m, k = map(int, input().split())
    AB = [map(int, input().split()) for _ in range(m)]
    CD = [map(int, input().split()) for _ in range(k)]

    graph_f = defaultdict(set)
    graph_b = defaultdict(set)

    for a, b in AB:
        graph_f[a - 1].add(b - 1)
        graph_f[b - 1].add(a - 1)

    for c, d in CD:
        graph_b[c - 1].add(d - 1)
        graph_b[d - 1].add(c - 1)

    searched = set()
    conns = []
    for i in range(n):
        if i not in searched:
            conn = dfs(graph_f, i)
            searched |= conn
            conns.append(conn)

    res = [0] * n
    for conn in conns:
        lenconn = len(conn)
        for i in conn:
            res[i] = len(conn - graph_b[i]) - len(graph_f[i]) - 1

    print(' '.join(map(str, res)))


### FIXED CODE ###

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.parents[self.find(x)]


if __name__ == "__main__":
    n, m, k = map(int, input().split())

    u = UnionFind(n)
    f_cnt = [0] * n
    b_cnt = [0] * n

    for _ in range(m):
        a, b = map(int, input().split())
        u.union(a - 1, b - 1)
        f_cnt[a - 1] += 1
        f_cnt[b - 1] += 1

    for _ in range(k):
        c, d = map(int, input().split())
        if u.same(c - 1, d - 1):
            b_cnt[c - 1] += 1
            b_cnt[d - 1] += 1

    print(*[(u.size(i) - f_cnt[i] - b_cnt[i] - 1) for i in range(n)])
### BUGGY CODE ###

n, k = map(int, input().split())
min = n
fin = 0

while n >= 0:
    n = n - k
    if n >= 0:
        min = n
    else:
        fin = abs(n)

if min < fin:
    print(min)
else:
    print(fin)


### FIXED CODE ###

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

x = n % k
y = abs(x - k)

if x  < y:
    print(x)
else:
    print(y)