Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	for i := 0; i < n; i++ {
		a := -1
		b := -1
		ans := true
		// それぞれの筒の一番上にあるたまの数字に着目すればよい
		for j := 0; j < 10; j++ {
			x := nextInt()
			if x > a {
				a = x
			} else if x > b {
				b = x
			} else {
				ans = false
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

Python: x=int(input())
for i in range(x):
	num=[int(i) for i in 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: for _ in range(int(input())):
    a = list(map(int, input().split()))
    t = 1
    for i in a:
        if i == t:
            t += 1
    for i in a:
        if i == t:
            t += 1
    if t == 11:
        print("YES")
    else:
        print("NO")

Python: import sys

def stackBall(ball):
	sB, sC = [0], [0]
	for b in ball:
		if max(sB[-1], sC[-1]) < b:
			if sB[-1] >= sC[-1]:
				sB.append(b)
			else:
				sC.append(b)
		elif min(sB[-1], sC[-1]) < b:
			if sB[-1] >= sC[-1]:
				sC.append(b)
			else:
				sB.append(b)
		else:
			return False
	return True


n = int(input())

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

Python: x=int(input())
for i in range(x):
	num=[int(i) for i in input().split()]
	b=[]
	c=[]
	flag=0
	b.append(num[0])
	c.append(min(num)-1)
	for i in range(1,10):
		if b[len(b)-1]<num[i]:
			b.append(num[i])
		elif c[len(c)-1]<num[i]:
			c.append(num[i])
		else:
			flag=1
			break
	if flag==0:
		print("YES")
	else:
		print("No")

Python: n = int(input())

for i in range(n):
    l = list(map(int, input().split()))
    b, c, flag = 0, 0, 0
    for seq in l:
        if seq > b:
            b = seq
        elif seq > c:
            c = seq
        else:
            flag = 1
    if flag == 0:
        print("YES")
    else:
        print("NO")

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

Python: x=int(input())
for i in range(x):
	num=[int(i) for i in input().split()]
	b=[]
	c=[]
	flag=0
	b.append(num[0])
	c.append(int(0))
	for i in range(1,10):
		if b[len(b)-1]<num[i]:
			b.append(num[i])
		elif c[len(c)-1]<num[i]:
			c.append(num[i])
		else:
			flag=1
			break
	if flag==0:
		print("YES")
	else:
		print("No")

Python: 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: 
if __name__ == '__main__':

	n = int(input())

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

		tmp1 = [0]
		tmp2 = [0]

		Flg = True
		for j in A:
			if tmp1[-1] < j:
				tmp1.append(j)
			else:
				if tmp2[-1] < j:
					tmp2.append(j)
				else:
					Flg = False
					break

		if Flg:
			print("YES")
		else:
			print("NO")

Python: for _ in[0]*int(input()):
 b=c=0
 for e in map(int,input().split()):
  if e>b:b=e
  elif e>c:c=e
  else: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: 
n = int(input())

for i in range(n):
    tmp = list(map(int,input().split()))
    a,b,cnt = 0,0,0
    
    for j in range(10):
        if a<tmp[j]: a = tmp[j]
        elif b<tmp[j]: b = tmp[j]
        else: cnt += 1
        
    if cnt==0: print("YES")
    else: print("NO")

Python: x=int(input())
for _ 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: import sys

def solve(balls):
    ans = distribute(balls, [], [])
    if ans is True: print('YES')
    else: print("NO")
        
def distribute(balls, R, L):
    if len(balls) != 0:
        next = balls[0]
        ans = False
        #case R
        if isMutch(next, R):
            neoR = R
            neoR.append(next)
            ans = distribute(balls[1:], neoR, L)
        if isMutch(next, L):
            neoL = L
            neoL.append(next)
            ans =distribute(balls[1:], R, neoL)
        if ans: 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)
  
line = input()
size = -1;
while True:
    if size == -1:
        size = int(line)
    else:
        solve(line.split(' '))
        size -= 1
        print(size)
        if size == 0: break
    line = input()

Python: import sys
f = sys.stdin
def cylinder(balls):
    cy = []
    for ball in balls:
        if len(cy) == 0:
            pass
        elif len(cy) == 1:
            if cy[0] < ball:
                cy.remove(cy[0])
        elif min(ball, *cy) == ball:
            return False
        elif max(ball, *cy) == ball:
            cy.remove(max(cy))
        else:
            cy.remove(min(cy))
        cy.append(ball)
    return True

n = int(f.readline())
for _ in range(n):
    balls = list(map(int, f.readline().split()))
    print('YES' if cylinder(balls) else 'NO')

Python: # AOJ 0033

N = int(input())
for i in range(N):
    balls = list(map(int, input().split()))
    b = 0
    c = 0
    for ball in balls:
        if b < ball:
            b = ball
        elif c < ball:
            c = ball
        else:
            print('NO')
            break
    else:
        print('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')