# 4
n = gets.chomp.to_i

# 1 2 4 3
a = gets.chomp.split(" ").map(&:to_i);

# 1 2 3 4
b = a.min(n)

u = 0

for i in 0..(n-1) do
  if a[i] != b[i]
    u += 1
  end
end

if u == 0 || u == 2
  puts "YES"
else
  puts "NO"
end