use proconio::{fastout, input}; #[fastout] fn main() { input! { _n: usize, m: usize, a: [u32; m], } println!("{}", output(solve(m, a))); } fn solve(m: usize, a: Vec) -> Vec<(u32, u32)> { let mut ans = Vec::with_capacity(m); for a in a { if let Some((s, l)) = ans.last_mut() { if a == *s + *l { *l += 1; } else { ans.push((a, 1)); } } else { ans.push((a, 1)); } } ans } fn output(ans: Vec<(u32, u32)>) -> String { ans.len().to_string() + "\n" + &ans .into_iter() .map(|(s, l)| s.to_string() + " " + &l.to_string()) .collect::>() .join("\n") }