This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.

You are given a string $s$ consisting of $n$ lowercase Latin letters.

You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $s$).

After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.

The goal is to make the string sorted, i.e. all characters should be in alphabetical order.

Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.


-----Input-----

The first line of the input contains one integer $n$ ($1 \le n \le 200$) — the length of $s$.

The second line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters.


-----Output-----

If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line.

Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $n$ characters, the $i$-th character should be '0' if the $i$-th character is colored the first color and '1' otherwise).


-----Examples-----
Input
9
abacbecfd

Output
YES
001010101

Input
8
aaabbcbb

Output
YES
01011011

Input
7
abcdedc

Output
NO

Input
5
abcde

Output
YES
00000

Difficulty: MEDIUM_HARD

Solutions:
N = int(input())
s = input()
a = 'a'
b = 'a'
t = ''
flag = 0
for i in s:
	if a < b:
		if b <= i:
			b = i
			t += '1'
		elif a <= i:
			a = i
			t += '0'
		else:
			flag = 1
			break
	elif b < a:
		if a <= i:
			a = i
			t += '0'
		elif b <= i:
			b = i
			t += '1'
		else:
			flag = 1
			break
	elif a <= i:
		a = i
		t += '0'
	else:
		flag = 1
		break
if flag == 1:
	print('NO')
else:
	print('YES')
	print(t)


input()
s = input()
(a, b) = ([], [])
for (i, c) in enumerate(s):
	if not a or c >= s[a[-1]]:
		a.append(i)
	elif not b or c >= s[b[-1]]:
		b.append(i)
	else:
		print('NO')
		exit(0)
print('YES')
ans = ['0'] * len(s)
for c in b:
	ans[c] = '1'
print(''.join(ans))


n = int(input())
s = input()
col = [-1] * n
ans = 'YES'
inversions = False
used = [False] * n

def solve(i):
	global ans
	global inversions
	used[i] = True
	for j in range(n):
		if (ord(s[j]) - ord(s[i])) * (j - i) < 0:
			if col[j] != -1:
				if col[i] == col[j]:
					ans = 'NO'
			else:
				col[j] = col[i] ^ 1
			if not used[j]:
				solve(j)
for i in range(n):
	if not used[i]:
		col[i] = 0
		solve(i)
print(ans)
if ans == 'YES':
	print(*col, sep='')


n = int(input())
s = input()
res = ''
lst0 = 'a'
lst1 = 'a'
ans = 'YES'
for i in range(n):
	if s[i] >= lst0:
		res += '0'
		lst0 = s[i]
	elif s[i] >= lst1:
		res += '1'
		lst1 = s[i]
	else:
		ans = 'NO'
if ans == 'NO':
	print(ans)
else:
	print('YES')
	print(res)


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))

def err():
	print('NO')
	exit()
n = inp()
s = list(input())
for (i, x) in enumerate(s):
	s[i] = ord(x) - 97
color = [-1] * n
for t in range(26):
	now = []
	for (i, x) in enumerate(s):
		if x > t:
			now.append(i)
		if x == t:
			cnt = [0, 0]
			for j in now:
				if color[j] == -1:
					continue
				cnt[color[j]] += 1
			col = -1
			if min(cnt) > 0:
				err()
			if color[i] != -1 and cnt[color[i]]:
				err()
			elif cnt[1] == 0:
				col = 0
			else:
				col = 1
			for j in now:
				color[j] = col
			if now != []:
				color[i] = col ^ 1
for (i, x) in enumerate(color):
	if x == -1:
		x = 0
	color[i] = str(x)
print('YES')
print(''.join(color))


first = []
second = []
N = int(input())
s = input()
last_first = s[0]
first.append(0)
last_second = ''
check = -1
for i in range(1, N, 1):
	if last_first <= s[i]:
		last_first = s[i]
		first.append(i)
	elif last_second == '':
		last_second = s[i]
		second.append(i)
		check = len(first)
len_first = len(first)
if len_first != N:
	for i in range(second[0] + 1, N, 1):
		if check < len_first and i == first[check]:
			check += 1
			continue
		if last_second <= s[i]:
			last_second = s[i]
			second.append(i)
len_second = len(second)
if len_first + len_second != N:
	print('NO')
else:
	result = []
	(i, j) = (0, 0)
	while i < len_first and j < len_second:
		if first[i] < second[j]:
			result.append(0)
			i += 1
		else:
			result.append(1)
			j += 1
	while i < len_first:
		result.append(0)
		i += 1
	while j < len_second:
		result.append(1)
		j += 1
	print('YES')
	for i in range(0, N, 1):
		print(result[i], end='')
	print()


import math
import sys
from collections import defaultdict

def stdinWrapper():
	data = '8\naaabbcbb\n'
	for line in data.split('\n'):
		yield line
if '--debug' not in sys.argv:

	def stdinWrapper():
		while True:
			yield input()
inputs = stdinWrapper()

def inputWrapper():
	return next(inputs)

def getType(_type):
	return _type(inputWrapper())

def getArray(_type):
	return [_type(x) for x in inputWrapper().split()]
l = getType(int)
_str = getType(str)
s1 = []
s2 = []
colors = []
for _char in _str:
	if len(s1) == 0 or s1[-1] <= _char:
		s1.append(_char)
		colors.append('0')
	elif len(s2) == 0 or s2[-1] <= _char:
		s2.append(_char)
		colors.append('1')
	else:
		print('NO')
		exit()
print('YES')
print(''.join(colors))


import sys, math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
t = 1
for tt in range(t):
	n = inp()
	a = insr()
	(q, w, qw) = ('', '', '')
	for i in range(len(a)):
		if a[i] >= q:
			(qw, q) = (qw + '0', a[i])
		elif a[i] >= w:
			(qw, w) = (qw + '1', a[i])
		else:
			print('NO')
			sys.exit()
	print('YES\n' + qw)


from collections import defaultdict as dd
n = int(input())
s = input()
(l1, l2) = ([s[0]], [])
m1 = {0}
r = True
for i in range(1, n):
	if s[i] >= l1[len(l1) - 1]:
		m1.add(i)
		l1.append(s[i])
	elif len(l2) == 0:
		l2.append(s[i])
	elif l2[len(l2) - 1] <= s[i]:
		l2.append(s[i])
	else:
		r = False
		break
if r:
	print('YES')
	for i in range(n):
		if i in m1:
			print(0, end='')
		else:
			print(1, end='')
	exit()
print('NO')


n = int(input())
letters = list(input())
flag = True
flagarr = [0] * n
binarr = {x: [0, 0] for x in range(26)}
for i in range(n):
	for k in range(i + 1, n):
		if ord(letters[k]) % 97 < ord(letters[i]) % 97:
			flagarr[k] = 1
			if flagarr[i]:
				flag = False
				break
	if not flag:
		break
for letter in range(n):
	if not flag:
		break
	if flagarr[letter]:
		binarr[ord(letters[letter]) % 97][1] += 1
	else:
		binarr[ord(letters[letter]) % 97][0] += 1
if not flag:
	print('NO')
else:
	print('YES')
	print(''.join((str(i) for i in flagarr)))


n = int(input())
s = input()
ans = [-1 for i in range(n)]
last = chr(ord('a') - 1)
for i in range(n):
	if s[i] >= last:
		ans[i] = 0
		last = s[i]
last = chr(ord('a') - 1)
for i in range(n):
	if ans[i] == -1 and s[i] >= last:
		ans[i] = 1
		last = s[i]
	elif ans[i] == -1:
		print('NO')
		exit(0)
print('YES')
print(*ans, sep='')


def run():
	(flag1, flag2) = ('a', 'a')
	n = int(input())
	ret = ''
	mystr = input()
	for i in range(n):
		if mystr[i] >= flag1:
			ret += '0'
			flag1 = mystr[i]
		elif mystr[i] >= flag2:
			ret += '1'
			flag2 = mystr[i]
		else:
			print('NO')
			return
	print('YES')
	print(ret)
run()


n = int(input())
s = input()
(c1, c2, res) = ('a', 'a', [''] * n)
for i in range(n):
	if s[i] >= c1:
		res[i] = '0'
		c1 = s[i]
	elif s[i] >= c2:
		res[i] = '1'
		c2 = s[i]
	else:
		print('NO')
		break
else:
	print('YES')
	print(''.join(res))


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	n = II()
	s = SI()
	col = [-1] * 26
	ans = [0] * n
	A = ord('a')
	for (i, c) in enumerate(s):
		zero = one = False
		for j in range(i):
			if ord(s[j]) > ord(c):
				zero |= ans[j] == 0
				one |= ans[j] == 1
		if zero and one:
			print('NO')
			exit()
		elif zero:
			ans[i] = 1
	print('YES')
	print(*ans, sep='')
main()


n = int(input())
s = input()
(last, last1) = ('a', 'a')
ans = ''
flag = 1
for i in s:
	if i < last and i < last1:
		flag = 0
		break
	elif i >= last:
		last = i
		ans += '0'
	else:
		last1 = i
		ans += '1'
if flag:
	print('YES')
	print(ans)
else:
	print('NO')


n = int(input())
c = list(input())
for i in range(n):
	c[i] = [c[i], -1]
i = 0
flag = True
while flag and i < n:
	j = i + 1
	while j < n and c[i][1] == -1:
		if c[j][0] < c[i][0]:
			if c[j][1] != -1:
				c[i][1] = (c[j][1] + 1) % 2
				j = n + 1
		j += 1
	if c[i][1] == -1:
		c[i][1] = 0
	for j in range(i + 1, n):
		if c[j][0] < c[i][0]:
			if c[j][1] == -1:
				c[j][1] = (c[i][1] + 1) % 2
			elif (c[j][1] + c[i][1]) % 2 != 1:
				flag = False
	if not flag:
		break
	i += 1
ans = []
for i in c:
	ans.append(i[1])
if flag:
	print('YES')
	print(*ans, sep='')
else:
	print('NO')


import sys

def main():
	n = int(sys.stdin.readline().split()[0])
	s = sys.stdin.readline().split()[0]
	color = [None] * n
	color[0] = 0
	for i in range(n):
		if color[i] == None:
			color[i] = 0
		for j in range(i + 1, n):
			if ord(s[j]) < ord(s[i]):
				if color[j] == color[i]:
					print('NO')
					return
				if color[j] == None:
					color[j] = color[i] ^ 1
	print('YES')
	print(*color, sep='')
main()


while True:
	try:
		n = int(input())
		s = input()
		a = ''
		b = ''
		a += s[0]
		ans = '0'
		for i in range(1, n):
			if s[i] >= a[-1]:
				a += s[i]
				ans += '0'
			elif b == '' or s[i] >= b[-1]:
				b += s[i]
				ans += '1'
			else:
				ans = 'N'
				break
		if ans == 'N':
			print('NO')
		else:
			print('YES')
			print(ans)
	except EOFError:
		break


import sys
input = sys.stdin.readline
import math
import copy
import collections
from collections import deque
n = int(input())
s = input().rstrip()
arr = []
for c in s:
	arr.append(c)
arr.sort()
ind = dict()
for i in range(n):
	if arr[i] not in ind:
		ind[arr[i]] = i
move = []
for i in range(n):
	temp = s[i]
	move.append(ind[temp])
	ind[temp] += 1
