Problem:


玉

図のように二股に分かれている容器があります。1 から 10 までの番号が付けられた10 個の玉を容器の開口部 A から落とし、左の筒 B か右の筒 C に玉を入れます。板 D は支点 E を中心に左右に回転できるので、板 D を動かすことで筒 B と筒 C のどちらに入れるか決めることができます。

開口部 A から落とす玉の並びを与えます。それらを順番に筒 B 又は筒 Cに入れていきます。このとき、筒 B と筒 C のおのおのが両方とも番号の小さい玉の上に大きい玉を並べられる場合は YES、並べられない場合は NO と出力するプログラムを作成してください。ただし、容器の中で玉の順序を入れ替えることはできないものとします。また、続けて同じ筒に入れることができるものとし、筒 B, C ともに 10 個の玉がすべて入るだけの余裕があるものとします。

Input

複数のデータセットが与えられます。１行目にデータセット数 N が与えられます。つづいて、N 行のデータセットが与えられます。各データセットに 10 個の番号が左から順番に空白区切りで与えられます。

Output

各データセットに対して、YES または NO を１行に出力して下さい。

Sample Input

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

Output for the Sample Input

YES
NO



Sample input:
2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1


Sample output:
YES
NO

Submission status: Wrong Answer

Solution code:
N = input() + 1
for val in range(1,N):
	x = map(int,raw_input().split(' '))
	no_num = []
	for l in range(1,10):
		GE_num = []
		for n in range(0,l):
			if x[n] >= x[l]:
				GE_num.append('GE')
		if len(GE_num) == l:
			no_num.append('no')
	if len(no_num) <= 1:
		print 'YES'
	else:
		print 'NO'

Submission status: Wrong Answer

Solution code:
N = input() + 1
for val in range(1,N):
	x = map(int,raw_input().split(' '))
	branch = 1
	for l in range(2,10):
		lessthan = []
		for n in range(0,l):
			if x[n] < x[l]:
				lessthan.append('<')
		if len(lessthan) == 0:
			branch += 1
	if branch <= 2:
		print 'YES'
	else:
		print 'NO'

Submission status: Wrong Answer

Solution code:
N = input() + 1
for val in range(1,N):
	x = map(int,raw_input().split(' '))
	branch = 1
	for l in range(1,10):
		lessthan = []
		for n in range(0,l):
			if x[n] < x[l]:
				lessthan.append('<')
		if len(lessthan) == 0:
			branch += 1
	if branch <= 2:
		print 'YES'
	else:
		print 'NO'

Submission status: Wrong Answer

Solution code:
N = input() + 1
for val in range(1,N):
	x = map(int,raw_input().split(' '))
	branch = 1
	for l in range(1,10):
		lessthan = []
		for n in range(0,l):
			if x[n] < x[l]:
				lessthan.append('<')
		if lessthan == []:
			branch += 1
	if branch <= 2:
		print 'YES'
	else:
		print 'NO'

Submission status: Wrong Answer

Solution code:
N = input() + 1
for val in range(1,N):
	branches = [[100] for x in range(0,10)]
	x = map(int,raw_input().split(' '))
	branches[0][0] = x[0]
	branch_num = 0
	for l in range(1,10):
		small_num = 0
		for n in range(0,l):
			if branches[n][0] < x[l]:
				small_num += 1
		if small_num == 0:
			branches[l][0] = x[l]
	for val in range(0,10):
		if branches[val][0] != 100:
			branch_num += 1
	if branch_num <= 2:
		print 'YES'
	else:
		print 'NO'

Submission status: Wrong Answer

Solution code:
def check(x):
    a, b = 0, 0
    for ball in x:
        if a > ball:
             a = ball
        elif b > ball:
             b = ball
        else:
             return False
    return True

n = int(raw_input())
for i in range(n):
    all = map(int, raw_input().split())
    print "YES" if check(all) else "NO"

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    data = [int(i) for i in input().split()]
    flag = False
    a = [0]
    b = [0]
    for ball in data:
        if ball > a[-1]:
            a.append(ball)
        elif ball > b[-1]:
            b.append(ball)
        else:
            flag = True
            break
    print("NO") if flag else print("YES")

Submission status: Accepted

Solution code:
from sys import stdin

for _ in range(int(stdin.readline())):
    s = list(map(int, stdin.readline().split()))
    a = 0
    b = 0
    for c in s:
        if a<c: a=c
        elif b<c: b=c
        else:
            print("NO")
            break
    else:
        print("YES")

Submission status: Accepted

Solution code:
n = int(raw_input())

