let readIntArray () =
    stdin.ReadLine().Split(" ") |> Array.map int64

let rec solve (now: int64) (rest: int64) d: int64 =
    let a: int64 = now + d
    let b: int64 = now - d

    let next =
        if (System.Math.Abs a) > (System.Math.Abs b)
        then b
        else a

    if rest = 0L then
        (System.Math.Abs now)
    else if (System.Math.Abs now) < (System.Math.Abs next)
            && rest % 2L = 0L then
        (System.Math.Abs now)
    else if (System.Math.Abs now) < (System.Math.Abs next)
            && rest % 2L = 1L then
        (System.Math.Abs next)
    else
        solve next (rest - 1L) d

readIntArray ()
|> fun [| a; b; c |] -> solve a b c
|> printfn "%d"
