fn main() { let (r, w) = (std::io::stdin(), std::io::stdout()); let mut sc = IO::new(r.lock(), w.lock()); let n = sc.read(); let mut a: Vec = sc.vec(n); let mut place = vec![0; n]; for i in 0..n { place[a[i] - 1] = i; } let mut cost = 0; for i in 0..n { let idx = a[i] - 1; if i != idx { a.swap(i, place[i]); place.swap(i, idx); cost += 1; } } println!("{}", cost); } pub struct IO(R, std::io::BufWriter); impl IO { pub fn new(r: R, w: W) -> Self { Self(r, std::io::BufWriter::new(w)) } pub fn write(&mut self, s: S) { use std::io::Write; self.1.write_all(s.to_string().as_bytes()).unwrap(); } pub fn read(&mut self) -> T { use std::io::Read; let buf = self.0.by_ref().bytes() .map(|b| b.unwrap()) .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t') .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t') .collect::>(); unsafe { std::str::from_utf8_unchecked(&buf) }.parse().ok().expect("Parse error.") } pub fn chars(&mut self) -> Vec { self.read::().chars().collect() } pub fn usize0(&mut self) -> usize { self.read::() - 1 } pub fn vec(&mut self, n: usize) -> Vec { (0..n).map(|_| self.read()).collect() } }