program main implicit none integer::N,K,i,j,l type bar integer::x,y end type bar integer::indx(100),pos(100),ans(100),temp type(bar)::bars(6000) data l/0/ read *,N,K if(K.gt.0) read *,bars(1:K) read *,ans(1:N) indx = (/(i,i=1,N)/) do i=1,K temp = indx(bars(i)%y) indx(bars(i)%y) = indx(bars(i)%x) indx(bars(i)%x) = temp end do do i=1,N pos(indx(i)) = i end do print *, indx(1:N) do i=1,N if(indx(i).eq.ans(i)) cycle do j=pos(ans(i))-1,i,-1 l = l + 1 bars(l)%x = j bars(l)%y = j+1 pos(indx(i)) = pos(indx(i)) + 1 indx(j+1) = indx(j) end do indx(i) = ans(i) print *, indx(1:N) end do print '(i0)', l do i=1,l print '(i0," ",i0)',bars(i)%x,bars(i)%y end do end program main