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 = int(raw_input())
a = [0]
b = [0]
for i in range(n):
    ball = map(int, raw_input().split())
    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: Wrong Answer

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

import sys
import itertools
input()

for s in sys.stdin:
  d = map( int, s.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: Wrong Answer

Solution code:
import sys
f = sys.stdin
def cylinder(balls):
    cy = []
    for ball in balls:
        if len(cy) < 2:
            pass
        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: Wrong Answer

Solution code:
def hantei(A,B,C):
    while len(A)>0:
        if B == [] or B[-1] < A[0]:
            B.append(A[0])
            del A[0]
        elif C == [] or C[-1] < A[0]:
            C.append(A[0])
            del A[0]
        else:
            print 'NO'
            break
    else:
        print 'YES'

N = int(raw_input())
A = []; B = []; C = []
for i in range(N):
    A = map(int,raw_input().split())
    hantei(A,B,C)

Submission status: Wrong Answer

Solution code:
def hantei(A,B,C):
    while len(A)>0:
        if B == []:
            B.append(A[0])
            del A[0]
        elif B[-1] < A[0] and C[-1] < A[0]:
            if B[-1] < C[-1]:
                C.append(A[0])
                del A[0]
            elif B[-1] > C[-1]:
                B.append(A[0])
                del A[0]
        
        elif B[-1] < A[0]:
            B.append(A[0])
            del A[0]
        elif C == [] or C[-1] < A[0]:
            C.append(A[0])
            del A[0]
        else:
            print 'NO'
            break
    else:
        print 'YES'

N = int(raw_input())
A = []; B = []; C = []
for i in range(N):
    A = map(int,raw_input().split())
    hantei(A,B,C)

Submission status: Wrong Answer

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"
                break
            elif 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: Wrong Answer

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"
                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: Wrong Answer

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 s in sys.stdin:
	ball = list(map(int, s.split()))
	if stackBall([], [], ball):
		print("YES")
	else:
		print("NO")

Submission status: Wrong Answer

Solution code:
N = int(raw_input())


def dfs(depth, l, r):
    print "depth: %d l: %d r: %d" % (depth, l, r)
    if depth == 10:
        return True

    if l < A[depth] :
        if dfs(depth+1, A[depth], r):
            return True
    if r < A[depth]:
        if  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: Wrong Answer

Solution code:
n = input()
data = []
for i in range(n):
	tmp = map(int,raw_input().split())
	data.append(tmp)

Submission status: Wrong Answer

Solution code:
for i in range(int(input())):
    b = list(map(int, input().split()))
    for j in range(8):
        if b[j] > b[j + 2]:
            print("NO")
            break
    else:
        print("YES")

Submission status: Wrong Answer

Solution code:
for i in range(int(input())):
    b = list(map(int, input().split()))
    for j in range(8):
        if b[j] >= b[j + 2]:
            print("NO")
            break
    else:
        print("YES")

Submission status: Wrong Answer

Solution code:
for _ in range(int(input())):
    a = list(map(int, input().split()))
    t = 1
    for i in a:
        if i == t:
            t += 1
    for i in a:
        if i == t:
            t += 1
    if t == 11:
        print("YES")
    else:
        print("NO")

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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):
        if B[i] >= B[i+1]:
            flag = False
            break
        if C[i] >= C[i+1]:
            flag = False
            break
    if flag:
        print "YES"
    else:
        print "NO"

Submission status: Wrong Answer

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):
        if B[i] > B[i+1]:
            flag = False
            break
        if C[i] > C[i+1]:
            flag = False
            break
    if flag:
        print "YES"
    else:
        print "NO"

Submission status: Wrong Answer

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: Wrong Answer

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 not flag:
                break
    if flag:
        print "YES"
    else:
        print "NO"

Submission status: Wrong Answer

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 == False:
                break
    if flag:
        print "YES"
    else:
        print "NO"

Submission status: Wrong Answer

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(5):
        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 == False:
            break
    if flag:
        print "YES"
    else:
        print "NO"

Submission status: Wrong Answer

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(5):
        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: Wrong Answer

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):
        if B[i+1] < B[i]:
            flag = False
            break
        if C[i+1] < C[i]:
            flag = False
            break
    if flag:
        print "YES"
    else:
        print "NO"

Submission status: Wrong Answer

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):
        if B[i+1] <= B[i]:
            flag = False
            break
        if C[i+1] <= C[i]:
            flag = False
            break
    if flag:
        print "YES"
    else:
        print "NO"

Submission status: Wrong Answer

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):
        if B[i+1] <= B[i]:
            flag = False
        if C[i+1] <= C[i]:
            flag = False
    if flag:
        print "YES"
    else:
        print "NO"

Submission status: Wrong Answer

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(A) + len(B) == 12:
        print "YES"
    else:
        print "NO"

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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: Wrong Answer

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.pop(0)
            if boll > max(left):
                self.search(left+[boll], right, remaining)
            if boll > max(right):
                self.search(left, right+[boll], remaining)

    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: Wrong Answer

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(10,0,0) else "NO")

Submission status: Wrong Answer

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

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.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: Wrong Answer

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

