// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($exp_input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                let start = std::time::Instant::now();
                let input = solve($exp_input);
                let end = start.elapsed();
                assert_eq!(input, $output, "{}.{:03}", end.as_secs(), end.subsec_millis());
                assert!(end.as_secs() <= 2, "expected_sec: {}sec, actual_sec: {}sec", 2, end.as_secs());
                assert!(end.as_secs() <= 1, "expected_sec: {}sec, actual_sec: {}sec", 1, end.as_secs());
                assert!(end.subsec_millis() <= 10, "expected_ms: {}ms, actual_ms: {}ms", 10, end.subsec_millis());
                assert!(end.subsec_millis() <= 2, "expected_ms: {}ms, actual_ms: {}ms", 2, end.subsec_millis());
            )*
        }
    };
}

test! {
r#"7
beat
vet
beet
bed
vet
bet
beet"# => r#"beet
vet"#,

r#"8
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo
buffalo"# => r#"buffalo"#,

r#"7
bass
bass
kick
kick
bass
kick
kick"# => r#"kick"#,

r#"4
ushi
tapu
nichia
kun"# => r#"kun
nichia
tapu
ushi"#,

}

use std::collections::HashMap;

fn solve(src: &str) -> String {
    let mut src_iter = src.split_whitespace();
    input! {
        source = src_iter,
        n: usize,
        s: [String; n],
    }

    let mut max_list:Vec<String> = Vec::new();
    let mut max = 0;

    let mut map = HashMap::new();
    for i in 0..n {
        let count = map.entry(s[i].to_string()).or_insert(0);
        *count += 1;

        if *count < max {
            continue;
        }

        if max < *count {
            max_list.clear();
            max = *count
        }

        if max == *count {
            max_list.push(s[i].to_string());
        }
    }
    max_list.sort();

    let mut ans = "".to_string();
    for i in 0..max_list.len() {
        ans.push_str(&max_list[i].to_string());
        if i != max_list.len() - 1 {
            ans.push_str(&"\n");
        }
    }

    ans.to_string()
}

Measured memory_bytes: 37768