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: 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(n,left,right):
    if n==10:
        return 1
    if a[n]>left:
        return solve(n+1,a[n],right)
    if a[n]>right:
        return solve(n+1,left,a[n])
    return 0

n=int(input())
for _ in range(n):
    a=[int(i) for i in input().split()]
    print("YES" if solve(0,0,0) else "NO")

Python: a=[]
n=int(input())
for i in range(10):
        a.append(-1)
while(n!=0):
    n-=1
    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):
    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):
    B = C = 0
    yes = True
    a = list(map(int,input().split()))
    for j in range(10):
	    if a[j] > B:
		    B = a[j]
	    elif a[j] > C:
		    C = a[j]
	    else:
		    yes = False
    print("YES" if yes else "NO")

Python: def solve(n,left,right):
    if n==10:
        return 1
    if a[n]>left:
        return solve(n+1,a[n],right)
    if a[n]>right:
        return solve(n+1,left,a[n])
    return 0

n=int(input())
for _ in range(n):
    a=[int(i) for i in input().split()]
    print("YES" if solve(10,0,0) else "NO")

Python: n = int(input())
for i in range(n):
    Bt = [0]
    Ct = [0]
    Alis = list(map(int,input().split()))
    Bt.append(Alis[0])
    for i in range(1,len(Alis)):
        if Bt[len(Bt) - 1] < Alis[i] and Ct[len(Ct) - 1] > Alis[i]:
            Bt.append(Alis[i])
        elif Bt[len(Bt) - 1] > Alis[i] and Ct[len(Ct) - 1] < Alis[i]:
            Ct.append(Alis[i])
        elif Bt[len(Bt) - 1] > Alis[i] and Ct[len(Ct) - 1] > Alis[i]:
            print("NO")
            break
        else:
            if Alis[i] - max(Bt) > Alis[i] - max(Ct):
                Ct.append(Alis[i])
            elif Alis[i] - max(Ct) > Alis[i] - max(Bt):
                Bt.append(Alis[i])
        if i == len(Alis) - 1:
            print("YES")

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(arr) == len(left) + len(right):
        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: #!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright  : @Huki_Hara
# Created    : 2015-03-11

for _ in range(int(input())):
    l=[0]
    r=[0]
    c=True
    n=map(int, input().split())
    for i in n:
        if l[-1] > i and r[-1] > i:
            c=False
            break
        if l[-1] < i:
            l.append(i)
        else:
            r.append(i)
    print("YES" if c else "NO" )

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

import sys
sys.setrecursionlimit(10**6)

def dfs(balls,B=-2,C=-1,cp=0):
	if cp==len(balls): 	return True
	ball = balls[cp]
	if C<ball:
		is_find = dfs(balls,B,ball,cp+1)
		if is_find: return True
	if B<ball:
		is_find = dfs(balls,ball,C,cp+1)
		if is_find: return True
	return False

def not_dfs(balls):
	B, C = -2, -1
	for ball in balls:
		if C<ball:
			C = ball
			continue
		if B<ball:
			B = ball
			continue
		return False
	return True

def main():
	N = int(input().strip())
	for _ in range(N):
		balls = list(map(int,input().split(' ')))
#		is_find = dfs(balls)
		is_find = not_dfs(balls)
		if is_find:		print('YES')
		else:			print('NO')

if __name__=='__main__':
	main()

"""
2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
"""

Python: n=input()
for _ in xrange(n):
    b=[0]
    c=[0]
    a=map(int,raw_input().split())
    for i in a:
        if b[-1]<=c[-1]:
            if c[-1]<=i:
                c.append(i)
            elif b[-1]<=i:
                b.append(i)
        else:
            if b[-1]<=i:
                b.append(i)
            elif c[-1]<=i:
                c.append(i)
    if len(b)+len(c)==len(a)+2:
        print('YES')
    else:
        print('NO')

Python: N = int(input())
for i in range(N):
    a = [int(n) for n in input().split()]
    b = []
    c = []
    jurge = "YES"
    for n in a:
        if len(b) == 0\
        or b[len(b)-1] < n:
            b.append(n)
        elif len(c) == 0\
        or c[len(c)-1] < n:
            c.append(n)
        else:
            print("NO")
            jurge = "NO"
            break
    if jurge == "YES":
        print("YES")

Python: n = int(input())
for i in range(0,n):
    a = b = 0
    arr = list(int(x) for x in input().split())
    ans = "YES"
    for j in range(0,10):
        if arr[j] < a and arr[j] < b:
            ans = "NO"
            break
        else:
            if a > b:
                if a < arr[j]:
                    a = arr[j]
                else :
                    b = arr[j]
            else:
                if b < arr[j]:
                    b = arr[j]
                else:
                    a = arr[j];
    print(ans)

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