Problem: 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.

Submission attempts (in order):
def main():
    N, K = map(int, input().split())
    value_diff_abs = 0

    if N == 0 :
        print("0")
    elif N > K :
        ans = N % K
        print(ans)
    else :
        for i in range(0 , N + 1) :
            value_diff_abs = N
            N = abs(N - K)
            if value_diff_abs < N :
                print(str(value_diff_abs))
                break


if __name__ == '__main__':
    main()

def main():
    N, K = map(int, input().split())
    value_diff_abs = 0

    if N == 0 or N == K :
        print("0")
    elif N > K :
        ans = N % K
        print(ans)
    else :
        for i in range(0 , N + 1) :
            value_diff_abs = N
            N = abs(N - K)
            if value_diff_abs < N :
                print(str(value_diff_abs))
                break


if __name__ == '__main__':
    main()


def main():
    N, K = map(int, input().split())
    value_diff_abs = 0

    if N == 0 or N == K :
        print("0")
    elif N > K :
        ans = N % K
        print(ans)
    else :
        for i in range(0 , N + 1) :
            value_diff_abs = N
            N = abs(N - K)
            if value_diff_abs < N :
                print(str(value_diff_abs))
                break
            elif value_diff_abs == N :
                print(str(value_diff_abs))
                break


if __name__ == '__main__':
    main()

def main():
    N, K = map(int, input().split())
    value_diff_abs = 0

    if N == 0 or N == K :
        print("0")
    elif N > K :
        ans = N % K
        print(ans)
    elif K == 1 and N != 0 :
        print("0")
    elif K == 2 and N % 2 == 0 and N != 0 :
        print("0")
    elif K == 2 and N % 2 != 0 and N != 0 :
        print ("1")
    else :
        for i in range(0 , N + 1) :
            value_diff_abs = N
            N = abs(N - K)
            if value_diff_abs < N :
                print(str(value_diff_abs))
                break
            elif value_diff_abs == N :
                print(str(value_diff_abs))
                break


if __name__ == '__main__':
    main()

def main():
    N, K = map(int, input().split())
    value_diff_abs = 0

    if N == 0 or N == K :
        print("0")
    elif N > K :
        ans = N % K
        #print(ans)
        N = ans
        for i in range(0 , N + 1) :
            value_diff_abs = N
            N = abs(N - K)
            #print(str(value_diff_abs))
            if value_diff_abs < N :
                print(str(value_diff_abs))
                break
            elif value_diff_abs == N :
                print(str(value_diff_abs))
                break
    else :
        for i in range(0 , N + 1) :
            value_diff_abs = N
            N = abs(N - K)
            if value_diff_abs < N :
                print(str(value_diff_abs))
                break
            elif value_diff_abs == N :
                print(str(value_diff_abs))
                break


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted