program test03_2
 implicit none
 integer N
 character(len=10),allocatable :: S(:)
 character(len=10),allocatable :: Smax(:)
 integer,allocatable :: Sk(:)
 integer :: kaisuu=1, maxkaisuu=0
 integer i, ii
 integer :: j=1
 integer :: yatta=0

 read *, N
 allocate(S(N))
 allocate(Sk(N))
 allocate(Smax(N))
 do i=1,N
  read *, S(i)
! S(i)=trim(S(i))
 end do

Smax='a'
Sk=1

 call quicksort1(S,1,N)

 do i=2,N
  if (S(i)==S(i-1)) then
   Sk(i)=Sk(i-1)+1
 print *,i, S(i) ,Sk(i), 'yes'
  else
   Sk(i)=1
 print *,i, S(i) ,Sk(i), 'no'
  end if
 !print *,i, S(i) ,Sk(i)
 end do

 yatta=MAXVAL(Sk) 
!print *, 'yatta=',yatta

 print *,''
 do i=1,N
  if ( Sk(i) == yatta ) then
   print '(A)', trim(S(i))
  end if
 end do

!print *,''
!print '(A)', S(1)


contains
recursive subroutine quicksort1(a, first, last)
  implicit none
   character(len=10),intent(inout)::a(*)
   integer,intent(in)::first,last

   character(len=10)::x,t
   integer::i,j

   x = a((first+last)/2)
   i = first
   j = last
   do 
     do while (a(i) < x)
       i=i+1
     end do
     do while (x < a(j))
       j=j-1
     end do
     if (i >= j) exit
      t = a(i)
      a(i) = a(j)
      a(j) = t
      i=i+1
      j=j-1
   end do
   if (first < i-1) call quicksort1(a, first, i-1)
   if (j+1 < last)  call quicksort1(a, j+1, last)
 return
end subroutine quicksort1

endprogram test03_2
