using System; using System.Linq; using System.Collections.Generic; public class P0079 { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var dict = new Dictionary(); foreach(int i in Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToList()) { dict[i] = dict.GetValueOrDefault(i) + 1; } var entries = dict.AsEnumerable().ToList(); Console.WriteLine(entries.OrderByDescending(pair => pair.Value).ThenByDescending(pair => pair.Key).First().Key); } }