Two integer sequences existed initially, one of them was strictly increasing, and another one — strictly decreasing.

Strictly increasing sequence is a sequence of integers $[x_1 < x_2 < \dots < x_k]$. And strictly decreasing sequence is a sequence of integers $[y_1 > y_2 > \dots > y_l]$. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.

Elements of increasing sequence were inserted between elements of the decreasing one (and, possibly, before its first element and after its last element) without changing the order. For example, sequences $[1, 3, 4]$ and $[10, 4, 2]$ can produce the following resulting sequences: $[10, \textbf{1}, \textbf{3}, 4, 2, \textbf{4}]$, $[\textbf{1}, \textbf{3}, \textbf{4}, 10, 4, 2]$. The following sequence cannot be the result of these insertions: $[\textbf{1}, 10, \textbf{4}, 4, \textbf{3}, 2]$ because the order of elements in the increasing sequence was changed.

Let the obtained sequence be $a$. This sequence $a$ is given in the input. Your task is to find any two suitable initial sequences. One of them should be strictly increasing, and another one — strictly decreasing. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.

If there is a contradiction in the input and it is impossible to split the given sequence $a$ into one increasing sequence and one decreasing sequence, print "NO".


-----Input-----

The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$.


-----Output-----

If there is a contradiction in the input and it is impossible to split the given sequence $a$ into one increasing sequence and one decreasing sequence, print "NO" in the first line.

Otherwise print "YES" in the first line. In the second line, print a sequence of $n$ integers $res_1, res_2, \dots, res_n$, where $res_i$ should be either $0$ or $1$ for each $i$ from $1$ to $n$. The $i$-th element of this sequence should be $0$ if the $i$-th element of $a$ belongs to the increasing sequence, and $1$ otherwise. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.


-----Examples-----
Input
9
5 1 3 6 8 2 9 0 10

Output
YES
1 0 0 0 0 1 0 1 0 

Input
5
1 2 4 0 2

Output
NO

Difficulty: introductory

Starter code:

Solutions:
n = int(input())
a = list(map(int, input().split()))
inf = 10 ** 6
inc = [inf for i in range(0, n + 1)]
dec = [-inf for i in range(0, n + 1)]
trinc = [-1 for i in range(0, n + 1)]
trdec = [-1 for i in range(0, n + 1)]
inc[0] = -inf
dec[0] = inf
#inc means last dec was in i and we want minimize last inc
for i in range(0, n - 1):
    if a[i + 1] < a[i]:
        if inc[i + 1] > inc[i]:
            inc[i + 1] = inc[i]
            trinc[i + 1] = 1
    if a[i + 1] > a[i]:
        if dec[i + 1] < dec[i]:
            dec[i + 1] = dec[i]
            trdec[i + 1] = 1
    if a[i + 1] > inc[i]:
        if dec[i + 1] < a[i]:
            dec[i + 1] = a[i]
            trdec[i + 1] = 0
    if a[i + 1] < dec[i]:
        if inc[i + 1] > a[i]:
            inc[i + 1] = a[i]
            trinc[i + 1] = 0
if inc[n - 1] == inf and dec[n - 1] == -inf:
    print("NO")
    return
now_inc = False
ans = [0 for i in range(0, n)]
if inc[n - 1] != inf:
    now_inc = True
for i in range(n - 1, -1, -1):
    if now_inc:
        ans[i] = 1
        if trinc[i] == 0:
            now_inc = False
    else:
        ans[i] = 0
        if trdec[i] == 0:
            now_inc = True
print("YES")
print(" ".join(str(x) for x in ans))


# testing https://codeforces.com/contest/1144/submission/52125086

n = int(input())
a = [int(ai) for ai in input().split()] + [0]

inc, dec = -1, 10**6
marker = [0] * n

for i in range(n):
    if inc < a[i] and a[i] < dec:
        if a[i] < a[i + 1]:
            inc = a[i]
        else:
            dec = a[i]
            marker[i] = 1
    elif inc < a[i]:
        inc = a[i]
    elif dec > a[i]:
        dec = a[i]
        marker[i] = 1
    else:
        print('NO')
        break
else:
    print('YES')
    print(*marker)


n, a = int(input()), [int(ai) for ai in input().split()] + [0]
res, inc, dec = [0] * n, -1, 10**6
for i in range(n):
    if inc < a[i] and a[i] < dec:
        if a[i] < a[i + 1]:
            inc = a[i]
        else:
            dec = a[i]
            res[i] = 1
    elif inc < a[i]:
        inc = a[i]
    elif dec > a[i]:
        dec = a[i]
        res[i] = 1
    else:
        print('NO')
        break
else:
    print('YES')
    print(*res)


#!/usr/bin/env python

n, a = int(input()), list(map(int, input().split())) + [0, ]

ans, inc, dec = [0] * n, -1, 1e7
for i in range(n):
	if inc < a[i] < dec:
		if a[i] < a[i + 1]:
			inc = a[i]
		else:
			dec = a[i]
			ans[i] = 1
	elif inc < a[i]:
		inc = a[i]
	elif dec > a[i]:
		dec = a[i]
		ans[i] = 1
	else:
		print('NO')
		break
