defmodule Main do
  def main do
    IO.stream(:stdio, :line)
    |> Enum.take(4)
    |> Enum.map(&String.trim/1)
    |> Enum.map(&String.to_integer/1)
    |> process(0)
    |> IO.inspect()
  end
  
  def process([0, _k, _x, _y], acc), do: acc
  
  def process([n, k, x, y], acc) when n > k, do: process([n-1, k, x, y], acc + y)
  def process([n, k, x, y], acc), do: process([n-1, k, x, y], acc + x)
end