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: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)

def load_balls():
	LINE_NUM, TOTAL = 0, 0
	balls = []
	i = 0
	for line in sys.stdin:
		line = line.strip()
		LINE_NUM += 1
		if LINE_NUM == 1:
			TOTAL = int(line.strip())
			continue
		balls.append([int(i) for i in line.split(" ")])
		if LINE_NUM == TOTAL+1: break
	return balls

class VesselClass:

	def __init__(self):
		self.tmp = []
		self.left = [0]
		self.right = [0]

	def fill(self, balls:list):
		self.tmp = balls

	def DFS(self):
		if len(self.tmp) == 0: print("YES")
		elif self.left[-1] < self.tmp[0]:
			self.left.append(self.tmp[0])
			self.tmp.pop(0)
			self.DFS()
		elif self.right[-1] < self.tmp[0]:
			self.right.append(self.tmp[0])
			self.tmp.pop(0)
			self.DFS()
		else: print("NO")

balls_list = load_balls()
for balls in balls_list:
	Vessel = VesselClass()
	Vessel.fill(balls)
	Vessel.DFS()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

sys.setrecursionlimit(2**11)
size = int(input());
for i in range(size):
    balls = []
    for a in input().split(' '):
        balls.append(int(a))   
    solve(balls)

Submission status: Accepted

Solution code:
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 True

def isMutch(next, lis):
    if len(lis) != 0:
        return next >= lis[len(lis)-1]
    return True

sys.setrecursionlimit(2**11)
size = int(input());
for i in range(size):
    balls = []
    for a in input().split(' '):
        balls.append(int(a))   
    solve(balls)

Submission status: Accepted

Solution code:
import sys
def solve(balls):
    if distribute(balls, 0, 0): print('YES')
    else: print('NO')
  
def distribute(balls, lastR, lastL):    
    if len(balls) != 0:
        next = balls[0]
        if next>lastR:
            if distribute(balls[1:], next, lastL): return True
        
        if next>lastL:
            if distribute(balls[1:], lastR, next): return True
    else:
        return True

sys.setrecursionlimit(2**11)
size = int(input());
for i in range(size):
    balls = []
    for a in input().split(' '):
        balls.append(int(a))   
    solve(balls)

Submission status: Accepted

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

#datas = [1 5 2 6 3 7 8 9 10 4]
#datas = [1 4 2 6 5 3 7 8 9 10]

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

