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 # _n = ii() IO.binread(:line) a = IO.binread(:line) |> String.trim |> String.split |> Enum.map(&String.to_integer/1) # gg = a |> group_by2(fn a, b -> a+1 == b end) # for g <- gg, reduce: 0 do # acc -> # k = length(g) # div(k * (k-1), 2) + acc # end # |> IO.puts gg = a |> gp2(fn a, b -> a+1 == b end) IO.puts gg end def group_by2([], _pred), do: [] def group_by2(xs, pred) do n = Stream.chunk_every(xs, 2, 1, :discard) |> Stream.take_while(fn [a, b] -> pred.(a, b) end) |> Enum.count {a, b} = Enum.split(xs, n+1) [a | group_by2(b, pred)] end def gp2([], _pred), do: 0 def gp2(xs, pred) do n = Stream.chunk_every(xs, 2, 1, :discard) |> Stream.take_while(fn [a, b] -> pred.(a, b) end) |> Enum.count b = Enum.drop(xs, n+1) k = div((n+1) * n, 2) k + gp2(b, pred) #[n+1 | gp2(b, pred)] end end