zero = []
one = []
possible = True
for i in range(n):
	if not zero:
		zero.append(i)
	elif move[zero[-1]] < move[i]:
		zero.append(i)
	elif not one:
		one.append(i)
	elif move[one[-1]] < move[i]:
		one.append(i)
	else:
		possible = False
if possible:
	print('YES')
	i = 0
	j = 0
	while i < len(zero) or j < len(one):
		if not i < len(zero):
			print(1, end='')
			j += 1
		elif not j < len(one):
			print(0, end='')
			i += 1
		elif zero[i] < one[j]:
			print(0, end='')
			i += 1
		else:
			print(1, end='')
			j += 1
	print()
else:
	print('NO')


import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__

def ceil(tails, L, R, key):
	while L + 1 < R:
		m = (L + R) // 2
		if key < tails[m]:
			L = m
		else:
			R = m
	return R

def LIS(a, n):
	tails = [0] * (n + 1)
	tails[0] = a[0]
	seq_len = 1
	for i in range(1, n):
		if a[i] > tails[0]:
			tails[0] = a[i]
		elif a[i] < tails[seq_len - 1]:
			tails[seq_len] = a[i]
			seq_len += 1
		else:
			tails[ceil(tails, -1, seq_len - 1, a[i])] = a[i]
	return seq_len
n = int(input())
s = input()
maxOrd = 0
if LIS(s, n) <= 2:
	ans = []
	for c in s:
		if ord(c) >= maxOrd:
			maxOrd = ord(c)
			ans.append('0')
		else:
			ans.append('1')
	print('YES')
	print(''.join(ans))
else:
	print('NO')


n = int(input())
s = input()
s0 = ''
s1 = ''
k = ''
s0 += s[0]
k += '0'
cont = True
for x in range(1, n):
	if s1 == '':
		if s[x] >= s0[len(s0) - 1]:
			s0 += s[x]
			k += '0'
		else:
			s1 += s[x]
			k += '1'
	elif s[x] >= s0[len(s0) - 1]:
		s0 += s[x]
		k += '0'
	elif s[x] >= s1[len(s1) - 1]:
		s1 += s[x]
		k += '1'
	else:
		cont = False
		break
if cont:
	print('YES')
	print(k)
else:
	print('NO')


def main():
	n = int(input())
	ss = list(zip(input(), range(0, n)))
	prev = ' '
	res = ['0'] * n
	for i in range(1, n):
		if ss[i][0] < ss[i - 1][0]:
			if res[ss[i - 1][1]] == '0':
				res[ss[i][1]] = '1'
			j = i - 1
			while j >= 0 and ss[i][0] < ss[j][0]:
				if res[ss[i][1]] == res[ss[j][1]]:
					print('NO')
					return
				else:
					j -= 1
			ss[j + 1:i + 1] = [ss[i]] + ss[j + 1:i]
	print('YES')
	print(''.join(res))
main()


n = int(input())
s = input()
last_1 = 'a'
last_2 = 'a'
res = True
r = []
for c in s:
	if c < last_1:
		if c < last_2:
			res = False
		else:
			r.append('1')
			last_2 = max(last_2, c)
	else:
		last_1 = max(c, last_1)
		r.append('0')
if res:
	print('YES')
	print(''.join(r))
else:
	print('NO')


a = int(input())
s = input()
ans = [0]
flag = 0
g1 = [[s[0], 0, 0]]

def fit(g1, si, i):
	r = len(g1) - 1
	while r >= 0 and g1[r][0] > s[i] and (g1[r][1] == 0):
		r -= 1
	if r < 0:
		g1.insert(0, [si, 1, i])
		return 1
	if g1[r][0] > si and g1[r][1] == 1:
		return 0
	g1.insert(r + 1, [si, 1, i])
	return 1
for i in range(1, len(s)):
	if s[i] >= g1[-1][0]:
		g1.append([s[i], 0, i])
		continue
	if fit(g1, s[i], i):
		continue
	else:
		flag = 1
		break
if flag == 1:
	print('NO')
	exit(0)
print('YES')
g1.sort(key=lambda x: x[2])
for i in range(len(g1)):
	print(g1[i][1], end='')


n = int(input())
string = input()
arr = [ord(i) - 96 for i in string]
lmax = arr[0]
ans = '0'
flag = 0
flag2 = 1
for i in range(1, n):
	if arr[i] < lmax:
		if flag:
			if arr[i] < fmax:
				flag2 = 0
				break
			else:
				fmax = arr[i]
				ans += '1'
		else:
			flag = 1
			fmax = arr[i]
			ans += '1'
	else:
		lmax = arr[i]
		ans += '0'
if flag2:
	print('YES')
	print(ans)
else:
	print('NO')


n = int(input())
s = str(input())
ls = []
b_end = False
s_out = ''
for x in range(0, len(s)):
	tmp_tab = [s[x], -1]
	ls.append(tmp_tab)
ls[0][1] = 0
for x in range(1, len(ls)):
	tmp_val = ls[x]
	tmp_lit = ls[x][0]
	tmp_num = 0
	tmp_war = []
	for y in range(x - 1, -1, -1):
		if ls[y][0] > tmp_lit:
			tmp_war.append(ls[y][1])
	if not tmp_war:
		ls[x][1] = 0
	elif 0 not in tmp_war:
		ls[x][1] = 0
	elif 1 not in tmp_war:
		ls[x][1] = 1
	else:
		b_end = True
		break
if b_end == True:
	print('NO')
else:
	for x in range(0, len(ls)):
		s_out += str(ls[x][1])
	print('YES')
	print(s_out)


from bisect import insort, bisect_right, bisect_left
from sys import stdout, stdin, setrecursionlimit
from math import sqrt, ceil, floor, factorial, gcd, log2, log10
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from string import *
from queue import *
from heapq import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

def getInt():
	return int(input())

def listStr():
	return list(input())

def getStrs():
	return input().split()

def isInt(s):
	return '0' <= s[0] <= '9'

def input():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in input().split()]

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def getPrimes(N=10 ** 5):
	SN = int(sqrt(N))
	sieve = [i for i in range(N + 1)]
	sieve[1] = 0
	for i in sieve:
		if i > SN:
			break
		if i == 0:
			continue
		for j in range(2 * i, N + 1, i):
			sieve[j] = 0
	prime = [i for i in range(N + 1) if sieve[i] != 0]
	return prime

def primeFactor(n, prime=getPrimes()):
	lst = []
	mx = int(sqrt(n)) + 1
	for i in prime:
		if i > mx:
			break
		while n % i == 0:
			lst.append(i)
			n //= i
	if n > 1:
		lst.append(n)
	return lst
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = getInt()
arr = getStr()
for i in range(n):
	graph[i] = []
for i in range(n):
	for j in range(i):
		u = ord(arr[i]) - ord('a')
		v = ord(arr[j]) - ord('a')
		if v > u:
			graph[i].append(j)
			graph[j].append(i)
side = [-1] * n
ans = True
for i in range(n):
	if side[i] == -1:
		que = deque([i])
		side[i] = 0
		while que:
			x = que.pop()
			for i in graph[x]:
				if side[i] == -1:
					side[i] = side[x] ^ 1
					que.append(i)
				else:
					ans = ans and side[i] != side[x]
print('Yes'.upper() if ans else 'No'.upper())
if ans:
	print(''.join((str(i) for i in side)))


def find(x):
	r = x
	while r != f[r]:
		r = f[r]
	while x != r:
		pre = f[x]
		f[x] = r
		x = pre
	return r
a = input()
n = int(a)
a = input()
str = list(a)
id = [0] * n
f = [0] * 2 * n
name = [0] * 2 * n
for i in range(n):
	id[i] = i
for i in range(2 * n):
	f[i] = i
	name[i] = -1
Find = 0
for i in range(n):
	if Find:
		break
	for j in range(n - i - 1):
		if str[j] > str[j + 1]:
			(str[j], str[j + 1]) = (str[j + 1], str[j])
			(id[j], id[j + 1]) = (id[j + 1], id[j])
			fx = find(id[j])
			fnx = find(id[j] + n)
			fy = find(id[j + 1])
			fny = find(id[j + 1] + n)
			if fx == fy or fnx == fny:
				Find = 1
				break
			else:
				f[fx] = fny
				f[fy] = fnx
if Find:
	print('NO')
else:
	print('YES')
	for i in range(n):
		fx = find(i)
		if name[fx] < 0:
			name[fx] = 0
			if fx >= n:
				name[find(fx - n)] = 1
			else:
				name[find(fx + n)] = 1
		print('{:d}'.format(name[fx]), end='')


n = int(input())
s = input()
g = {}
for i in range(len(s)):
	g[i] = []
for i in range(len(s)):
	for j in range(i):
		if s[j] > s[i]:
			g[i].append(j)
			g[j].append(i)
colored = [False] * len(s)
color = [None] * len(s)

def brush(v, c):
	colored[v] = True
	color[v] = c
	for n in g[v]:
		if colored[n]:
			if color[n] == c:
				return False
		elif not brush(n, c ^ 1):
			return False
	return True
failed = False
for i in range(len(s)):
	if not colored[i]:
		if not brush(i, 0):
			failed = True
			break
if failed:
	print('NO')
else:
	print('YES')
	print(''.join(map(lambda i: '1' if color[i] == 1 else '0', range(len(s)))))


from collections import deque
n = int(input())
s = input()
graph = {}
for i in range(n):
	graph[i] = set()
rb = set()
for i in range(n):
	for j in range(i + 1, n):
		if s[i] > s[j]:
			graph[i].add(j)
			graph[j].add(i)
			rb.add((i, j))
			rb.add((j, i))
group = [0] * n
used = [0] * n
for p in range(n):
	if not used[p]:
		used[p] = 1
		q = deque([p])
		group[p] = 0
		while q:
			v = q.popleft()
			for u in graph[v]:
				if not used[u]:
					used[u] = 1
					q.append(u)
					group[u] = 1 - group[v]
(g1, g2) = (set(), set())
for i in range(n):
	if group[i] == 0:
		g1.add(i)
	else:
		g2.add(i)
for p in g1:
	for p2 in g1:
		if (p, p2) in rb:
			print('NO')
			exit(0)
for p in g2:
	for p2 in g2:
		if (p, p2) in rb:
			print('NO')
			exit(0)
print('YES')
for i in range(n):
	if i in g1:
		print('0', end='')
	else:
		print('1', end='')


from sys import stdin, stdout
t = 1
for _ in range(t):
	n = int(input())
	s = input()
	ans = [str(0)]
	last = s[0]
	color = 0
	for i in s[1:]:
		if i >= last:
			last = i
			ans.append(str(color))
		else:
			ans.append(str(color ^ 1))
	val1 = []
	val2 = []
	for i in range(n):
		if int(ans[i]):
			val1.append(s[i])
		else:
			val2.append(s[i])
	if val1 == sorted(val1) and val2 == sorted(val2):
		print('YES')
		print(''.join(ans))
	else:
		print('NO')


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 5)
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
n = int(input())
s = list(input())
i = 0
ans = [0] * (n + 1)
hash = defaultdict(int)
cnt = 0
while i < n - 1:
	if s[i] <= s[i + 1]:
		ans[i + 1] = ans[i]
		i += 1
	else:
		j = i + 1
		hash[j] = 1
		ans[j] = 1
		while s[j] < s[j - 1] and ans[j] != ans[j - 1]:
			(s[j - 1], s[j]) = (s[j], s[j - 1])
			(ans[j - 1], ans[j]) = (ans[j], ans[j - 1])
			j -= 1
			if j == 0:
				break
		i += 1
