import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] types = new int[n]; for (int types_i = 0; types_i < n; types_i++) { types[types_i] = in.nextInt(); } System.out.println(findCommonBird(types)); } /** * Finds the most common bird type with the smallest id. * * @param types List of bird types. * @return The bird type. */ public static int findCommonBird(int[] types) { List birds = getBirds(types); int maxType = findCommonBird(birds); return maxType; } /** * Finds the most common bird with the smallest id. * * @param birds A list of birds. * @return The bird type. */ private static int findCommonBird(List birds) { int maxType = birds.get(0).getType(); int maxCount = birds.get(0).getCount(); for (Bird bird : birds) { if (bird.getCount() < maxCount) { break; } if (bird.getType() < maxType) { maxType = bird.getType(); } } return maxType; } /** * Constructs birds with the given types. * * @param types The types of birds. * @return List of birds. */ private static List getBirds(int[] types) { Bird a = new Bird(1); Bird b = new Bird(2); Bird c = new Bird(3); Bird d = new Bird(4); Bird e = new Bird(5); for (int t : types) { switch (t) { case 1: a.count(); break; case 2: b.count(); break; case 3: c.count(); break; case 4: d.count(); break; case 5: e.count(); break; } } List birds = Arrays.asList(a, b, c, d, e); Collections.sort(birds); return birds; } } /** * A bird class. * * @author abantej */ class Bird implements Comparable { /** * The type of bird. */ private int type; /** * The number of birds this type. */ private int count; /** * Gets the type of bird. * * @return The type of bird. */ public int getType() { return type; } /** * The number of birds of its type. * * @return The number of birds of its type. */ public int getCount() { return count; } /** * Increments the count by 1. */ public void count() { this.count += 1; } /** * The constructor. * * @param type Type of bird. */ public Bird(int type) { this.type = type; } /** * Used in sorting the bird in descending order. */ @Override public int compareTo(Bird birds) { return birds.count - this.count; } }