implicit none
integer :: n
character(10) :: name(100), cswp
integer :: score(100), name_idx(100)
integer :: i, j,rswp
logical :: flg_swp
   
read *,n
do i = 1, n
   read *,name(i),score(i)
   name_idx(i) = i
enddo
   
! Sort name and score at the same time
! If two names are the same, see the two scores.
   i = n
   flg_swp = .false.
   do while (i > 1 .or. flg_swp)
      i = (i * 10) / 13
      if (i < 1) then
         i = 1
      else if (i == 9 .or. i == 10) then 
         i = 11
      endif
      flg_swp = .false.
      do j = 1, n-i
         if (name(j) == name(j+i)) then
            if (score(j) < score(j+i)) then  
               cswp = name(j) 
               name(j) = name(j+i)
               name(j+i) = cswp
               rswp = score(j)
               score(j) = score(j+i)
               score(j+i) = rswp
               rswp = name_idx(j)
               name_idx(j) = name_idx(j+i)
               name_idx(j+i) = rswp
               flg_swp = .true.
            endif
         else if (name(j) > name(j+i)) then
            cswp = name(j) 
            name(j) = name(j+i)
            name(j+i) = cswp
            rswp = score(j)
            score(j) = score(j+i)
            score(j+i) = rswp
            rswp = name_idx(j)
            name_idx(j) = name_idx(j+i)
            name_idx(j+i) = rswp
            flg_swp = .true.
         endif
      enddo
   enddo
   
do i = 1, n
   print '(i0)',name_idx(i)
enddo

end