defmodule Main do def input, do: IO.read(:line) |> String.trim def ii, do: input() |> String.to_integer def li, do: input() |> String.split |> Enum.map(&String.to_integer/1) def yn(b), do: IO.puts(if b, do: "Yes", else: "No") def main do t = ii() for _ <- 1..t do [a, b, c] = li() case kadomatu(a, b, c) do [] -> -1 res -> res |> Enum.map(fn {x, y, z} -> (a-x) + (b-y) + (c-z) end) |> Enum.min end |> IO.puts end end def kadomatu(a, b, c) do for {a, b, c} <- [{b, a, c}, {b, c, a}, {a, c, b}, {c, a, b}] do f(a, b, c) end |> List.flatten |> Enum.uniq |> Enum.filter(fn {x, y, z} -> a >= x and b >= y and c >= z end) end def f(1, _, _), do: [] def f(_, 1, _), do: [] def f(a, b, c) do cond do a <= b -> x = b - a + 1 f(a, b-x, c) b <= c -> x = c - b + 1 f(a, b, c-x) true -> [{a, c, b}, {b, c, a}, {b, a, c}, {c, a, b}] end end end