let rec power ( * ) one m = function
  | 0 -> one
  | n when n mod 2 = 0 ->
      power ( * ) one (m * m) (n / 2)
  | n ->
      m * power ( * ) one m (n - 1)

let () = Scanf.scanf "%d %d %d %d" @@ fun a b c k ->
  let mat =
    power
      (fun x y ->
        Array.init 3 (fun i ->
          Array.init 3 (fun j ->
            Array.fold_left ( +. ) 0. @@ Array.init 3 (fun k -> x.(k).(i) *. y.(j).(k)))))
      [|[| 1.; 0.; 0. |];
        [| 0.; 1.; 0. |];
        [| 0.; 0.; 1. |]|]
      [|[| 0.; 0.5; 0.5 |];
        [| 0.5; 0.; 0.5 |];
        [| 0.5; 0.5; 0. |]|] k in
  let a' = mat.(0).(0) *. float_of_int a +. mat.(0).(1) *. float_of_int b +. mat.(0).(2) *. float_of_int c in
  let b' = mat.(1).(0) *. float_of_int a +. mat.(1).(1) *. float_of_int b +. mat.(1).(2) *. float_of_int c in
  Printf.printf "%d\n" @@ int_of_float @@ (a' -. b') *. 2. ** float_of_int k