use proconio::{input, marker::Usize1}; fn main() { input! { n:usize, k:usize, mut xy:[(Usize1,Usize1);k], a:[Usize1;n], } let mut ids_a = vec![0; n]; for i in 0..n { ids_a[a[i]] = i; } for i in 0..n { let mut crr = ids_a[i]; for &(x, y) in xy.iter() { if crr == x { crr = y; } else if crr == y { crr = x; } } if crr < i { while crr < i { xy.push((crr, crr + 1)); crr += 1; } } if i < crr { while i < crr { xy.push((crr, crr - 1)); crr -= 1; } } } let l = xy.len() - k; println!("{}", l); for &(x, y) in &xy[k..] { println!("{} {}", x + 1, y + 1); } }