defmodule Main do def main do [n, m] = IO.read(:line) |> String.trim() |> String.split() |> Enum.map(&String.to_integer/1) p = IO.read(:line) |> String.trim() |> (fn s -> case s do "0" -> 0 "1" -> 1 _ -> s |> String.to_float() end end).() solve({n, m}, p) |> IO.puts() end def solve({n, m}, p) do case {n, m} do {1, 1} -> p {1, 2} -> 2 * :math.pow(p, 2) {1, _} -> m * :math.pow(p, 2) + :math.pow(p, 3) * (m - 2) {2, 1} -> 2 * :math.pow(p, 2) {_, 1} -> n * :math.pow(p, 2) + :math.pow(p, 3) * (n - 2) _ -> 4 * :math.pow(p, 3) + :math.pow(p, 4) * (2 * n + 2 * m - 8) + :math.pow(p, 5) * (n - 2) * (m - 2) end end end