Problem:


Score : 300 points

Problem Statement

Given any integer x, Aoki can do the operation below.

Operation: Replace x with the absolute difference of x and K.

You are given the initial value of an integer N. Find the minimum possible value taken by N after Aoki does the operation zero or more times.

Constraints

0 ≤ N ≤ 10^{18}

1 ≤ K ≤ 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the minimum possible value taken by N after Aoki does the operation zero or more times.

Sample Input 1

7 4

Sample Output 1

1

Initially, N=7.

After one operation, N becomes |7-4| = 3.

After two operations, N becomes |3-4| = 1, which is the minimum value taken by N.

Sample Input 2

2 6

Sample Output 2

2

N=2 after zero operations is the minimum.

Sample Input 3

1000000000000000000 1

Sample Output 3

0



Sample input:
7 4


Sample output:
1

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
if n == k:
  print(0)
  exit()
if n > k:
  k, n = n, k
l = k%n
print(min(l, n-l))

Submission status: Runtime Error

Solution code:
N = N % K;
var ans = Math.Min(N, Math.Abs(N - K));
Console.WriteLine(ans);

Submission status: Runtime Error

Solution code:
a=int(input())
b=int(input())
while(a>=b):
	a=abs(a-b)
print(a)

Submission status: Runtime Error

Solution code:
a, b = int(input().split(" "))

quotinent = a // b

res = max(a - b * quotinent, abs( a- b * (quotinent + 1)))
print(res)

Submission status: Runtime Error

Solution code:
N , K = map(int , input().split())

mini = N % K

if mini < abs(mini - K):
    mini = mini
else:
    mini = abs(mini - k)

print(mini)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
n %= m
print(min(n, k - n))

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
n %= m
print(min(n, m - n))

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())

x = abs(N - K*(int(N/K)-1))

for i in range(0,5):
    x = abs(x-K)
    ans = min(ans,x)

print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())