if sorted(s) == s:
	print('YES')
	for i in range(n):
		print(hash[i], end='')
else:
	print('NO')


n = int(input())
s = list(input())
adj_list = [[] for i in range(n)]
for i in range(n):
	for j in range(i + 1, n):
		if s[j] < s[i]:
			adj_list[i].append(j)
			adj_list[j].append(i)
color = [-1] * n
feasible = True
for i in range(n):
	if color[i] == -1:
		l = [i]
		color[i] = 0
		while len(l) > 0:
			cur = l.pop()
			for child in adj_list[cur]:
				if color[child] == color[cur]:
					feasible = False
				elif color[child] == -1:
					l.append(child)
					color[child] = 1 - color[cur]
if feasible:
	print('YES')
	print(''.join(map(str, color)))
else:
	print('NO')


from bisect import bisect_right

def main():
	n = int(input())
	line = list(input())
	sor = [(line[0], 0)]
	ans = ['0']
	for i in range(1, n):
		j = bisect_right(sor, (line[i], 1))
		if j == len(sor):
			col = (sor[j - 1][1] + 1) % 2
		else:
			col = sor[j][1]
		k = j
		while k < len(sor) and col == sor[k][1]:
			k += 1
		if k != len(sor):
			print('NO')
			return 0
		sor.insert(j, (line[i], (col + 1) % 2))
		ans.append(str((col + 1) % 2))
	print('YES')
	print(''.join(ans))
main()


import os, sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	s = input().strip()
	ls = [[[i - 1, i + 1] for i in range(n + 2)] for _ in range(26)]
	(ans, ans1) = ([], 1)
	for i in s:
		z = ord(i) - 97
		r = ls[z][0][1]
		ans.append(r - 1)
		ans1 = max(ans1, r)
		for j in range(z):
			k = ls[j][r]
			if k[0] != -1:
				ls[j][k[0]][1] = k[1]
				ls[j][k[1]][0] = k[0]
				ls[j][r][0] = -1
	if ans1 <= 2:
		print('YES')
		print(*ans, sep='')
	else:
		print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
s = input()
color = [0 for _ in range(n)]
f = 0
for i in range(n):
	for j in range(i + 1, n):
		if s[j] < s[i]:
			color[j] = 1 - color[i]
for i in range(n):
	for j in range(i + 1, n):
		if color[i] == color[j] and s[i] > s[j]:
			f = 1
			print('NO')
			break
	if f == 1:
		break
if f == 0:
	print('YES')
	for i in range(n):
		print(color[i], end='')


import sys
f_in = sys.stdin
f_out = sys.stdout
num = int(f_in.readline())
strings = f_in.readline()
grp = [[], [], []]
warning = 0
for i in range(0, num):
	if grp[0] == [] or grp[0][-1] <= strings[i]:
		grp[0].append(strings[i])
		grp[2].append('0')
	elif grp[1] == [] or grp[1][-1] <= strings[i]:
		grp[1].append(strings[i])
		grp[2].append('1')
	else:
		warning = 1
ans = ''.join(grp[2])
if warning == 1:
	f_out.write('NO\n')
else:
	f_out.write('YES\n')
	f_out.write(ans + '\n')
f_in.close()
f_out.close()


n = int(input())
s = list(map(ord, input()))
b = [0 for i in range(26)]
ans = []
for i in s:
	for j in range(26):
		if b[j] <= i:
			b[j] = i
			ans.append(j)
			break
if 26 - b.count(0) <= 2:
	print('YES')
	print(''.join(map(str, ans)))
else:
	print('NO')


n = int(input())
s = list(input())
lst1 = 'a'
lst2 = 'a'
res = ''
for i in range(n):
	if s[i] >= lst1:
		res += '0'
		lst1 = s[i]
	elif s[i] >= lst2:
		res += '1'
		lst2 = s[i]
	else:
		print('NO')
		exit(0)
print('YES')
print(res)


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline()

def sieve(x):
	a = [True] * (x + 1)
	sq = floor(sqrt(x))
	for i in range(3, sq + 1, 2):
		if a[i]:
			for j in range(i * i, x + 1, i):
				a[j] = False
	if x > 1:
		p = [2]
	else:
		p = []
	for i in range(3, x + 1, 2):
		if a[i]:
			p.append(i)
	return p
res = ['YES', 'NO']
f = 0
p = [[] for _ in range(26)]
n = ii()
ans = [0] * n
a = lsi()
for i in range(n):
	p[ord(a[i]) - 97].append(i)
	s = set()
	for x in p[ord(a[i]) - 96:]:
		if x:
			for j in x:
				s.add(ans[j])
	if s:
		if len(s) == 2:
			f = 1
			break
		else:
			el = s.pop()
			ans[i] = (1 + el) % 2
print(res[f])
if not f:
	print(*ans, sep='')


n = int(input())
s = input()
col = [-1 for i in range(n)]
ok = True
for i in range(n):
	if col[i] == -1:
		col[i] = 0
	for j in range(i + 1, n):
		if col[j] == -1:
			if s[i] > s[j]:
				col[j] = 1 - col[i]
		elif s[i] > s[j] and col[i] + col[j] != 1:
			ok = False
if ok:
	print('YES')
	ans = str()
	for i in range(n):
		ans += str(col[i])
	print(ans)
else:
	print('NO')


def dfs(adj, u, color):
	for v in adj[u]:
		if color[v] is None:
			color[v] = color[u] ^ 1
			if dfs(adj, v, color):
				return True
		elif color[v] != color[u] ^ 1:
			return True
	return False
n = int(input())
s = input()
adj = [[] for _ in range(n)]
for i in range(n):
	for j in range(i + 1, n):
		if s[i] > s[j]:
			adj[i].append(j)
			adj[j].append(i)
color = [None] * n
bad = False
for u in range(n):
	if color[u] is None:
		color[u] = 0
		if dfs(adj, u, color):
			bad = True
			break
if bad:
	print('NO')
else:
	print('YES')
	print(*color, sep='')


n = int(input())
s = list(input())
a = []
for i in range(n):
	a.append([s[i], i])
a.sort()
f = ['0'] * n
w = -1
tf = False
g = [0] * n
for i in range(n):
	if a[i][1] + g[a[i][1]] == i:
		pass
	elif g[a[i][1]] == 0:
		g[a[i][1]] = 1
		for j in range(a[i][1] - 1, -1, -1):
			g[j] += 1
		f[a[i][1]] = '1'
	else:
		tf = True
		break
if tf:
	print('NO')
else:
	print('YES')
	print(''.join(f))


n = int(input())
a = list(map(lambda c: ord(c) - 97, input()))
color = [0] * 26
ans = [0] * n
last = -1
for (i, c) in enumerate(a):
	col = 0
	if last <= c:
		last = c
		if color[c] == 0 or color[c] == 3:
			col = 1
		else:
			col = color[c]
	else:
		for j in range(last, c, -1):
			if color[j] == 0:
				continue
			if color[j] == 3:
				print('NO')
				return
			if col == 0:
				col = color[j] ^ 3
			elif col & color[j]:
				print('NO')
				return
	color[c] |= col
	ans[i] = col - 1
print('YES')
print(*ans, sep='')


n = int(input())
s = [ord(i) - ord('a') + 1 for i in input()]
clr = ['0'] * n
x = s[0]
bad = []
flag = 1
for i in range(n):
	if s[i] >= x:
		x = s[i]
	else:
		clr[i] = '1'
		bad.append(s[i])
		if any([s[i] < j for j in bad]):
			print('NO')
			flag = 0
			break
if flag:
	print('YES')
	print(''.join(clr))


n = int(input())
s = input()
res = ''
ele1 = 'a'
ele2 = 'a'
flag = 0
for ele in s:
	if ele >= ele1:
		res += '0'
		ele1 = ele
	elif ele >= ele2:
		res += '1'
		ele2 = ele
	else:
		flag = 1
		break
if flag == 1:
	print('NO')
else:
	print('YES')
	print(res)


import sys
n = int(sys.stdin.readline())
s = list(sys.stdin.readline().strip())
(s0, s1) = ('', '')
color = ''
works = True
for i in s:
	if s0 == '' or s0[-1] <= i:
		s0 += i
		color += '0'
	elif s1 == '' or s1[-1] <= i:
		s1 += i
		color += '1'
	else:
		works = False
		break
if works == True:
	print('YES')
	print(color)
else:
	print('NO')


from collections import deque, Counter
import array
from itertools import combinations, permutations
from math import sqrt

def read_int():
	return int(input().strip())

def read_int_array():
	return [int(i) for i in input().strip().split(' ')]
n = read_int()
s = input().strip()
s1 = [s[0]]
s2 = []
for c in s[1:]:
	if s1[-1] <= c:
		s1.append(c)
	elif not s2 or s2[-1] <= c:
		s2.append(c)
	else:
		break
if len(s1) + len(s2) == len(s):
	i = 0
	j = 0
	out = []
	for c in s:
		if i < len(s1) and c == s1[i]:
			out.append('0')
			i += 1
		else:
			out.append('1')
			j += 1
	print('YES')
	print(''.join(out))
else:
	print('NO')


def check(i, n, x, y, s, dp):
	if i == n:
		return 1
	if dp[i][x][y] != -1:
		return dp[i][x][y]
	ch = ord(s[i]) - 97
	dp[i][x][y] = 0
	if ch >= x and check(i + 1, n, ch, y, s, dp) > 0:
		dp[i][x][y] = 1
	elif ch >= y and check(i + 1, n, x, ch, s, dp) > 0:
		dp[i][x][y] = 2
	return dp[i][x][y]
n = int(input())
s = input()
dp = [[[-1] * 26 for j in range(26)] for i in range(n)]
if check(0, n, 0, 0, s, dp) == 0:
	print('NO')
else:
	print('YES')
	ans = ''
	x = 0
	y = 0
	for i in range(n):
		ch = ord(s[i]) - 97
		ans += str(dp[i][x][y] - 1)
		if dp[i][x][y] == 1:
			x = ch
		else:
			y = ch
	print(ans)


import sys
input = lambda : sys.stdin.readline().strip()
n = int(input())
s = input()
adj = [[] for i in range(n)]
for i in range(n):
	for j in range(i + 1, n):
		if s[i] > s[j]:
			adj[i].append(j)
			adj[j].append(i)
color = [0 for i in range(n)]
seen = [False for i in range(n)]

def bfs(s):
	q = [s]
	for u in q:
		for v in adj[u]:
			if not seen[v]:
				seen[v] = True
				color[v] = 1 - color[u]
				q.append(v)
for i in range(n):
	if not seen[i]:
		bfs(i)
if all((color[u] != color[v] for u in range(n) for v in adj[u])):
	print('YES')
	print(*color, sep='')
else:
	print('NO')


n = int(input())
s = input()
poss = 1
l1 = []
l2 = []
arr = [0 for i in range(n)]
for i in range(n):
	if l1 == []:
		l1.append(s[i])
		arr[i] = 0
	elif ord(s[i]) >= ord(l1[-1]):
		l1.append(s[i])
		arr[i] = 0
	elif l2 == []:
		l2.append(s[i])
		arr[i] = 1
	elif ord(s[i]) >= ord(l2[-1]):
		l2.append(s[i])
		arr[i] = 1
	else:
		poss = 0
		break
