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 heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


NUM = 10
POW = [1]*(NUM+1)
for i in range(1,NUM+1):
    POW[i] = POW[i-1]*2


N = int(input())

for _ in range(N):

    table = list(map(int,input().split()))

    FLG = False

    for state in range(POW[NUM]):
        A = []
        B = []

        for i in range(NUM):
            if state & POW[i] != 0:
                A.append(table[i])
            else:
                B.append(table[i])

        tmpFLG = True
        for i in range(len(A)-1):
            if A[i] >= A[i+1]:
                tmpFLG = False
                break

        if tmpFLG == False:
            continue

        for i in range(len(B)-1):
            if B[i] >= B[i+1]:
                tmpFLG = False
                break

        if tmpFLG == True:
            FLG = True
            break


    if FLG == True:
        print("YES")
    else:
        print("NO")

Python: N = int(input())
for _ in range(N):
	balls = list(map(int, input().split()))
	left = right = 0
	ans = "YES"
	for i in range(10):
		if min(left, right) > balls[i]:
			ans = "NO"
			break
		if left < right:
			if right < balls[i]:
				right = balls[i]
			else:
				left = balls[i]
		else:
			if left < balls[i]:
				left = balls[i]
			else:
				right = balls[i]
	print(ans)

Python: for i in range(int(input())):
	a=b=c=0
	for n in map(int,input().split()):
		if n>b: n=b
		elif n>c: n=c
		else: a=1
	print(['YES','N'][a])

Python: def solve(A):
	B=[]
	C=[]
	#print(A)
	#??????
	B.append(A[0])
	C.append(0)#?????§??????
	for i in range(1,9):
		if B[-1]<A[i] and C[-1]>A[i]:
			B.append(A[i])
			#print("B",B)
			#print("C",C)
		elif B[-1]>A[i] and C[-1]<A[i]:
			C.append(A[i])
			#print("B",B)
			#print("C",C)
		elif B[-1]<A[i] and C[-1]<A[i]:
			for j in range(i+1,len(A)):
				if A[j]<A[i]:
					if B[-1]<C[-1]:
						C.append(A[i])
						#print("B",B)
						#print("C",C)
						break
					else:
						B.append(A[i])
						#print("B",B)
						#print("C",C)
						break
			else:
				B.append(A[i])
				#print("B",B)
				#print("C",C)
		else:
			break
	del C[0]
	#print("B is ",B)
	#print("C is ",C)
	if B[-1]<A[-1] or C[-1]<A[-1]:
		if len(B)+len(C)==len(A)-1:
			print("YES")
		else:
			print("NO")
	else:
		print("NO")










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

Python: n = int(input())
for i in range(n):
    left = right = []
    arr = map(int, input().split())
    for a in arr:
        if len(left) == 0 or left[-1] < a:
            left.append(a)
        elif len(right) == 0 or right[-1] < a:
            right.append(a)
        else:
            break
    if len(left) + len(right) == 10:
        print("YES")
    else:
        print("NO")

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

        if j == 9:
            print("YES")

Python: n = int(input())
for i in range(n):
    l = list(map(int, input().split()))
    k , c= l[0], 0
    for j in l:
        if j < k:
            c += 1
        else:
            c = 0
    if 2 <= c:
        print("NO")
    else:
        print("YES")

Python: def f(x):
    a,b=0,0
    for e in x:
        if e>a: a=e
        elif e>b: b=e
        else: return 0
    return 1

n=input()
for i in range(n):
    D = map(int, raw_input().split())
    print ["NO","YES"][f(D)]

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

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

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 bLast == 0:
			b.append(a)
			continue
		if b[bLast] > a:
			if cLast == 0 or c[cLast] < a:
				c.append(a)
				continue
			else:
				ans = False
				break
		
	print('YES' if ans is True else 'NO')

Python: import sys

def solve(balls):
    ans = distribute(balls, [], [])
    if ans is True: print('YES')
    else: print("NO")
        
def distribute(balls, R, L):    
    if len(balls) != 0:
        next = balls[0]
        ans = False
        #case R
        if isMutch(next, R):
            neoR = R
            neoR.append(next)
            ans = distribute(balls[1:], neoR, L)
        if ans: return True
        
        if isMutch(next, L):
            neoL = L
            neoL.append(next)
            ans =distribute(balls[1:], R, neoL)
        if ans: return True
    else:
        return isOrdered(R) and isOrdered(L)

def isMutch(next, lis):
    if len(lis) != 0:
        return next >= lis[len(lis)-1]
    return True
    
def isOrdered(lis):
    #check both R and L are ordered
    checker = sorted(lis)
    return checker == lis
  
limit = 2**11
sys.setrecursionlimit(limit)
  
line = input()
size = -1;
while True:
    if size == -1:
        size = int(line)
    else:
        balls = []
        for a in line.split(' '):
            balls.append(int(a))   
        solve(balls)
        size -= 1
        if size == 0: break
    line = input()

Python: # Aizu Problem 0033: Ball
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


N = int(input())
for n in range(N):
    balls = [int(_) for _ in input().split()][::-1]
    left, right = [0], [0]
    fail = False
    while len(balls) > 0:
        ball = balls.pop()
        if ball > left[-1]:
            left.append(ball)
        elif ball > right[-1]:
            right.append(ball)
        else:
            fail = True
            break
    print("YES" if not fail else "NO")