defmodule Main do def count_num(i, a, b, c, d) do cond do i > b -> 0 i >= c && i <= d -> 1 + count_num(i + 1, a, b, c, d) True -> count_num(i + 1, a, b, c, d) end end def same_number_count(a, b, c, d) do count_num(a, a, b, c, d) end def solve(a, b, c, d) do (b - a + 1) * (d - c + 1) - same_number_count(a, b, c, d) end def main do [a, b, c, d] = IO.gets("") |> String.trim |> String.split |> Enum.map(&String.to_integer/1) solve(a, b, c, d) |> IO.puts end end