N = N % K

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

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
amari=n%k
mainasu=n-(n//k+1)*k
if amari<abs(mainasu):
  print(amari)
else:
  print(abs(mainasu))
n,k=map(int,input().split())
amari=n%k
mainasu=n-(n//k+1)*k
if amari<abs(mainasu):
  print(amari)
else:
  print(abs(mainasu))

Submission status: Runtime Error

Solution code:
#C
NK = input().split(' ')
N=int(NK[0]) ; K = int(NK[1])
ans = [N]
if K == a:
    print(0)
else:
    while N > abs(N-K):
        N = abs(N-K)
        ans.append(N)
    print(min(ans))

Submission status: Runtime Error

Solution code:
if N > 100000000:
    N /= 10000000
syou = int(N/K)
print(syou)
min_1 = int(N - syou*K + 0.5)
min_2 = -int(N - (syou+1)*K - 0.5)
print('{} {}'.format(min_1,min_2))
if min_1 < min_2:
    print(min_1)
else :
    print(min_2)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
print(min(abs(n%k),k-abs(n%k))

Submission status: Runtime Error

Solution code:
from collections import deque
k = int(input())
Q = deque(range(1, 10))
for _ in range(k):
  x = Q.popleft()
  y = x % 10
  z = 10*x + y
  if y != 0:
    Q += [z-1]
  Q += [z]
  if y != 9:
    Q += [z+1]
print(x)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
import math
# stdin = open("sample.txt")

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

K = int(stdin.readline().rstrip())
a = list(range(1,10))
b = []
attack = 100000
while attack > 0:
    go = a.pop(0)
    ue = go*10
    shimo = go%10
    b.append(go)
    if shimo == 0:
        a.append(ue)
        a.append(ue+1)
    elif shimo == 9:
        a.append(ue+shimo-1)
        a.append(ue+shimo)
    else:
        a.append(ue+shimo-1)
        a.append(ue+shimo)
        a.append(ue+shimo+1)
    attack -= 1

print(b[K-1])

Submission status: Runtime Error

Solution code:
K = int(input())
a = 0
count = 0
mm = [0,1]
while True:
    a += 1
    if a == 1:
        for i in range(1,10):
            count += 1
            if count == K:
                print(i)
                exit()

    elif a == 2:
        for i in range(1,10):
            for j in range(0,10):
                if abs(i-j)<=1:
                    count+= 1
                    mm.append(i*10+j)
                    if count == K:
                        print(i*10+j)
                        exit()

    elif a >= 3:
        tmp = [] 
        for i in range(1,10):
            # print(mm)
            for j in mm:
                b = j//(10**(a-2))
                # print(b)
                if abs(i-b) <=1:
                    count+= 1
                    e = i*(10**(a-1))+j
                    # print(count,e)
                    tmp.append(e)
                    if count == K:
                        print(e)
                        exit()
        # print(tmp)
        mm = mm + tmp

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())

a = abs(N - K)
ans1 = N % a
b = abs((N % a) - a)
ans2 = N % b

print(min(ans1, ans2))

Submission status: Runtime Error

Solution code:
N, K = list(map(int, input().split()))

if N >= K:
    print(N % K)
else:
    print(K % N)

Submission status: Runtime Error

Solution code:
N = int(input())
tmp = [i for i in range(1, 10)]
ans = list(tmp)
for i in range(10):
    tmp2 = []
    for x in tmp:
        k = int(str(x)[-1])
        if k != 0:
            ans.append(10*x-1 + k)
            tmp2.append(10*x-1 + k)
        if k != 9:
            tmp2.append(10*x+1 + k)
            ans.append(10*x+1 + k)
        tmp2.append(10*x + k)
        ans.append(10*x + k)
    tmp = list(tmp2)

ans.sort()
print(ans[N-1])

Submission status: Runtime Error

Solution code:
import sys
n ,k = map(int, input().split())
 
 
if n == k or k == 1:
    print(0)
    sys.exit()
    
def min_N(n, k):
    b = abs(n-k)
    if b == 0:
        print(0)
        sys.exit()
    elif b == 1:
        print(1)
        sys.exit()
    elif n < b:
        print(n)
        sys.exit()
    n = b
    min_N(n, k)

min_N(n, k)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
K = int(input())
mod = N % K
  
if(abs(mod-K) < mod)
  mod = abs(mod-K);
  
print(mod)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
print(min(N%K, K(N%K)))

Submission status: Runtime Error

Solution code:
import sys
n ,k = map(int, input().split())
m = 0

if n == k or k == 1:
    print(0)
    sys.exit()
    
def abs_N(n, k):
    m = abs(n-k)
    compare_N_M(n, m)

def compare_N_M(n, m):
    if m == 1:
        print(1)
        sys.exit()
    elif m == 0:
        print(0)
        sys.exit
    elif n >= m:
        n = m
        abs_N(n, k)
    else:
        print(n)
        sys.exit()
        
abs_N(n, k)

Submission status: Runtime Error

Solution code:
N,K=map(int, input().split()) 
min = abs(N-K)
while min >= abs(min-K):
      if min % K ==0:
        print(0)
        break
    min = abs(min-K)
    if min < K:
        if min < abs(min-K):
            print(min)
            break
        else:
            print(abs(min-K))
            break
else :
    print(min)

Submission status: Runtime Error

Solution code:
N, K = list(map(int, input().split()))


def x(N, K):
    y = (N)
    f = 0
    while True:
        N = abs(N - K)

        if y > N:
            y = N

        if y == N:
            f += 1

        if f > 4:
            return y


# if K == 0:
#     print(N)
# elif K == 1:
#     print(0)
# else:
#     print(x(N, K))
print(x(N, K)

Submission status: Runtime Error

Solution code:
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <cassert>
#include <fstream>
#include <stdio.h>
#include<unordered_map>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

int main(){
	int n,k,c; cin >> n >> k>> c;
	string s; cin >> s;
	if(c == 0){
		rip(i,n,0) if(s[i]=='o') k--;
		if(k < 0) return 0;
		rip(i,n,0){
			if(s[i] == 'o') printf("%d\n", i+1);
		}
		return 0;
	}
	vector<int> dp(n),dpp(n);
	dp[0] = 1;
	dpp[n-1] = 1;
	if(s[0] == 'x') dp[0] = 0;
	if(s[n-1] == 'x') dp[n-1] = 0;
	rip(i,n,1){
		dp[i] = dp[i-1];
		if(c < i && s[i] == 'o') chmax(dp[i], dp[i-c-1]+1);
		else chmax(dp[i], 1);
	}
	for(int i = n-2;i>-1;i--){
		dpp[i] = dpp[i+1];
		if(i+c+1 < n && s[i] == 'o') chmax(dpp[i], dpp[i+c+1]+1);
		else chmax(dpp[i], 1);
	}
	vector<int> ans(0);
	vector<int> su(n+1);
	rip(i,c+1,0){
		if(dpp[i] >= k) su[0]++, su[i]--;
	}
	rip(i,n-c-1,0){
		if(dp[i] + dpp[i+c+1] >=k) su[i+1]++, su[i+c+1]--;
	}
	rip(i,n,n-c-1){
		if(dp[i] >= k) su[n]--, su[i+1]++;
	}
	int ok= 0;
	rip(i,n,0){
		ok += su[i];
		if(ok == 0) ans.push_back(i+1);
	}
	// vdeb(dp);vdeb(dpp);vdeb(su);
	rip(i,ans.size(),0) printf("%d\n", ans[i]);
}

Submission status: Runtime Error

Solution code:
N = int(input())
K = int(input())
temp = N
while N>0:
    if temp > K:
        N = N-K
        if N <= 0:
            print(abs(N))
    else:
        print(abs(N))

Submission status: Runtime Error

Solution code:
import sys
n ,k = map(int, input().split())
m = 0

if n == k or k == 1:
    print(0)
    sys.exit()
    
def abs_N(n, k):
    m = abs(n-k)
    compare_N_M(n, m)

def compare_N_M(n, m):
    if m == 1:
        print(1)
        sys.exit()
    elif n >= m:
        n = m
        abs_N(n, k)
    else:
        print(n)
        sys.exit()
        

abs_N(n, k)

Submission status: Runtime Error

Solution code:
line = input().split()
N = int(line[0])
K = int(line[1])
A = abs(N-K)
if A % K == 0:
  print(0) 
elseif:
  K > (A % K):
  print(abs(K-(A % K)))
else:
  print(K > (A % K))

Submission status: Runtime Error

Solution code:
def ans(a,b,m):
    k = abs(a[0]-a[1])
    if(k>=m):
        return a
    ans(k,b,k)
if True:
    a = list(map(int,input().split()))
    m = 10**20
    if(a[1]==1):
        print(0)
    else:
        print(ans(a[0],a[1],m))

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
if N > K:
  print(N%K)
elif N = K:
  print(0)
elif N < K:
  print(K%N)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# coding: utf-8
# import pprint
# import numpy as np
# import code
# import functools

if __debug__:
    def debug(arg):
        pass
else:
    import sys
    def debug(arg):
        debug = lambda *x: None
        print(arg, file=sys.stderr)

n, k = (int(x) for x in input().split())

d = abs(n - k)
debug(d)
if(n >= k):
    a = n % d
    debug(a)
else:
    a = n
    debug(a)
debug([a, k])
m = min(a, abs(a - k))
debug(m)
print(m)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
import sys

if __name__ == '__main__':
    nums = input().split()
    a = nums[0]
    b = nums[1]

    while int(a) - int(b) < 0:
        x = int(a) - int(b)
        a = x - int(b)
    print(a - int(b))
    sys.exit()

Submission status: Runtime Error

Solution code:
import math
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
N, K = map(int, input().split())
if K == 1:
    print(0)
elif N % 2 == 0 andK % 2 == 0:
    print(lcm(N, K))

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
a = abs(n - k)
if k == 1:
    print(0)
elif a > n:
    print(n)
else:
    while n // k > 0:
        tmp = n % k
        n = n // k
    print(abs(tmp - k))

Submission status: Runtime Error

Solution code:
N=input(int("Enter the number of N")
K=input(int("Enter the number of K")
result1 = N-K
if (N-k=~0)
        return 0;
        if( result2 = result1 - K <0)
            result2 = result * (-1)
                return (result2);
print(result2)

Submission status: Runtime Error

Solution code:
import sys
import math

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

if N < K:
    print(N)
elif N == 0:
    print(0)
elif N == K:
    print(0)
else:
    gcd = math.gcd(N, K)

    ans1 = abs((N - (K * gcd)))
    ans2 = abs(ans1 - K)

    print(min(ans1, ans2))

Submission status: Runtime Error

Solution code:
# C - Replacing Integer
n, k = map((int),(input().split()))


count = (int)(n / k)

print(min((abs(n - k * count - 1), abs(n - k * count)), abs(n - k * (count + 1)), abs(n - k * (count + 2))))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())

V = 1
num = 0
if N > M:
    s = N//M
    N = N%(s-1)

if N <= M:
    while V == 1:
        num = abs(N - M)
        if num >= N:
            V = 0
        else:
            N = num
    
print(N)

Submission status: Runtime Error

Solution code:
a, b = map(int,input().split())

if a<b:
    a,b=b,a

if a%b == 0:
    print(0)
else:
    c=a//b
    d=a%b
    a=a-b*c
    while abs(a-b)<a:
        a=abs(a-b)
    print(a)

Submission status: Runtime Error

Solution code:
while counter < 50:
    # print(n)
    
    if n == 0 or n == k or k == 0:
        print(n)
        switch = True
        break

    # test
    if n % k == 0:
        print('0')
        switch = True
        break


    n = min(n, abs(n - k))

    # detect loop
    if n in results:
        print(min(results))
        switch = True
        break
    else:
        results.add(n)

    counter += 1


if not switch:
    # print('loop ended n:', n)
    results = list(results)
    print(min(min(results), min(results) % k))

Submission status: Runtime Error

Solution code:
import sys


def get():
    return list(map(int, input().split()))


a = get()
b = a[0]
c = a[1]
if b < c:
    if abs(b - c) < b:
        print(abs(b - a))
        sys.exit(0)
    else:
        print(b)
        sys.exit(0)
else:
    if a[0] % a[1] == a[1] or a[0] % a[1] == 0:
        print(0)
        sys.exit(0)
    else:
        if abs((a[0] % a[1]) - a[1]) < abs(((a[0] % a[1]) - a[1]) % a[1]):
            if abs(a[0] % a[1]) < abs((a[0] % a[1]) - a[1]):
                print(abs(a[0] % a[1]))
                sys.exit(0)
            else:
                print(abs((a[0] % a[1]) - a[1]))
                sys.exit(0)
        else:
            if abs(a[0] % a[1]) < abs(((a[0] % a[1]) - a[1]) % a[1]):
                print(abs(a[0] % a[1]))
                sys.exit(0)
            else:
                print(abs(((a[0] % a[1]) - a[1]) % a[1]))
                sys.exit(0)

Submission status: Runtime Error

Solution code:
# C - Replacing Integer
n, k = map((int),(input().split()))


count = (int)(n / k)

print((min((abs(n - k * count - 1)), abs(n - k * count)), abs(n - k * (count + 1)), abs(n - k * (count + 2)))))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())

V = 1
num = 0
if N >= M:
    s = N//M
    N = N%(s-1)

if N < M:
    while V == 1:
        num = abs(N - M)
        if num >= N:
            V = 0
        else:
            N = num
    
print(N)

Submission status: Runtime Error

Solution code:
k = input()
k = int(k)

if 1 <= k and k <= 12:
    print(k)
elif 13 <= k and k <= 35:
    temp = k-9
    q = temp // 3
    p = temp % 3
    
    s = ""
    s = s + str(q)
    if p == 0:
        s = s + str(q+1)
    elif p == 1:
        s = s + str(q)
    elif p == 2:
        s = s + str(q-1)
print(s)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
if K==1 :
    print(0)
    exit()
if abs(N-K) < 10**5:
 for i in range(10**8):
    if abs(N-K*(i+1)) >= abs(N-K*i) :
        print(abs(N-K*i))
        exit()
else :
    for n in range(10**5,10**8):
        if abs(N-K(i+1))>= abs(N-K*i) :
            print(abs(N-K*i))
            exit()

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
if K==1 :
    print(0)
    exit()
if abs(N-K) < 10**5:
 for i in range(10**8):
    if abs(N-K*(i+1)) >= abs(N-K*i) :
        print(abs(N-K*i))
        exit()
else :
    for n in range(10**5.10**8):
        if abs(N-K(i+1))>= abs(N-K*i) :
            print(abs(N-K*i))
            exit()

Submission status: Runtime Error

Solution code:
for i in range(1000000000000000000):
    diff = abs(n - k)
    if n > diff:
        n = diff
    else:
        break
print(n)

Submission status: Runtime Error

Solution code:
def abs_result(x,y):
    tmp = abs(x-y)
    return tmp

def main():
    line = list(map(int,input().split()))
    n,k = line[0],line[1]
    
    # nを、nとkの差の絶対値で置き換える
    if n == 0 or k == 1:
        print(0)
        return
    
    if n % 2 == 0 k % 2 == 0 and n < k:
        print(2)
    
    if n % 2 == 0 k % 2 == 0 and n > k:
        print(0)
        
    if n % 2 == 1 and k % 2 == 0 and n > k:
        print(1)
        
    
    com = 2
    for i in range(0,10**18):
        ans = abs_result(n,k)
        if ans == 0:
            print(0)
            return
        elif ans == 1:
            print(1)
            return
        if ans <= com:
            print(ans)
            return
        n = ans

main()

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())

delta = abs(N-K)
print(min(N,N%K,N%delta))

Submission status: Runtime Error

Solution code:
n,k = map(int, input().split())
last = 0

if n < k:
  temp = int(k/n)
  remain = k - (n*temp)
  if remain > 0:
    last = abs(remain-n)
    print(min(remain, last))
  else:
  	print(remain)
else:
  temp = int(n/k)
  remain = n - (k*temp)
  if remain > 0:
    last = abs(remain-k)
    print(min(remain, last))
  else:
  	print(remain)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
Nj = N
while True:
    Nj = abs(Ni - K)
    if Ni > N:
        print(N)
        break
    elif Nj > Ni:
        print(Ni)
        break
    elif K == 1 or Nj == K:
        print(0)
        break
    else:
        continue

Submission status: Runtime Error

Solution code:
import sys


def get():
    return list(map(int, input().split()))


a = get()
b = a[0]
c = a[1]
if b < c:
    if abs(b - c) < b:
        print(abs(b - a))
        sys.exit(0)
    else:
        print(b)
        sys.exit(0)
else:
    if a[0] % a[1] == a[1] or a[0] % a[1] == 0 or abs((a[0] % a[1] - a[1])) == 0:
        print(0)
        sys.exit(0)
    else:
        if abs(a[0] % a[1] - a[1]) < abs((a[0] % a[1] - a[1]) % a[1]):
            if abs(a[0] % a[1]) < abs(a[0] % a[1] - a[1]):
                print(abs(a[0] % a[1]))
                sys.exit(0)
            else:
                print(abs(a[0] % a[1] - a[1]))
                sys.exit(0)
        else:
            if abs(a[0] % a[1]) < abs((a[0] % a[1] - a[1]) % a[1]):
                print(abs(a[0] % a[1]))
                sys.exit(0)
            else:
                print(abs((a[0] % a[1] - a[1]) % a[1]))
                sys.exit(0)

Submission status: Runtime Error

Solution code:
# coding: utf-8
 
a=list(map(int,input().split()))
#読み込み
N = a[0]
M = a[1]
b = []

if N % M == 0 or M%N ==0:
    ans = 0
    print(ans)

else:
    while True:
        N = abs(N-M)
        b.append(N)
        if b[-1]>b[-2]:
            break
    print(b[-2])

Submission status: Runtime Error

Solution code:
N, K = (int(x) for x in input().split())
memo = {}

if N == K:
    print(0)
elif N > K and N % K == 0:
    print(0)
elif N < K and K % N == 0:
    print(N)
else:
    last = N
    for n in range(10 ** 18):
        x = abs(last - K)
        if x not in memo.values():
            last = x
            memo[n] = last
        else:
            print(last)
            break

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
if n % k ==0:
    print(0)
else:
    l = [n]
    p = n//k
    c = n-(p*k)
half = k//2
while c > half:
    c = abs(c-k)
l.append(c)
print(min(l))

Submission status: Runtime Error

Solution code:
while x>0:
    if (k == 1):
        rlist = [0]
        break
    rlist.append(abs(x-k))
    x = abs(x-k)
    min_n = min(rlist)
    if (min_n == abs(x-k)):break
    if (min_n == 0):break
    if(len(set(rlist)) != len(rlist)):
        break

print(min(rlist))

Submission status: Runtime Error

Solution code:
a, b = map(int,input().split())

if a<b:
    a,b=b,a

if a%b == 0:
    print(0)

else:
    c=list(divmod(a,b))
    while a%b != 0 and abs(b-c[1])<c[1]:
        a=b
        b=c[1]
        c=list(divmod(a,b))

    print(c[1])

Submission status: Runtime Error

Solution code:
n, k = [int(i) for i in input().split()]

if n > k:
    tmp = k 
    while not (n - tmp) % k == 0:
        tmp -= 1
    n = tmp
    
while tmp >= n:
    tmp = n
    n = abs(n - k)
    if tmp < n:
        break
print(tmp)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
l = list(map(int,input().split()))

sum = sum(l)
l = sorted(l,reverse=True)
x = sum / (1 / 4*m)
ans = 0



for i in range(m):
    if(l[i] >= x):
        ans = ans + 1

if(ans >= m):
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
n, k = map(int,input().split())
b = n / 2
if b >= k:
    print(n % k)
else:
    if n <= a:
        print(n)
    else:
        while n > a:
            n = a
            a = abs(a - k)
            if n < a:
                break
        print(n)

Submission status: Runtime Error

Solution code:
N, K = input().split()
N = int(N)
K = int(K)

middle = N % K
answer = middle
while True:
  if abs(answer-k) > N:
    answer = N
    break
  if abs(answer - K) < answer:
    answer = abs(answer-K)
  else:
    break
    
print(str(answer))

Submission status: Runtime Error

Solution code:
n,m=map(int,input())
N=n
x=0
z=m
for i in range(m+1):
    x=N-z
    x=abs(x)
    z=x*z
    N=min(N,x,n)

print(N)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
Nj = N
whhile True:
  Ni = Nj
  Nj = vbs(Ni-K)
  if Ni > N:
    print(N)
    break
  elif Nj > Ni:
    print(Ni)
    break
  elif K == 1 or Nj == K:
    print(0)
    break
  else: 
    continue

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())