for i in range(n):
    ball = map(int, raw_input().split())
    a = [0]
    b = [0]
    for j in ball:
        if a[-1] < j:
            a.append(j)
        elif b[-1] < j:
            b.append(j)
        else:
            print "NO"
            break
    else:
        print"YES"

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(a,i,b,c):
	return  b == sorted(b) and c == sorted(c) if i == 10 else solve(a,i+1,b+[a[i]],c) or solve(a,i+1,b,c+[a[i]])
	
for roop in range(int(raw_input())):
	print "YES" if solve(map(int,raw_input().split()),0,[],[]) else "NO"

Submission status: Accepted

Solution code:
def s(a,i,b,c):
	return  b==sorted(b) and c==sorted(c) if i==10 else s(a,i+1,b+[a[i]],c) or s(a,i+1,b,c+[a[i]])
	
for roop in range(int(raw_input())):
	print "YES" if s(map(int,raw_input().split()),0,[],[]) else "NO"

Submission status: Accepted

Solution code:
def s(a):
	b = c = 0
	for i in a:
		if i > b:
			b = i
		elif i > c:
			c = i
		else:
			return False
	return True
	
for n in range(int(raw_input())):
	print "YES" if s(map(int,raw_input().split())) else "NO"

Submission status: Accepted

Solution code:
def s(a):
	b=c=0
	for i in a:
		if   i>b:b=i
		elif i>c:c=i
		else:return 0
	return 1
for n in range(int(raw_input())):
	print "YES" if s(map(int,raw_input().split())) else "NO"

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

n = input()
for s in xrange(n):
  d = map( int, raw_input().split() )
  a = b = 0
  flag = True
  for e in d:
    if a < e: a = e
    elif b < e: b = e
    else: flag = False
  if flag: print "YES"
  else: print "NO"

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
#!/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" )

Submission status: Accepted

Solution code:
for data in range(input()):
    dataset=map(int,raw_input().split(" "))
    B,C=0,0
    B=dataset.pop(0)
    while len(dataset)!=0:
        ball = dataset.pop(0)
        if ball-B<0 or ball-C<0:
            if ball-B<0 and ball-C<0:
                print "NO"
                dataset.append(0)
                break
            else:
                if ball-B<0:
                    C=ball
                else:
                    B=ball
        else:
            if ball-B<ball-C:
                B=ball
            else:
                C=ball
    if(len(dataset)==0):
        print "YES"

Submission status: Accepted

Solution code:
def kyoto():
    for ball in ball_lis:
        if B[-1] <= C[-1] < ball:
            C.append(ball)
        elif C[-1] < B[-1] < ball:
            B.append(ball)
        elif B[-1] < ball < C[-1]:
            B.append(ball)
        elif C[-1] < ball < B[-1]:
            C.append(ball)
        else:
            print 'NO'
            break
    else:
        print 'YES'
            
for i in range(int(raw_input())):
    ball_lis = [int(char) for char in raw_input().split()]
    B = [0]
    C = [0]
    kyoto()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(raw_input())

def dfs(depth, l, r):
    if depth == 10:
        return True

    if l < A[depth] and dfs(depth+1, A[depth], r):
        return True
    if r < A[depth] and dfs(depth+1, l, A[depth]):
        return True

    return False

for c in range(N):
    A = map(int, raw_input().split(" "))
    if dfs(0, 0, 0):
        print "YES"
    else:
        print "NO"

Submission status: Accepted

Solution code:
n = int(input())
while n > 0:
  l = [int(i) for i in input().split()]
  m1 = [0]
  m2 = [0]
  for i in l:
    M1 = max(m1)
    M2 = max(m2)
    if i < M1 and i < M2:
      print('NO')
      break
    elif M1 <= i <= M2:
      m1.append(i)
    elif M2 <= i <= M1:
      m2.append(i)
    elif M2 <= M1 <= i:
      m1.append(i)
    elif M1 <= M2 <= i:
      m2.append(i)
  else:
    print('YES')
  n -= 1

Submission status: Accepted

Solution code:
def sol(a):
    b=c=0
    for i in a:
        if i>b:
            b=i
        elif i>c:
            c=i
        else:
            return 0
    return 1
n=int(raw_input())
for i in range(n):
    l=map(int,raw_input().split())
    print 'YES' if sol(l) else 'NO'

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import collections


def judge(balls):
    left_balls = collections.deque([0])
    right_balls = collections.deque([0])
    while balls:
        ball = balls.popleft()
        if ball > left_balls[-1]:
            left_balls.append(ball)
        elif ball > right_balls[-1]:
            right_balls.append(ball)
        else:
            return "NO"
    return "YES"


