#!/bin/python3 from collections import Counter MIN_EXPECTED = 5 MAX_EXPECTED = 2 * 10**5 INPUT_RANGE = range(1,6) def sanity_check(expected:int, recieved:list) -> bool: """ Checks the inputs againts the expected inputs and contraints. :param expected: The number of expected arguments. :param recieved: An array of the recieved arguments :return: True if valid, raises Exception if not. """ allowed_types = list(map(str, INPUT_RANGE)) # Gets an array of any recieved values that aren't in the allowed types blacklist = set(recieved) - set(allowed_types) if expected != len(recieved): raise ValueError ('The number of arguments does not match expected amount.') elif expected < MIN_EXPECTED: raise ValueError ("There are not enough birds to sort. The minimum input is 5") elif expected > MAX_EXPECTED: raise ValueError ('That is far too many birds. Max input is 2 x 10^5') elif blacklist: raise ValueError ( 'The folowing arguments are invalid: {} (allowed are: {})'.format( ", ".join(blacklist), allowed_types ) ) return True n = int(input().strip()) types = input().strip().split(' ') if sanity_check(n, types): # Counter docs here: https://docs.python.org/dev/library/collections.html#collections.Counter counted_types = Counter(types).most_common() # List comprehension for all the id's that match the most common and then minning it. print(min([ct[0] for ct in counted_types if ct[1] == counted_types[0][1]]))