program sample
    implicit none
    character(100)::s
    integer(8) :: i,j,m,n,k,d,x
    
  
    read(*,*) x,k,d
    x=abs(x)
    if(x/d>=k)then
        write(*,*)x-k*d
    else
        m=x/d
        if(mod(k-m,2)==0)then
            write(*,*)x-m*d
        
        else
            write(*,*)(m+1)*d-x
        end if
    end if
    stop
end program sample
  

