program main implicit none integer*8::N,K,i,j,count,tmp,tmp2,total integer*8,allocatable::D(:) data count/0/,total/0/ read *,N,K allocate(D(N)) read *,D do i=1, N-1 if(D(i).ne.i) then count = 0 tmp = i do tmp2 = D(tmp) ! print *,tmp,tmp2 D(tmp) = tmp tmp = tmp2 count = count + 1 if(tmp.eq.i) then total = total + count - 1 exit end if end do end if end do if(total .gt. K ) then print '("NO")' else if(MOD(total,2).eq.MOD(K,2)) then print '("YES")' else print '("NO")' end if ! print *, total, K ! call aprinter(D) contains subroutine aprinter(array) integer*8::array(:) character*32::cformat='(i0, (1x,i0))' write(cformat(5:9),'(i0)'),size(array) write(*,cformat) array end subroutine aprinter end program main