n = gets
p = gets.strip.split.map(&:to_i)

c = 0

if p == p.sort
  puts "YES"
  exit
end

p.each.with_index(1) do |num,i|
  if num > i 
    c = c + i
    if c > 2
      puts "NO"
      exit
    end
  end
end
puts "YES"