n=gets.to_i

while p1 = $stdin.gets do
  p = p1.chomp.split(" ")
end

cange = []
p.zip(p.sort) do |p, p_sort|
  cange << p if p != p_sort
end

return puts 'NO' if cange.size > 2

canged = p.map do |p|
  case p
  when cange.nil?
    p
  when cange[0]
    cange[1]
  when cange[1]
    cange[0]
  else
    p
  end
end

if canged == p.sort
  puts 'YES'
else
  puts 'NO'
end
