recursive function qsort(x) result(y)
  integer,intent(in) ::x(:)
  integer,allocatable::y(:)
  integer::pivot,total
  total = size(x)
  if (total <=1) then
     y = x
  else
     pivot = x(total/2)
     y = [qsort(pack(x, x .lt. pivot)), &
          pack(x, x .eq. pivot),        &
          qsort(pack(x, x .gt. pivot))]
  endif
end function qsort

program main
  interface
     recursive function qsort(x) result(y)
       integer,intent(in) ::x(:)
       integer,allocatable::y(:)
     end function qsort
  end interface
  integer::N,i,j,max_len,tmp, tmp2
  integer,allocatable::x(:),y(:),dp(:)
  read *, N
  allocate(x(N),y(N),dp(N))
  read *, x

  y = qsort(x)
  ! max length of good series @ index num
  dp = 1
  do i=2, N
     max_len = 0
     do j=1,i-1
        if(MOD(y(i),y(j)).eq.0) then
           max_len = MAX(max_len, dp(j))
        end if
     end do
     dp(i) = max_len + 1
  end do
  print '(i0)', MAXVAL(dp)

end program main