object Main extends App {
  val Array(a,b,c,k) = io.StdIn.readLine.split(" ").map(_.toLong)
  
    if (a == b && b == c) println(0)
    else {
        def rec(count: Long, x: Long, y: Long, z: Long): (Long, Long, Long) = {
            if (k == count) (x,y,z)
            else rec(count+1, y+z, x+z, x+y)
        }
    
        val abc = rec(0, a,b,c) // (high-hashi, mid-hashi, low-hashi
        val result = abc._1 - abc._2
    
        if (math.pow(10, 18) < result.abs) println("Unfair")
        else println(result)
    }
}