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)

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

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds; 
 
typedef long long int ll;
typedef long int li;

const ll mod = 1000000007;
const ll inf = 1000000000000000000;

typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vli> vvli;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef map<ll, ll> mll;
typedef map<ll, string> mls;
typedef map<string, ll> msl;
typedef pair<ll, ll> pll;

// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#pragma GCC optimize ("-O3")
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(), v.end()
#define mini(a) *min_element(all(a))
#define maxi(a) *max_element(all(a))
#define tol(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define tou(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define FOR(i, j, k, in) for(li i=j; i<k; i+=in)
#define RFOR(i, j, k, de) for(li i=j; i>=k; i-=de)
#define rep(i,j,k) FOR(i, j, k, 1)
#define rrep(i,j,k) RFOR(i, j, k, 1)
#define repc(v) for(auto it=v.begin(); it!=v.end(); it++)
#define rrepc(v) for(auto it=v.rbegin(); it!=v.rend(); it--)
#define T ll t; cin>>t; while(t--)

ll gen(){
    ll temp;
    cin>>temp;
    return temp;
}

ll power(ll a, ll b, ll m){    
    ll res=1;
    while(b>0){
        if(b&1){
            res=(res*a)%m;
            b--;
        }
        a=(a*a)%m;
        b=b>>1;
    }
    return res;
}

ll gcd(ll a, ll b){if(a==0)return b; else return gcd(b%a, a);}
ll lcm(ll a, ll b){return (a*b)/gcd(a,b);}

#define inpt(v) generate(all(v),gen)
#define sum(v) accumulate(all(v),0LL)
#define vpll vector<pll>
#define umap unordered_map
#define uset unordered_set
#define print(v) rep(i,0,n) cout<<v[i]<<" ";

int32_t main(){
  FAST

    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout); 

	
    ll x,k,d;
    cin>>x>>k>>d;

    ll X = (ll)abs(x);
    ll xto0 = X/d;

    if(xto0 >= k){
      x = x - k * d;
      cout<<(ll)abs(x);
    }
        
    else{
      k = k - xto0;
      if(x >= 0)
      x = x - xto0 * d;
      else 
      x = x + xto0 * d;

      if(k&1){
        if(x >= 0)
        x -= d;
        else
        x += d;        
      }

     cout<<(ll)abs(x);
    }
  
  return 0;
}