def solve():
    b=0
    c=0
    count = 1
    q = dfs(datas, 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()
    datas = line.split(" ")
    q = solve()
    counter += 1
    if int(nums) == counter:
        break

Submission status: Accepted

Solution code:
# -*- 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

Submission status: Accepted

Solution code:
N = input()
inputs = [map(int, raw_input().split(' ')) for i in range(N)]
for xs in inputs:
    a, b = 0, 0
    for x in xs:
        if min(a,b) > x:
            print 'NO'
            break
        else:
            if (a>b and x>a) or (b>x):
                a=x
            else:
                b=x
        if x == xs[-1]:
            print 'YES'

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    l = list(map(int, input().split()))
    x = y = z = 0
    for j in l:
        if j > y:
            y = j
        elif j > z:
            z = j
        else:
            x = 1
    print(["YES", "NO"][x])

Submission status: Accepted

Solution code:
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 bLen == 0 or b[bLast] < a:
			b.append(a)
			continue
		if b[bLast] > a:
			if cLen == 0 or c[cLast] < a:
				c.append(a)
				continue
			else:
				ans = False
				break
	print('YES' if ans is True else 'NO')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
def dfs(i, b, c):
    if i == 11:
        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")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    balls = list(map(int, input().split()))
    b = c = 0
    for ball in balls:
        if b < ball:
            b = ball
        elif c < ball:
            c = ball
        else:
            print('NO')
            break
    else:
        print('YES')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    b = list(map(int, input().split()))
    c_r = [-1]
    c_l = [-1]
    for j in range(10):
        if c_r[-1] < b[j]:
            c_r.append(b[j])
        elif c_l[-1] < b[j]:
            c_l.append(b[j])
        else:
            print("NO")
            break
    else:
        print("YES")

Submission status: Accepted

Solution code:
N = int(input())
for l in range(N):
    A = [int(i) for i in input().split()]
    B = 0
    C = 0
    ans = "YES"
    for i in range(10):
        if A[i] > B:
            B = A[i]
        elif A[i] > C:
            C = A[i]
        else:
            ans = "NO"
    print(ans)

Submission status: Accepted

Solution code:
for _ in[0]*int(input()):
 a=list(map(int,input().split()))
 b=[a[0]];c=[0]
 for e in a[1:]:
  if e>b[-1]:b+=[e]
  elif e>c[-1]:c+=[e]
  else:print('NO');break
 else:print('YES')

Submission status: Accepted

Solution code:
for _ in[0]*int(input()):
 b=c=0
 for e in map(int,input().split()):
  if e>b:b=e
  elif e>c:c=e
  else:print('NO');break
 else:print('YES')

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x=int(input())
for _ in range(x):
	num=list(map(int,input().split()))
	b,c=0,0
	flag=True
	for i in num:
		if b<i:
			b=i
		elif c<i:
			c=i
		else:
			print("NO")
			flag=False
			break
	if flag:
		print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solution():
    n = input()
    data = []
    for _ in range(n):
        data.append([int(val) for val in raw_input().split()])
    for i in range(n):
        ans = True
        l = 0
        r = 0
        for j in range(10):
            if data[i][j] > l:
                l = data[i][j]
            elif data[i][j] > r:
                r = data[i][j]
            else:
                ans = False
                break
        if ans:
            print 'YES'
        else:
            print 'NO'

solution()

Submission status: Accepted

Solution code:
n = int(input())
def bi(ball, i, x, y):
    # print(i, len(x), len(y))
    if i != 10:
        x2, y2 = x + [ball[i]], y + [ball[i]]
        bi(ball, i + 1, x2, y)
        bi(ball, i + 1, x, y2)
    else:
        nx = x[:]
        ny = y[:]
        x.sort(), y.sort()
        if nx == x and ny == y:
            global ans
            ans = 'YES'
            # print(nx, ny)

for i in range(n):
    ans = 'NO'
    ball = list(map(int, input().split()))
    bi(ball, 0, [], [])
    print(ans)

Submission status: Accepted

Solution code:
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]

Submission status: Accepted

Solution code:
#数列に対し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")
      return
    
    #last_b < new <= last_c   --> Bを更新
    elif new <= last_c:
      last_b = new
    
    #last_b < last_c < new    --> Cを更新
    else:
      last_c = new
  
  print("YES")
  return

def main():
  n = int(input())

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

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def int_input():
    return list(map(int, input().split()))


def is_sorted(l):
    return all(l[i] <= l[i + 1] for i in range(len(l) - 1))


def dfs(arr, i, a, b):
    if i == 10:
        return is_sorted(a) and is_sorted(b)
    na = a + [arr[i]]
    nb = b + [arr[i]]
    return any([
        dfs(arr, i + 1, na, b) if is_sorted(na) else False,
        dfs(arr, i + 1, a, nb) if is_sorted(nb) else False])


n = int(input())
for _ in range(n):
    raw = int_input()
    print("YES" if dfs(raw, 0, list(), list()) else "NO")

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    b = list()
    c = list()
    a =  list(map(int, input().split()))
    # print(a)
    b.append(a.pop(0))

    for _  in range(9):
        a0 = a.pop(0)
        if b[-1] < a0:
            b.append(a0)
        elif len(c)==0 or c[-1]<a0:
            c.append(a0)
        else:
            a.append(a0)
            print('NO')
            break
    if len(a)==0:
        print('YES')

Submission status: Accepted

Solution code:
for i in xrange(input()):
    head1,head2=0,0
    frag=True
    for a in map(int,raw_input().split()):
        if head1>a and head2>a:
            frag=False
            break
        if head1<a and head1 > head2 or head2>a:
            head1=a
        else:
            head2=a
    if frag:print "YES"
    else:print "NO"