if K == 1:
    print(0)

elif N == K:
    print(0)

elif N % 2 == 0 and K % 2 == 0 and N > K and K % N == 0:
    print(0)
elif N % 2 == 0 and K % 2 == 0 and N > K and K % N != 0:
    if abs(N - K) > N:
        print(N)
    else:
        for i in range(10 ** 18):
            if N > abs(N - K):
                N = abs(N - K)
            else:
                print(N)
                break


elif N % 2 == 0 and K % 2 == 0 and N < K and K % N == 0:
    print(N)
elif N % 2 == 0 and K % 2 == 0 and N < K and K % N != 0:
    if abs(N - K) > N:
        print(N)
    else:
        print(abs(N - K))


elif N % 2 == 1 and K % 2 == 1 and N > K and K % N == 0:
    print(0)
elif N % 2 == 1 and K % 2 == 1 and N > K and K % N != 0:
    if abs(N - K) > N:
        print(N)
    else:
        for i in range(10**18):
            if N > abs(N - K):
                N = abs(N - K)
            else:
                print(N)
                break


elif N % 2 == 0 and K % 2 == 0 and N < K and K % N == 0:
    print(N)
elif N % 2 == 0 and K % 2 == 0 and N < K and K % N != 0:
    if abs(N - K) > N:
        print(N)
    else:
        for i in range(10 ** 18):
            if N > abs(N - K):
                N = abs(N - K)
            else:
                print(N)
                break