else:
	print('YES')
	print(*ans)


n, a = int(input()), [int(i) for i in input().split()] + [0]
ans, inc, dec = [0 for _ in range(n)], -1,float('inf')
for i in range(n):
    if inc < a[i] < dec:
        if a[i] < a[i+1]:
            inc = a[i]
        else:
            dec = a[i]
            ans[i] = 1
    elif inc < a[i]:
        inc = a[i]
    elif dec > a[i]:
        dec = a[i]
        ans[i] = 1
    else:
        print('NO')
        break
else:
    print('YES')
    print(*ans)


n, a = int(input()), list(map(int, input().split())) + [0, ]
ans, inc, dec = [0] * n, -1, 1e7
for i in range(n):
	if inc < a[i] < dec:
		if a[i] < a[i + 1]:
			inc = a[i]
		else:
			dec = a[i]
			ans[i] = 1
	elif inc < a[i]:
		inc = a[i]
	elif dec > a[i]:
		dec = a[i]
		ans[i] = 1
	else:
		print('NO')
		break
else:
	print('YES')
	print(*ans)

n, a = int(input()), list(map(int, input().split())) + [0, ]

ans, inc, dec = [0] * n, -1, 1e7
for i in range(n):
	if inc < a[i] < dec:
		if a[i] < a[i + 1]:
			inc = a[i]
		else:
			dec = a[i]
			ans[i] = 1
	elif inc < a[i]:
		inc = a[i]
	elif dec > a[i]:
		dec = a[i]
		ans[i] = 1
	else:
		print('NO')
		break
else:
	print('YES')
	print(*ans)

n = int(input())
a = list(map(int, input().split())) + [0]

answer = [0] * n
current_increase_max = -1
current_decrease_min = 1e6

for i in range(n):
    if current_increase_max < a[i] and a[i] < current_decrease_min:
        if a[i] < a[i + 1]:
            current_increase_max = a[i]
            answer[i] = 0
        else:
            current_decrease_min = a[i]
            answer[i] = 1
    elif current_increase_max < a[i]:
        current_increase_max = a[i]
        answer[i] = 0
    elif current_decrease_min > a[i]:
        current_decrease_min = a[i]
        answer[i] = 1
    else:
        print("NO")
        return

print("YES")
print(*answer)




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

n = int(input())
data = list(map(int, input().split())) + [0, ]

ans, inc, dec = [0] * n, -1, 1e7
for i in range(n):
    if inc < data[i] < dec:
        if data[i] < data[i + 1]:
            inc = data[i]
        else:
            dec = data[i]
            ans[i] = 1
    elif inc < data[i]:
        inc = data[i]
    elif dec > data[i]:
        dec = data[i]
        ans[i] = 1
    else:
        print("NO")
        break
else:
    print("YES")
    print(*ans)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    result = [0] * n
    last_increasing = -1
    last_decreasing = 200001

    for i, x in enumerate(a):
        if i == n - 1:
            if x < last_decreasing:
                result[i] = 1
            elif x <= last_increasing:
                print('NO')
                return
        else:
            if last_increasing >= x >= last_decreasing:
                print('NO')
                return
            if x > last_increasing and x >= last_decreasing:
                last_increasing = x
            if x <= last_increasing and x < last_decreasing:
                last_decreasing = x
                result[i] = 1
            if last_increasing < x < last_decreasing:
                if a[i + 1] > x:
                    last_increasing = x
                else:
                    last_decreasing = x
                    result[i] = 1

    print('YES')
    print(' '.join(map(str, result)))


def __starting_point():
    main()

__starting_point()

MAX = 1+2*10**5
MIN = -1

ASC = 0
DSC = 1

n = int(input())
a = list(map(int, input().split()))

asc = MIN
dsc = MAX
res = []

for i in range(n):

    if a[i] > asc and a[i] < dsc:
        # can place in either
        if i+1 == n:
            res.append(DSC)
        elif a[i] > a[i+1]:
            # place in dsc
            res.append(DSC)
            dsc = a[i]
        else:
            # place in asc
            res.append(ASC)
            asc = a[i]  

    elif a[i] > asc:
        # can only place in asc
        res.append(ASC)
        asc = a[i]

    elif a[i] < dsc:
        # can only place in dsc
        res.append(DSC)
        dsc = a[i]

    else:
        # can't place anywhere
        print("NO")
        return
    
print("YES")
print(*res)

MAX = 1+2*10**5
MIN = -1

ASC = 0
DSC = 1

n = int(input())
a = list(map(int, input().split()))

asc = MIN
dsc = MAX
res = []

for i in range(n):

    if a[i] > asc and a[i] < dsc:
        # can place in either
        if i+1 == n:
            res.append(DSC)
        elif a[i] > a[i+1]:
            # place in dsc
            res.append(DSC)
            dsc = a[i]
        else:
            # place in asc
            res.append(ASC)
            asc = a[i]  

    elif a[i] > asc:
        # can only place in asc
        res.append(ASC)
        asc = a[i]

    elif a[i] < dsc:
        # can only place in dsc
        res.append(DSC)
        dsc = a[i]

    else:
        # can't place anywhere
        print("NO")
        return
    
print("YES")
print(*res)