def main():
    n = int(input())
    for x in range(n):
        balls = collections.deque(map(int, input().split()))
        print(judge(balls))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = input()
for i in xrange(N):
    ball = map(int, raw_input().split())
    a = [0]
    b = [0]
    for x in ball:
        if a[-1] < x:
            a.append(x)
        elif b[-1] < x:
            b.append(x)
        else:
            print "NO"
            break
    else:
        print "YES"

Submission status: Accepted

Solution code:
def solve(A):
	B=[]
	C=[]
	#print(A)
	#??????
	B.append(A[0])
	C.append(0)#?????§??????
	for i in range(1,9):
		if B[-1]<A[i] and C[-1]>A[i]:
			B.append(A[i])
			#print("B",B)
			#print("C",C)
		elif B[-1]>A[i] and C[-1]<A[i]:
			C.append(A[i])
			#print("B",B)
			#print("C",C)
		elif B[-1]<A[i] and C[-1]<A[i]:
			for j in range(i+1,len(A)):
				if A[j]<A[i]:
					if B[-1]<C[-1]:
						C.append(A[i])
						#print("B",B)
						#print("C",C)
						break
					else:
						B.append(A[i])
						#print("B",B)
						#print("C",C)
						break
			else:
				B.append(A[i])
				#print("B",B)
				#print("C",C)
		else:
			break
	del C[0]
	#print("B is ",B)
	#print("C is ",C)
	if B[-1]<A[-1] or C[-1]<A[-1]:
		if len(B)+len(C)==len(A)-1:
			print("YES")
		else:
			print("NO")
	else:
		print("NO")










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

Submission status: Accepted

Solution code:
#encoding=utf-8

x = input()
for i in xrange(x):
	num,a,b = [],[0],[0]
	num = map(int, raw_input().split())
	for i in xrange(10):
		if num[i] > a[0]:
			a.insert(0,num[i])
		elif num[i] > b[0]:
			b.insert(0,num[i])
		else:
			pass

	if len(a) + len(b) == 12:
		print "YES"
	else:
		print "NO"

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    bs = list(map(int, input().split()))
    lanes = [0,0]
    for j in bs:
        if j > lanes[0] and  j > lanes[1]:
            lanes[lanes.index(max(lanes))] = j
        elif j>lanes[0]:
            lanes[0] = j
        elif j>lanes[1]:
            lanes[1] = j
        else:
            print('NO')
            break
    else:
        print('YES')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

n = int(raw_input())
for i in range(n):
    A, B, C = [], [0], [0]
    A = map(int, raw_input().split())
    for i in range(10):
        if A[i] > B[0]:
            B.insert(0, A[i])
        elif A[i] > C[0]:
            C.insert(0, A[i])
        else:
            break
    if len(B) + len(C) == 12:
        print "YES"
    else:
        print "NO"

Submission status: Accepted

Solution code:
for _ in range(int(input())):
    pipe = [0, 0]
    a = list(map(int, input().split()))
    for i in a:
        if i > max(pipe):
            pipe[pipe.index(max(pipe))] = i
        elif i > min(pipe):
            pipe[pipe.index(min(pipe))] = i
        else:
            print('NO')
            break
    else:
        print('YES')

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    str = input().split()
    arr = [int(str[j]) for j in range(len(str))]
    b,c = 0,0
    flag = True
    for i in range(len(arr)):
        if b < arr[i]:
            b = arr[i]
            continue
        if c < arr[i]:
            c = arr[i]
            continue
        print("NO")
        flag = False
        break
    if flag:
        print("YES")

Submission status: Accepted

Solution code:
for i in range(int(input())):
    res = "YES"
    b = c = 0
    for t in map(int,input().split()):
        if t > b >= c:
            b = t
        elif t > c:
            c = t
        else:
            res = "NO"

    print(res)

Submission status: Accepted

Solution code:
N = int(input())
for _ in range(N):
	balls = list(map(int, input().split()))
	left = right = 0
	ans = "YES"
	for i in range(10):
		if min(left, right) > balls[i]:
			ans = "NO"
			break
		if left < right:
			if right < balls[i]:
				right = balls[i]
			else:
				left = balls[i]
		else:
			if left < balls[i]:
				left = balls[i]
			else:
				right = balls[i]
	print(ans)

Submission status: Accepted

Solution code:
N = int(raw_input())

for i in range(N):

  Ball = map(int, raw_input().split())

  left, right = [], []

  for i in Ball:
    if len(left) == 0 or left[len(left) - 1] < i:
      left.append(i)

    elif len(right) == 0 or right[len(right) - 1] < i:
      right.append(i)

    else:
      break

  if len(right) + len(left) == 10:
    print "YES"

  else:
    print "NO"

