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
Tags: Graph algorithms

Constructive algorithms

Sorting

Greedy algorithms

Dynamic programming
Skill types: Dynamic programming

Sorting

Greedy algorithms

Starter code:

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)


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')
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

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

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

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
from bisect import bisect_left, insort

def main():
	n = N()
	s = input()
	s = [-ord(i) for i in s]
	rec = [INF] * n
	res = []
	ma = 1
	for i in s:
		p = bisect_left(rec, i)
		res.append(p + 1)
		rec[p] = i
		ma = max(ma, p + 1)
	print(ma)
	print(*res)
main()


import sys
import math
from collections import defaultdict, Counter, deque
n = int(input())
s = list(input())
colour = [1] * n
dp = [0] * 26
for i in range(n):
	for j in range(25, ord(s[i]) - 97, -1):
		colour[i] = max(colour[i], dp[j] + 1)
	dp[ord(s[i]) - 97] = max(dp[ord(s[i]) - 97], colour[i])
print(max(colour))
print(*colour)


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 = [1]
res = 1
r = [x[0]]
for k in x[1:]:
	appended = False
	for cl in range(res):
		if k >= r[cl]:
			c.append(cl + 1)
			r[cl] = k
			appended = True
			break
	if not appended:
		res += 1
		r.append(k)
		c.append(res)
print(res)
print(' '.join([str(k) for k in c]))


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


INF = 10 ** 10

def main():
	n = get_int()
	st = list(input())
	ch = 'z'
	res = [0] * n
	for i in reversed(range(n - 1)):
		if st[i] > st[i + 1]:
			if st[i] > ch:
				print('NO')
				return
			else:
				ch = st[i]
				res[i] = 1
				(st[i + 1], st[i]) = (st[i], st[i + 1])
	print('YES')
	print(''.join(map(str, res)))
import sys
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right
import math
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
main()
print(*out, sep='\n')


n = int(input())
s = input()
l = [-1] * n
flag = True

def check(f, l, i, s):
	for j in range(i - 1, -1, -1):
		if s[i] < s[j]:
			if l[j] == -1:
				l[j] = 1 - f
			elif l[j] == f:
				return False
	return True
for i in range(n - 1, -1, -1):
	if l[i] == 0:
		for j in range(i - 1, -1, -1):
			if s[i] < s[j]:
				if l[j] == -1:
					l[j] = 1
				elif l[j] == 0:
					flag = False
					break
	elif l[i] == 1:
		for j in range(i - 1, -1, -1):
			if s[i] < s[j]:
				if l[j] == -1:
					l[j] = 0
				elif l[j] == 1:
					flag = False
					break
		if flag == False:
			break
	else:
		l[i] = 1
		if check(1, l, i, s):
			l[i] = 1
			continue
		elif check(0, l, i, s):
			l[i] = 0
			continue
		else:
			flag = False
			break
if flag == False:
	print('NO')
else:
	print('YES')
	for i in l:
		print(i, end='')
	print()


from sys import stdin, stdout
t = 1
for _ in range(t):
	n = int(input())
	s = input()
	ans = []
	dict = {}
	count = 0
	for i in s:
		count += 1
		maxi = -1
		taken = set()
		for j in range(97 + 25, 96, -1):
			if chr(j) in dict and chr(j) > i:
				taken.add(dict[chr(j)][1])
		j = 0
		while 1:
			j += 1
			if j not in taken:
				ans.append(j)
				dict[i] = (count, j)
				break
	assert len(set(ans)) <= 26
	print(len(set(ans)))
	print(*ans)


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 sys
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
import math

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def main():
	n = inin()
	s = sin()
	a = [[s[0], 0]]
	b = []
	x = 0
	c = []
	for i in range(1, n):
		if s[i] >= a[-1][0]:
			a.append([s[i], i])
		else:
			for j in range(len(a)):
				if s[i] < a[j][0]:
					c = a[j:]
					a = a[:j]
					a.append([s[i], i])
					b.extend(c)
					break
	for i in range(1, len(a)):
		if a[i - 1][0] > a[i][0]:
			x = 1
			break
	for i in range(1, len(b)):
		if b[i - 1][0] > b[i][0]:
			x = 1
			break
	ans = [1] * n
	for i in a:
		ans[i[1]] = 0
	if x == 1:
		print('NO')
	else:
		print('YES')
		print(*ans, sep='')
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


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


def solve():
	n = int(input())
	s = input()
	color = [1] * n
	prevMaxColor = [0] * 30
	for i in reversed(range(n)):
		c = ord(s[i]) - ord('a')
		for j in range(0, c):
			color[i] = max(color[i], prevMaxColor[j] + 1)
		prevMaxColor[c] = max(color[i], prevMaxColor[c])
	print(max(color))
	for c in color:
		print(c, end=' ')
solve()


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 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())
s = input()
indexes = [[] for i in range(26)]
for i in range(len(s)):
	indexes[ord(s[i]) - 97] += [i]
order = [0] * n
count = 1
for each in indexes:
	incount = False
	for k in each:
		incount = True
		order[k] = count
	if incount:
		count += 1
coloring = [''] * n
opposites = [[] for i in range(n + 1)]
for i in range(n):
	for j in range(i + 1, n):
		if order[i] > order[j]:
			for k in range(i, j):
				opposites[j] += [i]
				opposites[i] += [j]
coloring[0] = '0'

def opp(x):
	return '0' if x == '1' else '1'
poss = True
for i in range(n):
	if not coloring[i]:
		coloring[i] = '0'
	for k in opposites[i]:
		if coloring[k] == '':
			coloring[k] = opp(coloring[i])
		elif coloring[k] != opp(coloring[i]):
			poss = False
			break
if poss:
	print('YES')
	print(''.join(coloring))
else:
	print('NO')


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


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:
			col = 1
		else:
			col = color[c] & -color[c]
	else:
		col = 1
		for j in range(last, c, -1):
			while col & color[j]:
				col <<= 1
	color[c] |= col
	ans[i] = len(bin(col)) - 2
print(max(ans))
print(*ans)


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
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 = [0] * 27
	ans = [0] * n
	a = ord('a')
	for (i, c) in enumerate(s):
		code = ord(c) - a
		cur = max(col[code + 1:]) + 1
		ans[i] = cur
		col[code] = cur
	print(max(col))
	print(*ans)
main()


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
t = 1
for i in range(t):
	n = int(input())
	s = [ord(i) - 97 for i in input().strip()]
	dicta = [0 for i in range(26)]
	ans = [1 for i in s]
	for i in range(n - 1, -1, -1):
		for j in range(s[i]):
			ans[i] = max(ans[i], dicta[j] + 1)
		dicta[s[i]] = ans[i]
	t = max(ans)
	if t <= 2:
		yn(1)
		print(''.join([str(i - 1) for i in ans]))
	else:
		yn(0)


(n, s) = (int(input()), input())
k = {0: 'a', 1: 'a'}
ans = ''
maxColor = 1
for symb in s:
	for i in range(len(k)):
		if symb >= k[i]:
			ans += str(i + 1) + ' '
			if i + 1 > maxColor:
				maxColor = i + 1
				k[i + 1] = 'a'
			k[i] = symb
			break
print(maxColor)
print(ans)


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 char_to_int(c):
	res = ord(c) - ord('a')
	return res

def int_to_char(n):
	n_ord = ord('a') + n
	res = chr(n_ord)
	return res
n = int(input())
s = input()
maxdp = [0] * 26
dp = [1] * n
for i in range(n):
	si = s[i]
	isi = char_to_int(si)
	for c in range(25, isi, -1):
		dp[i] = max(dp[i], maxdp[c] + 1)
	maxdp[isi] = max(maxdp[isi], dp[i])
m = max(maxdp)
print(m)
print(' '.join(map(str, dp)))


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


def main():
	n = int(input())
	ss = list(zip(input(), range(0, n)))
	res = [1] * n
	max_colour = 1
	nextx = [0] * 26
	colours_after = [[True] + [False] * 26 for _ in range(26)]
	for i in range(n):
		ch = ord(ss[i][0]) - ord('a')
		opos = ss[i][1]
		nx = nextx[ch]
		col = colours_after[ch].index(False)
		if col > max_colour:
			max_colour = col
		res[opos] = col
		for c in range(ch):
			colours_after[c][col] = True
		for c in range(ch, 26):
			nextx[c] = min(nextx[c], nx + 1)
	print(max_colour)
	print(' '.join(map(str, res)))
main()


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


import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)
input = sys.stdin.readline

def ceil(n, k):
	return n // k + (n % k != 0)

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

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

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
n = ii()
s = input()
flag = 0
res = [0 for i in range(n)]
for i in range(n):
	for j in range(i + 1, n):
		if s[i] > s[j]:
			res[j] = 1
			for k in range(j + 1, n):
				if s[j] > s[k]:
					flag = 1
					break
if flag == 1:
	print('No')
else:
	print('YES')
	prr(res, '')


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 bisect import *
input()
(l, a) = ([], '')
for c in [-ord(i) for i in input()]:
	i = bisect_left(l, c)
	a += str(i)
	if i < len(l):
		l[i] = c
	else:
		l += (c,)
if len(l) < 3:
	print('Yes')
	print(a)
else:
	print('No')


n = int(input())
s = input()
zero = False
one = False
mx = s[n - 1]
zero = True
final = ['0']
o = ''
z = s[n - 1]
ans = 1
for i in range(n - 2, -1, -1):
	if s[i] <= z:
		z = s[i]
		final.append('0')
	elif s[i] > z:
		if o == '':
			o = s[i]
			final.append('1')
		elif s[i] > o:
			ans = -1
			break
		else:
			o = s[i]
			final.append('1')
if ans == -1:
	print('NO')
else:
	print('YES')
	print(''.join(final[::-1]))


def main():
	n = int(input().strip())
	s = input().strip()
	result = []
	(a, b) = ('', '')
	for c in s:
		if c >= a:
			a = c
			result.append('1')
		elif c >= b:
			b = c
			result.append('0')
		else:
			print('NO')
			return
	print('YES')
	print(''.join(result))
main()


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


