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

change_needed = Array.new(n, 0)
(n - 1).times do |i|
  change_needed[i] = 1 if p[i] != p[i + 1] - 1
end

count = change_needed.count { |n| n == 1 }
if count.zero? || count == 2 || count == 4
  puts 'YES'
else
  puts 'NO'
end