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

def D_RestoringRoadNetwork(N, A):
    dist = [x[:] for x in A] # 全ての町同士の距離
    dist2 = [x[:] for x in A] # 不要な経路を削ぎ落とした町同士の距離
    isMinDist = True  # 与えられた行列が真に最短距離を表しているか

    # ワーシャルフロイド法
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if A[i][j] > dist[i][k] + dist[k][j]:
                    # 迂回路の方が短いとなれば元の行列は最短距離を表していない
                    isMinDist = False
                elif A[i][j] == dist[i][k] + dist[k][j] and dist[i][k] > 0 and dist[k][j] > 0:
                    # 最短経路でも迂回路でも同じ距離ならば、表にあった最短距離の経路は不要
                    dist2[i][j] = 0
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    if isMinDist:
        ans = 0
        for i in range(N):
            for j in range(i, N):
                # 行列の上三角しか見ないのは、対称行列(ij成分=ji成分)になるから
                ans += dist2[i][j]
        return ans
    else:
        return -1

N=int(input())
A=[[int(i) for i in input().split()] for j in range(N)]
print(D_RestoringRoadNetwork(N, A))

### FIXED CODE ###

def D_RestoringRoadNetwork(N, A):
    dist = [x[:] for x in A] # 全ての町同士の距離
    dist2 = [x[:] for x in A] # 不要な経路を削ぎ落とした町同士の距離
    isMinDist = True  # 与えられた行列が真に最短距離を表しているか

    # ワーシャルフロイド法
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if A[i][j] > dist[i][k] + dist[k][j]:
                    # 迂回路の方が短いとなれば元の行列は最短距離を表していない
                    isMinDist = False
                elif A[i][j] == dist[i][k] + dist[k][j] and dist[i][k] > 0 and dist[k][j] > 0:
                    # 最短経路でも迂回路でも同じ距離ならば、表にあった最短距離の経路は不要
                    dist2[i][j] = 0
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    if isMinDist:
        ans = 0
        for i in range(N):
            for j in range(i, N):
                # 行列の上三角しか見ないのは、対称行列(ij成分=ji成分)になるから
                ans += dist2[i][j]
        return ans
    else:
        return -1

N=int(input())
A=[[int(i) for i in input().split()] for j in range(N)]
print(D_RestoringRoadNetwork(N, A))
### BUGGY CODE ###

def solve(string):
    q_pos = [i for i, s in enumerate(string[::-1]) if s == "?"]
    table = [[0] * 13 for _ in range(len(q_pos) + 1)]
    table[0][int(string.replace("?", "0")) % 13] = 1
    for i in range(len(q_pos)):
        base = pow(10, q_pos[i], 13)
        for j in range(13):
            for k in range(10):
                table[i + 1][(j + k * base) % 13] += table[i][j]
    return str(table[-1][5] % (10**9 + 7))


if __name__ == '__main__':
    print(solve(input()))


### FIXED CODE ###

def solve(string):
    n = len(string)
    q_pos = [i for i in range(n) if string[n - i - 1] == "?"]
    table = [[0] * 13 for _ in range(2)]
    table[0][int(string.replace("?", "0")) % 13] = 1
    for i in range(len(q_pos)):
        base = pow(10, q_pos[i], 13)
        for j in range(13):
            for k in range(10):
                table[1][(j + k * base) % 13] += table[0][j]
        for j in range(13):
            table[1][j] %= (10**9 + 7)
        table[0] = table[1]
        table[1] = [0] * 13
    return str(table[0][5])


if __name__ == '__main__':
    print(solve(input()))
### BUGGY CODE ###

def merge(a, left, mid, right):
#    global x
    x = 0
    n1 = mid - left
    n2 = right - mid
    l = []
    r = [] 
    for i in range(n1):
        l.append(a[left + i])
    for i in range(n2):
        r.append(a[mid + i])
    l.append(float("inf"))
    r.append(float("inf"))
    i = 0
    j = 0
    for k in range(left,right):
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else :
            a[k] = r[j]
            j += 1
        x += 1
    return x

def mergeSort(a, left, right):
    global x
    if left+1 < right:
        mid = int((left + right)/2)
        mergeSort(a, left, mid)
        mergeSort(a, mid, right)
        x += merge(a, left, mid, right)

n = int(input())
s = list(map(int,input().split()))
global x
x = 0
mergeSort(s,0,n)
print(*s)
print(x)



### FIXED CODE ###


