use std::collections::HashMap;

fn main() {
    let mut numbers = vec![100, 23, 1, 2, 100, 38, 57, 100, 23, 44, 163];
    numbers.sort();

    let is_even = numbers.len() % 2 == 0;
    let median: i32;
    let mut count = HashMap::new();

    if is_even {
        let n1 = numbers[(numbers.len() / 2) - 1];
        let n2 = numbers[numbers.len() / 2];
        median = (n1 + n2) / 2;
    } else {
        median = numbers[numbers.len() / 2];
    }

    let mut mode: i32 = 0;
    
    for num in numbers {
        let entry = count.entry(num).or_insert(0);
        *entry += 1;

        if *entry > count.get(&mode).copied().unwrap_or(0) {
            mode = num;
        }
    }

    println!("median: {median}");
    println!("mode: {mode}");
}
