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: 
n = int(input())

for i in range(n):
    tmp = list(map(int,input().split()))
    a,b,cnt = 0,0,0
    
    for j in range(10):
        if a<tmp[j]: a = tmp[j]
        elif b<tmp[j]: b = tmp[j]
        else: cnt += 1
        
    if cnt==0: print("YES")
    else: print("NO")

Python: x=int(input())
for _ 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: 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 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:
        solve(line.split(' '))
        size -= 1
        print(size)
        if size == 0: break
    line = input()

Python: import sys
f = sys.stdin
def cylinder(balls):
    cy = []
    for ball in balls:
        if len(cy) == 0:
            pass
        elif len(cy) == 1:
            if cy[0] < ball:
                cy.remove(cy[0])
        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: # AOJ 0033

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

Python: import sys
from itertools import compress


def is_right_order(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):
        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



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

    # ????????????
    for d in data:
        result = solve_bf(d)

        # ???????????¨???
        if result:
            print('YES')
        else:
            print('NO')

Python: def solve():
    N = int(input())
    for _ in range(N):
        balls = list(map(int, input().split()))
        lefts, rights = [0], [0]
        for ball in balls:
            if lefts[-1] < ball:
                lefts.append(ball)
            elif rights[-1] < ball:
                rights.append(ball)
            else:
                print('NO')
                break
        else:
            print('YES')

if __name__ == "__main__":
    solve()

Python: N = int(input())

for testCase in range(N):
    A = list(map(int,input().split()))
    ok = False
    for i in range(2 ** 10):
        x = []
        y = []
        for j in range(10):
            if i & (1 << j):
                x.append(A [j])
            else:
                y.append(A [j])
        if x == sorted(x) and y == sorted(y):
            ok = True
    if ok:
        print('YES')
    else:
        print('NO')

Python: 
def solve(Balls,Left,Right,i):
	if i==len(Balls):#???????????¶
		return True

	#????????\????????´???
	if len(Left)==0 or Left[-1]<Balls[i]:
		Left.append(Balls[i])
		return solve(Balls,Left,Right,i+1)

	#????????\????????´???
	if len(Right)==0 or Right[-1]<Balls[i]:
		Right.append(Balls[i])
		return solve(Balls,Left,Right,i+1)
	
	return False#??\???????????????



if __name__ == "__main__":
	n=int(input())
	for i in range(n):
		Balls = [int(i) for i in input().split()]
		Left=[]
		Right=[]
		i=0
		if solve(Balls,Left,Right,0):
			print("YES")
		else:
			print("NO")

Python: num = int(input())
for _ in range(num):
    n = [int(i) for i in input().split()]
    b = 0
    able = 1
    for j in range(10):
        if j == 0:
            a = n[0]
        else:
            if n[j] < a:
                if n[j] < b:
                    print("NO")
                    able = 0
                    break
                else:
                    b = n[j]
            else:
                a = n[j]
    if able == 1:
        print("YES")

Python: n = input()
data = []
for i in range(n):
	tmp = map(int,raw_input().split())
	data.append(tmp)

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.BALL_NUM = 10
		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()
Vessel = VesselClass()
for balls in balls_list:
	Vessel.fill(balls)
	Vessel.DFS()