elif N % 2 == 0 and K % 2 == 1 and N > K and N % K != 0:
    if abs(N - K) > N:
        print(N)
    else:
        for i in range(10 ** 18):
            if N > abs(N - K):
                N = abs(N - K)
            else:
                print(N)
                break
elif N % 2 == 0 and K % 2 == 1 and N > K and N % K == 0:
    print(0)


elif N % 2 == 0 and K % 2 == 1 and N < K and N % K != 0:
    if abs(N - K) > N:
        print(N)
    else:
        for i in range(10 ** 18):
            if N > abs(N - K):
                N = abs(N - K)
            else:
                print(N)
                break
elif N % 2 == 0 and K % 2 == 1 and N < K and N % K == 0:
    print(0)


elif N % 2 == 1 and K % 2 == 0 and N > K and N % K != 0:
    if abs(N - K) > N:
        print(N)
    else:
        for i in range(10 ** 18):
            if N > abs(N - K):
                N = abs(N - K)
            else:
                print(N)
                break
elif N % 2 == 1 and K % 2 == 0 and N > K and N % K == 0:
    print(0)


elif N % 2 == 1 and K % 2 == 0 and N < K and N % K != 0:
    if abs(N - K) > N:
        print(N)
    else:
        for i in range(10 ** 18):
            if N > abs(N - K):
                N = abs(N - K)
            else:
                print(N)
                break
