object Main extends App {
  @scala.annotation.tailrec
  def loop(pairs: List[(Int, Int)], k: Int, acc: Int): Int = pairs match {
    case _ if k <= 0 => acc
    case Seq() => acc
    case (i, j) :: xs if i <= k => loop(xs, k - i, acc + i * j)
    case (_, j) :: xs => loop(xs, 0, acc + k * j)
  }

  val sc = new java.util.Scanner(System.in)
  val A, B, C, K = sc.nextInt()
  println(loop(List(A, B, C).zip(List(1, 0, -1)), K, 0))
}
