defmodule Int do def fac(n, m) do ans = [] cond do m*m > n -> ans ++ [n] rem(n, m) == 0 -> ans ++ [m] ++ (div(n, m) |> fac(m)) true -> ans ++ fac(n, m+1) end end end defmodule Comb do def permutations(n, n_remain, used) do ans = for x <- 1..n do if Enum.at(used, x-1) == false do ps = permutations(n, n_remain-1, List.replace_at(used, x-1, true)) case n_remain <= 1 do true -> [x] _ -> Enum.map(ps, fn p -> List.insert_at(p, -1, x) end) end end end |> Enum.filter(fn p -> p != nil end) |> List.flatten case n_remain > 1 do true -> Enum.chunk(ans, n_remain) _ -> [ans] end end end defmodule Prob do def judge(a, b, pa, pb) do result = for x <- 1..length(a) do Enum.at(a, Enum.at(pa, x-1)-1) > Enum.at(b, Enum.at(pb, x-1)-1) end length(Enum.filter(result, fn r -> r == true end))*2 > length(a) end end defmodule Main do def main do n = IO.gets("") |> String.trim() |> String.to_integer used = for _ <- 1..n, do: false p = Comb.permutations(n, n, used) q = p a = IO.gets("") |> String.trim() |> String.split(" ") |> Enum.map(fn s -> String.to_integer(s) end) b = IO.gets("") |> String.trim() |> String.split(" ") |> Enum.map(fn s -> String.to_integer(s) end) result = for pa <- p, pb <- q, do: Prob.judge(a, b, pa, pb) ans = length(Enum.filter(result, fn r -> r == true end))/length(result) IO.inspect(ans) end end