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 rec(s, {0, 0}, pred, next) |> then(fn {_p, d} -> d end) |> IO.puts end def rec(s, acc, pred, next) do x = Enum.take(s, 1) |> hd a = next.(acc, x) if pred.(a) do a else rec(Stream.drop(s, 1), a, pred, next) end end def f(s, p, d, x) do t = Enum.take(s, 1) |> hd p2 = p + t d2 = d + abs(t) if p2 == x do d2 else f(Stream.drop(s, 1), p2, d2, x) end end end