PROGRAM ATCODER

implicit none
integer(16) :: n,i,ti,tp,j
character(len=10) :: tmp
integer(16),allocatable :: p(:),turn(:)
character(len=10),allocatable :: s(:)

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

do i = 1, n, 1
  turn(i) = i
end do

do i = 1, n-1, 1
  do j = i+1, n, 1
    if ( p(i) < p(j) ) then
      tp = p(i)
      p(i) = p(j)
      p(j) = tp
      ti = turn(i)
      turn(i) = turn(j)
      turn(j) = ti
      tmp = trim(s(i))
      s(i) = trim(s(j))
      s(j) = trim(tmp)
    end if
  end do
end do

do i = 1, n-1, 1
  do j = i+1, n, 1
    if ( trim(s(i)) > trim(s(j)) ) then
      tmp = trim(s(i))
      s(i) = trim(s(j))
      s(j) = trim(tmp)
      ti = turn(i)
      turn(i) = turn(j)
      turn(j) = ti
    end if
  end do
end do

print'(i0)', turn(1:n)

END PROGRAM ATCODER
