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())
i=1
while i<=n:
    ball=list(map(int,input().split()))
    left=[0]
    right=[0]
    m=0
    while True:
        #終了条件
        if m==10:
            print("YES")
            #print("left",left,"right",right)
            break
        #noの条件
        if ball[m]<left[len(left)-1] and ball[m]<right[len(right)-1]:
            print("NO")
            #print("left",left,"right",right,"ball",ball[m])
            break

        #左側に入れるか右側に入れるかの条件
        if ball[m]>left[len(left)-1] and ball[m]>right[len(right)-1]:
            if left[len(left)-1]>right[len(right)-1]:
                left.append(ball[m])
            else:
                right.append(ball[m])
        elif ball[m]>left[len(left)-1]:
            left.append(ball[m])
        else:
            right.append(ball[m])
        m+=1
    i+=1

Python: N = int(input())
for i in range(N):
    lst = list(map(int, input().split()))
    B = 0
    C = 0
    r = 0
    for j in lst:
        if B < j:
            B = j
        elif C < j:
            C = j
        else:
            r = 1
            break
    
    if r:
        print('NO')
    else:
        print('YES')

Python: flag = False

def dfs(a, b, c, i):
  if i == 10:
    # print("OK")
    global flag
    flag = True
    return
  else:
    if a[i] > b:
     # print("b:",a[i], i)
      dfs(a, a[i], c, i + 1)
    else:
      pass
    
    if a[i] > c:
     # print("c:", a[i], i)
      dfs(a, b, a[i], i + 1)
    else:
      pass
    
    if a[i] < b and a[i] < c:
      return
    

n = int(input())
for i in range(n):
  a = list(map(int, input().split()))
  dfs(a, 0, 0, 0)
  if flag == True:
    print("YES")
  else:
    print("NO")
  flag = False

Python: N = int(input())
for i in range(N):
    tmp =  [int(x) for x in input().split()]
    B = 0
    C = 0
    flg = 0
    for i in tmp:
        if B >= C:
            if B < i :
                B = i
                continue
            else:
                if C < i :
                    C = i
                    continue
                else:
                    flg = 1
                    break

        else:
            if C < i :
                C = i
                continue
            else:
                if B < i :
                    C = i
                    continue
                else:
                    flg = 1
                    break
    if flg != 1:
        print("YES")
    else:
        print("NO")

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

Python: #数列に対しy/nの判定をする
def solve(balls):

  #B, Cの一番上の数(ただし常にB <= Cを保つ)
  last_b = last_c = 0

  while balls:
    new = balls.pop(0)
    
    #new <= last_b <= last_c  --> 不可能
    if new <= last_b:
      print("NO")
      break
    
    #last_b < new <= last_c   --> Bを更新
    elif new <= last_c:
      last_b = new
    
    #last_b < last_c < new    --> Cを更新
    else:
      last_c = new
  
  else:
    print("YES")

      


while True:
  try:
    n = int(input())

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

  except EOFError:
    break

Python: import sys

def stackBall(stackB, stackC, ball):
	if len(ball) == 0:
		return True
	if len(stackB) == 0 or stackB[-1] < ball[0]:
		stackB.append(ball.pop(0))
		if stackBall(stackB, stackC, ball):
			return True
	if len(stackC) == 0 or stackC[-1] < ball[0]:
		stackC.append(ball.pop(0))
		if stackBall(stackB, stackC, ball):
			return True
	return False

n = input()

for _ in range(n):
	ball = list(map(int, input().split()))
	if stackBall([], [], ball):
		print("YES")
	else:
		print("NO")

Python: import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


NUM = 10
POW = [1]*(NUM+1)
for i in range(1,NUM+1):
    POW[i] = POW[i-1]*2


N = int(input())

for _ in range(N):

    table = list(map(int,input().split()))

    FLG = False

    for state in range(POW[NUM]):
        A = []
        B = []

        for i in range(NUM):
            if state & POW[i] != 0:
                A.append(table[i])
            else:
                B.append(table[i])

        tmpFLG = True
        for i in range(len(A)-1):
            if A[i] >= A[i+1]:
                tmpFLG = False
                break

        if tmpFLG == False:
            continue

        for i in range(len(B)-1):
            if B[i] >= B[i+1]:
                tmpFLG = False
                break

        if tmpFLG == True:
            FLG = True
            break


    if FLG == True:
        print("YES")
    else:
        print("NO")

Python: N = int(input())
for _ in range(N):
	balls = list(map(int, input().split()))
	left = right = 0
	ans = "YES"
	for i in range(10):
		if min(left, right) > balls[i]:
			ans = "NO"
			break
		if left < right:
			if right < balls[i]:
				right = balls[i]
			else:
				left = balls[i]
		else:
			if left < balls[i]:
				left = balls[i]
			else:
				right = balls[i]
	print(ans)

Python: for i in range(int(input())):
	a=b=c=0
	for n in map(int,input().split()):
		if n>b: n=b
		elif n>c: n=c
		else: a=1
	print(['YES','N'][a])

Python: def solve(A):
	B=[]
	C=[]
	#print(A)
	#??????
	B.append(A[0])
	C.append(0)#?????§??????
	for i in range(1,9):
		if B[-1]<A[i] and C[-1]>A[i]:
			B.append(A[i])
			#print("B",B)
			#print("C",C)
		elif B[-1]>A[i] and C[-1]<A[i]:
			C.append(A[i])
			#print("B",B)
			#print("C",C)
		elif B[-1]<A[i] and C[-1]<A[i]:
			for j in range(i+1,len(A)):
				if A[j]<A[i]:
					if B[-1]<C[-1]:
						C.append(A[i])
						#print("B",B)
						#print("C",C)
						break
					else:
						B.append(A[i])
						#print("B",B)
						#print("C",C)
						break
			else:
				B.append(A[i])
				#print("B",B)
				#print("C",C)
		else:
			break
	del C[0]
	#print("B is ",B)
	#print("C is ",C)
	if B[-1]<A[-1] or C[-1]<A[-1]:
		if len(B)+len(C)==len(A)-1:
			print("YES")
		else:
			print("NO")
	else:
		print("NO")










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

Python: n = int(input())
for i in range(n):
    left = right = []
    arr = map(int, input().split())
    for a in arr:
        if len(left) == 0 or left[-1] < a:
            left.append(a)
        elif len(right) == 0 or right[-1] < a:
            right.append(a)
        else:
            break
    if len(left) + len(right) == 10:
        print("YES")
    else:
        print("NO")

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

        if j == 9:
            print("YES")