Submission status: Accepted

Solution code:
N = int(raw_input())

for i in range(N):

  A = map(int, raw_input().split())

  B, C = [], []

  B.append(0)
  C.append(0)

  flag = True

  for i in A:
    if B[-1] < i:
      B.append(i)

    elif C[-1] < i:
      C.append(i)

    else:
      flag = False
      break

  if flag:
    print "YES"

  else:
    print "NO"

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
for _ in range(int(input())):
    ano = []
    balls = list(map(int, input().split()))
    i = 0
    while balls != sorted(balls):
        if balls[i] > balls[i + 1]:
            ano.append(balls[i + 1])
            del balls[i + 1]
        else:
            i += 1
    print('YES' if ano == sorted(ano) else 'NO')

Submission status: Accepted

Solution code:
N = input()
for i in xrange(N):
    b, c = [0], [0]
    for j in map(int, raw_input().split()):
        if b[-1] < j: b.append(j)
        elif c[-1] < j: c.append(j)
        else: break
    else:
        print 'YES'
        continue
    print 'NO'

Submission status: Accepted

Solution code:
N = input()
for i in xrange(N):
    b, c = 0, 0
    for j in map(int, raw_input().split()):
        if b < j: b = j
        elif c < j: c = j
        else: break
    else:
        print 'YES'
        continue
    print 'NO'

Submission status: Accepted

Solution code:
for i in xrange(input()):
    b, c = 0, 0
    for j in map(int, raw_input().split()):
        if b < j: b = j
        elif c < j: c = j
        else: break
    else:
        print 'YES'
        continue
    print 'NO'

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


def ball(nums):
    l = []
    r = []
    for i, num in enumerate(nums):
        if i == 0:
            l.append(num)
        elif l[-1] < num:
            l.append(num)
        elif len(r) == 0:
            r.append(num)
        elif r[-1] < num:
            r.append(num)
        else:
            return 'NO'
    return 'YES'

N = int(input())
# N = 1


for _ in range(N):
    nums = [int(e) for e in input().split()]
    # nums = [3, 1, 4, 2, 5, 6, 7, 8, 9, 10]
    # nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
    print(ball(nums))

Submission status: Accepted

Solution code:
n=input()
for t in xrange(n):
	a=map(int,raw_input().split())
	pos=range(1,11)
	for i in xrange(len(a)):
		pos[a[i]-1]=i
	left=right=-1
	for i in xrange(len(pos)):
		if(left<pos[i]):
			left=pos[i]
		elif(right<pos[i]):
			right=pos[i]
		else:
			print "NO"
			break
	else:
		print "YES"

Submission status: Accepted

Solution code:
import sys

for _ in xrange(input()):
    A = map(int, raw_input().split())
    x, y = 0, 0
    for a in A:
        if a > x and a > y:
            if x >= y:
                x = a
            else:
                y = a
        elif a > x:
            x = a
        elif a > y:
            y = a
        else:
            print 'NO'
            break
    else:
        print 'YES'

Submission status: Accepted

Solution code:

def solve(Balls,Left,Right,i):
	if i==len(Balls):#???????????¶
		return True

	#????????\????????´???
	if len(Left)==0 or Left[-1]<Balls[i]:
		Left.append(Balls[i])
		return solve(Balls,Left,Right,i+1)

	#????????\????????´???
	if len(Right)==0 or Right[-1]<Balls[i]:
		Right.append(Balls[i])
		return solve(Balls,Left,Right,i+1)
	
	return False#??\???????????????



if __name__ == "__main__":
	n=int(input())
	for i in range(n):
		Balls = [int(i) for i in input().split()]
		Left=[]
		Right=[]
		i=0
		if solve(Balls,Left,Right,0):
			print("YES")
		else:
			print("NO")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
# import sys
from itertools import compress
# from random import shuffle, seed, random
from time import perf_counter