elif N % 2 == 1 and K % 2 == 0 and N < K and N % K == 0:
    print(N)

else:
    print("NG")

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
ans = int(N)
k_range = N // K
# print(k_range)

if k_range == 0:
    N = N - K
else:
    N_1 = N - (K * k_range)
    N_2 = N - (K * (k_range + 1))
    print(N_1)
    print(N_2)

if abs(N_1) < abs(N_2):
    if ans > abs(N_1):
        ans = abs(N_1)
    else:
        pass
else:
    if ans > abs(N_2):
        ans = abs(N_2)
    else:
        pass
print(ans)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
if N==0:print(0)
elif N<K:print(min(N,K-N))
elif N>=K*2:print(N%K)
else:print(N%(N-K))

Submission status: Runtime Error

Solution code:
list1=[]
a,b=map(int,input().split())
d=a
e=a
if b==1:
    print(0)
else:
    for i in range(d):
        a=abs(a-b)
        list1.append(a)
        if e<a:
            break
    list2= sorted(list1, reverse=True)
    print(list2[-1])

Submission status: Runtime Error

Solution code:
# coding: utf-8
 
a=list(map(int,input().split()))
#読み込み
N = a[0]
M = a[1]
b = []

if N % M == 0 or M%N ==0:
    ans = 0
