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:
n = int(raw_input())
for i in range(n):
  left, right = [], []
  arr = map(int, raw_input().split(' '))
  for a in arr:
    if len(left) == 0 or left[len(left)-1] < a:
      left.append(a)
    elif len(right) == 0 or right[len(right)-1] < a:
      right.append(a)
    else:
      break

  if len(arr) == len(left) + len(right):
    print 'YES'
  else:
    print 'NO'

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    a = list(map(int, input().split()))
    b = 0
    c = 0
    for j in range(10):
        if a[j] > b:
            if a[j] > c:
                if a[j] - b < a[j] - c:
                    b = a[j]
                else:
                    c = a[j]
            else:
                b = a[j]
        elif a[j] > c:
            c = a[j]
        else:
            print("NO")
            break

        if j == 9:
            print("YES")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
for i in range(N):
    Ball = list(map(int, input().split()))
    B = 0
    C = 0
    x = 'YES'
    for j in range(10):
        if B < Ball[j]:
            B = Ball[j]
        elif C < Ball[j]:
            C = Ball[j]
        else:
            x = 'NO'
    print(x)

Submission status: Accepted

Solution code:

n = int(input())

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def check(ary):
    for i in range(1, len(ary)):
        if ary[i] < ary[i - 1]:
            return False

    return True


def dfs(a, b, c, i):
    if len(b) + len(c) == 10:
        return check(b) and check(c)

    added_b = b[:]
    added_c = c[:]
    added_b.append(a[i])
    added_c.append(a[i])

    return dfs(a, added_b, c, i + 1) or dfs(a, b, added_c, i + 1)


def main():
    n = int(input())
    for i in range(n):
        datasets = [int(i) for i in input().split(' ')]
        result = dfs(datasets, [], [], 0)
        print('YES' if result else 'NO')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


NUM = 10
POW = [1]*(NUM+1)
for i in range(1,NUM+1):
    POW[i] = POW[i-1]*2


N = int(input())

for _ in range(N):

    table = list(map(int,input().split()))

    FLG = False

    for state in range(POW[NUM]):
        A = []
        B = []

        for i in range(NUM):
            if state & POW[i] != 0:
                A.append(table[i])
            else:
                B.append(table[i])

        tmpFLG = True
        for i in range(len(A)-1):
            if A[i] >= A[i+1]:
                tmpFLG = False
                break

        if tmpFLG == False:
            continue

        for i in range(len(B)-1):
            if B[i] >= B[i+1]:
                tmpFLG = False
                break

        if tmpFLG == True:
            FLG = True
            break


    if FLG == True:
        print("YES")
    else:
        print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    a = list(map(int, input().split()))
    b = 0
    c = 0
    for j in range(10):
        if a[j] > b:
            if a[j] > c:
                if a[j] - b < a[j] - c:
                    b = a[j]
                else:
                    c = a[j]
            else:
                b = a[j]
        elif a[j] > c:
            c = a[j]
        else:
            print("NO")
            break

        if j == 9:
            print("YES")

Submission status: Accepted

Solution code:
# AOJ 0033

N = int(input())
for i in range(N):
    balls = list(map(int, input().split()))
    b = 0
    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:
n = int(input())
for i in range(n):
    B = 0
    C = 0
    A = [int(i) for i in input().split()]
    ans = 'YES'
    for v in A:
        if B > v and C > v:
            ans = 'NO'
            break
        elif B < v and C < v:
            if B > C:
                B = v
            else:
                C = v
        elif B < v:
            B = v
        else:
            C = v
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(n):
  a = list(map(int,input().split()))
  b = 0
  c = 0
  for i in range(10):
    if a[i] > b:
      b = a[i]
    elif a[i] > c:
      c = a[i]
    else:
      print("NO")
      break
    if i == 9:
      print("YES")

Submission status: Accepted

Solution code:
n = int(input())