from sys import stdin, stdout
for _ in range(1):
	n = int(stdin.readline())
	s = input()
	ans = 0
	dp = [-1] * n
	dp[n - 1] = 0
	flag = 1
	for i in range(n - 2, -1, -1):
		for j in range(n - 1, i, -1):
			if s[i] > s[j]:
				if dp[i] == -1:
					dp[i] = 1 - dp[j]
				elif dp[i] == dp[j]:
					flag = 0
					break
		if dp[i] == -1:
			dp[i] = 0
	if flag == 0:
		print('NO')
	else:
		print('YES')
		for v in dp:
			if v == -1:
				stdout.write(str(0))
			else:
				stdout.write(str(v))
		print()


n = int(input())
A = list(str(input()))
A = [ord(c) - ord('a') for c in A]
B = [10 ** 18]
ans = [-1] * n
import bisect
for i in reversed(range(n)):
	a = A[i]
	j = bisect.bisect_left(B, a)
	ans[i] = j + 1
	if 0 <= j < len(B):
		B[j] = a
	else:
		B.append(a)
print(len(B))
print(*ans)


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()
ans = [-1] * n
for i in range(n - 1, -1, -1):
	c = d = 0
	for j in range(i - 1, -1, -1):
		if s[j] > s[i] and ans[j] == 0:
			c += 1
		if s[j] > s[i] and ans[j] == 1:
			d += 1
	if c > 0 and d > 0 or (ans[i] == 1 and d > 0) or (ans[i] == 0 and c > 0):
		print('NO')
		exit()
	if ans[i] == -1:
		ans[i] = 0
	for j in range(i - 1, -1, -1):
		if s[j] > s[i]:
			ans[j] = ans[i] ^ 1
print('YES')
print(*ans, sep='')


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


def r(t=int):
	return list(map(t, input().split()))

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

def cd(it):
	ret_val = dict()
	for v in it:
		ret_val[v] = ret_val.get(v, 0) + 1
	return ret_val
n = ri()
ans = [0] * n
alphabet = 'abcdefghijklmnopqrstuvwxyz'
a = [alphabet.index(ai) for ai in input()]
pa = []
for (i, ai) in enumerate(a):
	m = 100
	for (h, p) in enumerate(pa):
		p1 = ai - p
		if p <= ai and p1 < m:
			f = h + 1
			m = p1
	if m == 100:
		pa.append(ai)
		f = len(pa)
	ans[i] = f
	pa[f - 1] = ai
print(len(pa))
print(' '.join((str(i) for i in ans)))


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


import sys
input = sys.stdin.readline

class SegmentTree:

	def __init__(self, a):
		self.op = lambda a, b: max(a, b)
		self.e = 0
		self.n = len(a)
		self.lv = (self.n - 1).bit_length()
		self.size = 2 ** self.lv
		self.data = [self.e] * (2 * self.size - 1)
		self._check = lambda x, acc: acc >= x
		self._acc = self.e
		self.initialize(a)

	def initialize(self, a):
		for i in range(self.n):
			self.data[self.size + i - 1] = a[i]
		for i in range(self.size - 2, -1, -1):
			self.data[i] = self.op(self.data[i * 2 + 1], self.data[i * 2 + 2])

	def update(self, k, x):
		k += self.size - 1
		self.data[k] = x
		while k > 0:
			k = (k - 1) // 2
			self.data[k] = self.op(self.data[2 * k + 1], self.data[2 * k + 2])

	def fold(self, l, r):
		L = l + self.size
		R = r + self.size
		s = self.e
		while L < R:
			if R & 1:
				R -= 1
				s = self.op(s, self.data[R - 1])
			if L & 1:
				s = self.op(s, self.data[L - 1])
				L += 1
			L >>= 1
			R >>= 1
		return s

	def _bisect_forward(self, x, start, k):
		if k >= self.size - 1:
			self._acc = self.op(self._acc, self.data[k])
			if self._check(x, self._acc):
				return k - (self.size - 1)
			else:
				return -1
		width = 2 ** (self.lv - (k + 1).bit_length() + 1)
		mid = (k + 1) * width + width // 2 - self.size
		if mid <= start:
			return self._bisect_forward(x, start, 2 * k + 2)
		tmp_acc = self.op(self._acc, self.data[k])
		if start <= mid - width // 2 and (not self._check(x, tmp_acc)):
			self._acc = tmp_acc
			return -1
		vl = self._bisect_forward(x, start, 2 * k + 1)
		if vl != -1:
			return vl
		return self._bisect_forward(x, start, 2 * k + 2)

	def bisect_forward(self, x, start=None):
		if start:
			ret = self._bisect_forward(x, start, 0)
		else:
			ret = self._bisect_forward(x, 0, 0)
		self._acc = self.e
		return ret

	def _bisect_backward(self, x, start, k):
		if k >= self.size - 1:
			self._acc = self.op(self._acc, self.data[k])
			if self._check(x, self._acc):
				return k - (self.size - 1)
			else:
				return -1
		width = 2 ** (self.lv - (k + 1).bit_length() + 1)
		mid = (k + 1) * width + width // 2 - self.size
		if mid >= start:
			return self._bisect_backward(x, start, 2 * k + 1)
		tmp_acc = self.op(self._acc, self.data[k])
		if start > mid + width // 2 and (not self._check(x, tmp_acc)):
			self._acc = tmp_acc
			return -1
		vl = self._bisect_backward(x, start, 2 * k + 2)
		if vl != -1:
			return vl
		return self._bisect_backward(x, start, 2 * k + 1)

	def bisect_backward(self, x, start=None):
		if start:
			ret = self._bisect_backward(x, start, 0)
		else:
			ret = self._bisect_backward(x, self.n, 0)
		self._acc = self.e
		return ret
n = int(input())
s = input().rstrip()
array = [0] * n
ST = SegmentTree(array)
event = []
for (i, ch) in enumerate(s):
	event.append((ch, i))
event.sort(reverse=True)
ans = [0] * n
for (ch, index) in event:
	val = ST.fold(0, index) + 1
	ans[index] = val
	ST.update(index, val)
print(max(ans))
print(*ans)


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


import sys
input = lambda : sys.stdin.readline().strip()
n = int(input())
s = input()
color = [0 for i in range(n)]
counter = [0 for i in range(26)]
for i in range(n):
	color[i] = max(counter[ord(s[i]) - ord('a') + 1:], default=0) + 1
	counter[ord(s[i]) - ord('a')] = max(counter[ord(s[i]) - ord('a')], color[i])
print(max(color))
print(*color)


import random
from bisect import bisect_left, bisect_right
from typing import List
import collections
import bisect
import itertools
import functools
from fractions import gcd
import heapq
from math import ceil, sqrt, floor
import sys
sys.setrecursionlimit(50000)
import collections
from collections import defaultdict, deque
import collections
import bisect
from collections import defaultdict, deque
import collections
n = int(input())
s = input()
si = [(i, c) for (i, c) in enumerate(s)]
edges = defaultdict(list)
for _ in range(n):
	for i in range(n - 1):
		if si[i][1] > si[i + 1][1]:
			edges[si[i][0]].append(si[i + 1][0])
			edges[si[i + 1][0]].append(si[i][0])
			(si[i], si[i + 1]) = (si[i + 1], si[i])

def dfs(node, edges, color_map, color):
	if node in color_map:
		return color_map[node] == color
	color_map[node] = color
	ret = True
	for dest in edges[node]:
		ret &= dfs(dest, edges, color_map, 1 if color == 0 else 0)
	return ret
color_map = {}
result = 'YES'
for i in range(n):
	if i not in color_map:
		if not dfs(i, edges, color_map, 0):
			result = 'NO'
print(result)
if result == 'YES':
	print(''.join((str(color_map[i]) for i in range(n))))


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


INF = 10 ** 10

def main():
	print = out.append
	n = get_int()
	st = list(input())
	li = [0] * 26
	res = [0] * n
	for (i, ele) in reversed(list(enumerate(st))):
		cnt = 0
		for j in range(ord(ele) - ord('a')):
			cnt = max(li[j], cnt)
		res[i] = cnt + 1
		li[ord(ele) - ord('a')] = cnt + 1
	print(max(res))
	print(' '.join(map(str, res)))
import sys
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right
import math
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
main()
print(*out, sep='\n')


from sys import stdin, stdout
from math import pow
from os import path
if path.exists('inp.txt'):
	stdin = open('inp.txt', 'r')
d = [1 for i in range(26)]
q = []
color = 1
n = int(stdin.readline())
s = stdin.readline()
cur = 'a'

def check(x):
	ans = 0
	for i in range(x + 1, 26):
		ans = max(d[i], ans)
	return ans
for i in range(n):
	if s[i] < cur:
		d[ord(s[i]) - ord('a')] = check(ord(s[i]) - ord('a')) + 1
		color = max(color, d[ord(s[i]) - ord('a')])
	else:
		cur = s[i]
	q.append(d[ord(s[i]) - ord('a')])
print(color)
for v in q:
	print(v, end=' ')


import os, sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	s = input().strip()
	dp = []
	color = []
	for i in s:
		fl = 0
		for j in range(len(dp)):
			if dp[j] <= i:
				dp[j] = i
				color.append(j + 1)
				fl = 1
				break
		if not fl:
			dp.append(i)
			color.append(len(dp))
	print(max(color))
	print(*color)
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()
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)


n = int(input())
s = input()
p = [-1] * n
dd = [0] * 26
p[0] = 1
dd[ord(s[0]) - 97] = 1
for i in range(1, n):
	f = 0
	mxj = 0
	for j in range(26):
		if dd[j] != 0 and j > ord(s[i]) - 97:
			f = 1
			mxj = max(mxj, dd[j])
	p[i] = mxj + 1
	dd[ord(s[i]) - 97] = p[i]
print(max(p))
for i in p:
	print(i, end=' ')


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
from math import ceil, floor, sqrt, gcd

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

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

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

def si():
	return input()
n = ii()
s = si()
c1 = 'a'
c2 = 'a'
f = 0
s1 = ''
for i in s:
	if i >= c1:
		s1 += '0'
		c1 = i
	elif i >= c2:
		s1 += '1'
		c2 = i
	else:
		f = 1
		break
if f == 0:
	print('Yes')
	print(s1)
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')


n = int(input())
s = input()
kol = [-1] * n
cur = 1
ind = 0
while ind < n:
	if kol[ind] != -1:
		ind += 1
	else:
		kol[ind] = cur
		best = s[ind]
		for i in range(ind + 1, n):
			if kol[i] != -1:
				continue
			elif s[i] >= best:
				kol[i] = cur
				best = s[i]
		ind += 1
		cur += 1
