Go: package main

import "fmt"

func isOrdered(a []int) bool {
	if len(a) <= 1 {
		return true
	}
	for i := 0; i+1 < len(a); i++ {
		if a[i] > a[i+1] {
			return false
		}
	}
	return true
}

func main() {
	// ボールの数がせいぜい10個しかないので、全てのボールの落とし方を全探索することが可能
	// Bit全探索を行う。右から見てj番目のビットが立っているときには左側の筒、立っていない時は右側の筒にいれる物とする。
	// 全てのボールを落とし終わった後に、それぞれの筒で昇順に並んでいるか調べることにする。
	var t int
	fmt.Scan(&t)
	ans := make([]bool, t)
	for i := 0; i < t; i++ {
		balls := make([]int, 10)
		for i := range balls {
			fmt.Scan(&balls[i])
		}
		ans[i] = false
		for bits := 0; bits < (1 << uint(10)); bits++ {
			pipeB := make([]int, 0)
			pipeC := make([]int, 0)
			for j := 0; j < 10; j++ {
				if (bits & (1 << uint(j))) != 0 {
					pipeB = append(pipeB, balls[j])
				} else {
					pipeC = append(pipeC, balls[j])
				}
			}
			if isOrdered(pipeB) && isOrdered(pipeC) {
				// fmt.Printf("test case %d - OK pattern - pipeB %v, pipec %v\n", i, pipeB, pipeC)
				ans[i] = true
				break
			}
		}
	}
	for i := range ans {
		if ans[i] {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

Python: import sys
sys.setrecursionlimit(100000)

def load_balls():
	balls = []
	LINE_NUM, TOTAL = 0, 0
	while True:
		line = sys.stdin.readline().strip()
		LINE_NUM += 1
		if LINE_NUM == 1:
			TOTAL = int(line)+1
			continue
		balls.append([int(i) for i in line.split(" ")])
		if LINE_NUM == TOTAL: break
	return balls
balls_list = load_balls()
for balls in balls_list:
	left, right = [0], [0]
	for ball in balls:
		if left[-1] < ball: left.append(ball)
		elif right[-1] < ball: right.append(ball)
	print("YES" if len(left)-1 + len(right)-1 == 10 else "NO")

Python: n = int(input())
for i in range(n):
    a = list(map(int, input().split()))
    b,c = 0,0
    for i in range(len(a)):
        if b < a[i]:
            b = a[i]
            continue
        if c < a[i]:
            c = a[i]
            continue
        print("NO")
        break
    else:
        print("YES")

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

if __name__ == '__main__':
    main()

Python: import sys
def solve(balls):
    if distribute(balls, [], []): print('YES')
    else: print("NO")
        
def distribute(balls, R, L):    
    if len(balls) != 0:
        next = balls[0]
        if isMutch(next, R):
            neoR = R
            neoR.append(next)
            if distribute(balls[1:], neoR, L): return True
        
        if isMutch(next, L):
            neoL = L
            neoL.append(next)
            if distribute(balls[1:], R, neoL): 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)
  
size = int(input());
for i in range(0,size):
    balls = []
    for a in input().split(' '):
        balls.append(int(a))   
    solve(balls)
    size -= 1
    if size == 0: break

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: 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")