else:
    while True:
        N = abs(N-M)
        b.append(N)
        if b[-1]>b[-2]:
            break

print(b[-2])

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
if n % k ==0:
    print(0)
else:
    l = [n]
    p = n//k
    c = n-(p*k)
half = k//2
while c > half:
    c = abs(c-k)
    l.append(c)
print(min(l))

Submission status: Runtime Error

Solution code:
n,m=map(int,input())
N=n
x=0

for i in range(m+1):
    x=N-m
    x=abs(x)
    m=x*m
    N=min(N,x,n)

print(N)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())

if N < K:
    print(N)
else:
    a = N % K
    b = abs(a-k)
    if a<b:
      print(a)
    else:
      print(b)

Submission status: Runtime Error

Solution code:
def getInput():
    return [int(i) for i in input().rstrip().split(' ')]

def swap(x, K):
    return abs(x-K)

def loops (x, K, mins):
    if x < K:
        ab = swap(x, K)
        return min(ab, x)
    elif x % K == 0:
        return 0
    else:
        x = swap(x, K)
        if x == 0:
            return x
        if x < mins:
            mins = x
            x = loops(x, K, mins)
            return x
        else:
            return mins

N, K = getInput()
x = N
print(loops(x, K, x))

Submission status: Runtime Error

Solution code:
n, k = [int(i) for i in input().split()]

