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):
    l = list(map(int, input().split()))
    k , c= l[0], 0
    for j in l:
        if j < k:
            c += 1
        else:
            c = 0
    if 2 <= c:
        print("NO")
    else:
        print("YES")

Python: def f(x):
    a,b=0,0
    for e in x:
        if e>a: a=e
        elif e>b: b=e
        else: return 0
    return 1

n=input()
for i in range(n):
    D = map(int, raw_input().split())
    print ["NO","YES"][f(D)]

Python: n = int(input())
for i in range(n):
    balls = list(map(int, input().split()))
    b, c = 0, 0 
    flag = 0
    for ball in balls:
        if b == 0:
            b = ball
        elif b < ball:
            b = ball
        elif c > ball:
            flag = 1
            break
        else:
            c = ball
    if flag == 0:
        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: N = int(input())
for n in range(N):
	str = input().split()
	list = []
	for i in str:
		list.append(int(i))
	b = c = []
	ans = True

	for a in list:
		bLen = len(b)
		cLen = len(c)
		bLast = bLen - 1 if bLen > 0 else 0
		cLast = cLen - 1 if cLen > 0 else 0
		if bLast == 0:
			b.append(a)
			continue
		if b[bLast] > a:
			if cLast == 0 or c[cLast] < a:
				c.append(a)
				continue
			else:
				ans = False
				break
		
	print('YES' if ans is True else 'NO')

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 ans: return True
        
        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:
        balls = []
        for a in line.split(' '):
            balls.append(int(a))   
        solve(balls)
        size -= 1
        if size == 0: break
    line = input()

Python: # Aizu Problem 0033: Ball
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


N = int(input())
for n in range(N):
    balls = [int(_) for _ in input().split()][::-1]
    left, right = [0], [0]
    fail = False
    while len(balls) > 0:
        ball = balls.pop()
        if ball > left[-1]:
            left.append(ball)
        elif ball > right[-1]:
            right.append(ball)
        else:
            fail = True
            break
    print("YES" if not fail else "NO")

Python: BALL_NUM = 10


def main():
    n = int(input())
    while n > 0:
        balls = list(map(int, input().split()))
        if dfs(balls, 0, 0):
            print("YES")
        else:
            print("NO")

        n -= 1


def dfs(balls, b, c):
    if len(balls) == 1:
        if balls[0] > b or balls[0] > c:
            return True
        else:
            return False

    # ????????????b?????\????????´???
    if balls[0] > b and dfs(balls[1:], balls[0], c):
        return True
    # ????????????c?????\????????´???
    if balls[0] > c and dfs(balls[1:], b, balls[0]):
        return True

    return False


if __name__ == '__main__':
    main()

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 < l:
                r,l = l,r
            
        if r == -777:
            continue
        else:
            print("Yes")

if __name__ == '__main__':
    main()

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):
            print(j)
            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: N = input()
for x in range(int(N)):
    B = map(int, input().split())
    a = b = 0
    for y in B:
        if y > a:
            a = y
        elif y > b:
            b = y
        else:
            print('NO')
            a = -1
            break
        if a < b:
            a, b = b, a
    if a == -1:
        continue
    else:
        print('YES')

Python: N = int(input())
for _ in range(N):
    balls = list(map(int, input().split()))
    B, C = [0], [0]
    ans = 1
    for i in range(10):
        b = balls[i]
        if b > B[-1]:
            B.append(b)
        else:
            if b > C[-1]:
                C.append(b)
            else:
                ans = 0
                break
    print("YES" if ans else "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: n = int(input())
for i in range(n):
    B = 0
    C = 0
    A = [int(i) for i in input().split()]
    ans = 'YES'
    for v in A:
        if B > v and C > v:
            ans = 'NO'
            break
        elif B < v and C < v:
            if B > C:
                B = v
            else:
                C = v
        elif B < v:
            B = v
        else:
            C = v
    print(ans)

Python: n = int(input())
for _ in range(n):
    data = list(map(int, input().split()))
    B, C = 0, 0
    flag = True
    for d in data:
        if B < d:
            B = d
        elif C < d:
            C = d
        else:
            print("NO")
            flag = False
            break
    if flag:
        print("YES")

Python: def bl(l):
    b=[]
    c=[]
    for (i,j) in enumerate(l):
        if(i==0):b.extend([j])
        elif(j>b[-1]):b.extend([j])
        elif(c and j>c[-1] and j<b[-1]):c.extend([j])
        elif(not c):c.extend([j])
        else:return 0
    return 1

l=[list(map(int,input().split())) for i in range(int(input()))]
[print("YES") if bl(i) else print("NO") for i in l]