def merge(a, left, mid, right):
    x = 0
    l = a[left:mid] + [float("inf")]
    r = a[mid:right] + [float("inf")]
    i = 0
    j = 0
    for k in range(left,right):
        if l[i] <= r[j]:
            a[k] = l[i]
            i += 1
        else :
            a[k] = r[j]
            j += 1
        x += 1
    return x

def mergeSort(a, left, right,x):
    if left+1 < right:
        mid = int((left + right)/2)
        mergeSort(a, left, mid,x)
        mergeSort(a, mid, right,x)
        x[0] += merge(a, left, mid, right)

n = int(input())
s = list(map(int,input().split()))
x = [0]
mergeSort(s,0,n,x)
print(*s)
print(x[0])
### BUGGY CODE ###

import sys
import math as mt
input=sys.stdin.buffer.readline  

MAXN = 10000001
# stores smallest prime factor for 
# every number 
spf = [0 for i in range(MAXN)] 
  
# Calculating SPF (Smallest Prime Factor)  
# for every number till MAXN. 
# Time Complexity : O(nloglogn) 
def sieve(): 
    spf[1] = 1
    for i in range(2, MAXN): 
          
        # marking smallest prime factor  
        # for every number to be itself. 
        spf[i] = i 
  
    # separately marking spf for  
    # every even number as 2 
    for i in range(4, MAXN, 2): 
        spf[i] = 2
  
    for i in range(3, mt.ceil(mt.sqrt(MAXN))): 
          
        # checking if i is prime 
        if (spf[i] == i): 
              
            # marking SPF for all numbers 
            # divisible by i 
            for j in range(i * i, MAXN, i):  
                  
                # marking spf[j] if it is  
                # not previously marked 
                if (spf[j] == j): 
                    spf[j] = i 
 
  
def getFactorization(x): 
    d={}
    while (x != 1): 
        d[spf[x]]=d.get(spf[x],0)+1
        x = x//spf[x] 
    mul=1
    #print(d)
    for i1 in d:
        mul*=(d[i1]+1)
    #print(11,x,mul)
    return mul    
sieve()
t=1
#t=int(input())
for _ in range(t):
    n=int(input())
    #n,m,k=map(int,input().split())
    #l1=list(map(int,input().split()))
    #l2=list(map(int,input().split()))
    ans=1
    for i in range(2,n+1):
        ans+=(i*getFactorization(i))
    print(ans)    
        
        

### FIXED CODE ###

#in the name of allah
import sys
import math as mt
import bisect
input=sys.stdin.buffer.readline  
t=1
#t=int(input())
for _ in range(t):
    #n,m,k=map(int,input().split())
    #a=list(map(int,input().split()))
    #b=list(map(int,input().split()))
    n=int(input())
    ans=0
    for i in range(1,n+1):
        for j in range(i,n+1,i):
            ans+=j
    print(ans)
### BUGGY CODE ###

n = int(input())
b = 0
for c in range(1,n):
    m = n - c
    for i in range(1,m+1):
        if m % i == 0:
            b += 1

print(b)


### FIXED CODE ###

n = int(input())
count = 0
for a in range(1,n):
    b = (n-1) // a
    count += b

print(count)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

def input_converter(key_string):
    key_string = key_string.replace('A', '1')
    key_string = key_string.replace('T', '2')
    key_string = key_string.replace('C', '3')
    key_string = key_string.replace('G', '4')
    return int(key_string)


class HashTable(object):
    def __init__(self, hash_size = 2 ** 22):
        self.hash_size = hash_size
        self.hash_array = [None] * self.hash_size

    def insert_value(self, data, key):
        collision_number = 0
        next_index = self.hash_function(key, collision_number)
        while self.hash_array[next_index] is not None:
            collision_number += 1
            next_index = self.hash_function(key, collision_number)
        # print self.hash_array[next_index]
        self.hash_array[next_index] = data

    def search_value(self, data, key):
        collision_number = 0
        next_index = self.hash_function(key, collision_number)
        while True:
            if (self.hash_array[next_index] is None) or (collision_number > self.hash_size):
                return False
            elif self.hash_array[next_index] == data:
                return True
            else:            
                collision_number +=1
                next_index = self.hash_function(key, collision_number)

    def hash_function(self, key, collision_number):
        def h1(key):
            return key % self.hash_size
    
        def h2(key):
            return key % (self.hash_size - 1)

        return (h1(key) + collision_number * h2(key)) % self.hash_size


