implicit none
integer :: n
integer,allocatable :: a(:),idx(:)
integer :: i,jcomb,rswp
logical :: flg_swp

read *,n
allocate(a(n))
allocate(idx(n))
do i = 1,n
   read *,a(i)
   idx(i) = i
enddo

   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 jcomb = 1, n-i
         if (a(jcomb) > a(jcomb+i)) then
            rswp = a(jcomb) 
            a(jcomb) = a(jcomb+i)
            a(jcomb+i) = rswp
            rswp = idx(jcomb)
            idx(jcomb) = idx(jcomb+i)
            idx(jcomb+i) = rswp
            flg_swp = .true.
         endif
      enddo
   enddo

do i = 1, n
   print '(i0)',a(merge(n,n-1,idx(i)==n))
enddo

stop
end