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,max_val integer,allocatable::x(:),y(:) integer::dp(10**6) data dp/1000000*0/ read *, N allocate(x(N),y(N)) read *, x y = qsort(x) max_val = y(N) do i=1,N dp(y(i)) = 1 end do max_len = 1 do i=1,N tmp = y(i) tmp2 = dp(y(i)) do j = tmp+tmp, max_val, tmp dp(j) = MAX(dp(j), tmp2 + 1) end do max_len = MAX(max_len, dp(y(i))) end do print '(i0)', max_len end program main