def main():
    input_size = int(raw_input())
    hash_table = HashTable(2 ** 20)
    counter = 0
    while counter < input_size:
        command, key = raw_input().split(' ')
        if command == 'insert':
            hash_table.insert_value(key, input_converter(key))
        else:
            if hash_table.search_value(key, input_converter(key)):
                print 'yes'
            else:
                print 'no'
        counter += 1


if __name__ == '__main__':
    main()

### FIXED CODE ###

# -*- coding: utf-8 -*-

dictionary = {}
input_num = int(raw_input())
counter = 0
while counter < input_num:
    command, key = raw_input().split(' ')
    if command == 'insert':
        dictionary[key] = None
    else:
        if key in dictionary:
            print 'yes'
        else:
            print 'no'

    counter += 1
### BUGGY CODE ###

N, K, Q = map(int, input().split())
A, P = [], []
for q in range(Q):
  A.append(int(input()))
for _ in range(N):
  P.append(K)
for a in A:
  for i, p in enumerate(P):
    if i != (a - 1):
      P[i] -= 1
for p in P:
  if p <= 0:
    print("No")
  else:
    print("Yes")

### FIXED CODE ###

N, K, Q = map(int, input().split())
A = []
for q in range(Q):
    A.append(int(input()))
score = [K - Q] * (N + 1)
for a in A:
    score[a] += 1
ans = "\n".join("No" if s <= 0 else "Yes" for s in score[1:])
print(ans)
### BUGGY CODE ###

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

N = int(input())
S = list(input().strip())

dp = [0] * N
max_leng = 0

for i in range(1, N):
    leng = 0
    idx_i = i
    sta_j = -1

    j = i - 1
    while j > -1:
        if sta_j == idx_i:
            leng = 0
            idx_i = i
            j = sta_j-1
            sta_j = -1
            continue

        if S[idx_i] == S[j]:
            if leng == 0:
                sta_j = j
            leng += 1
            idx_i -= 1
            max_leng = max(leng, max_leng)
        else:
            leng = 0
            idx_i = i
        j -= 1
print(max_leng)

### FIXED CODE ###

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

N = int(input())
S = list(input().strip())

dp = [[0] * N for i in range(N)]
max_leng2 = 0 
for i in range(0, N):
    leng2 = 0

    j = i - 1
    while j > -1:
        if S[i] == S[j]:
            sta_j = j
            if j != 0:
                leng2 = dp[i-1][sta_j-1] + 1
            else: 
                leng2 = 1
            
            if i - sta_j < leng2:
                leng2 = i - sta_j
                
            dp[i][sta_j] = leng2
            max_leng2 = max(max_leng2, leng2)
        j -= 1
print(max_leng2)
### BUGGY CODE ###

n=int(input())
h_list=list(map(int,input().split()))
cnt=0
mx=0
for i in range(len(h_list)):
    if mx>=(len(h_list)-i):
        break
    num=i
    cnt=0
    for num in range(num,len(h_list)-1):
        if h_list[num]>=h_list[num+1]:
            cnt+=1
        else:
            i=num+1
            break
    if cnt>mx:
        mx=cnt
print(mx)

### FIXED CODE ###

n=int(input())
h_list=list(map(int,input().split()))
cnt=0
mx=0
i=0
while i<len(h_list):
    if mx>=(len(h_list)-i):
        break
    num=i
    cnt=0
    for j in range(num,len(h_list)-1):
        if h_list[j]>=h_list[j+1]:
            cnt+=1
        else:
            i=j
            break
    i+=1
    if cnt>mx:
        mx=cnt
print(mx)
### BUGGY CODE ###

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b,c=INTM()
    abl=b-a+1
    ablist=[i for i in range(a,b+1)]
    #print(ablist)
    ansa=ablist[0:min(c,abl)]
    ansb=ablist[max(0,abl-c):abl]
    #print(ansa,ansb)
    ans=set(ansa) | set(ansb)
    anslist=[]
    for i in ans:
        anslist.append(i)
    anslist.sort()
    for i in anslist:
        print(i)
if __name__ == '__main__':
    do()

### FIXED CODE ###

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b,c=INTM()
    ans=[]
    for i in range(c):
        ai=a+i
        bi=b-i
        if a<=ai and ai<=b:
            ans.append(ai)
        if a<=bi and bi<=b:
            ans.append(bi)
    ans=sorted(set(ans))
    for i in ans:
        print(i)
    
if __name__ == '__main__':
    do()