for i in range(n):
    l = list(map(int, input().split()))
    b, c, flag = 0, 0, 0
    for seq in l:
        if seq > b:
            b = seq
        elif seq > c:
            c = seq
        else:
            flag = 1
    if flag == 0:
        print("YES")
    else:
        print("NO")

Submission status: Accepted

Solution code:
def solve():
    from sys import stdin
    f_i = stdin
    N = int(f_i.readline())
    
    from itertools import combinations
    ans = []
    for m in (map(int, f_i.readline().split()) for i in range(N)):
        for a, b, c in combinations(m, 3):
            if a > b > c:
                ans.append('NO')
                break
        else:
            ans.append('YES')
    print('\n'.join(ans))

solve()

Submission status: Accepted

Solution code:
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:
N=int(input())
answer=[]
for i in range(N):
  A=list(map(int,input().split()))
  B=[-1 for i in range(10)]
  C=[-1 for i in range(10)]
  B[0]=A[0]
  C[0]=0
  for i in range(1,10):
    if B[i-1]<A[i]:
      B[i]=A[i]
      C[i]=C[i-1]
    elif C[i-1]<A[i]:
      C[i]=A[i]
      B[i]=B[i-1]
    else:
      answer.append("NO")
      break
    if i==9:
      answer.append("YES")
for i in range(N):
  print(answer[i])

Submission status: Accepted

Solution code:

