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: def ball(nums):
    b, c = 0, 0
    for i in range(len(nums)):
        if b < nums[i]:
            b = nums[i]
            continue
        if c < nums[i]:
            c = nums[i]
            continue
        return "NO"
    return "YES"

N = int(input())

for _ in range(N):
    a = list(map(int, input().split()))
    print(ball(a))

Python: n = int(input())

for j in range(n):
    nums = list(map(int, input().split()))

    b = [0]
    c = []
    ans = "YES"

    for i in range(10):
        if nums[i] > b[-1]:
            b.append(nums[i])
        else:
            c.append(nums[i])

    if len(c) > 1:
        x = c[0]
        for i in range(1, len(c)):
            if x > c[i]:
                ans = "NO"
            else:
                x = c[i]
    print(ans)

Python: def check(a):
    b = [a[0]]
    c = [0]
    for i in range(1, len(a)):
        x = a[i]
        if x < b[-1] and x < c[-1]:
            return False
        elif b[-1] < x < c[-1]:
            b.append(x)
        elif c[-1] < x < b[-1]:
            c.append(x)
        elif b[-1] > c[-1]:
            b.append(x)
        else:
            c.append(x)
    return True

n = int(input())
for i in range(n):
    a = list(map(int, input().split()))
    print('YES' if check(a) else 'NO')

Python: n=int(input())
for i in range(n):
    ball=list(map(int,input().split()))
    b=0
    c=0
    flag=0
    for j in ball:
        if b>j and c>j:
            flag=1
            break
        elif b>j or j-c<j-b:
            c=j
        else:
            b=j
    print('YNEOS'[flag::2])

Python: import sys
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    n = Z()
    for _ in range(n):
        A = ZZ()
        done = [False] * 10

        def dfs(i, a):
            if done[i]:
                if i+1 < 10: dfs(i+1, a)
                else: return
            else:
                if a < A[i]:
                    done[i] = True
                    if i+1 < 10: dfs(i+1, A[i])
                else:
                    if i+1 < 10: dfs(i+1, a)

        cc = 0
        for i in range(10):
            if done[i]: continue
            cc += 1
            done[i] = True
            dfs(i, A[i])

        print('YES' if cc <= 2 else 'NO')


    return

if __name__ == '__main__':
    main()

Python: ans=0
def solve(n,left,right):
    if n==10:
        ans=1
    else:
        if a[n]>left:
            ans=solve(n+1,a[n],right)
        if a[n]>right:
            ans=solve(n+1,left,a[n])
    return ans

n=int(input())
for _ in range(n):
    a=[int(i) for i in input().split()]
    print("YES" if solve(0,0,0) else "NO")

Python: # AOJ 0033 Ball
# Python3 2018.6.16 bal4u

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: n = int(input())
for i in range(n):
    b = list()
    c = list()
    a =  list(map(int, input().split()))
    # print(a)
    b.append(a.pop(0))

    for _  in range(9):
        a0 = a.pop(0)
        if b[-1] < a0:
            b.append(a0)
        elif len(c)==0 or c[-1]<a0:
            c.append(a0)
        else:
            a.append(a0)
            print('NO')
            break
    if len(a)==0:
        print('YES')

Python: n=int(input())
for i in range(n):
    a=list(map(int,input().aplit()))
    b,c=0,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: n = int(input())
for i in range(n):
    data = [int(i) for i in input().split()]
    flag = False
    a = [0]
    b = [0]
    for ball in data:
        if ball > a[-1]:
            a.append(ball)
        elif ball > b[-1]:
            b.append(ball)
        else:
            flag = True
            break
    print("NO") if flag else print("YES")

Python: a=[]
n=int(input())
for i in range(10):
        a.append(-1)
while(n!=0):
    n-=1
    b=[]
    c=[]
    a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9]=map(int,input().split())
    for i in range(10):
        b.append(-1)
        c.append(-1)
    j=1
    k=0
    lenb=0
    lenc=0
    b[0]=a[0]
    for i in range(1,10):
        if(a[i]>b[j-1]):
            b[j]=a[i]
            j+=1
        else:
            if(k==0):
                c[0]=a[i]
                k+=1
            elif(a[i]>c[k-1]):
                c[k]=a[i]
                k+=1
    for i in range(10):
        if(b[i]!=-1):
            lenb+=1
        if(c[i]!=-1):
            lenc+=1
    if(len(a)==(lenb+lenc)):
        print("YES")
    else:
        print("NO")

Python: N = int(input())
for l in range(N):
    A = [int(i) for i in input().split()]
    B = 0
    C = 0
    ans = "YES"
    for i in range(10):
        if A[i] > B:
            B = A[i]
        elif A[i] > C:
            C = A[i]
        else:
            ans = "NO"
    print(ans)

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: N = int(input())
for i in range(N):
    Ball = list(map(int, input().split()))
    B = 0
    C = 0
    x = 'YES'
    for j in range(10):
        if B < Ball[j]:
            B = Ball[j]
        elif C < Ball[j]:
            C = Ball[j]
        else:
            x = 'NO'
    print(x)

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

for _ in range(N):
    A = list(map(int, input().split()))
    b, c = 0, 0
    flag = True
    for a in A:
        if b < a:
            b = a
        elif c < a:
            c = a
        else:
           print('NO') 
           flag = False
           break
    if flag:
        print('YES')