program poll
    implicit none
    integer(4):: n,i,count
    character(10),allocatable:: s(:)

    read*, n   
    allocate(s(n))
    do i=1,n
        read*,s(i)
    end do

    call smerge_sort(s, 1,n)

    count = serch_max_remain_word(s)
    count = serch_max_remain_word(s, (count))
    

contains
function serch_max_remain_word(s, count_print) result(max_count)
    integer(4):: max_count
    integer(4),intent(in), optional:: count_print
    character(10),allocatable:: s(:)
    integer(4):: i
    count=1
    max_count=0

    do i=2,size(s(:))
        if (s(i) == s(i-1)) then
            count=count+1
        else
            max_count=max(max_count,count)
            if (present(count_print)) then
                if (count == count_print) print*,s(i-1)
            end if
            count=1
        end if
    end do
    max_count=max(max_count,count)
    if (present(count_print)) then
        if (count == count_print) print*,s(i-1)
    end if
end function

recursive subroutine smerge_sort(s, fst,lst)
    integer(4):: fst,lst,mid
    character(10):: s(:), tmp

    if (lst-fst < 2) then
        if (s(lst) < s(fst)) then
            tmp = s(fst)
            s(fst) = s(lst)
            s(lst) = tmp
        end if
        return
    end if

    mid = (fst+lst)/2
    call smerge_sort(s,fst,mid)
    call smerge_sort(s,mid+1,lst)
    call smerge(s,fst,mid,lst)

end subroutine

subroutine smerge(s,fst,mid,lst)
    integer(4):: fst,mid,lst
    integer(4):: li,ri,ti
    character(10):: s(:)
    character(10),allocatable:: tmp(:)

    allocate(tmp(lst-fst+1))
    li=fst
    ri=mid+1
    ti=1

    do while(li <= mid .and. ri <= lst)
        if (s(li) <= s(ri)) then
            tmp(ti) = s(li)
            li=li+1
        else
            tmp(ti) = s(ri)
            ri=ri+1
        end if
        ti=ti+1
    end do

    if (ri > lst) then
        tmp(ti:) = s(li:mid)
    else
        tmp(ti:) = s(ri:lst)
    end if

    s(fst:lst) = tmp(:)
    deallocate(tmp)
end subroutine
end program

