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
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: # -*- coding:utf-8 -*-

def dfs(datas, b, c, count):
    if len(datas) == count: return 1
    if int(datas[count]) > b:
        return dfs(datas, int(datas[count]), c, count+1)
    if int(datas[count]) > c:
        return dfs(datas, b, int(datas[count]), count+1)
    return 0

def solve():
    b=0
    c=0
    count = 1
    q = dfs(datas, b, c, count)
    if q==1:
        print("YES")
    elif q==0:
        print("NO")

counter = 0
line = input()
if not " " in line:
    nums = line
while True:
    line = input()
    datas = line.split(" ")
    q = solve()
    counter += 1
    if int(nums) == counter:
        break

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

def solve():
    arr1 = [0]
    arr2 = [0]
    for i in range(len(datas)):
        if i == 0:
            arr1.append(datas[0])
        elif int(datas[i]) > int(datas[i-1]):
            arr1.append(datas[i])
        elif int(datas[i]) < int(datas[i-1]):
            if int(arr2[-1]) < int(datas[i]):
                arr2.append(datas[i])
            else:
                return 0
                break
    return 1

i=0
counter = 0
while True:
    line = input()
    if not " " in line:
        nums = line
    else:
        datas = line.split(" ")
        q = solve()
        counter += 1
        if q == 1:print("YES")
        else:print("NO")
    if int(nums) == counter:
        break

Python: n = int(input())
while n > 0:
  l = [int(i) for i in input().split()]
  m1 = [0]
  m2 = [0]
  for i in l:
    M1 = max(m1)
    M2 = max(m2)
    if i < M1 and i < M2:
      print('NO')
      break
    elif M1 <= i <= M2:
      m1.append(i)
    elif M2 <= i <= M1:
      m2.append(i)
    elif M2 <= M1 <= i:
      m1.append(i)
    elif M1 <= M2 <= i:
      m2.append(i)
  else:
    print('YES')
  n -= 1

Python: for i in range(int(input())):
    res = "YES"
    b = c = 0
    for t in map(int,input().split()):
        if t > b >= c:
            b = t
        elif t > c:
            c = t
        else:
            res = "NO"

    print(res)

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

for _ in range(n):
    balllist = list(map(int, input().split()))
    leftlist = []
    rightlist = []

    for i, ball in enumerate(balllist):
        if i == 0:
            leftlist.append(ball)
            continue
        if leftlist[-1] < ball:
            leftlist.append(ball)
        elif rightlist == [] or rightlist[-1] < ball:
            rightlist.append(ball)
        else:
            print("NO")
            break
    else:
        print("YES")

Python: def solve():
    from sys import stdin
    f_i = stdin
    N = int(f_i.readline())
    
    from itertools import combinations
    ans = []
    for m in (map(int, f_i.readline().split()) for i in range(N)):
        for a, b, c in combinations(m, 3):
            if a > b > c:
                ans.append('NO')
                break
        else:
            ans.append('YES')
    print('\n'.join(ans))

solve()

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

import sys
import os

N = int(input())
for _ in range(N):
    balls = list(map(int, input().split()))
    left = right = 0
    impossible = False

    for ball in balls:
        if ball > left and ball > right:
            # ?????£????????\?????????
            if left < right:
                right = ball
            else:
                left = ball
        elif ball > left:
            left = ball
        elif ball > right:
            right = ball
        else:
            impossible = True
            break

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

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: # -*- coding:utf-8 -*-

#datas = [1 5 2 6 3 7 8 9 10 4]
#datas = [1 4 2 6 5 3 7 8 9 10]

def dfs(datas, b, c, count):
    if len(datas) == count: return 1
    if int(datas[count]) > b:
        return dfs(datas, int(datas[count]), c, count+1)
    if int(datas[count]) > c:
        return dfs(datas, b, int(datas[count]), count+1)
    return 0

def solve():
    b=0
    c=0
    count = 1
    q = dfs(datas, b, c, count)
    print("YES") if q==1 else print("NO")

counter = 0
while True:
    line = input()
    if not " " in line:
        nums = line
    else:
        datas = line.split(" ")
        q = solve()
        counter += 1
    if int(nums) == counter:
        break