if poss == 0:
	print('NO')
else:
	print('YES')
	for i in arr:
		print(i, end='')


import math
import cmath
from decimal import *
from fractions import *
n = int(input())
s = input()
a = [-1] * n
a[0] = 0
for i in range(1, n):
	for j in range(0, i):
		if s[i] < s[j]:
			if a[i] == a[j]:
				print('NO')
				exit(0)
			else:
				a[i] = 1 - a[j]
	if a[i] == -1:
		a[i] = 0
print('YES')
for x in a:
	print(x, end='')


n = int(input())
s = input()
najm = [0] * n
najm[n - 1] = s[n - 1]
for i in range(n - 1):
	j = n - i - 2
	najm[j] = min(najm[j + 1], s[j + 1])
can_sort = True
for i in range(n):
	for j in range(i + 1, n - 1):
		if s[i] > s[j] and s[j] > najm[j]:
			can_sort = False
			break
if not can_sort:
	print('NO')
else:
	print('YES')
	kol = [-1] * n
	kol[0] = 0
	ind = 0
	while ind < n:
		if kol[ind] == -1:
			kol[ind] = 0
		for i in range(ind + 1, n):
			if s[i] < s[ind]:
				kol[i] = (kol[ind] + 1) % 2
		ind += 1
	print(''.join(map(str, kol)))


n = int(input())
s = input()
fl = True
dp = [1] * n
for i in range(1, n):
	for j in range(i):
		if s[j] > s[i]:
			dp[i] = max(dp[i], 1 + dp[j])
for i in dp:
	if i >= 3:
		fl = False
		break
if not fl:
	print('NO')