def is_right_order(B, C):
    """ 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):  # ????????§??????????????????????????????????????????????????????B?????????C????????????????????????
        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


def solve_greed(d):
    """ ????¬????????????????
    ????????¨?????????????????????????????\????????????C?????\?????????????????\?????????B?????\?????????
    ??? ???????????????????????????????????°????????¨???????????????????????¨????????????????????????????????´?????????
    """
    used = [False] * 11  # ???????????????????????????????????????????????°?????????????????????index??????????????????used[1]?????????????????????????????§????????????+1????????????

    B = []  # ?????\????????????????????\?????????
    C = []  # ????????\???????????????????????????????????\?????????
    for b in d:
        cb = 0
        for i in range(1, 11):
            if used[i] == False:
                cb = i  # ?????????????????????????????????????????\????????????cb??¨?????¶
                break
        if b == cb:
            C.append(b)
        else:
            B.append(b)
        used[b] = True  # ????????????????????????????????????B?????????C???????????????????????????????????§????????¨?????????
    return is_right_order(B, C)


if __name__ == '__main__':
    # ??????????????\???
    num = int(input())
    data = []
    for _ in range(num):
        data.append(list(map(int, input().split(' '))))

    # ???????????¨??????????????????????????????
#    for i in range(100):
#        t = list(range(1, 11))
#        shuffle(t)
#        data.append(t)

    # start_time = perf_counter()
    # ????????????
    for d in data:
        # print('trying: {0}'.format(d))
        #result = solve_bf(d)
        result = solve_greed(d)

        if result:
            print('YES')
        else:
            print('NO')

    # end_time = perf_counter()
    # print('elapsed: {0}'.format(end_time - start_time))

Submission status: Accepted

Solution code:
class Depth_First_Search:
    def __init__(self, bolls):
        self.bolls = bolls
        self.possible = False

    def search(self, left, right, remaining):
        if len(remaining) == 0:
            self.possible = True
        else:
            boll = remaining[0]
            if boll > max(left):
                self.search(left+[boll], right, remaining[1:])
            if boll > max(right):
                self.search(left, right+[boll], remaining[1:])

    def run(self):
        self.search([-1], [-1], self.bolls)

if __name__ == '__main__':
    N = int(input())
    for i in range(N):
        bolls = list(map(int, input().split(' ')))
        DFS = Depth_First_Search(bolls)
        DFS.run()
        if DFS.possible:
            print('YES')
        else:
            print('NO')

Submission status: Accepted

Solution code:
def solve(n,left,right):
    if n==0:
        return 1
    if a[n-1]>left:
        return solve(n-1,a[n-1],right)
    if a[n-1]>right:
        return solve(n-1,left,a[n-1])
    return 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ans=0
def solve(n,left,right):
    global ans
    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")
    ans=0

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def judge(data):
    num = list(map(int,data.split()))
    a,b = 0,0
    for i in range(10):
        if a <= num[i]:
            a = num[i]
        elif b <= num[i]:
            b = num[i]
        else:
            print('NO')
            return 0
    print('YES')
    return 0
            
n = int(input())
array = [0]*n
for i in range(n):
    array[i] = input()

for i in range(n):
    judge(array[i])

Submission status: Accepted

Solution code:
for _ in range(int(input())):
    a=b=c=0
    for x in map(int,input().split()):
        if x>b:b=x
        elif x>c:c=x
        else:a=1
    print(['YES','NO'][a])

Submission status: Accepted

Solution code:
n = int(raw_input().rstrip())

for i in xrange(n):
  a = 0
  b = 0
  is_ok = True
  l = raw_input().rstrip().split(" ")
  for e in l:
    ball = int(e)
    if ball-a <= ball-b and ball-a > 0:
      a = ball
    elif ball-b > 0:
      b = ball
    else:
      is_ok = False
  if is_ok:
    print "YES"
  else:
    print "NO"

Submission status: Accepted

Solution code:
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')

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(n):
    balls = list(map(int, input().split()))
    b = 0
    c = 0
    flag = True
    for itm in balls:
        if b>c: b,c = c,b
        if c<itm: c=itm; continue
        elif b<itm: b=itm; continue
        else: flag = False; break
    if flag: print("YES")
    else: print("NO")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os

N = int(input())
for _ in range(N):
    balls = list(map(int, input().split()))
    left = right = 0
    impossible = False

    for ball in balls:
        if ball > left and ball > right:
            # ?????£????????\?????????
            if left < right:
                right = ball
            else:
                left = ball
        elif ball > left:
            left = ball
        elif ball > right:
            right = ball
        else:
            impossible = True
            break

    if impossible:
        print('NO')
    else:
        print('YES')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**6)

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

def main():
	N = int(input().strip())
	for _ in range(N):
		balls = list(map(int,input().split(' ')))
		is_find = 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
"""

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**6)

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**6)

def dfs(balls,B=-1,C=-2,cp=0):
	if cp==len(balls): 	return True
	ball = balls[cp]
	if B<ball:
		is_find = dfs(balls,ball,C,cp+1)
		if is_find: return True
	if C<ball:
		is_find = dfs(balls,B,ball,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
"""