#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools as fts
import itertools as its
import math
import sys

INF = float('inf')


def solve(X: int, K: int, D: int):
    return abs(X) - K * D if abs(X) > K * D else X % D if (K - X//D) % 2 == 0 else abs(X % D - D)


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    print(f'{solve(X, K, D)}')


if __name__ == '__main__':
    main() from typing import * import collections collections import functools as fts functools import itertools as its itertools import math math import sys sys INF = float('inf') INF float('inf') float 'inf' def solve(X: int, K: int, D: int):
    return abs(X) - K * D if abs(X) > K * D else X % D if (K - X//D) % 2 == 0 else abs(X % D - D) solve return abs(X) - K * D if abs(X) > K * D else X % D if (K - X//D) % 2 == 0 else abs(X % D - D) abs(X) - K * D if abs(X) > K * D else X % D if (K - X//D) % 2 == 0 else abs(X % D - D) abs(X) > K * D abs(X) abs X K * D K D abs(X) - K * D abs(X) abs X K * D K D X % D if (K - X//D) % 2 == 0 else abs(X % D - D) (K - X//D) % 2 == 0 (K - X//D) % 2 K - X//D K X//D X D 2 0 X % D X D abs(X % D - D) abs X % D - D X % D X D D X: int X K: int K D: int D def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    print(f'{solve(X, K, D)}') main sys.setrecursionlimit(10 ** 6) sys.setrecursionlimit sys setrecursionlimit 10 ** 6 10 6 def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
     iterate_tokens for line in sys.stdin:
            for word in line.split():
                yield word
     line sys.stdin sys stdin for word in line.split():
                yield word
     word line.split() line.split line split yield word word tokens = iterate_tokens() tokens iterate_tokens() iterate_tokens X = int(next(tokens)) X int(next(tokens)) int next(tokens) next tokens K = int(next(tokens)) K int(next(tokens)) int next(tokens) next tokens D = int(next(tokens)) D int(next(tokens)) int next(tokens) next tokens print(f'{solve(X, K, D)}') print f'{solve(X, K, D)}' if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    print(f'{solve(X, K, D)}') def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    print(f'{solve(X, K, D)}') main INF = float('inf') float('inf') INF def solve(X: int, K: int, D: int):
    return abs(X) - K * D if abs(X) > K * D else X % D if (K - X//D) % 2 == 0 else abs(X % D - D) def solve(X: int, K: int, D: int):
    return abs(X) - K * D if abs(X) > K * D else X % D if (K - X//D) % 2 == 0 else abs(X % D - D) solve
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools as fts
import itertools as its
import math
import sys

INF = float('inf')


def solve(X: int, K: int, D: int):
    return abs(X) - K * D if abs(X) > K * D else X % D if (K - X//D) % 2 == 0 else abs(X % D - D)


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    print(f'{solve(X, K, D)}')


if __name__ == '__main__':
    main()
