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):
    x = input()
    y = x.split(' ')
    a = []
    b = []
    text='YES'
    for j in range(10):
        number = int(y[j])
        aNum = 0
        bNum = 0
        if a != [] :
            aNum = a[-1]
        if b != [] :
            bNum = b[-1]

        if(aNum > bNum):
            if(aNum < number):
                a.append(number)
            else:
                if(bNum < number):
                    b.append(number)
                else:
                    text = 'NO'
                    break
        else:
            if(bNum < number):
                b.append(number)
            else:
                if(aNum < number):
                    a.append(number)
                else:
                    text = 'NO'
                    break
#    print(a)
#    print(b)
    print(text)

Python: for n in range(int(input())):
  A = [int(i) for i in input().split()]
  B = [0]
  C = [0]
  for a in A:
    if a > B[-1] and a > C[-1]:
      if a - B[-1] <= a - C[-1]:
        B.append(a)
      else:
        C.append(a)
    elif a > B[-1] and a < C[-1]:
      B.append(a)
    elif a > C[-1]:
      C.append(a)
    else:
      print("NO")
      break
  if len(B) + len(C) == 12:
    print("YES")

Python: def dfs(i, b, c):
    if i == 10:
        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: n=int(input())
for i in range(n):
    a=list(map(int,input().split()))
    b,c=0,0
    yes = True
    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: n = int(input())
a = [[0 for i in range(10)] for j in range(n)]

for i in range(n):
    a[i] = list(map(int, input().split()))
    
for i in range(n):
    l = 0
    r = 0
    f = 1
    for j in range(10):
        if l>=r and l<a[i][j]:
            l = a[i][j]
        elif r<a[i][j]:
            r = a[i][j]
        else:
            f = 0
            break
    if f == 1:
        print("YES")
    else:
        print("NO")

Python: from itertools import product
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    *B, = map(int, readline().split())
    N = 10
    for p in product([0, 1], repeat = N):
        p1 = p2 = 0
        ok = 1
        for b, e in zip(B, p):
            if e:
                if not p1 < b:
                    break
                p1 = b
            else:
                if not p2 < b:
                    break
                p2 = b
        else:
            write("YES\n")
            break
    else:
        write("NO\n")
T = int(readline())
for i in range(T):
    solve()

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: # -*- coding:utf-8 -*-

def dfs(datas, b, c, count):
    if len(data) == count: return 1
    p = int(data[count])
    if p > b:
        q = dfs(data, p, c, count+1)
        if q==1:return 1
    if p > c:
        q = dfs(data, b, p, count+1)
        if q==1:return 1
    return 0

def solve():
    b=0
    c=0
    count = 0
    q = dfs(data, b, c, count)
    if q==1:
        print("YES")
    elif q==0:
        print("NO")

counter = 0
line = input()
if not " " in line:
    nums = line
while True:
    line = input()
    data = line.split(" ")
    q = solve()
    counter += 1
    if int(nums) == counter:
        break

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

Python: def ball(nums):
    b, c = 0, 0
    for i in range(len(nums)):
        if b < nums[i]:
            b = nums[i]
            continue
        if c < nums[i]:
            c = nums[i]
            continue
        return "NO"
    return "YES"

N = int(input())

for _ in range(N):
    a = list(map(int, input().split()))
    print(ball(a))

Python: n = int(input())

for j in range(n):
    nums = list(map(int, input().split()))

    b = [0]
    c = []
    ans = "YES"

    for i in range(10):
        if nums[i] > b[-1]:
            b.append(nums[i])
        else:
            c.append(nums[i])

    if len(c) > 1:
        x = c[0]
        for i in range(1, len(c)):
            if x > c[i]:
                ans = "NO"
            else:
                x = c[i]
    print(ans)

Python: def check(a):
    b = [a[0]]
    c = [0]
    for i in range(1, len(a)):
        x = a[i]
        if x < b[-1] and x < c[-1]:
            return False
        elif b[-1] < x < c[-1]:
            b.append(x)
        elif c[-1] < x < b[-1]:
            c.append(x)
        elif b[-1] > c[-1]:
            b.append(x)
        else:
            c.append(x)
    return True

n = int(input())
for i in range(n):
    a = list(map(int, input().split()))
    print('YES' if check(a) else 'NO')

Python: n=int(input())
for i in range(n):
    ball=list(map(int,input().split()))
    b=0
    c=0
    flag=0
    for j in ball:
        if b>j and c>j:
            flag=1
            break
        elif b>j or j-c<j-b:
            c=j
        else:
            b=j
    print('YNEOS'[flag::2])

Python: import sys
sys.setrecursionlimit(10 ** 8)

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    n = Z()
    for _ in range(n):
        A = ZZ()
        done = [False] * 10

        def dfs(i, a):
            if done[i]:
                if i+1 < 10: dfs(i+1, a)
                else: return
            else:
                if a < A[i]:
                    done[i] = True
                    if i+1 < 10: dfs(i+1, A[i])
                else:
                    if i+1 < 10: dfs(i+1, a)

        cc = 0
        for i in range(10):
            if done[i]: continue
            cc += 1
            done[i] = True
            dfs(i, A[i])

        print('YES' if cc <= 2 else 'NO')


    return

if __name__ == '__main__':
    main()

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

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: # AOJ 0033 Ball
# Python3 2018.6.16 bal4u

n = int(input())
for i in range(n):
	a = list(map(int, input().split()))
	b = c = 0
	yes = True
	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')