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
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: n = int(input())
for i in range(n):
    b = list(map(int, input().split()))
    c_r = [-1]
    c_l = [-1]
    for j in range(10):
        if c_r[-1] < b[j]:
            c_r.append(b[j])
        elif c_l[-1] < b[j]:
            c_l.append(b[j])
        else:
            print("NO")
            break
    else:
        print("YES")

Python: n = int(input())
for _ in range(n):
  a = list(map(int,input().split()))
  b = 0
  c = 0
  for i in range(10):
    if a[i] > b:
      b = a[i]
    elif a[i] > c:
      c = a[i]
    else:
      print("NO")
      break
    if i == 9:
      print("YES")

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: 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: def check(ary):
    for i in range(1, len(ary)):
        if ary[i] < ary[i - 1]:
            return False

    return True


def dfs(a, b, c, i):
    if len(b) + len(c) == 10:
        return check(b) and check(c)

    added_b = b[:]
    added_c = c[:]
    added_b.append(a[i])
    added_c.append(a[i])

    return dfs(a, added_b, c, i + 1) or dfs(a, b, added_c, i + 1)


def main():
    n = int(input())
    for i in range(n):
        datasets = [int(i) for i in input().split(' ')]
        result = dfs(datasets, [], [], 0)
        print('YES' if result else 'NO')


if __name__ == '__main__':
    main()

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: for i in range(int(input())):
    b = list(map(int, input().split()))
    for j in range(8):
        if b[j] > b[j + 2]:
            print("NO")
            break
    else:
        print("YES")

Python: x=int(input())
for _ in range(x):
	num=list(map(int,input().split()))
	b,c=0,0
	flag=True
	for i in num:
		if b<i:
			b=i
		elif c<i:
			c=i
		else:
			print("No")
			flag=False
			break
	if flag:
		print("YES")

Python: for _ in[0]*int(input()):
 a=list(map(int,input().split()))
 b=[a[0]];c=[0]
 for e in a[1:]:
  if e>b[-1]:b+=[e]
  elif e>c[-1]:c+=[e]
  else:print('NO');break
 else:print('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:
            print('NO')
            break
    if len(a)==0:
        print('YES')

Python: for _ in range(int(input())) :
    b, c = 0, 0
    for number, a in enumerate(input().split()) :
        a = int(a)
        if a < b and a < c :
            print('NO')
            break
        elif b < a and c <= b : b = a
        else : c = a
    if number == 9 : print('YES')

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

import collections


def judge(balls):
    left_balls = collections.deque([0])
    right_balls = collections.deque([0])
    while balls:
        ball = balls.popleft()
        if ball > left_balls[-1]:
            left_balls.append(ball)
        elif ball > right_balls[-1]:
            right_balls.append(ball)
        else:
            return "NO"
    return "YES"


def main():
    n = int(input())
    for x in range(n):
        balls = collections.deque(map(int, input().split()))
        print(judge(balls))


if __name__ == "__main__":
    main()

Python: n = int(input())
for i in range(n):
    str = input().split()
    arr = [int(str[j]) for j in range(len(str))]
    b,c = 0,0
    flag = True
    for i in range(len(arr)):
        if b < arr[i]:
            b = arr[i]
            continue
        if c < arr[i]:
            c = arr[i]
            continue
        print("NO")
        flag = False
        break
    if flag:
        print("YES")

Python: a=[]
n=int(input())
for i in range(10):
        a.append(-1)
while(n!=0):
    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 i in range(n):
    balls = list(map(int, input().split()))
    min_ball = balls[0]
    count = 0
    for ball in balls:
        if ball > min_ball:
            min_ball = ball
            count += 1
    if count > 1:
        print('YES')
    else:
        print('NO')