Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var num int
	fmt.Scan(&num)

	for i := 0; i < num; i++ {
		sc.Scan()
		line := sc.Text()

		insertCheck(line)
	}
}

func insertCheck(line string) {
	var B, C []int

	for _, v := range strings.Split(line, " ") {
		ball, _ := strconv.Atoi(v)
		switch {
		case len(B) == 0:
			B = append(B, ball)
		case B[len(B)-1] < ball:
			B = append(B, ball)
		case B[len(B)-1] >= ball:
			switch {
			case len(C) == 0:
				C = append(C, ball)
			case C[len(C)-1] < ball:
				C = append(C, ball)
			case C[len(C)-1] >= ball:
				fmt.Println("NO")
				return
			}
		}
	}
	fmt.Println("YES")
}

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')

Python: import sys
sys.setrecursionlimit(100000)

def load_balls():
	balls = []
	LINE_NUM, TOTAL = 0, 0
	while True:
		line = sys.stdin.readline().strip()
		LINE_NUM += 1
		if LINE_NUM == 1:
			TOTAL = int(line)+1
			continue
		balls.append([int(i) for i in line.split(" ")])
		if LINE_NUM == TOTAL: break
	return balls
balls_list = load_balls()
for balls in balls_list:
	left, right = [0], [0]
	for ball in balls:
		if left[-1] < ball: left.append(ball)
		elif right[-1] < ball: right.append(ball)
	print("YES" if len(left)-1 + len(right)-1 == 10 else "NO")

Python: n = int(input())
for i in range(n):
    a = list(map(int, input().split()))
    b,c = 0,0
    for i in range(len(a)):
        if b < a[i]:
            b = a[i]
            continue
        if c < a[i]:
            c = a[i]
            continue
        print("NO")
        break
    else:
        print("YES")

Python: def main():
    n = int(input())
    for i in range(n):
        Ball = map(int,input().split())
        l = r = 0
        for value in Ball:
            if value > r:
                r = value
            elif value > l:
                l = value
            else:
                print("NO")
                r = -777
                break
            
        if r == -777:
            continue
        else:
            print("Yes")

if __name__ == '__main__':
    main()

Python: import sys
def solve(balls):
    if distribute(balls, [], []): print('YES')
    else: print("NO")
        
def distribute(balls, R, L):    
    if len(balls) != 0:
        next = balls[0]
        if isMutch(next, R):
            neoR = R
            neoR.append(next)
            if distribute(balls[1:], neoR, L): return True
        
        if isMutch(next, L):
            neoL = L
            neoL.append(next)
            if distribute(balls[1:], R, neoL): 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)
  
size = int(input());
for i in range(0,size):
    balls = []
    for a in input().split(' '):
        balls.append(int(a))   
    solve(balls)
    size -= 1
    if size == 0: break

Python: #!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright  : @Huki_Hara
# Created    : 2015-03-11

for _ in range(int(input())):
    l=[0]
    r=[0]
    c=True
    n=map(int, input().split())
    for i in n:
        if l[-1] > i and r[-1] > i:
            c=False
            break
        if l[-1] < i:
            l.append(i)
        else:
            r.append(i)
    print("YES" if c else "NO" )