Problem:
Score : 300 points

Problem Statement

Takahashi, who lives on the number line, is now at coordinate X. He will make exactly K moves of distance D in the positive or negative direction.

More specifically, in one move, he can go from coordinate x to x + D or x - D.

He wants to make K moves so that the absolute value of the coordinate of the destination will be the smallest possible.

Find the minimum possible absolute value of the coordinate of the destination.

Constraints

-10^{15} \leq X \leq 10^{15}

1 \leq K \leq 10^{15}

1 \leq D \leq 10^{15}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X K D

Output

Print the minimum possible absolute value of the coordinate of the destination.

Sample Input 1

6 2 4

Sample Output 1

2

Takahashi is now at coordinate 6. It is optimal to make the following moves:

Move from coordinate 6 to (6 - 4 =) 2.

Move from coordinate 2 to (2 - 4 =) -2.

Here, the absolute value of the coordinate of the destination is 2, and we cannot make it smaller.

Sample Input 2

7 4 3

Sample Output 2

1

Takahashi is now at coordinate 7. It is optimal to make, for example, the following moves:

Move from coordinate 7 to 4.

Move from coordinate 4 to 7.

Move from coordinate 7 to 4.

Move from coordinate 4 to 1.

Here, the absolute value of the coordinate of the destination is 1, and we cannot make it smaller.

Sample Input 3

10 1 2

Sample Output 3

8

Sample Input 4

1000000000000000 1000000000000000 1000000000000000

Sample Output 4

1000000000000000

The answer can be enormous.

Solution in C# (.NET Core 3.1.201) (judge verdict: Wrong Answer)

using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramC a = new ProgramC();
            a.main();//実行する

        }

    }
    //ABC175
    class ProgramA
    {
        public void main()
        {
            //入力
            string s = Console.ReadLine();

            //30以上ならYes、それ以外はNoを出力
            if (s == "RRR")
                Console.WriteLine(3);
            else if(s == "RRS" || s == "SRR")
                Console.WriteLine(2);
            else if (s == "SSS")
                Console.WriteLine(0);
            else
                Console.WriteLine(1);

        }
    }

    class ProgramB
    {
        public void main()
        {
            //入力

            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');

            long count = 0;
            //それぞれの距離を求めて、距離がD以下なら1足す
            for (int i = 0; i < n; i++)
                for (int j = i + 1; j < n; j++)
                    for (int k = j + 1; k < n; k++)
                    {
                        long a = long.Parse(s[i]);
                        long b = long.Parse(s[j]);
                        long c = long.Parse(s[k]);
                        if (a == b || b == c || c == a)
                            continue;

                        if (a + b> c  && b + c > a && c +a > b)
                            count++;
                    }

            //答え出力
            Console.WriteLine(count);

        }
    }

    class ProgramC
    {
        public void main()
        {

            //入力
            string[] s = Console.ReadLine().Split(' ');
            long X = Math.Abs(long.Parse(s[0]));
            long k = long.Parse(s[1]);
            long D = long.Parse(s[2]);

            if(X == 0)
            {
                Console.WriteLine(D);
                return;
            }

            if(X >= k * D)
            {
                Console.WriteLine(X - k * D);
                return;
            }

            long count = X / D;
            k -= count;
            long ans1 = 0;
            long ans2 = 0;
          
           


            ans1 = X - count * D;
            ans2 = Math.Abs(X - (count + 1) * D);
            
            if (k % 2 == 0)
                Console.WriteLine(ans1);
            else
                Console.WriteLine(ans2);
           


        }
    }

    class ProgramD
    {
        public void main()
        {

            //入力
            long n = long.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            int wc = 0;
            int rc = 0;
            //まずは赤と白の石の数を数える
            for (int i = 0; i < n; i++)
            {
                if (s[i] == 'R')
                    rc++;
                else
                    wc++;
            }

            //白が0なら0（冷静に赤が0なら0だがこの下に通しても通る）
            if (wc == 0)
            {
                Console.WriteLine("0");
                return;
            }

            int rw = 0;
            int ww = 0;

            //左から赤の数だけ並べる。不一致の白の数を数える
            for (int i = 0; i < rc; i++)
            {
                if (s[i] == 'W')
                    rw++;
            }

            //残りは白。不一致の赤の数を数える
            for (int i = rc; i < n; i++)
            {
                if (s[i] == 'R')
                    ww++;
            }

            
            //答は、赤か白の違う数の小さい方と絶対値の差の和を足す
            Console.WriteLine(Math.Min(rw,ww) + Math.Abs(rw - ww));
            

        }

    }

    class ProgramE
    {

        public void main()
        {
            //入力
            string[] s = Console.ReadLine().Split(' ');
            long n = long.Parse(s[0]);
            long k = long.Parse(s[1]);

            long[] a = new long[n];

            string[] t = Console.ReadLine().Split(' ');

            for(int i = 0;i < n;i++)
                a[i] = long.Parse(t[i]);

            long min = 0;//最初を0にすると1に答えができる
            long max = 1000000000;//答候補の最大

            //二分探索（答えを決め打ちして、切る回数を数える。k回以下ならmax,そうでないならmin)
            //小さくした方が回数がかかるので、maxが満たす最小の丸太の長さ
            while(min + 1 != max)
            {
                long temp = (min + max) / 2;
                long cut = 0;
                //切る回数を数える
                for (int i = 0; i < n; i++)
                {
                    //tempが大きいなら切らない
                    if (a[i] < temp)
                        continue;
                    //割り切れるかどうかで回数は変わる
                    if(a[i] % temp == 0)
                        cut += a[i] / temp - 1;
                    else
                        cut += a[i] / temp;
                }

                //k回以下ならmax更新、そうでないならminを更新
                if (cut <= k)
                    max = temp;
                else
                    min = temp;

            }

            //答え出力
            Console.WriteLine(max);

        }


    }

}