if __name__ == '__main__':

	n = int(input())

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

		tmp1 = [0]
		tmp2 = [0]

		Flg = True
		for j in A:
			if tmp1[-1] < j:
				tmp1.append(j)
			else:
				if tmp2[-1] < j:
					tmp2.append(j)
				else:
					Flg = False
					break

		if Flg:
			print("YES")
		else:
			print("NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(raw_input())
for i in range(0, N):
	ball = map(int, raw_input().split())
	stack = [[1, ball[0], 0]]
	flag = False
	while stack != []:
		now = stack.pop(-1)
		if now[0] == 10:
			flag = True
			break
		b = ball[now[0]]
		if now[1] < b: stack.append([now[0]+1, b, now[2]])
		if now[2] < b: stack.append([now[0]+1, now[1], b])
	if flag: print 'YES'
	else: print 'NO'

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num = int(input())
for _ in range(num):
    n = [int(i) for i in input().split()]
    b = 0
    able = 1
    for j in range(10):
        if j == 0:
            a = n[0]
        else:
            if n[j] < a:
                if n[j] < b:
                    print("NO")
                    able = 0
                    break
                else:
                    b = n[j]
            else:
                a = n[j]
    if able == 1:
        print("YES")

Submission status: Accepted

Solution code:
def balling(balls, left, right):
    if len(balls) == 0:
        return True
    elif balls[0] <= left and balls[0] <= right:
        return False
    else:
        complete = False
        if balls[0] > left:
            complete = balling(balls[1:], balls[0], right)
        if not complete and balls[0] > right:
            complete = balling(balls[1:], left, balls[0])
        return complete

for _ in range(int(input())):
    balls  = [int(x) for x in  input().split()]
    print("YES" if balling(balls, 0, 0) else "NO")

Submission status: Accepted

Solution code:
n = int(input())

for _ in range(n):
    balllist = list(map(int, input().split()))
    leftlist = []
    rightlist = []

    for i, ball in enumerate(balllist):
        if i == 0:
            leftlist.append(ball)
            continue
        if leftlist[-1] < ball:
            leftlist.append(ball)
        elif rightlist == [] or rightlist[-1] < ball:
            rightlist.append(ball)
        else:
            print("NO")
            break
    else:
        print("YES")

Submission status: Accepted

Solution code:
N = int(input())

for _ in range(N):
    A = list(map(int, input().split()))
    b, c = 0, 0
    flag = True
    for a in A:
        if b < a:
            b = a
        elif c < a:
            c = a
        else:
           print('NO') 
           flag = False
           break
    if flag:
        print('YES')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect


def LIS(seq):
    r = [seq[0]]
    for n in seq[1:]:
        if n > r[-1]:
            r.append(n)
        else:
            idx = bisect.bisect_left(r, n)
            r[idx] = n
    return r
N = int(input())
for _ in range(N):
    seq = list(map(int, input().split()))
    left = set(LIS(seq))
    remain = [n for n in seq if n not in left]
    right = LIS(remain)
    print("YES" if len(left) + len(right) == len(seq) else "NO")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    for _ in range(N):
        balls = list(map(int, input().split()))
        lefts, rights = [0], [0]
        for ball in balls:
            if lefts[-1] < ball:
                lefts.append(ball)
            elif rights[-1] < ball:
                rights.append(ball)
            else:
                print('NO')
                break
        else:
            print('YES')

if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
n=int(input())
for i in range(n):
    a=list(map(int,input().aplit()))
    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: Runtime Error

Solution code:
def s(a):
	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: Runtime Error

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

import sys
import itertools
input()
lis = list(itertools.product([False,True],repeat=10))
for s in sys.stdin:
  d = map( int, s.split() )
  flag = False
  for e in lis:
    lis_r = []
    lis_l = []
    for i in range(10):
      if e[i]:
        lis_r.append(d[i])
      else:
        lis_l.append(d[i])
    f_r = sorted(lis_r)
    f_l = sorted(lis_l)
    if f_r == lis_r and f_l == lis_l:
      flag = True
      break
  if flag:
    print "YES"
  else:
    print "NO"

Submission status: Runtime Error

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

import sys
import itertools
input()

lis = list(itertools.product([False,True],repeat=10))
for s in sys.stdin:
  d = map( int, s.split() )
  flag = False
  for e in lis:
    lis_r = []
    lis_l = []
    for i in range(10):
      if e[i]:
        lis_r.append(d[i])
      else:
        lis_l.append(d[i])
    f_r = sorted(lis_r)
    f_l = sorted(lis_l)
    if f_r == lis_r and f_l == lis_l:
      flag = True
      break
  if flag:
    print "YES"
  else:
    print "NO"

Submission status: Runtime Error

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

import sys
import itertools
input()
lis = list(itertools.product([False,True],repeat=10))
for s in sys.stdin:
  d = map( int, s.split() )
  flag = False
  for e in lis:
    l = [ d[i] if e[i] else -d[i] for i in xrange(10) ]
    m = [ [ e for e in l if e > 0 ],[ -e for e in l if e < 0 ]]
    n = 0
    for e in m:
      n += sum([ 1 if e[i] > e[i+1] else 0 for i in range(len(e)-1)])
    if not n:
      print "YES"
      break
  if n:
    print "NO"

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

input = map(lambda x:x[:-1], sys.stdin.readlines())


n = int(input[0])

input = input[1:]

input = map(lambda x:x.split(' '), input)

for i in range(len(input)):
    input[i] = map(lambda x:int(x), input[i])

print input
A = []
B = []

def a_can_add(e):
    if ((len(A) != 0) and (A[-1] < e)) or len(A) == 0:
        return True    

def b_can_add(e):
    if ((len(B) != 0) and (B[-1] < e)) or len(B) == 0:
        return True

def a_add(e):
    if (len(A) != 0) and (A[-1] < e):
        A.append(e)
    elif len(A) == 0:
        A.append(e)
    else: return False

def b_add(e):
    if len(B) != 0 and (B[-1] < e):
        B.append(e)
    elif len(B) == 0:
        B.append(e)
    else: return False


for i in range(len(input)):
    for j in range(10):
        if a_can_add(input[i][j]):
            a_add(input[i][j])
        elif b_can_add(input[i][j]):
            b_add(input[i][j])
            
    if len(A) + len(B) == 10:
        print "YES"
    else:
        print "NO"

Submission status: Runtime Error

Solution code:
import sys

input = map(lambda x:x[:-1], sys.stdin.readlines())


n = int(input[0])

input = input[1:]

input = map(lambda x:x.split(' '), input)

for i in range(len(input)):
    input[i] = map(lambda x:int(x), input[i])

#print input
A = []
B = []

def a_can_add(e):
    if ((len(A) != 0) and (A[-1] < e)) or len(A) == 0:
        return True    

def b_can_add(e):
    if ((len(B) != 0) and (B[-1] < e)) or len(B) == 0:
        return True

def a_add(e):
    if (len(A) != 0) and (A[-1] < e):
        A.append(e)
    elif len(A) == 0:
        A.append(e)
    else: return False

def b_add(e):
    if len(B) != 0 and (B[-1] < e):
        B.append(e)
    elif len(B) == 0:
        B.append(e)
    else: return False


for i in range(len(input)):
    for j in range(10):
        if a_can_add(input[i][j]):
            a_add(input[i][j])
        elif b_can_add(input[i][j]):
            b_add(input[i][j])
            
    if len(A) + len(B) == 10:
        print "YES"
    else:
        print "NO"

Submission status: Runtime Error

Solution code:
a=[]
n=int(input())
for i in range(10):
        a.append(-1)
while(n!=0):
    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: Runtime Error

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

n = int(raw_input())
for i in range(n):
    A = map(int, raw_input().split())
    B = []
    C = []
    flag = True
    for i in range(5):
        B.append(A[2*i])
        C.append(A[2*i+1])
    for i in range(4):
        for j in range(i+1, 4)
            if B[j] > B[i]:
                flag = False
                break
            if C[ij > C[i]:
                flag = False
                break
    if flag:
        print "YES"
    else:
        print "NO"

Submission status: Runtime Error

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

n = int(raw_input())
for i in range(n):
    A = map(int, raw_input().split())
    B = []
    C = []
    flag = True
    for i in range(5):
        B.append(A[2*i])
        C.append(A[2*i+1])
    for i in range(4):
        for j in range(i+1, 5)
            if B[j] > B[i]:
                flag = False
                break
            if C[j] > C[i]:
                flag = False
                break
    if flag:
        print "YES"
    else:
        print "NO"

Submission status: Runtime Error

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 num[i] > A[0]:
            A.insert(0, num[i])
        elif num[i] > B[0]:
            B.insert(0, num[i])
        else:
            break
    if len(A) + len(B) == 12:
        print "YES"
    else:
        print "NO"

Submission status: Runtime Error

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, num[i])
        elif A[i] > C[0]:
            C.insert(0, num[i])
        else:
            break
    if len(A) + len(B) == 12:
        print "YES"
    else:
        print "NO"

Submission status: Runtime Error

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 = j
        elif c[-1] < j: c = j
        else: break
    else:
        print 'YES'
        continue
    print 'NO'

Submission status: Runtime Error

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(arr) == len(left) + len(right):
        print("YES")
    else:
        print("NO")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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.BALL_NUM = 10
		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()
Vessel = VesselClass()
for balls in balls_list:
	Vessel.fill(balls)
	Vessel.DFS()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
for i in range(n):
    arr = map(int, input().split())
    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: Runtime Error

Solution code:
def ball(nums):
????????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
        return "NO"
    return "YES"
??
N = int(input())
??
for _ in range(N):
????????a = list(map(int, input().split()))
????????print(ball(a))

Submission status: Runtime Error

Solution code:
x=int(input())
for i in range(x):
	num=[int(i) for i in input().split()]
	b=[]
	c=[]
	flag=0
	b.append(num[0])
	c.append(int(0))
	for i in range(1,10):
		if b[0]<num[i]:
			b.append(num[i])
		elif c[0]<num[i]:
			c.append(num[i])
		else:
			flag=1
			break
	if flag==:
		print("YES")
	else:
		print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

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