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 x = ii() s = Stream.cycle([2, 2, -1, -1, 2, -1, -1]) pred = fn {p, _d} -> p == x end next = fn {p, d}, x -> {p+x, d+abs(x)} end {_, d} = loop(s, {0, 0}, pred, next) IO.puts d end def loop(stream, acc, pred, next) do x = Enum.take(stream, 1) |> hd a = next.(acc, x) if pred.(a) do a else loop(Stream.drop(stream, 1), a, pred, next) end end end