tubeB = []
tubeC = []

n = STDIN.gets.to_i
n.times do
  balls = STDIN.gets.chop!.split(/ /)
  balls.each do |b| 
    b = b.to_i

    topB = tubeB[tubeB.length - 1] || 0
    topC = tubeC[tubeC.length - 1] || 0

    if topB < b 
      tubeB.push(b)
    elsif topC < b 
      tubeC.push(b)
    else
      print "NO\n"
      exit
    end 
  end
  print "YES\n" 
end