n = gets().to_i
a = gets().split(' ').map(&:to_i)

big = -1
s = 0
for i in 0..(n-1)
  if i < n - 1
    if a[i] > a[i + 1]
      case s
      when 0 then
        s = 1
        big = i
      when 1 then
        s = 2
        break # impossible
      end
    end
  end
  if big != -1
    if (a[big - 1] < a[i] || big == 0) && (a[i] < a[big + 1] || big == n - 1) &&
      a[i - 1] < a[big] && (a[big] < a[i + 1] || i == n - 1)
      s = 3
      break
    end
  end
end
  
  case s
when 0, 3 then
  puts 'YES'
else
  puts 'NO'
end
    