       program csort

       integer  L(100), C(50)
       integer  i, j, n, max, pos;


*      Read in list L

       print *, "Number of elements?"
       read *, n

       print *, "Enter list:"
       do i = 1, n
           read *, L(i)
       end do
        
*      Find maximum value in list L

       max = 0
       do i = 1, n
           if (L(i).gt.max) then
    	       max = L(i)
           end if
       end do

*      Count-sort algorithm

       do i = 1, max
           C(i) = 0
       end do
       do i = 1, n
           C(L(i)) = C(L(i)) + 1
       end do
       pos = 1
       do i = 1, max
           do j = 1, C(i)
    	       L(pos) = i
    	       pos = pos + 1
           end do
       end do
       
*      Print out sorted version of list L

       print *, "Sorted list:"
       do i = 1, n
           print *, L(i)
       end do

       end
