require 'pry'

X, K, D = gets.split.map(&:to_i)


def cal(x)
  puts "x=#{x}"
  return x if x < D
  xp = cal(x - 1) + D
  xm = cal(x - 1) - D
  result = if xp.abs < xm.abs
    xp
  else
    xm
  end
  puts "reslut=#{result}"
  result
end

result = cal(X)

puts result.abs