if n > k:
    tmp = k 
    while not (n - tmp) % k == 0: tmp -= 1
    n = tmp
    
while tmp >= n:
    tmp = n
    n = abs(n - k)
    if tmp < n:
        break
print(tmp)

Submission status: Runtime Error

Solution code:
import sys

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


if(N > K):
    if(N % K == 0):
        print(0)
        sys.exit()
    else:
        tmp=N % K
        print(min(tmp,abs(K - tmp)))
        sys.exit()
else:
    tmp = abs(N - K)
    if(tmp <= N):
        print(tmp)
    else:

Submission status: Runtime Error

Solution code:
n,k = map(int, input().split())

rem = n % k
a = rem - k
ans = min(abs(a)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
 
if n % k == 0 or abs(n - k) == 0:
    print(0)
else:
    while n > n % abs(n - k):
        n = n % abs(n - k)
    print(n)

Submission status: Runtime Error

Solution code:
import numpy as np

tmp = list(map(int, input().split()))

N = tmp[0]
K = tmp[1]


# i = N % K

if N < K:
    print(N)
elif N == K:
    print(0)    
else:



    solve = [0] * K

    for i in range(0, K-1):
        solve[i] = N % (K - i)

    solve.reverse()

    for iter in range(0,K-1):
        if solve[iter] == 0:
            continue
        else:
            print(solve[iter])
            break
    print(0)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
if n % k ==0:
print(0)
else:
l = [n]
p = n//k
c = n-(p*k)
half = k//2
while c > half:
c = abs(c-k)
l.append(c)
print(min(l))

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
c = 0
a = []

while 1:
    if (N%2==0)and(K%2==0)and(N>=K):
        print(0)
        break
    if K==1:
        print(0)
        break
    if N==0:
        print(0)
        break
    if N==1:
        print(1)
        break
    
    for i in range(2):
        if i==0:
            N = N-((N//K)*K)
        N = abs(N-K)
        a.append(N)
    b = min(a)
        
    break
print(b)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())

if n % k == 0:
    print(0)
else:
    while n > n % abs(n - k):
        n = n % abs(n - k)
    print(n)

Submission status: Runtime Error

Solution code:
import numpy as np

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

while N>=K:
  N = N - K

while N!=0:
  if N>=np.abs(N-K):
    N = N-K
    if N<0:
      N = N * -1
  elif N==0:
    break
  else:
    break            
print(N)

Submission status: Runtime Error

Solution code:
x,y,z = list(map(int,input().split()))
def swap(a,b):
tmp = a
a = b
b = tmp
return (a,b)
x,y = swap(x,y)
x, z = swap(x, z)
print(x,y,z)
n,k = map(int,input().split())
if n % k ==0:
print(0)
else:
l = [n]
p = n//k
c = n-(p*k)
half = k//2
while c > half:
c = abs(c-k)
l.append(c)
print(min(l))

Submission status: Runtime Error

Solution code:
print("Enter N and K value below:")
N = input()
K = input()
print(N + " " + K)
while 0 <= int(N) <= 10**8 and 0 <= int(K) <= 10**8:
    N = abs(N-M)
    N = 0
print(N)

Submission status: Runtime Error

Solution code:
#coding:utf-8
import math
n, k = map(int, input().split())

if n < k:
    print(min(n, k%n))
elif k == 1 or n == 0 or n%k == 0:
    print(0)
elif k % 2 == 0 and n % 2 == 0 and n%k != 0:
    print(n%k)
elif n%k != 0:
    print(min(abs(n%k-k), n%k))

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())

if N < K:
    print(N)
elif N % K == 0:
    print(0)
else:
    a = N % K
    if a<k:
      print(a)
    else:
      print(k)