defmodule Main do def main do _ = IO.gets("") sorted_list = IO.gets("") |> String.trim |> String.split |> Enum.map(&String.to_integer/1) |> Enum.sort index = median_index(sorted_list) median(sorted_list, index) |> IO.puts end def median(sorted_list, index) when is_integer(index) do sorted_list |> Enum.at(index) end def median(sorted_list, index) when is_list(index) do index |> Enum.map(&Enum.at(sorted_list, &1)) |> Enum.sum |> (fn sum -> sum/2 end).() end def median_index(sorted_list) do list_count = sorted_list |> Enum.count case list_count |> rem(2) do 0 -> list_count/2 - 0.5 |> (fn hoge -> [floor(hoge), ceil(hoge)] end).() 1 -> list_count/2 - 0.5 |> ceil end end end