print(max(kol))
for i in range(n):
	print(kol[i], end=' ')


n = int(input())
s = str(input())
lit = ['Z'] * 26
wyn = ''
m = -1
for x in s:
	for y in range(26):
		if lit[y] <= x:
			wyn += str(y + 1) + ' '
			lit[y] = x
			if y + 1 >= m:
				m = y + 1
			break
print(m)
print(wyn)


n = int(input())
s = str(input())
(x, ans) = ([0] * n, 1)
for i2 in range(n):
	for i in range(i2 + 1, n):
		if s[i] < s[i2] and x[i] != 0:
			if x[i2] == x[i]:
				ans = 0
			x[i2] = x[i] * -1
	if x[i2] == 0:
		x[i2] = 1
	for i in range(i2 + 1, n):
		if s[i] < s[i2] and x[i] == 0:
			x[i] = x[i2] * -1
		elif s[i] < s[i2] and x[i] == x[i2]:
			ans = 0
if ans == 0:
	print('NO')
else:
	print('YES')
	for i in range(n):
		if x[i] == 1:
			print(1, end='')
		else:
			print(0, end='')


def main():
	n = int(input())
	s = input()
	dp = []
	ans = []
	for i in range(n - 1, -1, -1):
		letters = [0] * 26
		if dp:
			for j in range(26):
				letters[j] = dp[-1][j]
			for j in range(ord(s[i]) - ord('a')):
				letters[ord(s[i]) - ord('a')] = max(letters[ord(s[i]) - ord('a')], dp[-1][j] + 1)
			letters[ord(s[i]) - ord('a')] = max(letters[ord(s[i]) - ord('a')], 1)
		else:
			letters[ord(s[i]) - ord('a')] = 1
		ans.append(letters[ord(s[i]) - ord('a')])
		dp.append(letters)
	ans.reverse()
	max_val = max(dp[-1])
	print(max_val)
	for i in ans:
		print(i, end=' ')
main()


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 = sys.stdin.readline
from collections import *

def bfs(sta):
	q = deque([sta])
	color[sta] = 1
	while q:
		v = q.popleft()
		for nv in G[v]:
			if color[nv] == 0:
				color[nv] = -color[v]
				q.append(nv)
			elif color[nv] == color[v]:
				return False
	return True
n = int(input())
s = input()[:-1]
G = [[] for _ in range(n)]
for i in range(n):
	for j in range(i):
		u = ord(s[i]) - ord('a')
		v = ord(s[j]) - ord('a')
		if v > u:
			G[i].append(j)
			G[j].append(i)
color = [0] * n
flag = True
for i in range(n):
	if color[i] == 0:
		flag &= bfs(i)
if not flag:
	print('NO')
	exit()
ans = []
for i in range(n):
	if color[i] == 1:
		ans.append('1')
	else:
		ans.append('0')
print('YES')
print(''.join(ans))


n = int(input())
s = input()
c = 1
k = [0 for i in range(26)]
code = ord('a')
k[0] = 1
ans = []
for i in range(n):
	letter = ord(s[i]) - code
	if k[letter] != 0:
		ans.append(k[letter])
	else:
		for j in range(letter, -1, -1):
			if k[j] != 0:
				ans.append(k[j])
				k[letter] = k[j]
				k[j] = 0
				break
			if j == 0:
				c += 1
				k[letter] = c
				ans.append(c)
print(c)
print(*ans)


n = int(input())
s = input()
arr = [0 for i in range(n)]
grps = []
col = 0
for i in range(len(s)):
	if grps == []:
		grps.append(s[i])
		arr[i] = 1
		col += 1
	else:
		found = 0
		for j in range(len(grps)):
			if ord(s[i]) >= ord(grps[j]):
				found = 1
				grps[j] = s[i]
				arr[i] = j + 1
				break
		if found == 0:
			grps.append(s[i])
			col += 1
			arr[i] = col
print(col)
for i in range(n):
	print(arr[i], end=' ')
print()


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)
print(color)
for i in ans:
	print(i, end=' ')


n = int(input())
s = list(input())
dg = 10 ** 6
for i in range(n):
	s[i] = ord(s[i]) * dg + i
s.sort()

def init_max(init_max_val):
	for i in range(n):
		seg_max[i + num_max - 1] = init_max_val[i]
	for i in range(num_max - 2, -1, -1):
		seg_max[i] = max(seg_max[2 * i + 1], seg_max[2 * i + 2])

def update_max(k, x):
	k += num_max - 1
	seg_max[k] = x
	while k:
		k = (k - 1) // 2
		seg_max[k] = max(seg_max[k * 2 + 1], seg_max[k * 2 + 2])

def query_max(p, q):
	if q <= p:
		return ide_ele_max
	p += num_max - 1
	q += num_max - 2
	res = ide_ele_max
	while q - p > 1:
		if p & 1 == 0:
			res = max(res, seg_max[p])
		if q & 1 == 1:
			res = max(res, seg_max[q])
			q -= 1
		p = p // 2
		q = (q - 1) // 2
	if p == q:
		res = max(res, seg_max[p])
	else:
		res = max(max(res, seg_max[p]), seg_max[q])
	return res
ide_ele_max = 0
num_max = 2 ** (n - 1).bit_length()
seg_max = [ide_ele_max] * 2 * num_max
res = [0] * n
for e in s:
	ind = e % dg
	ad = query_max(ind, n)
	res[ind] = ad + 1
	update_max(ind, ad + 1)
print(max(res))
print(*res)


import sys
import math
input = sys.stdin.readline
from functools import cmp_to_key

def pi():
	return int(input())

def pl():
	return int(input(), 16)

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

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

def invr():
	return map(int, input().split())
mod = 998244353
f = []

def fact(n, m):
	global f
	f = [1 for i in range(n + 1)]
	f[0] = 1
	for i in range(1, n + 1):
		f[i] = f[i - 1] * i % m

def fast_mod_exp(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b = b >> 1
	return res

def inverseMod(n, m):
	return fast_mod_exp(n, m - 2, m)

def ncr(n, r, m):
	if r == 0:
		return 1
	return f[n] * inverseMod(f[n - r], m) % m * inverseMod(f[r], m) % m

def main():
	stringColoring()

def xdfs(root, v, sub, parent):
	st = [root]
	while len(st) > 0:
		node = st.pop()
		for i in range(len(v[node])):
			if v[node][i] != node:
				st.append(v[node][i])

def X():
	try:
		t = pi()
		while t:
			t -= 1
			n = pi()
			v = [[] for i in range(n)]
			for i in range(n - 1):
				[x, y] = ti()
				v[x - 1].append(y - 1)
				v[y - 1].append(x - 1)
			m = pi()
			p = ti()
			e = [0 for i in range(n - 1)]
			sub = [0 for i in range(n)]
			dfs(0, v, sub, -1)
			for i in range(1, n):
				e[i - 1] = sub[i] * (n - sub[i])
			if len(p) < n - 1:
				while len(p) < n - 1:
					p.append(1)
			p = sorted(p)
			if len(p) > n - 1:
				x = 1
				for i in range(n - 2, len(p)):
					x = x * p[i]
				while len(p) > n - 2:
					p.pop()
				p.append(x)
			e = sorted(e)
			res = 0
			for i in range(n - 1):
				res = (res + p[i] * e[i]) % mod
			print(res)
	except:
		print(sys.exc_info())

def bfs(v, root):
	q = [root, None]
	l = 0
	visited = [0 for i in range(len(v))]
	dist = [0 for i in range(len(v))]
	while len(q) > 0:
		node = q.pop(0)
		if node is not None:
			visited[node] = 1
			dist[node] = l
			for i in range(len(v[node])):
				if visited[v[node][i]] == 0:
					visited[v[node][i]] = 1
					q.append(v[node][i])
		else:
			l += 1
			if len(q) != 0:
				q.append(None)
	return dist

def B():
	n = pi()
	v = [[] for i in range(n)]
	for i in range(n - 1):
		[x, y] = ti()
		v[x - 1].append(y - 1)
		v[y - 1].append(x - 1)
	leafs = []
	for i in range(n):
		if len(v[i]) == 1:
			leafs.append(i)
	mn = 1
	d = bfs(v, leafs[0])
	for i in range(1, len(leafs)):
		if d[leafs[i]] % 2 != 0:
			mn = 3
			break
	count = 0
	for i in range(n):
		f = 0
		for j in range(len(v[i])):
			if len(v[v[i][j]]) == 1:
				f = 1
				break
		if f:
			count += 1
	mx = n - 1 - len(leafs) + count
	print(mn, mx)

def KMP(s):
	a = [0 for i in range(len(s))]
	i = 0
	j = 1
	while j < len(s):
		if s[i] == s[j]:
			a[j] = i + 1
			i += 1
			j += 1
		else:
			i = a[j - 1]
			if s[i] == s[j]:
				a[j] = i + 1
				i += 1
				j += 1
			else:
				j += 1
	return a

def getLargetPrefixPallindrome(s):
	r = str(s)[::-1]
	a = KMP(str(s) + '?' + r)
	return str(s[0:a[2 * len(s)]])

def D2():
	t = pi()
	while t:
		t -= 1
		s = input()
		s = s[:len(s) - 1]
		l = 0
		n = len(s)
		if len(s) == 1:
			print(s)
			continue
		for i in range(len(s)):
			if s[i] == s[n - i - 1]:
				l += 1
				continue
			break
		pre = getLargetPrefixPallindrome(s[l:-l] if l != 0 else s)
		suf = getLargetPrefixPallindrome(str(s[l:-l])[::-1] if l != 0 else s[::-1])
		if len(pre) > len(suf):
			print(str(s[0:l]) + pre + str(s[n - l:len(s)]))
		else:
			print(str(s[0:l]) + str(suf[::-1]) + str(s[n - l:len(s)]))

def D():
	t = pi()
	while t:
		t -= 1
		[n, s] = input().split(' ')
		s = s[:len(s) - 1]
		n = int(n)
		mx = [-1 for i in range(n)]
		i = 0
		x = 1
		while i < n - 1:
			while i < n - 1 and s[i] == '>':
				i += 1
			mx[i] = x
			j = i - 1
			while j >= 0 and mx[j] == -1:
				x += 1
				mx[j] = x
				j -= 1
			i += 1
			x += 1
		i = n - 1
		x = 1
		mn = [-1 for i in range(n)]
		f = 0
		while i >= 1:
			if i >= 1 and i < len(s) and (s[i] == '<') and (s[i - 1] == '>'):
				mn[i] = x
				x += 1
			i -= 1
		if x != 1:
			for i in range(n - 1, -1, -1):
				if mn[i] == -1:
					mn[i] = x
					x += 1
		elif s[0] == '<':
			for i in range(n):
				mn[i] = x
				x += 1
		else:
			x = n
			for i in range(n):
				mn[i] = x
				x -= 1
		print(*mn, sep=' ')
		print(*mx, sep=' ')

def cmp(a, b):
	if ord(a[1]) < ord(b[1]):
		return -1
	if ord(a[1]) > ord(b[1]):
		return 1
	if ord(a[1]) == ord(b[1]):
		if a[0] < b[0]:
			return -1
		if a[0] < b[0]:
			return 1
		return 0
	return 0

def stringColoring():
	(n, s) = (pi(), ts())
	dp = [[[0 for k in range(26)] for j in range(26)] for i in range(n + 1)]
	p = [[[[] for k in range(26)] for j in range(26)] for i in range(n + 1)]
	dp[0][0][0] = 1
	for i in range(n):
		c = ord(s[i]) - ord('a')
		for c1 in range(26):
			for c2 in range(26):
				if dp[i][c1][c2] == 0:
					continue
				if c >= c1:
					dp[i + 1][c][c2] = 1
					p[i + 1][c][c2] = [[c1, c2], 0]
				if c >= c2:
					dp[i + 1][c1][c] = 1
					p[i + 1][c1][c] = [[c1, c2], 1]
	(x, y) = (-1, -1)
	for i in range(26):
		for j in range(26):
			if dp[n][i][j]:
				x = i
				y = j
	if x == -1:
		print('NO')
		return
	res = ''
	px = -1
	py = -1
	for i in range(n, 0, -1):
		px = p[i][x][y][0][0]
		py = p[i][x][y][0][1]
		if p[i][x][y][1]:
			res += '1'
		else:
			res += '0'
		(x, y) = (px, py)
	print('YES')
	print(res[::-1])
main()


n = int(input())
s = input()
ans = [1]
cc = 0
color = ['z'] * 26
color[0] = s[0]
for i in range(1, n):
	flag = False
	for j in range(cc + 1):
		if color[j] <= s[i]:
			ans.append(j + 1)
			flag = True
			color[j] = s[i]
			break
	if not flag:
		cc += 1
		color[cc] = s[i]
		ans.append(cc + 1)
print(cc + 1)
for i in range(n):
	print(ans[i], end=' ')


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


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()
lis = [0] * (n + 1)
lis[1] = st[0]
r = 1
ans = [1]
for i in st[1:]:
	if i >= lis[1]:
		lis[1] = i
		ans.append(1)
	elif i < lis[r]:
		r += 1
		lis[r] = i
		ans.append(r)
	else:
		left = 1
		right = r
		while left < right:
			mid = (left + right) // 2
			if i < lis[mid]:
				left = mid + 1
			else:
				right = mid
		ans.append(left)
		lis[left] = i
print(r)
print(*ans)


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().strip()
CONTRADICT = False
color = [-1 for i in range(len(s))]
color[-1] = 1
for i in range(n - 1, -1, -1):
	for j in range(i - 1, -1, -1):
		if s[i] < s[j]:
			if color[j] == -1:
				color[j] = 1 if color[i] == 0 else 0
			elif color[i] == -1:
				color[i] = 1 if color[j] == 0 else 0
			elif color[i] == color[j]:
				CONTRADICT = True
for i in range(len(color)):
	if color[i] == -1:
		color[i] = 1
if not CONTRADICT:
	print('YES')
	for i in color:
		print(i, end='')
else:
	print('NO')


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)