Submission status: Accepted

Solution code:
def dfs(al,bl,cl):
    if(len(al) == 0):
        return True
    else:
        if(al[0] > bl[-1]):
            b = dfs(al[1:], bl+al[0:1], cl)
            if(b):
                return True
        if(al[0] > cl[-1]):
            b = dfs(al[1:], bl, cl+al[0:1])
            if(b):
                return True
        return False

for i in xrange(int(raw_input())):
    if(dfs([int(j) for j in raw_input().split()],[-1],[-1])):
        print 'YES'
    else:
        print 'NO'

Submission status: Accepted

Solution code:
def solve(balls):
    B,C=[],[]
    B.append(balls[0])
    for ball in balls[1:]:
        if B[-1]<ball:
            B.append(ball)
        else:
            if len(C)==0: C.append(ball)
            else:
                if C[-1]<ball:
                    C.append(ball)
                else:
                    return "NO"
    return "YES"

if __name__=='__main__':
    N=int(raw_input())
    for i in range(N):
        balls=map(int,raw_input().split())
        print solve(balls)

Submission status: Accepted

Solution code:
def solve(balls):
    B,C=balls[0],0
    for ball in balls[1:]:
        if B<ball:
            B=ball
        else:
            if C<ball:
                C=ball
            else:
                return "NO"
    return "YES"

if __name__=='__main__':
    N=int(raw_input())
    for i in range(N):
        balls=map(int,raw_input().split())
        print solve(balls)

Submission status: Accepted

Solution code:
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

for _ in xrange(int(stdin.readline())):
    result = 'YES'
    b = c = 0
    for a in (int(s) for s in stdin.readline().split()):
        if b < a:
            b = a
        elif c < a:
            c = a
            if b < c:
                b, c = c, b
        else:
            result = 'NO'
            break
    print(result)

Submission status: Accepted

Solution code:
N = input() + 1
for val in range(1,N):
	c = 0
	x = map(int,raw_input().split(' '))
	a = x[0]
	b = 0
	for n in range(1,10):
		if b > a:
			e = a
			d = b
			a = d
			b = e
		else:
			pass
		if a < x[n]:
			a = x[n]
		elif a > x[n] and b < x[n]:
			b = x[n]
		elif x[n] < b:
			c += 1
	if c == 0:
		print 'YES'
	else:
		print 'NO'

Submission status: Accepted

Solution code:

import sys


def fill_balls(a):
    b = [0]
    c = [0]
    for ball in a:
        if b[-1] == 0:
            b.append(ball)
        elif b[-1] < ball and c[-1] < ball:
            if b[-1] < c[-1]:
                c.append(ball)
            else:
                b.append(ball)
        elif b[-1] < ball:
            b.append(ball)
        elif c[-1] < ball:
            c.append(ball)
        else:
            return 'NO'
    return 'YES'



for i in range(input()):
    a = map(int, raw_input().split(' '))
    print fill_balls(a)

Submission status: Accepted

Solution code:
for i in range(input()):
 	q,w=[0],[0]
 	flag=0
 	_L=map(int,raw_input().split())
 	q.append(_L[0])
 	for j in _L[1:]:
  		if q[-1] > w[-1]:
    		 if q[-1] < j: q.append(j)
    		 elif w[-1] < j: w.append(j)
    		 else: 
        		  flag=1
        		  break
  		if q[-1] < w[-1]:
    		 if w[-1] < j: w.append(j)
    		 elif q[-1] < j: q.append(j)
    		 else: 
        		  flag=1
        		  break
 	print "YES" if flag==0 else "NO"

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=input()
for i in range(n):
    dt=map(int, raw_input().split())
    a1=0
    a2=0
    for e in dt:
        if e>a1: a1=e
        elif e>a2: a2=e
        else:
            print "NO"
            break
    else:
        print "YES"

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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


