n, k = gets.strip.split(' ').map(&:to_i) d = gets.strip.split(' ').map(&:to_i) =begin count = 0 count2 = 0 (0...n).each do |i| next if d[i] - 1 == i # print "#{i}:d[i]=#{d[i]} d[d[i] - 1]=#{d[d[i] - 1]}" if d[d[i] - 1] == i + 1 count += 1 else count2 += 1 end end p count p count2 if count2 == 0 if k - count / 2 >= 0 && (k - count / 2) % 2 == 0 puts "YES" else puts "NO" end elsif k - count / 2 - count2 + 1 >= 0 && (k - count / 2 - count2 + 1) % 2 == 0 puts "YES" else puts "NO" end =end count = 0 (0...n - 1).each do |i| next if d[i] - 1 == i jmin = 0 min = Float::INFINITY (i + 1...n).each do |j| if min > d[j] min = d[j] jmin = j end end d[i], d[jmin] = d[jmin], d[i] count += 1 end # p count if k - count >= 0 && (k - count) % 2 == 0 puts "YES" else puts "NO" end