a = int(input(''))
s = input('')

def recurse(s, m):
	if len(s) == 0:
		return ''
	char = min(s)
	i = s.index(char)
	if i < m and i != 0:
		return -1
	elif i < m and i == 0:
		return recurse(s[0:i] + s[i + 1:len(s)], m - 1)
	else:
		add = ''
		for l in range(i - m):
			add = add + '1'
		add = add + '0'
		xd = recurse(s[0:i] + s[i + 1:len(s)], i)
		if xd == -1:
			return -1
		else:
			return add + xd
ans = recurse(s, 0)
if ans != -1:
	print('YES')
	print(ans)
else:
	print('NO')


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)


import sys
input = sys.stdin.readline
n = int(input())
S = input().strip()
A = [97 - (ord(s) - 96) for s in S]
DP = [float('inf')] * n
ANS = []
import bisect
for a in A:
	pos = bisect.bisect_left(DP, a)
	ANS.append(pos + 1)
	DP[pos] = a
print(max(ANS))
print(*ANS)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
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 = input().strip()
l = [97 - (ord(i) - 96) for i in s]
dp = [float('inf')] * n
ans = []
for i in l:
	posn = bisect_left(dp, i)
	ans.append(posn + 1)
	dp[posn] = i
print(max(ans))
print(*ans)


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


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
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')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 30, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
n = int(input())
d = dict()
for i in range(97, 124):
	d[chr(i)] = 0
l = input()
d[l[0]] += 1
ans = [0] * n
ans[0] = d[l[0]]
for i in range(1, n):
	for j in sorted(d.keys(), reverse=True):
		if j > l[i]:
			ans[i] = max(ans[i], d[j] + 1)
		else:
			break
	d[l[i]] = ans[i]
print(max(ans))
print(*ans, sep=' ')


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


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()))
n = inp()
s = list(input())
for (i, x) in enumerate(s):
	s[i] = ord(x) - 97
s = s[::-1]
lis = [INF] * 30
color = [-1] * n
for (i, x) in enumerate(s):
	ind = bisect_left(lis, x)
	color[i] = ind + 1
	lis[ind] = x
print(max(color))
print(*color[::-1])


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


n = int(input())
s = input()
prev = -1
t = -1
ans = ''
for c in s:
	cur = ord(c) - ord('a')
	if cur >= prev:
		ans += '1'
		prev = cur
	else:
		if cur < t:
			print('NO')
			exit()
		ans += '0'
		t = cur
print('YES')
print(ans)


from sys import stdin
input = stdin.readline
n = int(input())
s = input().strip()
tmp = [s[0]] + ['' for i in range(25)]
ans = [1]
for i in range(1, len(s)):
	for j in range(26):
		if tmp[j] <= s[i]:
			ans.append(j + 1)
			tmp[j] = s[i]
			break
print(max(ans))
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()


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = input()
ck = []
ans = [0] * n
for (i, v) in enumerate(a):
	for j in range(len(ck)):
		if ck[j][-1] <= v:
			ck[j].append(v)
			ans[i] = j + 1
			break
	if not ans[i]:
		ck.append([v])
		ans[i] = len(ck)
print(len(ck))
print(*ans)


n = int(input())
s = list(input())
temp = s[:]
from collections import defaultdict
d = defaultdict(list)
pr = [i for i in range(n)]
for i in range(n):
	for j in range(n - 1):
		if s[j] > s[j + 1]:
			(pr[j], pr[j + 1]) = (pr[j + 1], pr[j])
			(s[j], s[j + 1]) = (s[j + 1], s[j])
			d[pr[j]].append(pr[j + 1])
			d[pr[j + 1]].append(pr[j])
f = 1
clr = [-1] * n
for x in range(n):
	if clr[x] != -1:
		continue
	clr[x] = 1
	q = []
	q = [x]
	while q:
		t = q.pop(0)
		if t in d[t]:
			f = 0
			break
		for i in d[t]:
			if clr[i] == -1:
				clr[i] = 1 - clr[t]
				q.append(i)
			elif clr[i] == clr[t]:
				f = 0
				break
if f:
	print('YES')
	print(*clr, sep='')
else:
	print('NO')


import math
import sys
from collections import defaultdict

def stdinWrapper():
	data = '200\nraaaaabbbccccccccccdddddeeeeeeeeeeeeeeffffffffffggggggggghhhhhiiiiiiiiijjjjkkkkkkkkkkllllllllmmmmmmmmnnnnnnnooooooooppppppqqqqqqqqqqrrrrrrrrssssttttttttttuuuuuuuuvvvvvvwwwwwwxxxxxxxyyyyyyyzzzzzzzzzzzz\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)
dp = [1] * l
maxdp = [0] * 26
dp = [1] * len(_str)
p = [-1] * len(_str)
for i in range(len(_str)):
	for c in range(ord(_str[i]) - ord('a') + 1, 26):
		dp[i] = max(dp[i], maxdp[c] + 1)
	maxdp[ord(_str[i]) - ord('a')] = max(dp[i], maxdp[ord(_str[i]) - ord('a')])
print(max(dp))
print(' '.join([str(x) for x in dp]))


n = int(input())
s = input()
a = []
for i in range(n):
	a.append([s[i], i, 0])
for i in range(n):
	mn = a[i][0]
	k = i
	for j in range(i + 1, n):
		if a[j][0] < mn:
			mn = a[j][0]
			k = j
	if k == i:
		continue
	if a[k][2]:
		print('NO')
		exit()
	for j in range(k, i, -1):
		a[j - 1][2] = 1
		(a[j - 1], a[j]) = (a[j], a[j - 1])
ans = [0] * n
for i in range(n):
	(pos, color) = (a[i][1], a[i][2])
	ans[pos] = color
print('YES')
print(''.join(map(str, ans)))


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


import math
import sys
from collections import defaultdict

def stdinWrapper():
	data = '9\nabacbecfd\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)
AL = 26
dp = [[[0] * AL for _ in range(AL)] for _ in range(l + 1)]
parents = [[[[0, 0, 0]] * AL for _ in range(AL)] for _ in range(l + 1)]
dp[0][0][0] = 1
for i in range(1, l + 1):
	prev_char = ord(_str[i - 1]) - ord('a')
	for c1 in range(AL):
		for c2 in range(AL):
			if not dp[i - 1][c1][c2]:
				continue
			if prev_char >= c1:
				dp[i][prev_char][c2] = 1
				parents[i][prev_char][c2] = [c1, c2, 0]
			if prev_char >= c2:
				dp[i][c1][prev_char] = 1
				parents[i][c1][prev_char] = [c1, c2, 1]
