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)


// Problem : 
// 			C - Walking Takahashi
// 			
// 		
// Contest : AtCoder - AtCoder Beginner Contest 175
// URL : https://atcoder.jp/contests/abc175/tasks/abc175_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*when the going gets tough the tough gets going  */
/*we are what we repeatedly do , Excellence then is not an act but a habit  - aristotle */
/*The best way to predict the future is to create it - abraham lincoln*/
/*First think , second believe , third dream and finally dare - walt disney*/
/*It is during our darkest moments that we must focus to see the light */
/*Nothing is impossible the word itself says "i'm fucking possible man just try me again and again till i seem impossible "*/
/*Dont judge each day by the harvest you reap but by the seeds you plant */
/*Do not dwell in the past, do not dream of the future, concentrate the mind on the present moment*/
/*Success is not final failure is not fatal : it is the courage to continue that counts */ 
/*the future belongs to those who believe in the beauty of their dreams */
/*The pessimist complains about the wind , the optimist waits for it to change; the realist adjusts the sails  */
/*Believe you can and you are half way there */
/*Everything has beauty but not everyone sees it */
/*Life is not about finding yourself , life is about creating yourself*/
/*You are the average of the 5 people you spend the most time with .........*/
/*Everything is hard before it is easy see for example now the list of examples is very long hahahahahaha...... ......*/
/*I believe in miracles .......*/
#include<bits/stdc++.h>
#define LL long long 
#define LD long double
#define pb push_back

#define P(n,m) pair<n,m> 

#define V(n) vector<n>
#define IN insert
#define wht while (t--)
#define FU( i , a  , n ) for ( int i = (int)a ; i <=(int)n ; i++  )
#define FD( i , n , a ) for (int i = (int)n ; i >=(int)a ;i--)
#define REP(i,n) for ( int i = 0 ; i < (int)n;  i++)
#define FST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define SZ(a) int((a).size())
#define pi(n) printf("%d" , n ) 
#define pl(n) printf("%lld" , n )
#define ff first
#define ss second
#define ii(n) scanf("%d" , &n)
#define il(n) scanf("%lld" , &n )
#define LB lower_bound
#define UB upper_bound
#define BS binary_search
#define ALL(V) V.begin(), V.end()
#define ic(n) cin>>n
#define pr printf
#define INF 99999999
#define en endl
using namespace std ;
struct HASH {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
    static uint64_t splitmix64(const pair<LL,LL>& p) {
        // http://xorshift.di.unimi.it/splitmix64.c
         static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        LL x = p.first + FIXED_RANDOM, y = p.second+ FIXED_RANDOM;
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
          y += 0x9e3779b97f4a7c15;
        y = (y ^ (y >> 30)) * 0xbf58476d1ce4e5b9;
        y = (y ^ (y >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31) ^  y ^ (y >> 31);
    }

    size_t operator()(const pair<LL,LL>& p) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(p);
    }
};
const int dx4[4]={-1, 0, 1, 0}, dy4[4]={0, 1, 0, -1};
const int dx8[8]={-1, -1, 0, 1, 1, 1, 0, -1}, dy8[8]={0, 1, 1, 1, 0, -1, -1, -1};

int n;
string str ;

void solve()
{
	int   m ,a , b ,c ;
	LL x , k , d ;
	cin>> x >> k >> d ;
	
	x = abs(x ) ;
	
	if (x / d >= k ) 
	{
		cout << x - (k)*d<< en;
		return;
	}
	
	if ( x % d  )
	{
		cout << x % d << en;
		return;
	}
	
	k = k - ( x - d )/d ;
	if (k % 2 == 0  )
	{
		cout << d << en;
		return;
	}
	cout << 0 ;
	return;
	
}
int main()
{
	FST;
	int tc = 1 ;
    // cin>> tc;
    while(tc--)
    {
    	solve();
    }	
   
   
	return 0 ;
	
 
}