### BUGGY CODE ###

from collections import defaultdict
import heapq

vertices,edges = map(int,input().split(" "))
link = defaultdict(dict)
weight = defaultdict(dict)
way = [float("inf")] * vertices
for e in range(edges):
    source,target,w = map(int,input().split(" "))
    link[source] = link.get(source,set()) | {target}
    link[target] = link.get(target,set()) | {source}
    weight[source].update({target:w})
    weight[target].update({source:w})
queue = []
heapq.heapify(queue)
heapq.heappush(queue,[0,0])
went = set()
now_weight = 0
way[0] = 0

while len(went) < vertices:
    here_weight,here = heapq.heappop(queue)
    #print(now_weight,here)
    now_weight += here_weight
    can_go = link.get(here,set()) - went
    min_weight,next_t = float("inf"),-1
    for c in can_go:
        #heapq.heappush(queue,[now_weight + weight[here][c],c])
        if c not in went and way[c] > weight[here][c]:
            heapq.heappush(queue,[weight[here][c],c])
            way[c] = weight[here][c]
    #print(queue)
    went = went | {here}
print(now_weight)

### FIXED CODE ###

from collections import defaultdict
import heapq
vertices, edges = (int(n) for n in input().split(" "))
conn = defaultdict(set)
weight = defaultdict(dict)
for i in range(edges):
    v1, v2, w = (int(n) for n in input().split(" "))
    conn[v1] |= {v2}
    conn[v2] |= {v1}
    weight[v1][v2] = w
    weight[v2][v1] = w

queue = []
heapq.heapify(queue)
heapq.heappush(queue, [0,0])
went = set()
went_vertices = 0
answer_weight = 0
while went_vertices < vertices:
    here_weight, here_v = heapq.heappop(queue)
    if here_v in went:
        continue
    went |= {here_v}
    for c in conn[here_v]:
        if c not in went:
            heapq.heappush(queue,[weight[here_v][c], c])
    answer_weight += here_weight
    went_vertices += 1
print(answer_weight)
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [a for a in A if a <K]
N = len(A)
dpm = [[0]*(K+1) for _ in range(N+1)]
dpm[0][0] = 1
for i, a in enumerate(A):
    for j in range(K, -1, -1):
        dpm[i+1][j] = dpm[i][max(0, j-a)] + dpm[i][j]
#print(dpm)

r = 0
dp2 = 1
for i, a in enumerate(A[::-1]):
    f = True
    for j in range(K, -1, -1):
        # 後ろiこの合計がjのもの
        if f and dp2&(1<<j):
            # K-j > x >= K-j-a
            if dpm[N-i-1][max(0, K-j-a)] > dpm[N-i-1][K-j]:
                f = False
    dp2 |= dp2<<a
    if f:
        r += 1
#    for j in range(K-1, 0, -1):
#        print("aa", i, N-i-1)
print(r)


### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [a for a in A if a <K]
N = len(A)
#dpm = [+1) for _ in range(N+1)]
dpm = [0]*(N+1)
dpm[0] = 1<<(K-1)
for i, a in enumerate(A):
    dpm[i+1] = dpm[i] | (dpm[i] >> a)

r = 0
dp2 = 1
for i, a in enumerate(A[::-1]):
    for j in range(a):
        if dp2 & dpm[N-i-1]:
            break
        dpm[N-i-1] >>= 1
    else:
        r += 1
    dp2 |= dp2<<a
    dp2 &= (1<<K)-1
print(r)
### BUGGY CODE ###

import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    X = il()

    ret = MAX
    for n in range(N - K + 1):
        T = X[n:n + K]
        sm = min(abs(T[0]), abs(T[len(T)-1]))
        for t in range(len(T)-1):
            sm += abs(T[t] - T[t+1])
        ret = min(ret, sm)
    print(ret)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

# import fractions

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    X = il()

    ret = MAX
    for n in range(N - K + 1):
        l = abs(X[n]) + abs(X[n]-X[n+K-1])
        r = abs(X[n+K-1]) + abs(X[n+K-1] - X[n])
        ret = min(ret, l, r)
    print(ret)


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

# 176 B
N = int(input())
length = len(str(N))
nine = 0
for i in range(1, length+1, 1):
    nine += (N % (10**i))/(10**(i-1))
    N -= N % (10**i)
    
print('Yes') if nine % 9 == 0 else print('No')

### FIXED CODE ###

# 176 B
N = int(input())
    
