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++ (GCC 9.2.1) (judge verdict: Wrong Answer)

// Biscuit_Generator
// https://atcoder.jp/contests/abc125/tasks/abc125_a
// date: 2020-08-15T19:20:35.753917

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=(ll) a;i<(ll) b;i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _repd(i,n) repdi(i,0,n)
#define repdi(i,a,b) for(ll i=(ll) b-1;i>=(ll) a;i--)
#define repd(...) _overload3(__VA_ARGS__,repdi,_repd,)(__VA_ARGS__)

#define all(x) x.begin(),x.end()
#define SIZE(x) ((ll)(x).size())

#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename T, typename ...Args>
void CIN(T& first, Args&... args) {
    ((cin >> first), ..., (cin >> args)); //C++17
}

template<char Sep, typename T, typename ...Args>
void COUNT_NL(const T& first, const Args&... args) {
    ((cout << first), ..., (cout << Sep << args)); //C++17
}

template<typename... Words>
void COUT(Words... words) {
    COUNT_NL<' '>(words...);
    cout << endl;
    return;
}

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange

int solve(void) {
    ll X,K,D;
    CIN(X,K,D);
//    COUT(X,K,D);
    if (K%2 == 0){
        D*=(ll) 2LL;
        K /= 2LL;
    } else {
        if(X>0) {
            X-=(ll) D;
        } else{
            X+=(ll) D;
        }
        K=(ll) (K-1LL)/2LL;
        D*=(ll) 2LL;
    }

    ll cnt = (ll) X / D;
    if ( K < cnt) {
        COUT(abs(X-K*D));
    } else {
        COUT(min(abs(X-cnt*D),abs(X-(cnt+1LL)*D)));
    }
    return 0;
}

int main(void){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);

    solve();
    return 0;
}