N = gets.to_i A = gets.split.map { _1.to_i } D = A.chunk_while { |a,b| a + 1 == b } .map { _1.size } .select { _1 >= 2 } .map { _1 * (_1 - 1) / 2 } .sum .tap { puts(_1) }