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 input() a = li() 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 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 group_by2([], _pred), do: [] def group_by2([x | xs], pred), do: _group_by2(xs, pred, [x]) defp _group_by2([], _pred, acc), do: [Enum.reverse(acc)] defp _group_by2([x | xs], pred, acc) do if pred.(hd(acc), x) do _group_by2(xs, pred, [x | acc]) else a = Enum.reverse(acc) [a | _group_by2(xs, pred, [x])] end end end