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

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


def ball(nums):
    l = []
    r = []
    for i, num in enumerate(nums):
        if i == 0:
            l.append(num)
        elif l[-1] < num:
            l.append(num)
        elif len(r) == 0:
            r.append(num)
        elif r[-1] < num:
            r.append(num)
        else:
            return 'NO'
    return 'YES'

N = int(input())
# N = 1


for _ in range(N):
    nums = [int(e) for e in input().split()]
    # nums = [3, 1, 4, 2, 5, 6, 7, 8, 9, 10]
    # nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
    print(ball(nums))

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

    count = 0
    first = 0
    for i, n in enumerate(balls):
        min_ball = 11
        for m in balls[i:]:
            if m != first and n < m < min_ball:
                min_ball = m
        if min_ball != 11:
            first = min_ball
            count += 1
        if count == 2:
            break
    if count == 2:
        print('YES')
    else:
        print('NO')

Python: def dfs(i, b, c):
    if i == 11:
        print(b)
        print(c)
        return (b == sorted(b) and c == sorted(c))

    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, [], []):
            print("YES")
        else:
            print("NO")

Python: class Depth_First_Search:
    def __init__(self, bolls):
        self.bolls = bolls
        self.possible = False

    def search(self, left, right, remaining):
        if len(remaining) == 0:
            self.possible = True
        else:
            boll = remaining[0]
            if boll > max(left):
                self.search(left+[boll], right, remaining[1:])
            if boll > max(right):
                self.search(left, right+[boll], remaining[1:])

    def run(self):
        self.search([-1], [-1], self.bolls)

if __name__ == '__main__':
    N = int(input())
    for i in range(N):
        bolls = list(map(int, input().split(' ')))
        DFS = Depth_First_Search(bolls)
        DFS.run()
        if DFS.possible:
            print('YES')
        else:
            print('NO')

Python: from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

for _ in xrange(int(stdin.readline())):
    result = 'YES'
    b = c = 0
    for a in (int(s) for s in stdin.readline().split()):
        if b < a:
            b = a
        elif c < a:
            c = a
            if b < c:
                b, c = c, b
        else:
            result = 'NO'
            break
    print(result)