gets.to_i.times do
  f = false
  a = [0]
  b = [0]

  gets.split.map(&:to_i).each do |x|
    if a.last < x && ((x-a.last).abs <= (x-b.last).abs)
      a << x
    elsif b.last < x
      b << x
    else
      f=true
    end
    puts a: a, b: b
  end
  puts f ? "NO" : "YES"
end