x = -1
y = -1
for c1 in range(AL):
	for c2 in range(AL):
		if dp[l][c1][c2]:
			x = c1
			y = c2
if x == -1:
	print('NO')
	exit()
res = ''
for i in reversed(range(1, l + 1)):
	previous_c1 = parents[i][x][y][0]
	previous_c2 = parents[i][x][y][1]
	if parents[i][x][y][2]:
		res += '1'
	else:
		res += '0'
	x = previous_c1
	y = previous_c2
print('YES')
print(''.join(reversed(res)))


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 bisect import *
input()
(l, *a) = ([],)
for c in [-ord(i) for i in input()]:
	i = bisect_left(l, c)
	a += (i + 1,)
	if i < len(l):
		l[i] = c
	else:
		l += (c,)
print(len(l))
print(*a)


def hello_nigga():
	n = int(input())
	s = input()
	s0 = []
	l_s0 = 'a'
	s1 = []
	l_s1 = 'a'
	t = 1
	for i in range(n):
		if s[i] >= l_s1:
			l_s1 = s[i]
			s1.append(i)
		elif s[i] >= l_s0:
			l_s0 = s[i]
		else:
			t = 0
			print('NO')
			break
	if t:
		ans = ['0'] * n
		for i in range(len(s1)):
			ans[s1[i]] = '1'
		print('YES')
		print(''.join(ans))
if 'compiler is alive':
	if 'it has sence' and 'the wether is nice':
		hello_nigga()


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())
k = ['a'] * 26
ans = []
maxColor = 1
c = 0
for symb in input():
	for i in range(len(k)):
		if symb >= k[i]:
			ans.append(str(i + 1))
			if i + 1 > maxColor:
				maxColor = i + 1
			k[i] = symb
			break
	c += 1
print(maxColor)
print(' '.join(ans))


def main():
	n = int(input())
	s = input()
	fst_lst = [s[0]]
	snd_lst = []
	ans = '1'
	for i in range(1, len(s)):
		if fst_lst[-1] <= s[i]:
			fst_lst.append(s[i])
			ans += '1'
		else:
			snd_lst.append(s[i])
			ans += '0'
	if sorted(snd_lst) == snd_lst:
		print('YES')
		print(ans)
	else:
		print('NO')
main()


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]
			ans.append(1)
		elif a[i] < tails[seq_len - 1]:
			tails[seq_len] = a[i]
			seq_len += 1
			ans.append(seq_len)
		else:
			pos = ceil(tails, -1, seq_len - 1, a[i])
			tails[pos] = a[i]
			ans.append(pos + 1)
	return seq_len
n = int(input())
s = input()
ans = [1]
res = LIS(s, n)
print(res)
print(*ans)


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
input = sys.stdin.readline
n = int(input())
S = input().strip()
ANS = [-1] * n
for i in range(n):
	flag = 0
	for j in range(i):
		if S[j] > S[i]:
			flag = 1
			if ANS[j] != -1:
				if ANS[j] == ANS[i]:
					print('NO')
					sys.exit()
				ANS[i] = 1 - ANS[j]
	if flag:
		ANS[i] = 0
		for j in range(i):
			if S[j] > S[i]:
				if ANS[j] == ANS[i]:
					print('NO')
					sys.exit()
				ANS[j] = 1 - ANS[i]
for i in range(n):
	if ANS[i] == -1:
		ANS[i] = 0
print('YES')
print(''.join(tuple(map(str, ANS))))


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


n = int(input())
s = input()
(c, res) = (['0'] * 26, [''] * n)
for i in range(n):
	for j in range(26):
		if s[i] >= c[j]:
			res[i] = str(j + 1)
			c[j] = s[i]
			break
print(26 - c.count('0'))
print(' '.join(res))


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, S):
	indices = [[0]]
	for (i, x) in enumerate(S[1:], 1):
		for l in indices:
			if S[l[-1]] <= x:
				l.append(i)
				break
		else:
			indices.append([i])
	ans = [None for i in range(N)]
	for (color, l) in enumerate(indices):
		for i in l:
			ans[i] = color
	possible = str(len(indices))
	return possible + '\n' + ' '.join((str(x + 1) for x in ans))
	if len(indices) <= 2:
		return 'YES\n' + ''.join(map(str, ans))
	else:
		return 'NO'
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N,) = [int(x) for x in input().split()]
S = input().decode().rstrip()
ans = solve(N, S)
print(ans)


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


n = int(input())
s = input()
colors = ['_'] * 26
ans = [''] * n
idx = 0
for c in s:
	for i in range(26):
		if c >= colors[i]:
			ans[idx] = str(i + 1)
			colors[i] = c
			break
	idx += 1
print(26 - colors.count('_'))
print(' '.join(ans))


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)


n = int(input())
s = input()
r = []
q = 0
f = ['a']
for i in range(n):
	z = 0
	while s[i] < f[z]:
		z = z + 1
		if z == len(f):
			f.append(s[i])
			break
	f[z] = s[i]
	r.append(z + 1)
print(max(r))
print(*r)


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()
used = [0] * n
col = [-1] * n
a = [(c, i) for (i, c) in enumerate(s)]
a.sort()
for (_, i) in a:
	tmp = -1
	for j in range(i):
		if used[j] or col[j] == -1:
			continue
		if tmp == -1:
			tmp = col[j]
		if tmp != col[j]:
			print('NO')
			exit()
	if tmp == -1 and col[i] == -1:
		tmp = 0
	elif tmp == -1 and col[i] != -1:
		tmp = 1 ^ col[i]
	elif tmp != -1 and col[i] == -1:
		pass
	elif tmp == col[i]:
		print('NO')
		exit()
	col[i] = 1 ^ tmp
	for j in range(i):
		if used[j]:
			continue
		col[j] = tmp
	used[i] = 1
ans = ''.join(map(str, col))
b = [c for c in s]
for i in range(1, n):
	while i and b[i - 1] > b[i]:
		if col[i - 1] == col[i]:
			print('NO')
			exit()
		(b[i - 1], b[i]) = (b[i], b[i - 1])
		(col[i - 1], col[i]) = (col[i], col[i - 1])
		i -= 1
print('YES')
print(ans)


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


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)]
color = [0 for _ in range(n)]
max_color = [0 for _ in range(26)]
for (i, x) in enumerate(data):
	now = 0
	for y in range(x + 1, 26):
		now = max(max_color[y], now)
	now += 1
	alpha_data[x].append(i)
	max_color[x] = max(max_color[x], now)
	color[i] = now
print(max(color))
print(*color)


from sys import stdin, stdout
t = 1
for _ in range(t):
	n = int(input())
	s = input()
	ans = []
	dict = {}
	count = 0
	for i in s:
		count += 1
		maxi = -1
		taken = set()
		for j in range(97 + 25, 96, -1):
			if chr(j) in dict and chr(j) > i:
				taken.add(dict[chr(j)][1])
		j = 0
		while 1:
			j += 1
			if j not in taken:
				ans.append(j)
				dict[i] = (count, j)
				break
	x = len(set(ans))
	if x > 2:
		print('no')
		continue
	print('yes')
	for i in range(n):
		ans[i] -= 1
		ans[i] = str(ans[i])
	print(''.join(ans))


import sys
input = sys.stdin.readline
from collections import *
n = int(input())
s = input()[:-1]
acc = [[0] * (n + 1) for _ in range(26)]
for i in range(n):
	for j in range(26):
		acc[j][i + 1] = acc[j][i] + (1 if ord(s[i]) - ord('a') == j else 0)
dp = [1] * n
M = [0] * 26
M[0] = 1
for i in range(n - 1, -1, -1):
	for j in range(ord(s[i]) - ord('a')):
		if acc[j][n] - acc[j][i + 1] > 0:
			dp[i] = max(dp[i], M[j] + 1)
	M[ord(s[i]) - ord('a')] = max(M[ord(s[i]) - ord('a')], dp[i])
print(max(dp))
print(*dp)


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


n = int(input())
s = input()
l = [[0, -1] for i in range(26)]
for i in range(n):
	l[ord(s[i]) - 97][0] += 1
j = -1
color = [-1 for i in range(n)]
for c in range(26):
	i = j + 1
	while l[c][0] > 0 and i < n:
		if ord(s[i]) - 97 == c:
			if l[c][1] == -1:
				was0 = False
				was1 = False
				for k in range(i):
					if ord(s[k]) - 97 > ord(s[i]) - 97:
						if color[k] == 0:
							was0 = True
						if color[k] == 1:
							was1 = True
				if was0 and was1:
					print('NO')
					exit(0)
				if was0:
					color[i] = 1
					l[c][1] = 1
				else:
					color[i] = 0
					l[c][1] = 0
			else:
				color[i] = l[c][1]
			l[c][0] -= 1
			j = i
		i += 1
	mx = ord(s[j]) - 97
	for i in range(j):
		if color[i] != -1:
			continue
		if ord(s[i]) - 97 > ord(s[j]) - 97:
			color[i] = 1 - color[j]
			if mx > ord(s[i]) - 97:
				print('NO')
				exit(0)
			mx = ord(s[i]) - 97
for j in range(n):
	for i in range(j):
		if ord(s[i]) - 97 > ord(s[j]) - 97 and color[i] == color[j]:
			print('NO')
			exit(0)
print('YES')
for c in color:
	print(c, end='')


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)


alp = 'abcdefghijklmnopqrstuvwxyz'
dic = {}
for (i, s) in enumerate(alp):
	dic[s] = i
lis = [0] * 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]
print(max(ans))
print(' '.join(map(str, ans)))


import math
L = int(input())
s = input()
color = [-1] * L
counts = {}
for l in s:
	if l in counts:
		counts[l] += 1
	else:
		counts[l] = 1
c = 'a'
indexs = {}
prefixsum = 0
while c <= 'z':
	if c in counts:
		indexs[c + 'start'] = prefixsum
		prefixsum += counts[c] - 1
		indexs[c + 'end'] = prefixsum
		prefixsum += 1
	c = chr(ord(c) + 1)

