func main() {
    var xkd = readLine()!.split(separator: " ").map{Int($0)!}
    if xkd[0] < 0 {
        xkd[0] = -xkd[0]
    }
    let remainder = xkd[0] % xkd[2]
    let devided = xkd[0] / xkd[2]
    if devided >= xkd[1] {
        print(xkd[0]-xkd[1]*xkd[2])
    } else {
        xkd[1] -= devided
        print(xkd[1] % 2 == 0 ? remainder : xkd[2] - remainder)
    }
    return
}

main()
