Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	for i := 0; i < n; i++ {
		a := -1
		b := -1
		ans := true
		// それぞれの筒の一番上にあるたまの数字に着目すればよい
		for j := 0; j < 10; j++ {
			x := nextInt()
			if x > a {
				a = x
			} else if x > b {
				b = x
			} else {
				ans = false
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

Python: def int_input():
    return list(map(int, input().split()))


def is_sorted(l):
    return all(l[i] <= l[i + 1] for i in range(len(l) - 1))


def dfs(arr, i, a, b):
    if i == 10:
        return is_sorted(a) and is_sorted(b)
    na = a + [arr[i]]
    nb = b + [arr[i]]
    return any([
        dfs(arr, i + 1, na, b) if is_sorted(na) else False,
        dfs(arr, i + 1, a, nb) if is_sorted(nb) else False])


n = int(input())
for _ in range(n):
    raw = int_input()
    print("YES" if dfs(raw, 0, list(), list()) else "NO")

Python: n = int(input())
for i in range(n):
    bs = list(map(int, input().split()))
    lanes = [0,0]
    for j in bs:
        if j > lanes[0] and  j > lanes[1]:
            lanes[lanes.index(max(lanes))] = j
        elif j>lanes[0]:
            lanes[0] = j
        elif j>lanes[1]:
            lanes[1] = j
        else:
            print('NO')
            break
    else:
        print('YES')

Python: import sys
def solve(balls):
    if distribute(balls, [], []): print('YES')
    else: print('NO')
        
def distribute(balls, R, L):    
    if len(balls) != 0:
        next = balls[0]
        if isMutch(next, R):
            neoR = R
            neoR.append(next)
            if distribute(balls[1:], neoR, L): return True
        
        if isMutch(next, L):
            neoL = L
            neoL.append(next)
            if distribute(balls[1:], R, neoL): return True
    else:
        return True

def isMutch(next, lis):
    if len(lis) != 0:
        return next >= lis[len(lis)-1]
    return True

sys.setrecursionlimit(2**11)
size = int(input());
for i in range(size):
    balls = []
    for a in input().split(' '):
        balls.append(int(a))   
    solve(balls)

Python: for _ in[0]*int(input()):
 b=c=f=0
 for e in map(int,input().split()):
  if e>b:b=e
  elif e>c:c=e
  else:f=1
 print(['YES','NO'][f])

Python: # AOJ 0033 Ball
# Python3 2018.6.16 bal4u

n = int(input())
for i in range(n):
	a = list(map(int, input().split()))
	b = c = 0
	yes = True
	for j in range(10):
		if a[j] > b: b = a[j]
		elif a[j] > c: c = a[j]
		else: yes = False
	print('YES' if yes else 'NO')

Python: for _ in range(int(input())):
    ano = []
    balls = list(map(int, input().split()))
    for i in range(10):
        if i > len(balls) - 2:
            break
        if balls[i] > balls[i + 1]:
            ano.append(balls[i + 1])
            del balls[i + 1]
    print('YES' if ano == sorted(ano) else 'NO')

Python: N=int(input())
answer=[]
for i in range(N):
  A=list(map(int,input().split()))
  B=[-1 for i in range(10)]
  C=[-1 for i in range(10)]
  B[0]=A[0]
  C[0]=0
  for i in range(1,10):
    if B[i-1]<A[i]:
      B[i]=A[i]
      C[i]=C[i-1]
    elif C[i-1]<A[i]:
      C[i]=A[i]
      B[i]=B[i-1]
    else:
      answer.append("NO")
      break
    if i==9:
      answer.append("YES")
for i in range(N):
  print(answer[i])

Python: N = int(input())
for n in range(N):
	str = input().split()
	list = []
	for i in str:
		list.append(int(i))
	b = []
	c = []
	ans = True

	for a in list:
		bLen = len(b)
		cLen = len(c)
		bLast = bLen - 1 if bLen > 0 else 0
		cLast = cLen - 1 if cLen > 0 else 0
		if bLen == 0 or b[bLast] < a:
			b.append(a)
			continue
		if b[bLast] > a:
			if cLen == 0 or c[cLast] < a:
				c.append(a)
				continue
			else:
				ans = False
				break
	print('YES' if ans is True else 'NO')

Python: n = int(input())
for i in range(n):
    balls = list(map(int, input().split()))
    b = c = 0
    for ball in balls:
        if b < ball:
            b = ball
        elif c < ball:
            c = ball
        else:
            print('NO')
            break
    else:
        print('YES')

Python: for _ in range(int(input())):
    ano = []
    balls = list(map(int, input().split()))
    i = 0
    while balls != sorted(balls):
        if balls[i] > balls[i + 1]:
            ano.append(balls[i + 1])
            del balls[i + 1]
        else:
            i += 1
    print('YES' if ano == sorted(ano) else 'NO')

Python: # -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**6)

"""
def dfs(balls,B=-1,C=-2,cp=0):
	if cp==len(balls): 	return True
	ball = balls[cp]
	if B<ball:
		is_find = dfs(balls,ball,C,cp+1)
		if is_find: return True
	if C<ball:
		is_find = dfs(balls,B,ball,cp+1)
		if is_find: return True
	return False
"""

def dfs(balls,B=-2,C=-1,cp=0):
	if cp==len(balls): 	return True
	if C<balls[cp] and dfs(balls,B,balls[cp],cp+1): return True
	if B<balls[cp] and dfs(balls,balls[cp],B,cp+1): return True
	return False

def main():
	N = int(input().strip())
	for _ in range(N):
		balls = list(map(int,input().split(' ')))
		is_find = dfs(balls)
		if is_find:		print('YES')
		else:			print('NO')

if __name__=='__main__':
	main()

"""
2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
"""

Python: #数列に対しy/nの判定をする
def solve(balls):

  #B, Cの一番上の数(ただし常にB <= Cを保つ)
  last_b = last_c = 0

  while balls:
    new = balls.pop(0)
    
    #new <= last_b <= last_c  --> 不可能
    if new <= last_b:
      print("NO")
      return
    
    #last_b < new <= last_c   --> Bを更新
    elif new <= last_c:
      last_b = new
    
    #last_b < last_c < new    --> Cを更新
    else:
      last_c = new
  
  print("YES")
  return

def main():
  n = int(input())

  for _ in range(n):
    balls = list(map(int, input().split()))
    solve(balls)

main()

Python: # -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**6)

"""
def dfs(balls,B=-1,C=-2,cp=0):
	if cp==len(balls): 	return True
	ball = balls[cp]
	if B<ball:
		is_find = dfs(balls,ball,C,cp+1)
		if is_find: return True
	if C<ball:
		is_find = dfs(balls,B,ball,cp+1)
		if is_find: return True
	return False
"""

def dfs(balls):
	B, C = -2, -1
	for ball in balls:
		if C<ball:
			C = ball
			continue
		if B<ball:
			B = ball
			continue
		return False
	return True

def main():
	N = int(input().strip())
	for _ in range(N):
		balls = list(map(int,input().split(' ')))
		is_find = dfs(balls)
		if is_find:		print('YES')
		else:			print('NO')

if __name__=='__main__':
	main()

"""
2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
"""

Python: n = int(input())
for i in range(n):
    arr = map(int, input().split())
    b,c = 0,0
    flag = True
    for i in range(len(arr)):
        if b < arr[i]:
            b = arr[i]
            continue
        if c < arr[i]:
            c = arr[i]
            continue
        print("NO")
        flag = False
        break
    if flag:
        print("YES")

Python: def balling(balls, left, right):
    if len(balls) == 0:
        return True
    elif balls[0] <= left and balls[0] <= right:
        return False
    else:
        complete = False
        if balls[0] > left:
            complete = balling(balls[1:], balls[0], right)
        if not complete and balls[0] > right:
            complete = balling(balls[1:], left, balls[0])
        return complete

for _ in range(int(input())):
    balls  = [int(x) for x in  input().split()]
    print("YES" if balling(balls, 0, 0) else "NO")

Python: def solve(n,left,right):
    if n==0:
        return 1
    if a[n-1]>left:
        return solve(n-1,a[n-1],right)
    if a[n-1]>right:
        return solve(n-1,left,a[n-1])
    return 0

n=int(input())
for _ in range(n):
    a=[int(i) for i in input().split()][::-1]
    print("YES" if solve(10,0,0) else "NO")