def f():
	global L, s, color, counts, indexs
	for i in range(len(s)):
		c = s[i]
		if i >= indexs[c + 'start'] and i <= indexs[c + 'end']:
			pass
		elif i < indexs[c + 'start']:
			currC = color[i]
			if currC == -1:
				if color[i + 1] == -1 or color[i + 1] == 0:
					currC = 1
				else:
					currC = 0
			targetC = 1
			if currC == 1:
				targetC = 0
			color[i] = currC
			targetIndex = indexs[c + 'start']
			j = i + 1
			while j < targetIndex + 1:
				nextChar = s[j]
				nextCol = color[j]
				if nextChar < c:
					if nextCol == currC:
						print('NO')
						return
					else:
						color[j] = targetC
				elif nextChar == c:
					if nextCol == currC:
						targetIndex += 1
					elif nextCol == -1:
						color[j] = currC
						targetIndex += 1
					else:
						print('NO')
						return
				else:
					color[j] == currC
				j += 1
		elif i > indexs[c + 'end']:
			currC = color[i]
			if currC == -1:
				if color[i - 1] == -1 or color[i - 1] == 0:
					currC = 1
				else:
					currC = 0
			targetC = 0
			if currC == 0:
				targetC = 1
			color[i] = currC
			targetIndex = indexs[c + 'end']
			j = i - 1
			while j > targetIndex - 1:
				nextL = s[j]
				nextC = color[j]
				if nextL > c:
					if nextC == currC:
						print('NO')
						return
					elif nextC == -1:
						nextC = targetC
					else:
						pass
				elif nextL == c:
					assert nextC != -1
					if nextC == currC:
						targetIndex -= 1
					else:
						print('NO')
						return
				elif nextC != currC:
					print('NO')
					return
				j -= 1
	print('YES')
	for i in color:
		if i == -1:
			print(0, end='')
		else:
			print(i, end='')
f()


n = int(input())
arr = list(input())
for i in reversed(range(1, n)):
	cc = arr[i]
	cl = 0
	for j in reversed(range(i)):
		if arr[j] > cc:
			cc = arr[j]
			cl += 1
			if cl == 2:
				print('NO')
				exit(0)
		elif arr[j] > arr[i]:
			cc = arr[j]
cc = arr[-1]
narr = ['1' for _ in range(n)]
for i in reversed(range(n)):
	if arr[i] <= cc:
		narr[i] = '0'
		cc = arr[i]
print('YES')
print(''.join(narr))


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


def ispossible(a, col, ind):
	for j in range(ind - 1, -1, -1):
		if a[j][0] <= a[ind][0]:
			return 1
		if a[j][2] == col:
			return 0
	return 1
n = int(input())
S = input()
s = []
col = [-1 for i in range(n)]
c = 0
for i in S:
	if ord('a') <= ord(i) <= ord('z'):
		s.append([ord(i) - ord('a'), c, -1])
		c += 1
possible = 1
for i in range(26):
	for j in range(n):
		if s[j][0] == i:
			if ispossible(s, 0, j) and s[j][2] != 1:
				ind = j
				s[j][2] = 0
				for k in range(ind, -1, -1):
					if k == 0 or s[k - 1][0] <= s[k][0]:
						break
					s[k - 1][2] = 1
					(s[k], s[k - 1]) = (s[k - 1], s[k])
			elif ispossible(s, 1, j) and s[j][2] != 0:
				s[j][2] = 1
				ind = j
				for k in range(ind, -1, -1):
					if k == 0 or s[k - 1][0] <= s[k][0]:
						break
					s[k - 1][2] = 0
					(s[k], s[k - 1]) = (s[k - 1], s[k])
			else:
				possible = 0
				break
if possible:
	print('YES')
	ans = [0 for i in range(n)]
	for i in s:
		ans[i[1]] = i[2]
	for i in ans:
		print(i, end='')
else:
	print('NO')


n = int(input())
s2 = input()
k = 0
s = []
l = {}
for i in range(n):
	s.append(i)
	l[i] = -1
for i in range(n):
	m = 'zz'
	index = -1
	for j in range(k, n):
		if index == -1:
			index = j
			m = s2[j]
		if s2[j] < m:
			index = j
			m = s2[j]
	col = -1
	for j in range(k, index):
		if col == -1:
			col = l[s[j]]
		if col == 0:
			if l[s[j]] == 1:
				print('NO')
				exit(0)
		if col == 1:
			if l[s[j]] == 0:
				print('NO')
				exit(0)
	if l[s[index]] == -1:
		if col == -1:
			l[s[index]] = 1
			for j in range(k, index):
				l[s[j]] = 0
		if col == 0:
			l[s[index]] = 1
			for j in range(k, index):
				l[s[j]] = 0
		if col == 1:
			l[s[index]] = 0
			for j in range(k, index):
				l[s[j]] = 1
	else:
		if l[s[index]] == col:
			print('NO')
			exit(0)
		if col == -1:
			if l[s[index]] == 0:
				for j in range(k, index):
					l[s[j]] = 1
			if l[s[index]] == 1:
				for j in range(k, index):
					l[s[j]] = 0
	s = s[:k] + [s[index]] + s[k:index] + s[index + 1:]
	s2 = s2[:k] + s2[index] + s2[k:index] + s2[index + 1:]
	k += 1
ss = ''
for i in range(n):
	ss += str(l[i])
print('YES')
print(ss)


n = int(input())
s = input()
col = [1] * n
prev = [0] * 26
for i in range(n):
	code = ord(s[i]) - ord('a')
	if code != 25:
		col[i] = max(prev[code + 1:]) + 1
	prev[code] = col[i]
print(max(col))
print(*col)


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()
dp = [0] * 26
ans = [0] * n
totans = 1
for i in range(n - 1, -1, -1):
	maxx = 0
	for j in range(ord(s[i]) - ord('a') - 1, -1, -1):
		maxx = max(dp[j], maxx)
	dp[ord(s[i]) - ord('a')] = maxx + 1
	ans[i] = maxx + 1
	totans = max(totans, ans[i])
print(totans)
print(*ans)


n = int(input())
s = input()
a = [-1] * 26
h = [-1] * n
ch = 1
for i in range(len(s)):
	f = s[i]
	y = ord(f) - 97
	st = set()
	for j in range(y + 1, 26):
		if a[j] != -1:
			st.add(a[j])
	if 2 in st:
		ch = 0
		break
	if len(st) == 0:
		h[i] = 0
		a[y] = 0
	elif len(st) == 1:
		yt = -1
		if 1 in st:
			yt = 1
		else:
			yt = 0
		h[i] = 1 - yt
		if a[y] == -1 or a[y] == 1 - yt:
			a[y] = 1 - yt
		else:
			a[y] = 2
	else:
		ch = 0
		break
if ch == 1:
	print('YES')
	for i in h:
		print(i, end='')
	print()
else:
	print('NO')


def r(t=int):
	return list(map(t, input().split()))

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

def cd(it):
	ret_val = dict()
	for v in it:
		ret_val[v] = ret_val.get(v, 0) + 1
	return ret_val
n = ri()
a = input()
ans = [0] * n
alphabet = 'abcdefghijklmnopqrstuvwxyzZ'
last = [alphabet, alphabet]
for (i, ai) in enumerate(a):
	try:
		a1 = last[0].index(ai)
	except ValueError:
		a1 = 100
	try:
		a2 = last[1].index(ai)
	except ValueError:
		a2 = 100
	m = min(a1, a2)
	if m != 100:
		if a1 < a2:
			last[0] = last[0][a1:]
			ans[i] = 0
		else:
			last[1] = last[1][a2:]
			ans[i] = 1
	else:
		print('NO')
		break
else:
	print('YES')
	print(''.join((str(i) for i in ans)))


n = int(input())
s = input()
tmp = [s[0]] + ['' for i in range(25)]
ans = [1]
for i in range(1, len(s)):
	for j in range(26):
		if tmp[j] <= s[i]:
			ans.append(j + 1)
			tmp[j] = s[i]
			break
print(max(ans))
print(*ans)


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


def main():
	n = int(input())
	s = input()
	subsequences = []
	for (i, c) in enumerate(s):
		ok = False
		for subseq in subsequences:
			if s[subseq[-1]] <= c:
				subseq.append(i)
				ok = True
				break
		if not ok:
			subsequences.append([i])
	color = [-1 for _ in range(n)]
	for i in range(len(subsequences)):
		for j in subsequences[i]:
			color[j] = i + 1
	print(len(subsequences))
	oneLineArrayPrint(color)
	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()


input()
string = input()
colors = [0] * 26
res = []
visited = set()
for char in string:
	i1 = ord(char) - ord('a')
	color = 0
	for v in visited:
		i2 = ord(v) - ord('a')
		if char < v:
			color = max(color, colors[i2])
	color += 1
	colors[i1] = color
	res.append(color)
	visited.add(char)
print(max(colors))
print(' '.join((str(i) for i in res)))


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


from bisect import bisect_left

def main():
	n = int(input().strip())
	s = input().strip()
	result = []
	fronts = []
	for c in s:
		i = bisect_left(fronts, -ord(c))
		if i >= len(fronts):
			fronts.append(-ord(c))
		else:
			fronts[i] = -ord(c)
		result.append(str(i + 1))
	print(len(fronts))
	print(' '.join(result))
main()


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


def main():
	n = int(input())
	s = input()
	lst = ['a'] * n
	ans = []
	m = 0
	for i in range(n):
		for j in range(n):
			if lst[j] <= s[i]:
				lst[j] = s[i]
				ans.append(j + 1)
				m = max(m, j + 1)
				break
	print(m)
	print(*ans)
main()


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())
s = input()
rama = []
for i in range(n):
	rama.append(ord(s[i]) - 96)
visit = [1 for i in range(27)]
a = []
maxi = 0
for i in range(n):
	p = visit[rama[i]]
	a.append(p)
	maxi = max(maxi, p)
	for j in range(rama[i]):
		visit[j] = max(visit[j], p + 1)
print(maxi)
for i in a:
	print(i, end=' ')


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


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


n = int(input())
s = input()
prev = -1
ans = ''
t = -1
flag = 1
for i in range(n):
	cur = ord(s[i]) - ord('a')
	if cur >= prev:
		ans += '1'
		prev = cur
	else:
		if cur < t:
			flag = 0
			break
		t = cur
		ans += '0'
if flag:
	print('YES')
	print(ans)
else:
	print('NO')


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


