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: import sys

def stackBall(stackB, stackC, ball):
	if len(ball) == 0:
		return True
	if len(stackB) == 0 or stackB[-1] < ball[0]:
		stackB.append(ball.pop(0))
		if stackBall(stackB, stackC, ball):
			return True
	if len(stackC) == 0 or stackC[-1] < ball[0]:
		stackC.append(ball.pop(0))
		if stackBall(stackB, stackC, ball):
			return True
	return False

n = input()

for s in sys.stdin:
	ball = list(map(int, s.split()))
	if stackBall([], [], ball):
		print("YES")
	else:
		print("NO")

Python: n = int(input())
for i in range(n):
    l = list(map(int, input().split()))
    x = y = z = 0
    for j in l:
        if j > y:
            y = j
        elif j > z:
            z = j
        else:
            x = 1
    print(["YES", "NO"][x])

Python: N = int(input())
for i in range(N):
    Ball = list(map(int, input().split()))
    cannot = 0
    right = 0
    left = 0
    for j in range(10):
        if abs(Ball[j] - right) <= abs(Ball[j] - left) and Ball[j] > right:
            right = Ball[j]
        elif abs(Ball[j] - right) > abs(Ball[j] - left) and Ball[j] > left:
            left = Ball[j]
        else:
            cannot = 1
            break
    if cannot == 1: print('NO')
    elif cannot == 0: print('YES')

Python: # import sys
from itertools import compress
# from random import shuffle, seed, random
from time import perf_counter


def is_right_order(B, C):
    """ B, C????????§??????????????????????????????(??????)????????§???????????? """
    max_val = 0
    for b in B:
        if b < max_val:
            return False
        max_val = b

    max_val = 0
    for c in C:
        if c < max_val:
            return False
        max_val = c
    return True


def solve_bf(d):
    """ ??????????????§?§£???(??????) """
    for i in range(1024):  # ????????§??????????????????????????????????????????????????????B?????????C????????????????????????
        bin_i = '{0:010b}'.format(i)
        bin_i = [int(x) for x in bin_i]
        comp = compress(d, bin_i)
        B = list(comp)
        C = d[:]
        for b in B:
            C.remove(b)
        if is_right_order(B, C):  # ???????????????????????????????????§?????¶???????????????????????????????¨???????
            return True
    return False


def solve_greed(d):
    """ ????¬????????????????
    ????????¨?????????????????????????????\????????????C?????\?????????????????\?????????B?????\?????????
    ??? ???????????????????????????????????°????????¨???????????????????????¨????????????????????????????????´?????????
    """
    used = [False] * 11  # ???????????????????????????????????????????????°?????????????????????index??????????????????used[1]?????????????????????????????§????????????+1????????????

    B = []  # ?????\????????????????????\?????????
    C = []  # ????????\???????????????????????????????????\?????????
    for b in d:
        cb = 0
        for i in range(1, 11):
            if used[i] == False:
                cb = i  # ?????????????????????????????????????????\????????????cb??¨?????¶
                break
        if b == cb:
            C.append(b)
        else:
            B.append(b)
        used[b] = True  # ????????????????????????????????????B?????????C???????????????????????????????????§????????¨?????????
    return is_right_order(B, C)


if __name__ == '__main__':
    # ??????????????\???
    num = int(input())
    data = []
    for _ in range(num):
        data.append(list(map(int, input().split(' '))))

    # ???????????¨??????????????????????????????
#    for i in range(100):
#        t = list(range(1, 11))
#        shuffle(t)
#        data.append(t)

    # start_time = perf_counter()
    # ????????????
    for d in data:
        # print('trying: {0}'.format(d))
        #result = solve_bf(d)
        result = solve_greed(d)

        if result:
            print('YES')
        else:
            print('NO')

    # end_time = perf_counter()
    # print('elapsed: {0}'.format(end_time - start_time))

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

Python: 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: import sys
f = sys.stdin
def cylinder(balls):
    cy = []
    for ball in balls:
        if len(cy) < 2:
            pass
        elif min(ball, *cy) == ball:
            return False
        elif max(ball, *cy) == ball:
            cy.remove(max(cy))
        else:
            cy.remove(min(cy))
        cy.append(ball)
    return True

n = int(f.readline())
for _ in range(n):
    balls = list(map(int, f.readline().split()))
    print('YES' if cylinder(balls) else 'NO')

Python: n = int(input())
for _ in range(n):
    data = list(map(int, input().split()))
    B, C = 0, 0
    flag = True
    for d in data:
        if B < d:
            B = d
        elif C < d:
            C = d
        else:
            print("NO")
            flag = False
            break
    if flag:
        print("YES")

Python: n = int(input())
for _ in range(n):
    balls = list(map(int, input().split()))
    b = 0
    c = 0
    flag = True
    for itm in balls:
        if b>c: b,c = c,b
        if c<itm: c=itm; continue
        elif b<itm: b=itm; continue
        else: flag = False; break
    if flag: print("YES")
    else: print("NO")

Python: import bisect


def LIS(seq):
    r = [seq[0]]
    for n in seq[1:]:
        if n > r[-1]:
            r.append(n)
        else:
            idx = bisect.bisect_left(r, n)
            r[idx] = n
    return r
N = int(input())
for _ in range(N):
    seq = list(map(int, input().split()))
    left = set(LIS(seq))
    remain = [n for n in seq if n not in left]
    right = LIS(remain)
    print("YES" if len(left) + len(right) == len(seq) else "NO")

Python: x=int(input())
for i in range(x):
	num=[int(i) for i in input().split()]
	b=[]
	c=[]
	flag=0
	b.append(num[0])
	c.append(min(num)-1)
	for i in range(1,10):
		if b[len(b)-1]<num[i]:
			b.append(num[i])
		elif c[len(c)-1]<num[i]:
			c.append(num[i])
		else:
			flag=1
			break
	if flag==0:
		print("YES")
	else:
		print("No")