program main
Implicit None
	integer(8)::n,i,j,t,f,e,k
	integer(8),allocatable::p(:),x(:)
	character(len = 10),allocatable::s(:)
	character(len =10)::tmp
	
	read*,n
	allocate(s(n),p(n),x(n))
	
	do i = 1,n
		read*,s(i),p(i)
		x(i) = i
	enddo
	
	do i = 1,n-1
		do j = 2,n
			if(s(j) < s(j-1))then
				tmp = s(j) ;t = p(j) ;k = x(j)
				s(j) = s(j-1) ;p(j) = p(j-1) ;x(j) = x(j-1)
				s(j-1) = tmp ;p(j-1) = t ;x(j-1) = k
			endif
		enddo
	enddo
	
	f = 1
	do i = 1,n-1
		if(s(i) /= s(i+1))then
			e = i
			if(e/=f) call h2(p(f:e),x(f:e),e-f+1)
			x(f:e) = x(e:f:-1)
			f = e+1
		endif
	enddo
	
	if(f /= n)then
		e = n
		if(e/=f) call h2(p(f:e),x(f:e),e-f+1)
		x(f:e) = x(e:f:-1)
	endif
	
	do i = 1,n
		print"(i0)",x(i)
	enddo
end program main

subroutine h2(a,b,n)
implicit None
	integer(8)::a(n),b(n),x,y
	integer(8)::n,i,ie,i0,i1,i2
	
	do i = n/2,1,-1
		x = a(i);y = b(i);ie = n + 1; i0 = i; i1 = i0 * 2
		do while(i1 < ie)
			i2 = i1 + 1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				b(i0) = b(i1);b(i1) = y
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
	do ie = n,2,-1
		x = a(ie);y = b(ie)
		a(ie) = a(1);b(ie) = b(1)
		a(1) = x;b(1) = y
		i0 =1;i1 =2
		do while(i1 <ie)
			i2 = i1 +1
			if(i2 < ie .and. a(i1) < a(i2)) i1 = i2
			if(a(i1) > x)then
				a(i0) = a(i1);a(i1) = x
				b(i0) = b(i1);b(i1) = y
				else
				exit
			endif
			i0 = i1;i1 = i0 *2
		enddo
	enddo
end subroutine h2