Problem:
Score : 100 points

Problem Statement

Cat Snuke is learning to write characters.
Today, he practiced writing digits 1 and 9, but he did it the other way around.

You are given a three-digit integer n written by Snuke.
Print the integer obtained by replacing each digit 1 with 9 and each digit 9 with 1 in n.

Constraints

111 \leq n \leq 999

n is an integer consisting of digits 1 and 9.

Input

Input is given from Standard Input in the following format:

n

Output

Print the integer obtained by replacing each occurrence of 1 with 9 and each occurrence of 9 with 1 in n.

Sample Input 1

119

Sample Output 1

991

Replace the 9 in the ones place with 1, the 1 in the tens place with 9 and the 1 in the hundreds place with 9. The answer is 991.

Sample Input 2

999

Sample Output 2

111

Solution in Rust (1.15.1) (judge verdict: Runtime Error)

use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::collections::HashMap;


fn main() {
  let n = read::<i32>();
  let mut even = HashMap::new();
  let mut odd = HashMap::new();

  for i in 1..n + 1 {
    let item = read::<u32>();
    if i % 2 == 0 {
      *even.entry(item).or_insert(0) += 1;
    } else {
      *odd.entry(item).or_insert(0) += 1;
    }
  }
  let even_max = get_max_key_value(&even);
  let odd_max = get_max_key_value(&odd);

  if even_max.0 != odd_max.0 {
    println!("{}", n as u32 - even_max.1 - odd_max.1);
  } else {
    even.remove(&even_max.0);
    odd.remove(&odd_max.0);

    let even_2nd_max = get_max_key_value(&even);
    let odd_2nd_max = get_max_key_value(&odd);
    if even_2nd_max.1 > odd_2nd_max.1 {
      println!("{}", n as u32 - odd_max.1 - even_2nd_max.1);
    } else {
      println!("{}", n as u32 - even_max.1 - odd_2nd_max.1);
    }
  }
}

fn get_max_key_value(map: &HashMap<u32, u32>) -> (u32, u32) {
  let mut max = (0, 0);
  for (key, value) in map {
    if max.1 < *value {
      max = (*key, *value);
    }
  }
  max
}