Go: package main

import "fmt"

func isOrdered(a []int) bool {
	if len(a) <= 1 {
		return true
	}
	for i := 0; i+1 < len(a); i++ {
		if a[i] > a[i+1] {
			return false
		}
	}
	return true
}

func main() {
	// ボールの数がせいぜい10個しかないので、全てのボールの落とし方を全探索することが可能
	// Bit全探索を行う。右から見てj番目のビットが立っているときには左側の筒、立っていない時は右側の筒にいれる物とする。
	// 全てのボールを落とし終わった後に、それぞれの筒で昇順に並んでいるか調べることにする。
	var t int
	fmt.Scan(&t)
	ans := make([]bool, t)
	for i := 0; i < t; i++ {
		balls := make([]int, 10)
		for i := range balls {
			fmt.Scan(&balls[i])
		}
		ans[i] = false
		for bits := 0; bits < (1 << uint(10)); bits++ {
			pipeB := make([]int, 0)
			pipeC := make([]int, 0)
			for j := 0; j < 10; j++ {
				if (bits & (1 << uint(j))) != 0 {
					pipeB = append(pipeB, balls[j])
				} else {
					pipeC = append(pipeC, balls[j])
				}
			}
			if isOrdered(pipeB) && isOrdered(pipeC) {
				// fmt.Printf("test case %d - OK pattern - pipeB %v, pipec %v\n", i, pipeB, pipeC)
				ans[i] = true
				break
			}
		}
	}
	for i := range ans {
		if ans[i] {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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")

Python: import sys
sys.setrecursionlimit(100000)

def load_balls():
	LINE_NUM, TOTAL = 0, 0
	balls = []
	i = 0
	for line in sys.stdin:
		line = line.strip()
		LINE_NUM += 1
		if LINE_NUM == 1:
			TOTAL = int(line.strip())
			continue
		balls.append([int(i) for i in line.split(" ")])
		if LINE_NUM == TOTAL+1: break
	return balls

class VesselClass:

	def __init__(self):
		self.tmp = []
		self.left = [0]
		self.right = [0]

	def fill(self, balls:list):
		self.tmp = balls

	def DFS(self):
		if len(self.tmp) == 0: print("YES")
		elif self.left[-1] < self.tmp[0]:
			self.left.append(self.tmp[0])
			self.tmp.pop(0)
			self.DFS()
		elif self.right[-1] < self.tmp[0]:
			self.right.append(self.tmp[0])
			self.tmp.pop(0)
			self.DFS()
		else: print("NO")

balls_list = load_balls()
for balls in balls_list:
	Vessel = VesselClass()
	Vessel.fill(balls)
	Vessel.DFS()

Python: n = int(input())
for i in range(n):
    b = list(map(int, input().split()))
    c_r = [-1]
    c_l = [-1]
    for j in range(10):
        if c_r[-1] < b[j]:
            c_r.append(b[j])
        elif c_l[-1] < b[j]:
            c_l.append(b[j])
        else:
            print("NO")
            break
    else:
        print("YES")

Python: n = int(input())
for _ in range(n):
  a = list(map(int,input().split()))
  b = 0
  c = 0
  for i in range(10):
    if a[i] > b:
      b = a[i]
    elif a[i] > c:
      c = a[i]
    else:
      print("NO")
      break
    if i == 9:
      print("YES")

Python: def dfs(i, b, c):
    if i == 10:
        b_sort = sorted(b)
        c_sort = sorted(c)
        return (b == b_sort and c == c_sort)

    if dfs(i + 1, b + [balls[i - 1]], c):
        return True

    if dfs(i + 1, b, c + [balls[i - 1]]):
        return True

    return False


if __name__ == '__main__':
    N = int(input())
    for i in range(N):
        balls = list(map(int, input().split()))
        if dfs(1, [0], [0]):
            print("YES")
        else:
            print("NO")

Python: def dfs(i, b, c):
    if i == 10:
        b_sort = sorted(b)
        c_sort = sorted(c)
        return (b == b_sort and c == c_sort)

    if dfs(i + 1, b + [balls[i - 1]], c):
        return True

    if dfs(i + 1, b, c + [balls[i - 1]]):
        return True

    return False


if __name__ == '__main__':
    N = int(input())
    for i in range(N):
        balls = list(map(int, input().split()))
        if dfs(1, [0], [0]):
            print("YES")
        else:
            print("NO")

Python: def check(ary):
    for i in range(1, len(ary)):
        if ary[i] < ary[i - 1]:
            return False

    return True


def dfs(a, b, c, i):
    if len(b) + len(c) == 10:
        return check(b) and check(c)

    added_b = b[:]
    added_c = c[:]
    added_b.append(a[i])
    added_c.append(a[i])

    return dfs(a, added_b, c, i + 1) or dfs(a, b, added_c, i + 1)


def main():
    n = int(input())
    for i in range(n):
        datasets = [int(i) for i in input().split(' ')]
        result = dfs(datasets, [], [], 0)
        print('YES' if result else 'NO')


if __name__ == '__main__':
    main()

Python: import sys
def solve(balls):
    if distribute(balls, 0, 0): print('YES')
    else: print('NO')
  
def distribute(balls, lastR, lastL):    
    if len(balls) != 0:
        next = balls[0]
        if next>lastR:
            if distribute(balls[1:], next, lastL): return True
        
        if next>lastL:
            if distribute(balls[1:], lastR, next): return True
    else:
        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 i in range(int(input())):
    b = list(map(int, input().split()))
    for j in range(8):
        if b[j] > b[j + 2]:
            print("NO")
            break
    else:
        print("YES")

Python: x=int(input())
for _ in range(x):
	num=list(map(int,input().split()))
	b,c=0,0
	flag=True
	for i in num:
		if b<i:
			b=i
		elif c<i:
			c=i
		else:
			print("No")
			flag=False
			break
	if flag:
		print("YES")

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