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() a = li() gg = a |> group_by2(fn a, b -> a+1 == b end) for g <- gg do k = length(g) div(k * (k-1), 2) end |> Enum.sum |> IO.puts 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 end