from math import *
n = int(input())
s = input()
pre = [0 for i in range(n)]
pre[0] = 1
prev = s[0]
lst = [-1 for i in range(26)]
lst[0] = s[0]
ct = 1
for i in range(1, n):
	for j in range(26):
		if lst[j] == -1 or lst[j] <= s[i]:
			lst[j] = s[i]
			pre[i] = j + 1
			ct = max(ct, j + 1)
			break
print(ct)
for i in pre:
	print(i, end=' ')


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


n = int(input())
it = list(input())
it = [ord(i) - 97 for i in it]
lds = [1]
pre = [0 for i in range(26)]
pre[it[0]] = 1
for i in range(1, n):
	lds.append(1)
	pre[it[i]] = max(pre[it[i]], 1)
	for j in range(it[i] + 1, 26):
		pre[it[i]] = max(pre[it[i]], pre[j] + 1)
	lds[-1] = pre[it[i]]
print(max(lds))
print(*lds)


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


n = int(input())
s = input()
col = [1] * n
prev = [0] * 27
for i in range(n):
	code = ord(s[i]) - ord('a')
	col[i] = max(prev[code + 1:]) + 1
	prev[code] = col[i]
print(max(col))
print(*col)


class SegmentTree:

	def __init__(self, n, op, e):
		self.n = n
		self.op = op
		self.e = e
		self.size = 2 ** (n - 1).bit_length()
		self.node = [self.e] * (2 * self.size)

	def built(self, array):
		for i in range(self.n):
			self.node[self.size + i] = array[i]
		for i in range(self.size - 1, 0, -1):
			self.node[i] = self.op(self.data[i << 1], self.data[(i << 1) + 1])

	def update(self, i, val):
		i += self.size
		self.node[i] = val
		while i > 1:
			i >>= 1
			self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])

	def get_val(self, l, r):
		(l, r) = (l + self.size, r + self.size)
		res = self.e
		while l < r:
			if l & 1:
				res = self.op(self.node[l], res)
				l += 1
			if r & 1:
				r -= 1
				res = self.op(self.node[r], res)
			(l, r) = (l >> 1, r >> 1)
		return res
import sys
input = sys.stdin.readline
n = int(input())
s = input()
st = SegmentTree(n, max, 0)
s = sorted([(s[i], i) for i in range(n)])[::-1]
cnt = 0
for (char, i) in s:
	min_ = st.get_val(0, i)
	st.update(i, min_ + 1)
	cnt = max(cnt, min_ + 1)
print(cnt)
print(*st.node[st.size:st.size + n])


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())
a = list(input())
max_color = 0
colors = [0 for _ in range(n)]
color_to_max = [-1]
for i in range(n):
	max_ok_color = -1
	for color in range(max_color + 1):
		if ord(a[i]) >= color_to_max[color]:
			if max_ok_color == -1 or color_to_max[color] > color_to_max[max_ok_color]:
				max_ok_color = color
	if max_ok_color == -1:
		colors[i] = max_color + 1
		max_color += 1
		color_to_max.append(ord(a[i]))
	else:
		colors[i] = max_ok_color
		color_to_max[max_ok_color] = ord(a[i])
print(max_color + 1)
print(' '.join([str(item + 1) for item in colors]))


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


input()
x = ['a']
d = []
for c in input():
	i = 0
	while c < x[i]:
		i += 1
		if i == len(x):
			x.append(c)
	x[i] = c
	d.append(i + 1)
print(max(d), *d)


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)


n = int(input())
s = input()
arr = ['a' for i in range(n)]
l = []
for i in s:
	for j in range(n):
		if i >= arr[j]:
			arr[j] = i
			l.append(j + 1)
			break
print(max(l))
print(*l)


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


def solve():
	for i in range(n):
		mine = i
		for j in range(i, n):
			if s[j] < s[mine]:
				mine = j
		if mine != i:
			color = -1
			for k in range(i, mine):
				if ans[ind[k]] != -1:
					if color != -1 and color != ans[ind[k]]:
						return False
					color = ans[ind[k]]
			if color == -1:
				ans[ind[mine]] = 0
				color = 1
			elif ans[ind[mine]] == -1:
				ans[ind[mine]] = 1 - color
			else:
				if ans[ind[mine]] != 1 - color:
					return False
				ans[ind[mine]] = 1 - color
			for k in range(i, mine):
				ans[ind[k]] = color
			tmp = s[mine]
			tmpind = ind[mine]
			for k in range(mine, i, -1):
				s[k] = s[k - 1]
				ind[k] = ind[k - 1]
			s[i] = tmp
			ind[i] = tmpind
	return True
n = int(input())
s = list(input())
ans = [-1] * n
ind = list(range(n))
if solve():
	print('YES')
	for i in range(n):
		if ans[i] == -1:
			ans[i] = 0
	for i in ans:
		print(i, end='')
	print()
else:
	print('NO')


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


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n').split(' ')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
n = val()
s = st()
l = [-(ord(i) - ord('a')) for i in s]
dp = [float('inf')] * n
ind = 0
ans = []
for i in l:
	ind = bl(dp, i)
	ans.append(ind + 1)
	dp[ind] = i
print(max(ans), *ans, sep='\n')


t = 1
while t != 0:
	t -= 1
	n = int(input())
	s = input()
	aux = 'abcdefghijklmnopqrstuvwxyz'
	maxi = [0 for _ in range(26)]
	dp = [1 for _ in range(n)]
	for i in range(n):
		for j in range(aux.find(s[i]) + 1, 26):
			dp[i] = max(dp[i], maxi[j] + 1)
		maxi[aux.find(s[i])] = dp[i]
	st = set(dp)
	print(len(st))
	print(*dp)


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)


def f(s, n):
	s = list(s)
	temp = list(zip(s, range(n)))
	ans = [-1] * n
	for i in range(0, n):
		for j in range(n - i - 1):
			if temp[j][0] > temp[j + 1][0]:
				if ans[temp[j][1]] == ans[temp[j + 1][1]] == -1:
					(temp[j], temp[j + 1]) = (temp[j + 1], temp[j])
					ans[temp[j][1]] = 1
					ans[temp[j + 1][1]] = 0
				elif ans[temp[j][1]] != -1 and ans[temp[j + 1][1]] == -1:
					ans[temp[j + 1][1]] = ans[temp[j][1]] ^ 1
					(temp[j], temp[j + 1]) = (temp[j + 1], temp[j])
				elif ans[temp[j + 1][1]] != -1 and ans[temp[j][1]] == -1:
					ans[temp[j][1]] = ans[temp[j + 1][1]] ^ 1
					(temp[j], temp[j + 1]) = (temp[j + 1], temp[j])
				elif ans[temp[j + 1][1]] ^ ans[temp[j][1]] == 1:
					(temp[j], temp[j + 1]) = (temp[j + 1], temp[j])
	l = ''
	for i in range(len(temp)):
		l += temp[i][0]
		if ans[temp[i][1]] == -1:
			ans[temp[i][1]] = 0
	if list(l) != sorted(l):
		return 'NO'
	print('YES')
	print(*ans, sep='')
	return ''
n = int(input())
s = input()
print(f(s, n))


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