def check_one(balls, partition):
    l_head = 0
    r_head = 0

    for i in xrange(10):
        ball = balls[i]
        # 左に入る場合
        if partition[i] == 1:
            if l_head > ball:
                # NG
                return False
            else:
                # OK
                l_head = ball
        # 右に入る場合
        else:
            if r_head > ball:
                # NG
                return False
            else:
                # OK
                r_head = ball

    # 最後まで return False しなかった
    return True


def generate_partitions():

    total = []

    for i in xrange(2**10):
        bin = [0] * 10
        for b in xrange(10):
            bin[b] = i >> b & 1

        total.append(bin)

    return total


def check_total(balls, total):
    for p in total:
        if check_one(balls, p):
            return True

    return False


def main():
    num_data_set = int(raw_input())

    for i in xrange(num_data_set):
        balls = map(int, raw_input().strip().split())
        total = generate_partitions()
        if check_total(balls, total):
            print 'YES'
        else:
            print 'NO'


main()

Submission status: Accepted

Solution code:
n = int(raw_input())
for i in range(n):
    ball = map(int, raw_input().split())
    a = [ball[0]]
    b = []
    flag = 0
    for j in range(1,10):
        if ball[j] > a[len(a)-1]:
            a.append(ball[j])
        else:
            b.append(ball[j])
            if len(b) > 1 and b[len(b)-2] > b[len(b)-1]:
                print "NO"
                flag = 1
                break
    if flag == 0:
        print "YES"

Submission status: Accepted

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:
def d(x):
    b, c = 0, 0
    for a in x:
        if b < a:
             b = a
        elif c < a:
             c = a
        else:
             return False
    return True
 
n = int(raw_input())
for i in range(n):
    all = map(int, raw_input().split())
    print "YES" if d(all) else "NO"

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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())
    s = ["NO","YES"][f(D)]
    print s

Submission status: Accepted

Solution code:
for i in range(input()):
	balls = map(int, raw_input().split())
	a = [balls.pop(0)]
	b = [0]
	flag = 0
	while len(balls) > 0:
		gapa = balls[0] - a[-1]
		gapb = balls[0] - b[-1]
		if gapa < gapb:
			if gapa > 0:
				a.append(balls.pop(0))
			elif gapb > 0:
				b.append(balls.pop(0))
			else:
				flag = 1
		elif gapb < gapa:
			if gapb > 0:
				b.append(balls.pop(0))
			elif gapa > 0:
				a.append(balls.pop(0))
			else:
				flag = 1
		if flag == 1:
			print "NO"
			break
		if len(balls) == 0: print "YES"

Submission status: Accepted

Solution code:
for i in range(input()):
    L = map(int, raw_input().split())
    L1, L2 = [], []
    for x in L:
        if not L1 or L1[-1] < x:
            L1.append(x)
        elif not L2 or L2[-1] < x:
            L2.append(x)
        else:
            print "NO"
            break
    else:
        print "YES"

Submission status: Accepted

Solution code:
def f(b):
    a = [0, 0]
    for p in b:
        if p > a[1]:
            a[1] = p
        elif p > a[0]:
            a[0] = p
        else:
            return False
        a.sort()
    return True

for i in range(int(raw_input())):
    print 'YES' if f(map(int, raw_input().split())) else 'NO'

Submission status: Accepted

Solution code:

N = int(raw_input())
    
for c in range(N):
    
    B = [0]
    C = [0]
    
    def dfs(depth):
        if depth == 10:
            return True
            
        res = False
        if B[-1] < A[depth]:
            B.append(A[depth])
            res |= dfs(depth+1)
            del B[-1]
        if C[-1] < A[depth]:
            C.append(A[depth])
            res |= dfs(depth+1)
            del C[-1]
        return res
    
    A = map(int, raw_input().split(" "))
    
    print "YES" if dfs(0) else "NO"

Submission status: Accepted

Solution code:
N = int(raw_input())

def dfs(depth, l, r):
    if depth == 10:
        return True
    res = False
    if l < A[depth]:
        res |= dfs(depth+1, A[depth], r)
    if r < A[depth]:
        res |= dfs(depth+1, l, A[depth])
    return res

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