print('Yes') if N % 9 == 0 else print('No')
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]

for l, r in LR:
    print(S[l-1:r].count("AC"))

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]

cnt, acc = [0] * N, 0
for i in range(1, N):
    if S[i-1:i+1] == "AC":
        acc += 1
    cnt[i] = acc

for l, r in LR:
    print(cnt[r-1] - cnt[l-1])
### BUGGY CODE ###

s = input()
ans = 0
for i in range(len(s) - 1):
    for j in range(i + 1, len(s)):
        if s[i] == 'A' and s[j] == 'Z':
            ans = max(ans, j - i + 1)
print(ans)


### FIXED CODE ###

s = input()
ansi = 0
ansj = 0
for i in range(len(s)):
    if s[i] == 'A':
        ansi = i
        break
for j in range(len(s)-1, -1, -1):
    if s[j] == 'Z':
        ansj = j
        break
print(j - i + 1)
### BUGGY CODE ###

n, m = list(map(int, input().split()))
for i in range(n, m+1):
    if m % i == 0:
        print(m // i)
        break

### FIXED CODE ###

from math import sqrt
n, m = list(map(int, input().split()))
i = 1
lst = []
while i <= sqrt(m):
    if m % i == 0:
        j = m // i
        if i >= n:
            lst.append(i)
        if j >= n:
            lst.append(j)
    i += 1
print(m//min(lst))
### BUGGY CODE ###

N = int(input())
a = list(map(int,input().split()))
l = []
for i in range(N-1):
    l.append(a[i+1]-a[i])
# print(l)
if any(i<=-2 for i in l):
    print("No")
    exit()
while 0 in l:
    l.remove(0)
# print(l)
for i in range(len(l)-1):
    if l[i] == -1 and l[i+1] == -1:
        print("No")
        exit()
print("Yes")

### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
l = []
for i in range(N-1):
    if a[i+1]-a[i] != 0:
        l.append(a[i+1]-a[i])
# print(l)
if any(i<=-2 for i in l):
    print("No")
    exit()
# while 0 in l:
#     l.remove(0)
# # print(l)
for i in range(len(l)-1):
    if l[i] == -1 and l[i+1] == -1:
        print("No")
        exit()
print("Yes")
### BUGGY CODE ###

import itertools
def aCb(a,b):return len(list(itertools.combinations([0]*a,b)))#組み合わせ
n,a=int(input()),list(map(int,input().split()));b=[0]#入力
b+=list(itertools.accumulate(a))#累積和
b.sort();c=1;ans=0
for i in range(n):#2個以上存在する要素があるとき、cC2を加える
  if b[i]==b[i+1]:c+=1
  else:
    if c>=2:ans+=aCb(c,2)
    c=1
if c>=2:ans+=aCb(c,2)#アレ対策
print(ans)

### FIXED CODE ###

n,a=int(input()),list(map(int,input().split()));b=[0]
for i in range(n):b.append(b[i]+a[i])
b.sort();c=1;ans=0
for i in range(n):
  if b[i]==b[i+1]:c+=1
  else:
    if c>=2:ans+=(c*(c-1))//2
    c=1
if c>=2:ans+=(c*(c-1))//2
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

ans = 0
n = int(input())
A = list(map(int,input().split()))
B = [0] * (10**6+3)
for i in range(n):
    B[A[i]] += 1

for i in range(n):
    ok = 1
    if (A[i] != 1 and B[1] > 0) or B[A[i]] > 1:
        ok = 0
    if ok == 1:
        for j in range(2, int(A[i]**0.5)+1):
            if A[i] % j == 0 and (B[j] > 0 or B[A[i]//j] > 0):
                ok = 0
                break
    ans += ok
print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

ans = 0
n = int(input())
A = list(map(int,input().split()))
B = [0] * (10**6+3)
ans = 0
A.sort()
for i in range(n):
    if (i == 0 or A[i] != A[i-1]) and (i == n-1 or A[i] != A[i+1]) and B[A[i]] == 0:
        ans += 1
    if (i == 0 or A[i] != A[i-1]):
        m = A[i]
        while m < len(B):
            B[m] = 1
            m += A[i]
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
if n % k == 0:
	print(0)
else:
	while True:
		prev = n
		n = abs(n - k)
		if n >= prev:
			break
	print(prev)


### FIXED CODE ###

n, k = map(int, input().split())
p = n // k
print(min(abs(n - p * k), abs(n - (p + 1) * k)))