class Yukicoder def initialize n = gets.to_i k = gets.to_i array = (1..n).to_a k.times do i, j = gets.split.map(&:to_i) array[i-1], array[j-1] = array[j-1], array[i-1] end list = gets.split.map(&:to_i) list = (1..n).map{|i| list.index(i)+1} swap_list = [] 0.upto(n-1) do |i| j = array.index(list[i]) while list[i] != array[i] array[j-1], array[j] = array[j], array[j-1] swap_list << "#{j} #{j+1}" j -= 1 end end puts swap_list.size puts swap_list end end Yukicoder.new