#include<bits/stdc++.h>
using namespace std;
#define DBG(a) cout<<#a<<':'<<a<<endl;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define btoe(v) (v).begin(),(v).end()
#define etob(v) (v).rbegin(),(v).rend()
#define F first
#define S second
#define SZ size()
#define pow(a,b) (pow(a,b)+0.5)

typedef unsigned long long int ulli;
typedef long long int lli;
typedef long double ldbl;
#define f(i,a,b) for(int i=(a); i<(b); ++i)
#define fr(i,a,b) for(int i=(a); i>(b); --i)
#define fl(i,a,b) for(lli i=(a); i<(b); ++i)
#define flr(i,a,b) for(lli i=(a); i>(b); --i)
#define w(x) lli x; cin>>x; while(x--) 
#define inpn(n,v,T) T n; cin>>n; vector<T> v(n); fl(i,0,n) cin>>v[i];
#define inp(n,v,T) vector<T> v(n); fl(i,0,n) cin>>v[i];

typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<pii> vpii;typedef vector<vector<pii>> vvpii;typedef pair<lli,lli> plli;typedef vector<lli> vlli;typedef vector<vlli> vvlli;typedef vector<plli> vplli;typedef vector<vector<plli>> vvplli;typedef vector<bool> vb;typedef vector<string> vs;typedef vector<vector<string>> vvs; typedef vector<char> vc; typedef vector<vc> vvc;

#define unmp unordered_map

#define PRIME ((lli)(1e9+7ll))
#define PRIME2 (998244353ll)
const lli TEN_18 = 1e18;
const lli TEN_9 = 1e9;
const lli TEN_5 = 1e5;

inline void debugORfast(int a=1,int b=1){
    if(a){
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
        #endif
    }
    if(b){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
}}

template<typename T>
void print(const T &v, int begin=-1, int end=-1, int w=2, bool printLen=false)
{
	if(begin!=-1 and end==-1) end = v.SZ;
	else if(begin==-1 and end!=-1) begin = 0;
	else if(begin==-1 and end==-1){
		begin=0; end=v.SZ;
	}
	if(begin<=end){
		if(printLen) cout<<end-begin<<endl;
		fl(i,begin,end) cout<<setw(w)<<v[i]<<' ';
		cout<<endl;
	}else{
		if(printLen) cout<<abs(end-begin)<<endl;
		flr(i,begin,end) cout<<setw(w)<<v[i]<<' ';
		cout<<endl;
	}
}

const int INF = 100000000;
int n,m;
//vvc g;
vvi mons;
int dx[] = {-1,0,0,1};
int dy[] = {0,-1,1,0};

int main(){
	debugORfast(0,1);
	lli x,k,d;
	cin>>x>>k>>d;
	lli ratio = abs(x)/d;
	if(k<ratio){
		cout<<abs(abs(x)-(d*k))<<endl;
	}else{
		if((k)%2==(ratio)%2){
			cout<<abs(x)%d<<endl;
		}else{
			cout<<abs(abs(x)%d - d)<<endl;
		}
	}
	return 0;
}

/*
int main()
{
	debugORfast(0,1);
	cin>>n>>m;
	g.resize(n,vc(m));
	mons.resize(n,vi(m,INF));
	vector<vb> inQ(n,vb(m,false));
	vvpii par(n,vpii(m,{-1,-1}));
	vvi dist(n,vi(m,INF));
	queue<pii> q;
	queue<pii> q2;
	f(i,0,n){
		f(j,0,m){
	   		cin>>g[i][j];
			if(g[i][j]=='M'){
				q.push({i,j});
				mons[i][j]=0;
				inQ[i][j]=1;
			}else if(g[i][j]=='A'){
				q2.push({i,j});
				par[i][j]={i,j};
				dist[i][j]=0;
			}
		}
	}

	//multi source BFS
	//requires queue built, inQ table and mons data table initialised
	//returns filled mons table
	while(!q.empty()){
		int x=q.front().F;
		int y=q.front().S;
		q.pop();
		f(k,0,4){
			int nx = x+dx[k];
			int ny = y+dy[k];
			if(nx<0 or nx>=n or ny<0 or ny>=m or g[nx][ny]=='#') continue;
			if(mons[x][y]+1 < mons[nx][ny])
				mons[nx][ny]=mons[x][y]+1;
			if(!inQ[nx][ny])
			{
				q.push({nx,ny});
				inQ[nx][ny]=true;
			}
		}
	}

	bool ans=false;
	int ansi,ansj;
	inQ.clear();
	inQ.resize(n,vb(m,false));
	inQ[q2.front().F][q2.front().S]=true;
	while(!q2.empty()){
		int x = q2.front().F;
		int y = q2.front().S;
		q2.pop();
		if(x==0 or x==n-1 or y==0 or y==m-1){
			ansi=x; ansj=y;
			ans=true;
			break;
		}
		f(k,0,4){
			int nx = x+dx[k];
			int ny = y+dy[k];
			if(nx<0 or nx>=n or ny<0 or ny>=m or g[nx][ny]!='.') continue;
			if(mons[nx][ny] > dist[x][y]+1 and !inQ[nx][ny]){
				dist[nx][ny] = dist[x][y]+1;
				q2.push({nx,ny});
				inQ[nx][ny]=1;
				par[nx][ny]={x,y};
			}
		}
		if(ans) break;
	}

	if(ans){
		cout<<"YES"<<endl;
		string path;
		int pi=-1,pj=-1;
		int x=ansi,y=ansj;
		do{
			pi=x; pj=y;
			x = par[pi][pj].F;
			y = par[pi][pj].S;
			if(x<pi) path.PB('D');
			else if(x>pi) path.PB('U');
			else if(y<pj) path.PB('R');
			else if(y>pj) path.PB('L');
		}while(x!=pi or y!=pj);

		reverse(btoe(path));
		cout<<path.SZ<<endl;
		cout<<path<<endl;
	}
	else cout<<"NO"<<endl;

	return 0;
}
*/


Measured memory_bytes: 3512