def solve():
    arr1 = [0]
    arr2 = [0]
    for i in range(len(datas)):
        if i == 0:
            arr1.append(datas[0])
        elif int(datas[i]) > int(datas[i-1]):
            arr1.append(datas[i])
        elif int(datas[i]) < int(datas[i-1]):
            if int(arr2[-1]) < int(datas[i]):
                arr2.append(datas[i])
            else:
                return 0
                break
    return 1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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 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:
        solve(line.split(' '))
        size -= 1
        print(size)
        if size == 0: break
    line = input()

Submission status: Wrong Answer

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 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:
        solve(line.split(' '))
        size -= 1
        print(size)
        if size == 0: break
    line = input()

Submission status: Wrong Answer

Solution code:
for _ in range(int(input())) :
    b, c = 0, 0
    for number, a in enumerate(input().split()) :
        a = int(a)
        if a < b and a < c :
            print('NO')
            break
        elif b < a and c <= b : b = a
        else : c = a
    if number == 9 : print('YES')

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(n):
    l = list(map(int, input().split()))
    k,c= l[0], 0
    for j in l:
        if j < k:
            c += 1
            k = j
    if 2 <= c:
        print("NO")
    else:
        print("YES")

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(n):
    l = list(map(int, input().split()))
    k , c= l[0], 0
    for j in l:
        if j < k:
            c += 1
        else:
            c = 0
    if 2 <= c:
        print("NO")
    else:
        print("YES")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def dfs(i, b, c):
    if i == 10:
        b_sort = sorted(b)
        c_sort = sorted(c)
        return (b == b_sort and c == c_sort)

    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, [0], [0]):
            print("Yes")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
def dfs(i, b, c):
    if i == 10:
        b_sort = sorted(b)
        c_sort = sorted(c)
        return (b == b_sort and c == c_sort)

    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, [0], [0]):
            print("YES")
        else:
            print("NO")

Submission status: Wrong Answer

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):
            print(j)
            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: Wrong Answer

Solution code:
def dfs(i, b, c):
    if i == 10:
        return (b == sorted(b) and c == sorted(c))

    if dfs(i + 1, b + [balls[i - 1]], c):
        return True

    if dfs(i + 1, b, c + [balls[i - 1]]):
        return True

    return False


if __name__ == '__main__':
    N = int(input())
    for i in range(N):
        balls = list(map(int, input().split()))
        if dfs(1, [], []):
            print("YES")
        else:
            print("NO")

Submission status: Wrong Answer

Solution code:
def dfs(i, b, c):
    if i == 11:
        print(b)
        print(c)
        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: Wrong Answer

Solution code:
n = int(input())
for i in range(n):
    balls = list(map(int, input().split()))
    min_ball = balls[0]
    count = 0
    for ball in balls:
        if ball > min_ball:
            min_ball = ball
            count += 1
    if count > 1:
        print('YES')
    else:
        print('NO')

Submission status: Wrong Answer

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

    count = 0
    first = 0
    for i, n in enumerate(balls):
        min_ball = 11
        for m in balls[i:]:
            if m != first and n < m < min_ball:
                min_ball = m
        if min_ball != 11:
            first = min_ball
            count += 1
        if count == 2:
            break
    if count == 2:
        print('YES')
    else:
        print('NO')

Submission status: Wrong Answer

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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: Wrong Answer

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==0:
		print("YES")
	else:
		print("No")

Submission status: Wrong Answer

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[len(b)-1]<num[i]:
			b.append(num[i])
		elif c[len(c)-1]<num[i]:
			c.append(num[i])
		else:
			flag=1
			break
	if flag==0:
		print("YES")
	else:
		print("No")

Submission status: Wrong Answer

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(min(num)-1)
	for i in range(1,10):
		if b[len(b)-1]<num[i]:
			b.append(num[i])
		elif c[len(c)-1]<num[i]:
			c.append(num[i])
		else:
			flag=1
			break
	if flag==0:
		print("YES")
	else:
		print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
N = int(input())
for i in range(N):
    Ball = list(map(int, input().split()))
    cannot = 0
    right = 0
    left = 0
    for j in range(10):
        if abs(Ball[j] - right) <= abs(Ball[j] - left) and Ball[j] > right:
            right = Ball[j]
        elif abs(Ball[j] - right) > abs(Ball[j] - left) and Ball[j] > left:
            left = Ball[j]
        else:
            cannot = 1
            break
    if cannot == 1: print('NO')
    elif cannot == 0: print('YES')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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:
            print('NO')
            break
    if len(a)==0:
        print('YES')

Submission status: Wrong Answer

Solution code:
def solve(balls):
    ans=False
    K=len(balls)
    for i in range(K):
        bi=balls[i]
        for j in range(i+1,K):
            bj=balls[j]
            if bi<bj: continue
            ans=False
            for l in range(j-1,0,-1):
                bl=balls[l]
                if bj>bl: ans=True
    return "YES" if ans else "NO"


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

Submission status: Wrong Answer

Solution code:
def findMin(balls, bn):
    if len(balls)==0: return True
    return True if min(balls)<bn else False

def solve(balls):
    K=len(balls)
    for i in range(K-2):
        bc=balls[i]
        bn=balls[i+1]
        if bc<bn: continue
        if not findMin(balls[:i],bn):
            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: 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) <= 2:
		print 'NO'
	else:
		print 'YES'

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) <= 2:
		print 'YES'
	else:
		print 'NO'