else:
	print('YES')
	mn1 = s[0]
	ans = str(0)
	for i in range(1, n):
		if s[i] >= mn1:
			ans += '0'
			mn1 = s[i]
		else:
			ans += '1'
	print(ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()
from random import randint
from collections import defaultdict, deque

class Graph(object):

	def __init__(self, dic):
		self.dict = dic
		self.vertex = set()

	def addedge(self, a, b):
		if self.dict[a] == []:
			self.vertex.add(a)
		if b != None:
			self.dict[a].append(b)

	def con_com_util(self, i, unvisited, count, comp):
		for j in self.dict[i]:
			if j in unvisited:
				unvisited.remove(j)
				comp[count].append(j)
				comp = self.con_com_util(j, unvisited, count, comp)
		return comp

	def conn_components(self):
		unvisited = self.vertex.copy()
		count = 0
		comp = defaultdict(list)
		while unvisited:
			i = unvisited.pop()
			comp[count].append(i)
			comp = self.con_com_util(i, unvisited, count, comp)
			count += 1
		return (count, comp)

def countSetBits(n):
	count = 0
	while n:
		n &= n - 1
		count += 1
	return count

def g():
	return -1
from math import ceil

def solve():
	n = int(inp())
	s = inp()
	cur0 = s[0]
	cur1 = 'a'
	ans = '0'
	t = 1
	for i in range(1, n):
		if s[i] >= cur0:
			cur0 = s[i]
			ans += '0'
		elif s[i] >= cur1:
			cur1 = s[i]
			ans += '1'
		else:
			t = -1
			break
	if t == -1:
		print('NO')
	else:
		print('YES')
		print(ans)
solve()


(n, s, x, y, answer) = (int(input()), input(), 'a', 'a', '')
for i in s:
	if i >= x:
		answer += '0'
		x = i
	elif i >= y:
		answer += '1'
		y = i
	else:
		print('NO')
		break
else:
	print('YES')
	print(answer)


n = int(input())
s = input()
ans = [0] * n
for i in range(n - 1):
	for j in range(i + 1, n):
		if s[i] > s[j]:
			if ans[i] == 0:
				ans[j] = 1
			else:
				ans[j] = 0
flag = True
for i in range(n - 1):
	for j in range(i + 1, n):
		if s[i] > s[j]:
			if ans[i] == ans[j]:
				flag = False
				break
if flag:
	print('YES')
	for i in ans:
		print(i, end='')
else:
	print('NO')


input()
arr = input().strip()
ans = []
color = 0
mx = [0 for i in range(26)]
for i in arr:
	c = ord(i) - 97
	_max = 0
	for j in range(c + 1, 26):
		_max = max(_max, mx[j])
	ans.append(_max + 1)
	color = max(color, ans[-1])
	mx[c] = max(mx[c], _max + 1)
if color > 2:
	print('NO')
else:
	print('YES')
	for i in ans:
		print(i - 1, end='')


n = int(input())
a = list(input())
a1 = [i for i in range(n)]
new = {i: set() for i in range(n)}
flag = False
while not flag:
	flag = True
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			(a[i], a[i + 1]) = (a[i + 1], a[i])
			new.setdefault(a1[i], set()).add(a1[i + 1])
			(a1[i], a1[i + 1]) = (a1[i + 1], a1[i])
			flag = False
i = 0
while i < n and len(new[i]) == 0:
	i += 1
if i == n:
	print('YES')
	print('0' * n)
	exit(0)
set1 = {i}
set2 = new[i]
for i in range(n):
	flag = True
	for x in new:
		flag = True
		if x in set1:
			if not len(new[x] & set1) == 0:
				flag = False
				break
			set2 |= new[x]
		elif x in set2:
			if not len(new[x] & set2) == 0:
				flag = False
				break
			set1 |= new[x]
		else:
			set1.add(x)
			set2 |= new[x]
	if not flag:
		break
if flag:
	print('YES')
	new = [0] * n
	for i in range(n):
		if i in set1:
			new[i] = 0
		else:
			new[i] = 1
	print(''.join(map(str, new)))
else:
	print('NO')


(n, s, a, b, ans) = (int(input()), input(), 'a', 'a', '')
check = True
for i in s:
	if i >= a:
		ans += '0'
		a = i
	elif i >= b:
		ans += '1'
		b = i
	else:
		print('NO')
		check = False
		break
if check:
	print('YES')
	print(ans)


import sys
import collections
input = sys.stdin.readline

def main():
	N = int(input())
	S = input().strip()
	first = 0
	second = 0
	ans = []
	for (i, s) in enumerate(S):
		if i == 0:
			first = ord(s) - ord('a')
			ans.append(0)
		elif ord(s) - ord('a') >= first:
			first = ord(s) - ord('a')
			ans.append(0)
		elif ord(s) - ord('a') >= second:
			second = ord(s) - ord('a')
			ans.append(1)
		else:
			print('NO')
			break
	else:
		print('YES')
		print(''.join(map(str, ans)))
main()


x = int(input())
y = input()
out = [0] * x
ch = 'a'
for i in range(x):
	if y[i] >= ch:
		ch = y[i]
		out[i] = 1
ch = 'a'
for i in range(x):
	if y[i] >= ch and out[i] == 0:
		ch = y[i]
		out[i] = 2
if 0 in out:
	print('NO')
else:
	print('YES')
	for i in out:
		print(i - 1, end='')


def main():
	n = int(input())
	s = list(input())
	colors = [-1] * n
	for i in range(len(s)):
		if colors[i] == -1:
			colors[i] = 0
		for j in range(i + 1, n):
			if s[j] < s[i]:
				if colors[j] == colors[i]:
					print('NO')
					return
				if colors[j] == -1:
					if colors[i] == 0:
						colors[j] = 1
					else:
						colors[j] = 0
	print('YES')
	for i in colors:
		print(i, end='')
main()


from collections import deque

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z
n = int(input())
s = list(input())
d = dict()
ans = [-1] * n
u = [i for i in range(n)]
w = sorted(s)
u = sort_list(u, s)
f = 0
for i in range(n):
	if w[i] not in d:
		d.update({w[i]: deque([i])})
	else:
		d[w[i]].append(i)
for i in range(n):
	if i > d[s[i]][0]:
		e = ''
		for j in range(d[s[i]][0], i):
			e += s[j]
			if ans[j] == -1:
				ans[j] = 0
		if list(e) == sorted(e):
			ind = d[s[i]][0]
			d[s[i]].popleft()
			e = s[i]
			if ans[i] == 0:
				f = 1
				break
			ans[i] = 1
			e1 = ans[i]
			for j in range(i - 1, ind - 1, -1):
				s[j + 1] = s[j]
				ans[j + 1] = ans[j]
			s[ind] = e
			ans[ind] = e1
		else:
			f = 1
			break
	else:
		d[s[i]].popleft()
if f == 1:
	print('NO')
else:
	for i in range(n):
		if ans[i] == -1:
			ans[i] = 0
	ans = sort_list(ans, u)
	print('YES')
	print(*ans, sep='')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
n = int(ri())
s = ri()
g = [[] for i in range(n)]
for i in range(n):
	for j in range(i + 1, n):
		if s[i] > s[j]:
			g[i].append(j)
			g[j].append(i)

def dfs(cur, par, col):
	vis[cur] = col
	for child in g[cur]:
		if child == par:
			continue
		if vis[child] == -1:
			if dfs(child, cur, col ^ 1):
				return True
		elif vis[child] == vis[cur]:
			return True
	return False
vis = [-1] * n
flag = False
for i in range(n):
	if vis[i] == -1:
		if dfs(i, -1, 0):
			flag = True
			break
if flag:
	NO()
else:
	YES()
	print(''.join(map(str, vis)))


n = int(input())
s = input()
x = '0'
flag = 'YES'
c = 0
initial = s[0]
for i in range(1, n):
	if s[i] < initial:
		x += '1'
		if c != 0:
			if s[i] < c:
				flag = 'NO'
				break
		c = s[i]
	else:
		x += '0'
		initial = s[i]
print(flag)
if flag != 'NO':
	print(x)


from collections import defaultdict
import copy
n = int(input())
arr = list(input())
arr2 = arr[:]
arr2.sort()
temp = [[arr[0], '0', 0]]
flag = 0
for i in range(1, n):
	temp += [[arr[i], '9', i]]
	temp2 = copy.deepcopy(temp)
	temp2.sort()
	ind = i
	temps = []
	while temp[ind][0] != temp2[ind][0]:
		temps += [temp[ind - 1][1]]
		(temp[ind], temp[ind - 1]) = (temp[ind - 1][:], temp[ind][:])
		ind -= 1
	if len(temps) == 0:
		temp[ind][1] = temp2[-2][1]
	elif temps.count(temps[0]) != len(temps):
		flag = 1
		break
	elif temps[0] == '1':
		temp[ind][1] = '0'
	else:
		temp[ind][1] = '1'
if flag == 1:
	print('NO')
	exit()
print('YES')
ans = [0] * n
for x in temp:
	ans[x[2]] = x[1]
print(*ans, sep='')


n = int(input())
s = input()
ans = ''
color1 = color2 = 'a'
flag = True
for c in s:
	if c >= color1:
		ans += '0'
		color1 = c
	elif c >= color2:
		ans += '1'
		color2 = c
	else:
		flag = False
		break
if flag:
	print('YES')
	print(ans)
else:
	print('NO')


import sys
a = int(sys.stdin.readline())
s = sys.stdin.readline().strip()
s1 = s[0]
s2 = ''
p = ''
f = False
for i in s:
	if i >= s1[-1]:
		s1 += i
		p += '0'
	elif not s2 or i >= s2[-1]:
		s2 += i
		p += '1'
	else:
		print('NO')
		f = True
		break
if not f:
	print('YES')
	print(p)


def main():
	n = int(input())
	s = input()
	ret = [-1 for _ in range(n)]
	flag = False
	for i in range(n):
		se = set()
		for j in range(i - 1, -1, -1):
			if s[j] > s[i]:
				se.add(ret[j])
		if len(se) > 1:
			flag = True
			break
		elif len(se) == 1:
			ret[i] = 1 - list(se)[0]
		else:
			ret[i] = 0
	if flag:
		print('NO')
	else:
		print('YES')
		print(''.join(list(map(str, ret))))
main()


n = int(input())
s = list(input())
color = [-1] * n
feasible = True
for i in range(n):
	for j in range(0, i):
		if s[j] > s[i]:
			if color[i] == -1:
				color[i] = 1 - color[j]
			elif color[i] == color[j]:
				feasible = False
	if color[i] == -1:
		color[i] = 0
if feasible:
	print('YES')
	print(''.join(map(str, color)))
else:
	print('NO')


(n, s) = (int(input()), input())
k = l = 'a'
ans = ''
breaker = False
for c in s:
	if c >= k:
		ans += '0'
		k = c
	elif c >= l:
		ans += '1'
		l = c
	else:
		print('NO')
		breaker = True
		break
if not breaker:
	print('YES')
	print(ans)


N = int(input())
L = input()
S = '0'
prev = L[0]
last = -1
for i in range(1, N):
	if L[i] < prev:
		S += '1'
		if last != -1:
			if L[i] < last:
				print('NO')
				exit(0)
		last = L[i]
	else:
		S += '0'
		prev = L[i]
print('YES')
print(S)


import os
import sys
from atexit import register
from io import StringIO
sys.stdout = StringIO()
register(lambda : os.write(1, sys.stdout.getvalue().encode()))
import math
n = int(input())
s = input()
x = [ord(c) - 97 for c in s]
c = [0]
prev = -1
l = [x[0]]
for k in x[1:]:
	if k >= l[-1]:
		c.append(0)
		l.append(k)
	else:
		if k < l[0] and k < prev:
			break
		j = 0
		while k > l[j]:
			j += 1
		c.append(1)
		prev = k
		l = l[j:]
if len(c) == n:
	print('YES')
	print(''.join([str(k) for k in c]))
else:
	print('NO')


import sys
n = int(input())
s = input()
l1 = [1] * n
l1[0] = 0
prev = s[0]
for i in range(1, n):
	if s[i] >= prev:
		l1[i] = 0
		prev = s[i]
temp = []
for i in range(n):
	if l1[i] == 1:
		temp.append(s[i])
if len(temp) == 0:
	print('YES')
	print(''.join((str(x) for x in l1)))
	sys.exit()
prev = temp[0]
for i in range(1, len(temp)):
	if temp[i] < prev:
		print('NO')
		sys.exit()
	prev = temp[i]
print('YES')
print(''.join((str(x) for x in l1)))


def bubbleSort(arr, n):
	tags = list(range(1, n + 1))
	dislikes = []
	for i in range(n - 1):
		for j in range(0, n - i - 1):
			if arr[j] > arr[j + 1]:
				(arr[j], arr[j + 1]) = (arr[j + 1], arr[j])
				(tags[j], tags[j + 1]) = (tags[j + 1], tags[j])
				dislikes.append([tags[j], tags[j + 1]])
	return dislikes
n = int(input())
s = input()
dislikes = bubbleSort(list(s), n)
if len(dislikes) == 0:
	print('YES')
	print('0' * n)
	exit()
from collections import defaultdict
g = defaultdict(list)
nodes = set()
for (i, j) in dislikes:
	g[i].append(j)
	g[j].append(i)
	nodes.add(i)
	nodes.add(j)

def dfs_twocolor_np(node, g):
	global ok
	for nbr in g[node]:
		if colors[nbr] == 0:
			colors[nbr] = -colors[node]
			dfs_twocolor_np(nbr, g)
		elif colors[nbr] == colors[node]:
			ok = False
colors = [0] * (n + 1)
for node in range(1, n + 1):
	if colors[node] == 0:
		ok = True
		colors[node] = -1
		dfs_twocolor_np(node, g)
		if not ok:
			print('NO')
			exit()
	else:
		continue
print('YES')
ans = []
for i in colors[1:]:
	if i == 1:
		ans.append(str(i))
	else:
		ans.append('0')
print(*ans, sep='')


from sys import stdin, stdout
input = stdin.readline

def im():
	return map(int, input().split())

def ii():
	return int(input())

def il():
	return list(map(int, input().split()))

def ins():
	return input()[:-1]
n = ii()
st = ins()
l = 'a'
l2 = 'a'
ans = ''
for i in st:
	if i >= l:
		l = i
		ans += '0'
	elif i >= l2:
		l2 = i
		ans += '1'
	else:
		print('NO')
		break
if len(ans) == len(st):
	print('YES')
	print(ans)


n = int(input())
a = list(input())
colors = [0 for _ in range(n)]
flag_yes = True
(last0, last1) = (-1, -1)
for i in range(n):
	if ord(a[i]) >= last0:
		if ord(a[i]) >= last1:
			if last0 >= last1:
				last0 = ord(a[i])
				colors[i] = 0
			else:
				last1 = ord(a[i])
				colors[i] = 1
		else:
			last0 = ord(a[i])
			colors[i] = 0
	elif ord(a[i]) >= last1:
		last1 = ord(a[i])
		colors[i] = 1
	else:
		flag_yes = False
		break
if flag_yes:
	print('YES')
	print(''.join([str(item) for item in colors]))
else:
	print('NO')


import sys
input = sys.stdin.readline
n = int(input())
s = input().rstrip()
pre = '0'
prev = s[0]
lst = -1
for i in range(1, n):
	if s[i] >= prev:
		prev = s[i]
		pre += '0'
	else:
		pre += '1'
		if lst != -1:
			if s[i] < lst:
				print('NO')
				exit()
		lst = s[i]
print('YES')
print(pre)


import sys
n = int(sys.stdin.readline())
s = sys.stdin.readline().strip()
a2int = {chr(97 + i): i for i in range(26)}
aaaaa = {'1': 1, '0': 0}
res = 'YES'
list_res = ['0'] * n
list_where = [[] for _ in range(26)]
for (i, now) in enumerate(s):
	count = [0, 0]
	for j in range(a2int[now] + 1, 26):
		for v in list_where[j]:
			count[aaaaa[list_res[v]]] += 1
	if count[0] and count[1]:
		res = 'NO'
		break
	if count[0]:
		list_res[i] = '1'
	else:
		list_res[i] = '0'
	list_where[a2int[now]].append(i)
if res == 'YES':
	print('YES')
	print(''.join(list_res))
else:
	print('NO')


n = int(input())
s = input()
x = 'a'
y = 'a'
w = ''
for i in range(n):
	if s[i] >= x:
		w += '0'
		x = s[i]
	elif s[i] >= y:
		w += '1'
		y = s[i]
	else:
		print('NO')
		exit()
print('YES')
print(w)


d = [[0] * 26 for _ in range(26)]
n = int(input())
s = input()
ans = [-1] * n
max_ = 0
for (i, x) in enumerate(s):
	pos = ord(x) - 97
	val = None
	if pos == 25:
		val = 0
	else:
		for (_, x) in enumerate(d[pos + 1]):
			if x == 0:
				val = _
				break
	max_ = max(max_, val)
	ans[i] = str(val)
	for j in range(pos, -1, -1):
		d[j][val] = 1
if max_ > 1:
	print('NO')
else:
	print('YES')
	print(''.join(ans))


n = int(input())
seq = input()
l1 = []
l2 = []
possible = True
l1.append(seq[0])
i = 0
for i in range(1, n):
	if seq[i] >= seq[i - 1]:
		l1.append(seq[i])
	else:
		l2.append(seq[i])
		break
i += 1
while i < n:
	if seq[i] >= l1[len(l1) - 1]:
		l1.append(seq[i])
	elif seq[i] >= l2[len(l2) - 1]:
		l2.append(seq[i])
	else:
		possible = False
		break
	i += 1
i = 0
j = 0
if possible:
	print('YES')
	for char in seq:
		if i < len(l1) and char == l1[i]:
			print('0', end='')
			i += 1
		else:
			print('1', end='')
			j += 1
else:
	print('NO')


from sys import stdin, stdout

class Solve:

	def __init__(self):
		R = stdin.readline
		W = stdout.write
		n = int(input())
		s = [x for x in R()]
		s.pop()
		tmps = [] + s
		sor = sorted(s)
		ans = ['0' for i in range(n)]
		for i in range(n):
			if s[i] != sor[i]:
				flg = 0
				for j in range(i + 1, n):
					if s[j] == sor[i]:
						for k in range(j, i, -1):
							s[k] = s[k - 1]
							if k == j:
								if ans[k] == '1':
									W('NO')
									return
								ans[k] = '1'
						s[i] = sor[i]
						break
		tmpans = [] + ans
		for i in range(n):
			if tmps[i] != sor[i]:
				for j in range(i + 1, n):
					if tmps[j] == sor[i]:
						for k in range(j, i - 1, -1):
							if tmpans[k] != tmpans[k - 1]:
								(tmpans[k], tmpans[k - 1]) = (tmpans[k - 1], tmpans[k])
								(tmps[k], tmps[k - 1]) = (tmps[k - 1], tmps[k])
							else:
								W('NO')
								return
						break
		W('YES\n')
		W(''.join(ans))

def main():
	s = Solve()
main()


(n, ar, x, y, d) = (int(input()), input(), 'a', 'a', '')
for i in ar:
	if i >= x:
		d += '0'
		x = i
	elif i >= y:
		d += '1'
		y = i
	else:
		print('NO')
		exit()
print('YES' + '\n' + d)


from math import *
n = int(input())
s = input()
a = {}
for i in range(n):
	a[i] = []
for i in range(len(s)):
	for j in range(i):
		if s[i] < s[j]:
			a[i].append(j)
c1 = []
c2 = []
for i in range(n):
	if len(a[i]) > 0:
		for j in a[i]:
			if j in c1:
				c2.append(i)
			elif j in c2:
				c1.append(i)
	elif i not in c1 and i not in c2:
		c1.append(i)
s1 = set(c1)
c1 = list(s1)
s2 = set(c2)
c2 = list(s2)
cn = []
for i in range(n):
	cn.append(i)
sn = s1 | s2
c_union = list(sn)
c_union.sort()
ans = ''
if c_union == cn and len(s1 & s2) == 0:
	for i in range(n):
		if i in c1:
			ans += '0'
		else:
			ans += '1'
	print('YES')
	print(ans)
else:
	print('NO')


n = int(input())
s = input()
dp = [0 for i in range(30)]
ans = [1 for i in range(n)]
for i in range(n):
	tmp = ord(s[i]) - ord('a')
	for j in range(tmp + 1, 26):
		ans[i] = max(ans[i], dp[j] + 1)
	dp[tmp] = ans[i]
if max(ans) <= 2:
	print('YES')
	for i in ans:
		print(i - 1, end='')
else:
	print('NO')


import math, sys, os
from io import BytesIO, IOBase
mod = 10 ** 9 + 7
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def minp():
	return map(int, sys.stdin.readline().rstrip().split())

def linp():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def inp():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
n = inp()
s = input()
(a, b) = ('a', 'a')
res = ''
for i in range(n):
	if s[i] >= a:
		res += '0'
		a = s[i]
	elif s[i] >= b:
		res += '1'
		b = s[i]
	else:
		print('NO')
		exit(0)
print('YES')
print(res)


import sys
n = int(sys.stdin.readline().rstrip())
s = list(sys.stdin.readline().rstrip())
a1 = 'a'
a2 = 'a'
sol = ''
for i in s:
	if i >= a1:
		a1 = i
		sol += '0'
	elif i >= a2:
		a2 = i
		sol += '1'
	else:
		print('NO')
		break
else:
	print('YES')
	print(sol)


def dfs(no, par=-1, c=0):
	nonlocal adj, vis, col, st
	col[no] = c
	for i in adj[no]:
		if vis[i] == 1:
			if col[i] == col[no]:
				st = 0
				continue
			else:
				continue
		vis[i] = 1
		dfs(i, no, 1 - c)
n = int(input())
s = list(input())
s = [ord(i) - 97 for i in s]
if sorted(s) == s:
	print('YES')
	print('0' * n)
else:
	st = 1
	adj = [[] for i in range(n)]
	for i in range(n):
		for j in range(i):
			if s[i] < s[j]:
				adj[i].append(j)
				adj[j].append(i)
	col = [-1 for i in range(n)]
	vis = [0 for i in range(n)]
	st = 1
	for i in range(n):
		if vis[i] == 0:
			vis[i] = 1
			dfs(i)
	if st:
		col = [str(i) for i in col]
		print('YES')
		print(''.join(col))
	else:
		print('NO')


def string(n, s):
	res = ''
	j = k = 'a'
	for i in range(n):
		if s[i] >= j:
			res += '0'
			j = s[i]
		elif s[i] >= k:
			res += '1'
			k = s[i]
		else:
			return 'NO'
	return ['YES', res]
n = int(input())
s = input()
if string(n, s) == 'NO':
	print('NO')
else:
	print(*string(n, s), sep='\n')


n = int(input())
s = str(input())
tre = [[] for i in range(n)]
clr = [-1 for i in range(n)]
for i in range(n):
	for j in range(0, i):
		if s[j] > s[i]:
			tre[i].append(j)
	for j in range(i + 1, n):
		if s[j] < s[i]:
			tre[i].append(j)
t = True
for i in range(n):
	if clr[i] != -1:
		continue
	s = [i]
	clr[i] = 0
	while s and t:
		x = s.pop()
		i = clr[x]
		for j in tre[x]:
			if clr[j] == -1:
				clr[j] = i ^ 1
				s.append(j)
			elif clr[j] == i:
				t = False
				break
if t:
	print('YES')
	print(''.join([str(i) for i in clr]))
else:
	print('NO')


import math
n = int(input())
s = input()
l = [-1 for i in range(n)]
possible = True
for i in range(n):
	if l[i] == -1:
		l[i] = 0
	for j in range(i + 1, n):
		if s[j] < s[i]:
			if l[j] == -1:
				l[j] = 1 - l[i]
			elif l[j] != -1 and l[j] + l[i] != 1:
				possible = False
				break
	if possible == False:
		break
if possible:
	print('YES')
	for el in l:
		print(el, end='')
else:
	print('NO')


n = int(input())
s = input()
r = ''
f = 'a'
se = 'a'
bool = True
for i in range(n):
	if s[i] >= f:
		r = r + '0'
		f = s[i]
	elif s[i] >= se:
		r = r + '1'
		se = s[i]
	else:
		bool = False
		print('NO')
		break
if bool:
	print('YES')
	print(r)


n = int(input())
s = input()
l = [s[0]]
ll = []
ss = '0'
for i in range(1, n):
	if l[-1] <= s[i]:
		l.append(s[i])
		ss += '0'
	elif len(ll) == 0 or ll[-1] <= s[i]:
		ll.append(s[i])
		ss += '1'
	else:
		ss = 'NO'
		break
if ss == 'NO':
	print(ss)
else:
	print('YES')
	print(ss)


n = int(input())
s = input()
ans = '0'
pre = s[0]
aft = -1
for i in range(1, n):
	if s[i] >= pre:
		ans += '0'
		pre = s[i]
	else:
		ans += '1'
		if aft != -1:
			if aft > s[i]:
				print('NO')
				exit(0)
		aft = s[i]
print('YES')
print(ans)


n = int(input())
s = input()
ans = [-1] * n
f = True
for i in range(n):
	if ans[i] == -1:
		ans[i] = 0
	for j in range(i + 1, n):
		if s[j] < s[i]:
			if ans[j] == -1:
				ans[j] = (ans[i] - 1) ** 2
			else:
				now = ans[j]
				new = (ans[i] - 1) ** 2
				if new != now:
					f = False
				else:
					ans[j] = new
if not f:
	print('NO')
else:
	print('YES')
	for i in range(n):
		print(ans[i], end='')


n = int(input())
s = input()
ans = [0] * n
f = 0
for i in range(n):
	for j in range(i + 1, n):
		if s[j] < s[i]:
			if ans[j] == 1 and ans[i] == 0:
				continue
			if ans[j] == 1 and ans[i] == 1:
				f = -1
				break
			ans[j] = 1 - ans[i]
	if f == -1:
		break
if f == -1:
	print('NO')
else:
	print('YES')
	for i in ans:
		print(i, end='')


import sys
n = int(input())
s = input()
if n == 1:
	print('YES')
	print(0)
	sys.exit()
(s1, s2) = ([0], [])
for i in range(1, n):
	if s[i] >= s[s1[-1]]:
		s1.append(i)
	elif not s2 or s[i] >= s[s2[-1]]:
		s2.append(i)
	else:
		print('NO')
		sys.exit()
print('YES')
ans = ['0'] * n
for i in s2:
	ans[i] = '1'
print(''.join(ans))


t = 1
while t != 0:
	t -= 1
	n = int(input())
	s = input()
	(l1, l2) = ('a', 'a')
	ans = ''
	for i in range(n):
		if s[i] >= l1:
			l1 = s[i]
			ans += '0'
		elif s[i] >= l2:
			l2 = s[i]
			ans += '1'
		else:
			ans = 'NO'
			break
	if ans == 'NO':
		print(ans)
	else:
		print('YES')
		print(ans)


alp = 'abcdefghijklmnopqrstuvwxyz'
dic = {}
for (i, s) in enumerate(alp):
	dic[s] = i
lis = [-1] * 27
n = int(input())
S = input()
ans = []
for (i, s) in enumerate(S):
	ind = dic[s]
	ans.append(max(lis[ind + 1:]) + 1)
	lis[ind] = ans[-1]
if max(ans) <= 1:
	print('YES')
	print(''.join(map(str, ans)))
else:
	print('NO')


n = int(input())
s = input()
ar = [-1] * n
b = True
for i in range(n - 1):
	if ar[i] == -1:
		ar[i] = 0
	for j in range(i + 1, n):
		if s[i] > s[j]:
			if ar[j] == -1 and ar[i] == 0:
				ar[j] = 1
			elif ar[j] == -1 and ar[i] == 1:
				ar[j] = 0
			elif ar[j] != -1:
				if ar[j] == ar[i]:
					b = False
					break
	if b == False:
		break
if ar[n - 1] == -1:
	ar[n - 1] = 0
if b == False:
	print('NO')
else:
	print('YES')
	for j in ar:
		print(j, end='')
	print()


n = int(input())
s = input()
f = [0 for _ in range(26)]
res = [1 for _ in range(n)]
for i in range(n):
	c = ord(s[i]) - ord('a')
	for j in range(c + 1, 26):
		res[i] = max(res[i], f[j] + 1)
	f[c] = max(f[c], res[i])
maxres = max(res)
if maxres <= 2:
	print('YES')
	for i in res:
		print(i - 1, end='')
else:
	print('NO')


n = int(input())
a = input()
ref = {chr(i + 97): [] for i in range(26)}
vis = [0] * n
high = a[0]
for i in range(1, n):
	if a[i] >= high:
		high = a[i]
		continue
	ref[a[i]].append(i)
flag = 0
mi = -1
for i in ref.keys():
	for j in ref[i]:
		if mi < j:
			mi = j
			vis[j] = 1
			continue
		flag = 1
if flag == 1:
	print('NO')
else:
	print('YES')
	for i in vis:
		print(i, end='')
	print()


from sys import stdin, stdout

def main():
	n = int(stdin.readline())
	s = stdin.readline().rstrip()
	h1 = 'A'
	h2 = 'B'
	res = []
	for (i, x) in enumerate(s):
		if i == 0:
			res.append('0')
			h1 = s[i]
			continue
		if s[i] < h2:
			stdout.write('NO')
			return
		if s[i] >= h1:
			h1 = s[i]
			res.append('0')
			continue
		elif s[i] >= h2 and s[i] < h1:
			h2 = s[i]
			res.append('1')
			continue
		res.append('1')
	stdout.write('YES\n' + ''.join(res))
main()


class Node:
	idx = None
	letter = None
	color = False

	def __init__(self, idx, letter):
		assert idx >= 0 and letter
		self.dependencies = []
		self.dependents = []
		self.idx = idx
		self.letter = letter

	def __repr__(self):
		return f'Node<{(self.idx, self.letter)}>'

	def add_dependency(self, node):
		assert type(node) is Node
		self.dependencies.append(node)
		node.dependents.append(self)
input()
string = input()
nodes = [Node(*x) for x in enumerate(string)]

def check_dep_depth(node, max_depth=1):
	if max_depth < 0:
		return False
	for n in node.dependencies:
		n.color = not node.color
		if not check_dep_depth(n, max_depth - 1):
			return False
	return True
for (idx, n1) in enumerate(nodes):
	if idx == len(nodes) - 1:
		continue
	for n2 in nodes[idx + 1:]:
		if n2.letter < n1.letter:
			n1.add_dependency(n2)
for n in nodes:
	if not check_dep_depth(n, 1):
		print('NO')
		exit()
print('YES')
print(''.join((str(int(n.color)) for n in nodes)))


from sys import stdin
input = stdin.readline
for xoxo in range(1):
	n = int(input())
	s = input()
	a = []
	b = []
	c = [0] * 26
	d = []
	for i in range(26):
		a.append([])
		b.append([])
		d.append([])
	for i in range(n):
		c[ord(s[i]) - 97] += 1
	for i in range(n):
		kk = 0
		for j in range(ord(s[i]) - 97):
			kk += c[j]
		a[ord(s[i]) - 97].append(i + kk)
		d[ord(s[i]) - 97].append(i)
		c[ord(s[i]) - 97] -= 1
	s2 = sorted(s)
	s1 = ''
	for i in range(1, n + 1):
		s1 += s2[i]
	for i in range(n):
		b[ord(s1[i]) - 97].append(i)
	ans = [-1] * n
	flag = 0
	for i in range(26):
		if flag == 1:
			break
		for j in range(len(a[i])):
			if flag == 1:
				break
			if b[i][j] >= a[i][j]:
				continue
			else:
				if ans[d[i][j]] != 0:
					ans[d[i][j]] = 1
				else:
					flag = 1
					break
				p = ans[d[i][j]]
				for k in range(d[i][j] - 1, d[i][j] - 1 - (a[i][j] - b[i][j]), -1):
					if i >= ord(s[k]) - 97:
						continue
					else:
						if ans[k] == -1:
							ans[k] = (p + 1) % 2
						if ans[k] == p:
							flag = 1
							break
	if flag == 1:
		print('NO')
	else:
		print('YES')
		for i in range(n):
			if ans[i] == -1:
				ans[i] = 0
			print(ans[i], end='')


n = int(input())
f = input()
t = ''
a = 'a'
b = 'a'
h = 0
for j in f:
	if ord(a[-1]) <= ord(j):
		a += j
		t += '0'
	elif ord(b[-1]) <= ord(j):
		b += j
		t += '1'
	else:
		print('NO')
		h += 1
		break
if h == 0:
	print('YES')
	print(t)


import sys
from math import *
input = sys.stdin.readline

def bo(v):
	return ord(v) - ord('a')
n = int(input())
a = list(input().rstrip())
p = list(sorted(a))
dp = [[-9, 0] for i in range(27)]
for i in range(n):
	if dp[bo(p[i])][0] == -9:
		dp[bo(p[i])][0] = i
	dp[bo(p[i])][1] += 1
s = [0 for i in range(n)]
prev = 0
flag = 0
for j in range(n):
	for i in range(n):
		if dp[bo(a[i])][0] < i:
			if prev > dp[bo(a[i])][0]:
				flag = 1
				break
			s[i] = 1
			prev = dp[bo(a[i])][0]
			z = a[i]
			a.pop(i)
			a.insert(dp[bo(z)][0], z)
			dp[bo(z)][0] += 1
		else:
			dp[bo(a[i])][0] += 1
if flag == 0 and a == p:
	print('YES')
	for i in range(n):
		print(s[i], end='')
	print()
else:
	print('NO')


def colorable(s):
	mn1 = 'a'
	mn2 = 'a'
	res = ''
	for c in s:
		if c >= mn1:
			res += '0'
			mn1 = c
		elif c >= mn2:
			res += '1'
			mn2 = c
		else:
			return (False, res)
	return (True, res)
n = input()
s = input()
(valid, res) = colorable(s)
if valid:
	print('YES')
	print(res)
else:
	print('NO')


import sys
import math
from collections import defaultdict, Counter, deque

def add(a, b):
	l[a].append(b)
	l[b].append(a)
n = int(input())
s = list(input())
l = defaultdict(list)
for i in range(n - 1):
	for j in range(i + 1, n):
		if s[j] < s[i]:
			add(i, j)
colour = [-1] * n
for i in range(n):
	if colour[i] == -1:
		flag = 0
		q = deque()
		q.append(i)
		colour[i] = 0
		while q:
			s1 = q.popleft()
			for j in l[s1]:
				if colour[j] == -1:
					colour[j] = 1 - colour[s1]
					q.append(j)
				elif colour[j] == colour[s1]:
					flag = 1
					break
			if flag == 1:
				break
	if flag == 1:
		break
if flag == 1:
	print('NO')
else:
	print('YES')
	print(''.join(list(map(str, colour))))


l = [0] * 26
n = int(input())
pres = [0] * 26
s = input()
res = [0] * n
ii = -1
for i in s:
	ii += 1
	ind = ord(i) - ord('a')
	lol = 0
	for j in range(ind + 1, 26):
		if pres[j] != 0:
			lol = 1
			if l[j] == 1:
				lol = 2
				break
	if lol == 2:
		break
	pres[ind] = 1
	if lol == 1:
		l[ind] = 1
		res[ii] = 1
if lol == 2:
	print('NO')
else:
	print('YES')
	print(*res, sep='')


from collections import deque
import sys
input = sys.stdin.readline

def bfs(r):
	q = deque()
	q.append(r)
	ok = 1
	while q:
		i = q.popleft()
		di = dist[i]
		for j in G[i]:
			if dist[j] == -1:
				dist[j] = di + 1
				q.append(j)
			elif dist[j] % 2 == di % 2:
				ok = 0
		if not ok:
			break
	return ok
n = int(input())
s = list(input().rstrip())
t = [ord(i) - 97 for i in s]
G = [[] for _ in range(n)]
for i in range(n):
	for j in range(i + 1, n):
		if t[i] > t[j]:
			G[i].append(j)
			G[j].append(i)
dist = [-1] * n
ok = 1
for i in range(n):
	if dist[i] == -1:
		dist[i] = 0
		ok &= bfs(i)
ans = 'YES' if ok else 'NO'
print(ans)
if ok:
	ans = [i % 2 for i in dist]
	print(''.join(map(str, ans)))


def line():
	return map(int, input().split())

def num():
	return int(input())
from itertools import tee

def pairwise(it):
	(a, b) = tee(it)
	next(b, None)
	return zip(a, b)
n = num()
s = input()
q = sorted(((i, j) for (j, (c, i)) in enumerate(sorted(((c, i) for (i, c) in enumerate(s))))))
w = [q[0]]
e = []
for (i, j) in q[1:]:
	if j > w[-1][1]:
		w.append((i, j))
	else:
		e.append((i, j))
if all((j1 < j2 for ((i1, j1), (i2, j2)) in pairwise(e))):
	print('YES')
	(kw, ke) = (0, 0)
	ans = []
	while kw < len(w) or ke < len(e):
		if kw < len(w) and ke < len(e):
			if w[kw][0] < e[ke][0]:
				ans.append('0')
				kw += 1
			else:
				ans.append('1')
				ke += 1
		elif kw < len(w):
			ans.append('0')
			kw += 1
		else:
			ans.append('1')
			ke += 1
	print(''.join(ans))
else:
	print('NO')


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	a = input().rstrip()
	b = [[] for _ in range(26)]
	for i in range(n):
		for j in range(26):
			if b[j] == []:
				b[j].append(i)
				break
			elif a[b[j][-1]] <= a[i]:
				b[j].append(i)
				break
	c = 0
	ans = [0] * n
	for i in b:
		if i == []:
			break
		c += 1
		for j in i:
			ans[j] = c
	if c < 3:
		print('YES')
		print(''.join(map(lambda x: '0' if x == 1 else '1', ans)))
	else:
		print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
s = str(input())
p1 = []
p2 = []
ans = []
flag = False
for elem in s:
	if len(p1) == 0:
		p1.append(elem)
		ans.append(0)
	elif ord(p1[-1]) <= ord(elem):
		p1.append(elem)
		ans.append(0)
	elif len(p2) == 0:
		p2.append(elem)
		ans.append(1)
	elif ord(p2[-1]) <= ord(elem):
		p2.append(elem)
		ans.append(1)
	else:
		flag = True
if flag:
	print('NO')
else:
	print('YES')
	print(''.join(map(str, ans)))


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7

def bisearch_min(mn, mx, func):
	ok = mx
	ng = mn
	while ng + 1 < ok:
		mid = (ok + ng) // 2
		if func(mid):
			ok = mid
		else:
			ng = mid
	return ok

def check(m):
	if m == len(B):
		return True
	if B[m][-1][0] <= a:
		return True
	else:
		return False
N = INT()
A = [ord(c) - 97 for c in input()]
B = [[] for i in range(1)]
B[0].append((A[0], 0))
for (i, a) in enumerate(A[1:], 1):
	idx = bisearch_min(-1, len(B), check)
	if idx == len(B):
		B.append([(a, i)])
	else:
		B[idx].append((a, i))
ans = [0] * N
for (a, li) in enumerate(B):
	for (_, idx) in li:
		ans[idx] = str(a)
if len(B) <= 2:
	YES()
	print(''.join(ans))
else:
	NO()


from math import *
n = int(input())
s = input()
pre = '0'
prev = s[0]
lst = -1
for i in range(1, n):
	if s[i] >= prev:
		prev = s[i]
		pre += '0'
	else:
		pre += '1'
		if lst != -1:
			if s[i] < lst:
				print('NO')
				return
		lst = s[i]
print('YES')
print(pre)


def solution():
	n = int(input())
	s = list(input())
	(s1, s2) = (['a'], ['a'])
	ans = []
	for i in range(n):
		if s[i] >= s1[-1]:
			s1.append(s[i])
			ans.append('0')
		elif s[i] >= s2[-1]:
			s2.append(s[i])
			ans.append('1')
		else:
			print('NO')
			return
	print('YES')
	print(''.join(ans))
	return
solution()


N = int(input())
s = input()
C = [0] * N
Sf = [0]
risultato = True
for n in range(1, N):
	if s[n] >= s[Sf[-1]]:
		Sf.append(n)
	else:
		C[n] = 1
		u = Sf[-1]
		Sf[-1] = n
		Sf.append(u)
		i = 3
		while n >= 2 and i <= len(Sf) and (s[n] < s[Sf[-i]]):
			if C[n] == C[Sf[-i]]:
				risultato = False
				break
			else:
				i = i + 1
		if risultato == False:
			break
if risultato:
	print('YES')
	r = ''
	for c in C:
		r = r + str(c)
	print(r)
else:
	print('NO')


n = int(input())
s = input()
last0 = last1 = 'a'
ans = ''
for i in range(n):
	if s[i] >= last0:
		ans += '0'
		last0 = s[i]
	elif s[i] >= last1:
		ans += '1'
		last1 = s[i]
	else:
		print('NO')
		break
if len(ans) == n:
	print('YES')
	print(ans)


import sys
import bisect
import math as mt
input = sys.stdin.readline
t = 1
mod = 10 ** 9 + 7
for _ in range(t):
	n = int(input())
	s = input()
	l = []
	for i in range(n):
		l.append([ord(s[i]) - ord('a'), i])
	l.sort()
	ans = [-1] * n
	ch = 1
	d = {}
	for i in range(n + 2):
		d[i] = []
	prev = n
	for i in range(n):
		if i > l[i][1]:
			for j in range(i, l[i][1] - 1, -1):
				if l[i][0] > ord(s[j]) - ord('a'):
					d[l[i][1]].append(j)
					d[j].append(l[i][1])
		else:
			for j in range(i, l[i][1]):
				if l[i][0] < ord(s[j]) - ord('a'):
					d[l[i][1]].append(j)
					d[j].append(l[i][1])
	for i in range(n):
		for j in range(len(d[i])):
			if ans[d[i][j]] != -1:
				if ans[i] == -1:
					ans[i] = ans[d[i][j]] ^ 1
				elif ans[d[i][j]] ^ 1 != ans[i]:
					ch = 0
					break
		if ans[i] == -1:
			ans[i] = 0
	if ch == 0:
		print('NO')
	else:
		print('YES')
		print(*ans, sep='')


import re
from io import BytesIO, IOBase
import sys
import math
import os
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def main():
	n = int(input())
	s = [ord(i) & 31 for i in input()]
	sorted_s = sorted(s)
	target = [[sorted_s[i], 0] for i in range(n)]
	ans = []
	ansans = ''
	for i in range(n):
		for j in range(n):
			if target[j][0] == s[i] and target[j][1] == 0:
				target[j][1] = 1
				if j < i:
					ansans += '1'
				else:
					ansans += '0'
				ans += [j]
				break
	a = [ans[i] - i for i in range(n)]
	while 1:
		f = 0
		for i in range(n - 1):
			if a[i] > 0 and a[i + 1] < 0:
				(a[i], a[i + 1]) = (a[i + 1] + 1, a[i] - 1)
				f = 1
		if not f:
			break
	if any(a):
		print('NO')
	else:
		print('YES')
		print(ansans)
main()


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = Int()
s = list(input())
s = [(s[i], i) for i in range(n)]
color = [-1] * n
ok = True
for i in range(n):
	ind = i
	if color[s[ind][1]] == -1:
		color[s[ind][1]] = 0
	for j in range(i + 1, n):
		if s[j][0] < s[ind][0]:
			ind = j
	if color[s[ind][1]] == -1:
		color[s[ind][1]] = 1
	for j in range(ind, i, -1):
		c1 = color[s[j][1]]
		c2 = color[s[j - 1][1]]
		if c2 == -1:
			color[s[j - 1][1]] = c1 ^ 1
			c2 = c1 ^ 1
		if c1 == c2:
			ok = False
		(s[j], s[j - 1]) = (s[j - 1], s[j])
if ok:
	print('YES')
	print(*color, sep='')
else:
	print('NO')


n = int(input())
string = input()
l = []
a1 = 'a'
b1 = 'a'
t = 0
for i in range(n):
	if string[i] >= a1:
		l.append(0)
		a1 = string[i]
	elif string[i] >= b1:
		l.append(1)
		b1 = string[i]
	else:
		t = 1
		break
if t == 1:
	print('NO')
else:
	print('YES')
	for i in range(n):
		print(l[i], end='')


from collections import defaultdict, Counter, deque
from math import sqrt, log10, log, floor, factorial, gcd
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations
from heapq import heapify, heappop, heappush
import sys, io, os
input = sys.stdin.readline
inf = float('inf')
mod = 10 ** 9 + 7

def get_list():
	return [int(i) for i in input().split()]

def yn(a):
	print('YES' if a else 'NO')
ceil = lambda a, b: (a + b - 1) // b

def check():
	for i in range(n):
		for j in range(i + 1, n):
			for k in range(j + 1, n):
				if s[i] > s[j] > s[k]:
					return 0
	return 1
t = 1
for i in range(t):
	n = int(input())
	s = list(input().strip())
	if not check():
		yn(0)
		continue
	curr_max = s[0]
	arr = [0 for i in s]
	for i in range(1, n):
		if s[i] > curr_max:
			curr_max = s[i]
		elif s[i] < curr_max:
			arr[i] = 1
	yn(1)
	print(''.join([str(i) for i in arr]))


def opp(c):
	if c == '0':
		return '1'
	return '0'
n = int(input())
s = input()
temp = 0
col = ['-1'] * n
for i in range(0, len(s)):
	if col[i] == '-1':
		col[i] = '0'
	c = col[i]
	for j in range(i + 1, len(s)):
		if ord(s[j]) < ord(s[i]):
			t = opp(c)
			if col[j] == '-1':
				col[j] = t
			elif col[j] != t:
				temp = 1
				break
	if temp == 1:
		break
if temp == 1:
	print('NO')
else:
	print('YES')
	col = ''.join(col)
	print(col)


n = int(input())
l = list(input())
k = [0 for i in range(n)]
z = [0 for i in range(n)]
x = sorted(l)
r = ''
for t in x:
	r += t
for t in range(1, n):
	if l[t] < l[t - 1]:
		k[t] = k[t - 1] ^ 1
		z[t] = k[t]
		i = t
		while i > 0 and l[i] < l[i - 1]:
			if k[i] == k[i - 1]:
				break
			(l[i], l[i - 1]) = (l[i - 1], l[i])
			(k[i], k[i - 1]) = (k[i - 1], k[i])
			i -= 1
s = ''
for t in l:
	s += t
if s == r:
	print('YES')
	print(*z, sep='')
else:
	print('NO')


n = int(input())
s = input()
a = []
for i in range(n):
	a.append(ord(s[i]))
visit = [0 for i in range(n)]
(i, flag) = (1, 0)
rama = [0 for i in range(n)]
while i < n:
	if a[i] < a[i - 1]:
		visit[i] = 1
		rama[i] = visit[i]
	temp = a[i]
	tempu = visit[i]
	j = i
	while j > 0:
		if temp < a[j - 1]:
			if tempu != visit[j - 1]:
				a[j] = a[j - 1]
				visit[j] = visit[j - 1]
			else:
				flag = -1
				break
		else:
			break
		j -= 1
	if flag == -1:
		break
	visit[j] = tempu
	a[j] = temp
	i += 1
if flag == -1:
	print('NO')
else:
	print('YES')
	for i in rama:
		print(i, end='')


n = int(input())
ok = True
string = input()
seq1 = 'a'
seq2 = 'a'
ans = '0'
for i in string:
	if i >= seq1:
		seq1 = i
		ans += '0'
		continue
	if i >= seq2:
		seq2 = i
		ans += '1'
	else:
		ok = False
if ok == True:
	print('YES')
	print(ans[1:])
else:
	print('NO')


import sys
input = sys.stdin.readline
n = int(input())
s = list(input())[:-1]
perm = [i for i in range(n)]
res = [0] * n
decided = [0] * n
decided[0] = 1
for _ in range(n):
	for i in range(n - 1):
		if s[perm[i]] > s[perm[i + 1]] and (decided[perm[i + 1]] == 0 or res[perm[i + 1]] != res[perm[i]]):
			res[perm[i + 1]] = res[perm[i]] ^ 1
			decided[perm[i + 1]] = 1
			(perm[i], perm[i + 1]) = (perm[i + 1], perm[i])
for i in range(n - 1):
	if s[perm[i]] > s[perm[i + 1]]:
		print('NO')
		exit(0)
print('YES')
print(''.join(list(map(str, res))))


N = int(input())
s = input()
A = []
for i in range(N):
	A.append((s[i], i))
A.sort()
B = [0] * N
C = [i for i in range(N)]
for i in range(N):
	(_, j) = A[i]
	B[i] = j
adj = [[] for _ in range(N)]
for i in range(N):
	x = B[i]
	j = C.index(x)
	while i < j:
		y = C[j - 1]
		adj[x].append(y)
		adj[y].append(x)
		(C[j], C[j - 1]) = (C[j - 1], C[j])
		j -= 1
vst = [-1] * N
succ = True
for i in range(N):
	if vst[i] < 0:
		vst[i] = 0
	for j in adj[i]:
		if vst[j] < 0:
			vst[j] = 1 - vst[i]
		elif vst[j] + vst[i] != 1:
			succ = False
if succ:
	print('YES')
	print(''.join(map(str, vst)))
else:
	print('NO')


def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def solve():
	n = ri()
	s = input().strip()
	out = [-1] * n
	for i in range(n):
		if out[i] == -1:
			out[i] = 0
		for j in range(i + 1, n):
			if s[j] < s[i]:
				if out[i] == out[j]:
					print('NO')
					return
				elif out[j] == -1:
					out[j] = 1 - out[i]
	print('YES')
	print(''.join(map(str, out)))
solve()


import sys
from _collections import deque
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = input()
a0 = deque(a[0])
a1 = deque()
for i in a[1:]:
	if ord(i) >= ord(a0[-1]):
		a0.append(i)
	else:
		a1.append(i)
if a1 == deque(sorted(a1)):
	print('YES')
	for i in a:
		if a0 and a0[0] == i:
			print(0, end='')
			a0.popleft()
		else:
			print(1, end='')
			a1.popleft()
	print()
else:
	print('NO')


n = int(input())
s = str(input())
a = '0'
b = '0'
rz = ''
pr = 1
for i in range(n):
	if s[i] >= a:
		rz += '0'
		a = s[i]
	elif s[i] >= b:
		rz += '1'
		b = s[i]
	else:
		pr = 0
		print('NO')
		break
if pr:
	print('YES')
	print(rz)


n = int(input())
s = input()
d = ''
flag = False
x = y = 'a'
for i in s:
	if i >= x:
		d += '0'
		x = i
	elif i >= y:
		d += '1'
		y = i
	else:
		print('NO')
		flag = True
		break
if not flag:
	print('YES')
	print(d)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
string1 = [ord(k) for k in input()]
colour = [2 for k in range(n)]
can = True
for j in range(n - 1):
	if can == False:
		break
	else:
		for k in range(j + 1, n):
			if string1[j] > string1[k]:
				if colour[k] == 2:
					colour[k] = 1
				elif colour[j] == colour[k]:
					can = False
					break
if can == True:
	print('YES')
	for s in range(len(colour)):
		if colour[s] == 2:
			colour[s] = 0
	outie = [str(v) for v in colour]
	print(''.join(outie))
elif can == False:
	print('NO')


def main():
	n = int(input())
	s = input()
	arr = list(s)
	arr.sort()
	s2 = ''.join(arr)

	def swap(i, j):
		temp = arr[i]
		arr[i] = arr[j]
		arr[j] = temp
	arr = []
	for (i, char) in enumerate(s):
		arr.append([char, -1, i])
	i = 0
	ok = True
	color = []
	while i < n and ok:
		c1 = arr[i][1]
		if c1 == -1:
			c1 = 0
		c2 = 1 ^ c1
		for j in range(i, n):
			if s2[i] == arr[j][0]:
				break
		if i == j:
			arr[i][1] = 0
			i += 1
			continue
		for k in range(i, j):
			if arr[k][1] == c2:
				ok = False
				break
			arr[k][1] = c1
		if arr[j][1] == c1:
			ok = False
		arr[j][1] = c2
		for k in range(j, i, -1):
			swap(k, k - 1)
		i += 1
	if ok:
		print('YES')
		color = [-1 for _ in range(n)]
		for (char, c, i) in arr:
			color[i] = c
		ans = ''.join([str(x) for x in color])
		print(ans)
	else:
		print('NO')
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(*args):
	assert len(args) >= 2, 'makeArr args should be (default value, dimension 1, dimension 2,...'
	if len(args) == 2:
		return [args[0] for _ in range(args[1])]
	else:
		return [makeArr(args[0], *args[2:]) for _ in range(args[1])]

def queryInteractive(x, y):
	print('? {} {}'.format(x, y))
	sys.stdout.flush()
	return int(input())

def answerInteractive(ans):
	print('! {}'.format(ans))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
for _abc in range(1):
	main()


alpha_small_dict = {chr(i): i - 97 for i in range(97, 97 + 26)}
n = int(input())
s = input()
data = [alpha_small_dict[x] for x in s]
G = [[] for _ in range(n)]
alpha_data = [[] for _ in range(26)]
for (i, x) in enumerate(data):
	for y in range(x + 1, 26):
		for j in alpha_data[y]:
			G[i].append(j)
			G[j].append(i)
	alpha_data[x].append(i)
color = [-1 for _ in range(n)]
t = True
for i in range(n):
	if color[i] == -1:
		que = [[-1, i]]
		color[i] = 0
		while que:
			(pre, now) = que.pop()
			for to in G[now]:
				if to == pre:
					continue
				if color[to] == color[now]:
					print('NO')
					exit()
				elif color[to] == -1:
					color[to] = 1 - color[now]
					que.append([now, to])
print('YES')
for x in color:
	print(x, end='')
print()