def binSearch(a, n):
	(i, j) = (0, len(a) - 1)
	while i != j:
		if (j - i) % 2 == 1:
			if a[i + (j - i) // 2] > n:
				i = i + (j - i) // 2 + 1
			else:
				j = i + (j - i) // 2
		elif a[i + (j - i) // 2] > n:
			i = i + (j - i) // 2
		else:
			j = i + (j - i) // 2
	return i
(n, s) = (int(input()), input())
k = 'aa'
ans = ''
maxColor = 1
for symb in s:
	i = binSearch(k, symb)
	ans += str(i + 1) + ' '
	if i + 1 > maxColor:
		maxColor = i + 1
		k += 'a'
	k = k[:i] + symb + k[i + 1:]
print(maxColor)
print(ans)


n = int(input())
s = list(str(input()))
for i in range(n):
	s[i] = ord(s[i]) - ord('a') + 1
dp = [[[0] * 27 for i in range(27)] for j in range(n + 1)]
dp[0][0][0] = ''
p = [[[0] * 27 for i in range(27)] for j in range(n + 1)]
for i in range(n):
	c = s[i]
	for j in range(27):
		for k in range(27):
			if dp[i][j][k] == 0:
				continue
			if c >= j:
				dp[i + 1][c][k] = 1
				p[i + 1][c][k] = [[j, k], '0']
			if c >= k:
				dp[i + 1][j][c] = 1
				p[i + 1][j][c] = [[j, k], '1']
x = -1
y = -1
for j in range(27):
	for k in range(27):
		if dp[-1][j][k] != 0:
			x = j
			y = k
if x == -1 and y == -1:
	print('NO')
	exit()
ans = ''
for i in reversed(range(n)):
	prvx = p[i + 1][x][y][0][0]
	prvy = p[i + 1][x][y][0][1]
	ans = p[i + 1][x][y][1] + ans
	x = prvx
	y = prvy
print('YES')
print(ans)


n = int(input())
s = input()
f = [0 for _ in range(26)]
ans = [1 for _ in range(n)]
for i in range(n):
	c = ord(s[i]) - ord('a')
	for j in range(c + 1, 26):
		ans[i] = max(ans[i], f[j] + 1)
	f[c] = max(f[c], ans[i])
ketqua = max(ans)
print(ketqua)
for i in ans:
	print(i, end=' ')


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


def hello_nigga():
	n = int(input())
	s = input()
	LAST = {1: 'a'}
	COLORS = {1: []}
	cnum = 1
	for i in range(n):
		nice = 0
		for j in range(1, cnum + 1):
			if s[i] >= LAST[j]:
				LAST[j] = s[i]
				COLORS[j].append(i)
				nice = 1
				break
		if not nice:
			cnum += 1
			LAST[cnum] = s[i]
			COLORS[cnum] = [i]
	ans = [0] * n
	for i in range(1, cnum + 1):
		for j in range(len(COLORS[i])):
			ans[COLORS[i][j]] = i
	print(cnum)
	print(*ans)
if 'compiler is alive':
	if 'it has sence' and 'the wether is nice':
		hello_nigga()


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


class RangeMinimumQuery:

	def __init__(self, n, func=min, inf=float('inf')):
		self.n0 = 2 ** (n - 1).bit_length()
		self.op = func
		self.inf = inf
		self.data = [self.inf] * (2 * self.n0)

	def query(self, l, r):
		l += self.n0
		r += self.n0
		res = self.inf
		while l < r:
			if r & 1:
				r -= 1
				res = self.op(res, self.data[r - 1])
			if l & 1:
				res = self.op(res, self.data[l - 1])
				l += 1
			l >>= 1
			r >>= 1
		return res

	def update(self, i, x):
		i += self.n0 - 1
		self.data[i] = x
		while i:
			i = ~-i // 2
			self.data[i] = self.op(self.data[2 * i + 1], self.data[2 * i + 2])
n = int(input())
s = input()
a = [(c, i) for (i, c) in enumerate(s)]
a.sort()
RMQ = RangeMinimumQuery(n, max, 0)
col = [0] * n
for (_, i) in a:
	c = RMQ.query(i, n) + 1
	col[i] = c
	RMQ.update(i, c)
max_col = RMQ.query(0, n)
print(max_col)
print(*col)


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


n = int(input())
s = [ord(i) - ord('a') + 1 for i in input()]
clr = ['1'] * n
current = 1
x = s[0]
last = [27, 1]
for i in range(n):
	if s[i] >= x:
		x = s[i]
		last[1] = s[i]
	else:
		check = [s[i] < j for j in last]
		if False in check:
			c = check.index(False)
			last[c] = s[i]
		else:
			current += 1
			c = current
			last.append(s[i])
		clr[i] = str(c)
print(len(set(clr)))
print(' '.join(clr))


n = int(input())
s = input()
(b, w) = ([s[0]], [])
ans = 'YES'
for i in range(1, n):
	if s[i] >= b[-1]:
		b.append(s[i])
	elif len(w) == 0 or s[i] >= w[-1]:
		w.append(s[i])
	else:
		ans = 'NO'
		break
if ans == 'YES':
	print(ans)
	(j, k) = (0, 0)
	for i in range(n):
		if j < len(b) and s[i] == b[j]:
			print('0', end='')
			j += 1
		else:
			print('1', end='')
			k += 1
	print()
else:
	print(ans)


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


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()
qq = []
ans = []
for c in s:
	for (j, q) in enumerate(qq):
		if c >= q:
			qq[j] = c
			ans.append(j + 1)
			break
	else:
		qq.append(c)
		ans.append(len(qq))
print(len(qq))
print(' '.join(map(str, ans)))


import math, sys
from collections import defaultdict
input = sys.stdin.readline
n = int(input())
s = input().strip()
color = [1 for i in range(n)]
d = defaultdict(int)
for i in 'abcdefghijklmnopqrst':
	d[i] = 0
for i in range(n):
	c = 0
	for j in range(1, 26):
		if ord(s[i]) + j > ord('z'):
			break
		c = max(c, d[chr(ord(s[i]) + j)])
	color[i] = c + 1
	d[s[i]] = c + 1
print(max(color))
print(*color)


n = int(input())
x = input()
s = [''] * n
for i in range(0, n, 1):
	s[i] = x[i]
ok = True
color = [-1] * n
ocolor = [-1] * n

def swap(i, j):
	global color, s, ocolor
	for index in range(j, i, -1):
		tmpx = s[index]
		tmpc = color[index]
		s[index] = s[index - 1]
		color[index] = color[index - 1]
		s[index - 1] = tmpx
		color[index - 1] = tmpc
	return
for i in range(0, n, 1):
	one = False
	zero = False
	alpha = []
	index = -1
	for j in range(0, i, 1):
		if s[j] <= s[i] and index != -1 or s[j] > s[i]:
			c = color[j]
			if c == -1:
				alpha.append(j)
			elif c == 1:
				one = True
			else:
				zero = True
			if index == -1:
				index = j
	if one and zero:
		ok = False
		break
	elif len(alpha) > 0 and (not (one or zero)):
		one = True
	for j in range(0, len(alpha), 1):
		if one:
			color[alpha[j]] = 1
			ocolor[alpha[j]] = 1
		else:
			color[alpha[j]] = 0
			ocolor[alpha[j]] = 0
	if one:
		color[i] = 0
		ocolor[i] = 0
	elif zero:
		color[i] = 1
		ocolor[i] = 1
	else:
		continue
	swap(index, i)
if ok:
	print('YES')
	for i in range(0, n, 1):
		if ocolor[i] == -1:
			ocolor[i] = 1
		print(ocolor[i], end='')
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='')


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

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

def solve():
	n = ri()
	s = input().strip()
	codes = [-1] * n
	highest = {i: 0 for i in range(ord('a'), ord('z') + 1)}
	for (p, c) in enumerate(s):
		max_before = 0
		for i in range(ord(c) + 1, ord('z') + 1):
			max_before = max(max_before, highest[i])
		codes[p] = max_before + 1
		highest[ord(c)] = max_before + 1
	print(max(highest.values()))
	print(*codes)
solve()


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')
from math import gcd, ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
	n = int(input())
	s = input()
	ans = [0] * n
	colors = ['a'] * 50
	for i in range(n):
		for j in range(50):
			if ord(s[i]) >= ord(colors[j]):
				colors[j] = s[i]
				ans[i] = j + 1
				break
	print(max(ans))
	print(*ans)


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


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)
print(maxres)
for i in res:
	print(i, end=' ')


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


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	x = f.readline().strip()
	return int(x)

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())
import string

def solution(s, n):
	lower = string.ascii_lowercase
	dp = [0 for i in range(n)]
	dp[0] = (0, -1)
	d = {c: None for c in lower}
	d[s[0]] = 0
	for i in range(1, n):
		d[s[i]] = i
		max_len = 0
		max_i = -1
		for c in lower:
			if d[c] is None:
				continue
			j = d[c]
			if s[j] > s[i]:
				if dp[j][0] + 1 > max_len:
					max_len = max(max_len, dp[j][0] + 1)
					max_i = j
		dp[i] = (max_len, max_i)
	colors = [x[0] + 1 for x in dp]
	num_colors = max(dp, key=lambda x: x[0])[0] + 1
	print(num_colors)
	return ' '.join(map(str, colors))

def main():
	T = 1
	for i in range(T):
		n = read_int()
		s = read_string()
		x = solution(s, n)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


import sys

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

def f(char):
	return ord(char) - ord('a')

def slv():
	n = int(input())
	a = list(input())
	a = list(map(f, a))
	if n == 1:
		print('YES')
		print(0)
		return
	ans = [0] * n
	sorted_ans = [0] * n
	for i in range(n - 2, -1, -1):
		v = a[i]
		if v > a[i + 1]:
			ans[i] = 1
			sorted_ans[i] = 1
			for j in range(i, n - 1):
				if a[j] > a[j + 1]:
					if sorted_ans[j] == sorted_ans[j + 1]:
						print('NO')
						return
					else:
						(a[j], a[j + 1]) = (a[j + 1], a[j])
						(sorted_ans[j], sorted_ans[j + 1]) = (sorted_ans[j + 1], sorted_ans[j])
				else:
					break
		else:
			continue
	print('YES')
	print(''.join(map(str, ans)))
	return

def main():
	t = 1
	for i in range(t):
		slv()
	return
main()


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 os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
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')

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=10 ** 6, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(10)]
pp = [0] * 10

def SieveOfEratosthenes(n=10):
	p = 2
	c = 0
	while p * p <= n:
		if prime[p] == True:
			c += 1
			for i in range(p, n + 1, p):
				pp[i] += 1
				prime[i] = False
		p += 1

def binarySearch(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = arr[n - 1]
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] >= key:
			res = arr[mid]
			right = mid - 1
		else:
			left = mid + 1
	return res

def binarySearch1(arr, n, key):
	left = 0
	right = n - 1
	mid = 0
	res = arr[0]
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] > key:
			right = mid - 1
		else:
			res = arr[mid]
			left = mid + 1
	return res
n = int(input())
s = input()
curr = [''] * 100
m = 1
res = []
for i in range(n):
	for j in range(100):
		if s[i] >= curr[j]:
			curr[j] = s[i]
			res.append(j + 1)
			break
print(max(res))
print(*res)


import sys
input = sys.stdin.readline
l = [0] * 26
n = int(input())
pres = [0] * 30
s = input()
s = s[:len(s) - 1]
res = [1] * n
ii = -1
mxx = -1
for i in s:
	ii += 1
	ind = ord(i) - ord('a')
	lol = 0
	mx = 1
	for j in range(ind + 1, 26):
		if pres[j] != 0:
			lol = 1
			if l[j] != 0:
				if mx < l[j]:
					mx = l[j]
	pres[ind] = 1
	if lol == 1:
		l[ind] = mx + 1
		res[ii] = mx + 1
	if res[ii] > mxx:
		mxx = res[ii]
print(mxx)
print(*res)


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


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

def binsearch(arr, left, right, x):
	l = left
	r = right + 1
	while l < r:
		mid = (l + r) // 2
		if arr[mid][-1] > x:
			l = mid + 1
		else:
			r = mid
	return l
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
piles = []
for i in range(n):
	ind = binsearch(piles, 0, len(piles) - 1, move[i])
	if ind >= len(piles):
		piles.append([move[i]])
	else:
		piles[ind].append(move[i])
colors = [-1] * n
for i in range(len(piles)):
	for j in range(len(piles[i])):
		colors[piles[i][j]] = i
ans = [-1] * n
for i in range(n):
	ans[i] = colors[move[i]]
print(len(piles))
for num in ans:
	print(num + 1, end=' ')
print()


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]
print(max(ans))
for i in ans:
	print(i, end=' ')


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


import sys
input = sys.stdin.readline

def main():
	N = int(input())
	S = input().strip()
	color = []
	ans = []
	for (i, s) in enumerate(S):
		if i == 0:
			color.append(ord(s) - ord('a'))
			ans.append(1)
		else:
			for j in range(len(color)):
				if ord(s) - ord('a') >= color[j]:
					color[j] = ord(s) - ord('a')
					ans.append(j + 1)
					break
			else:
				ans.append(len(color) + 1)
				color.append(ord(s) - ord('a'))
	else:
		print(len(color))
		print(*ans)
main()


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


n = int(input())
s = input()
alpha = [0] * 26
col = []
for i in range(0, len(s)):
	c = 0
	for j in range(ord(s[i]) - 97 + 1, 26):
		c = max(c, alpha[j])
	col.append(c + 1)
	alpha[ord(s[i]) - 97] = c + 1
print(max(col))
print(*col)


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 + 1)
			break
print(26 - b.count(0))
print(*ans)


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