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: introductory

Starter code:

Solutions:
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')
            return
for p in g2:
    for p2 in g2:
        if (p, p2) in rb:
            print('NO')
            return
print('YES')
for i in range(n):
    if i in g1:
        print('0', end='')
    else:
        print('1', 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)))

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))
    return
    
prev = temp[0]
for i in range(1, len(temp)):
    if temp[i] < prev:
        print("NO")
        return
    prev = temp[i]
print("YES")
print(''.join(str(x) for x in l1))

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


def 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)
          #  print(vis)
    if st:
        col=[str(i) for i in col]
        print("YES")
        print(''.join(col))
    else:
        print("NO")
                
            



alp = "abcdefghijklmnopqrstuvwxyz"

dic = {}
for i,s in enumerate(alp):
    dic[s] = i

lis = [-1] * 27

n = int(input())
S = input()
ans = []

for i,s in enumerate(S):

    ind = dic[s]

    ans.append(max(lis[ind+1:]) + 1)

    lis[ind] = ans[-1]

if max(ans) <= 1:

    print ("YES")
    print("".join(map(str,ans)))

else:
    print ("NO")


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

if maxres <= 2:
    print("YES")
    for i in res:
        print(i - 1, end = '')
else:
    print("NO")

n = int(input())
a = 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

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

#!/usr/bin/env python3
import sys
input = sys.stdin.readline

class SegmentTree:
    def __init__(self, a):
        # Operator
        self.op = lambda a, b : max(a, b)
        # Identity element
        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)
        # Bisect checking function 
        self._check = lambda x, acc : acc >= x
        self._acc = self.e

        self.initialize(a)

    # Initialize data
    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])

    # Update ak as x (0-indexed)
    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])

    # Min value in [l, r) (0-indexed)
    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):
        # When segment-k is at the bottom, accumulate and return.
        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 
        # When left-child isn't in range, just look at right-child. 
        if mid <= start:
            return self._bisect_forward(x, start, 2*k + 2)
        # When segment-k is in range and has no answer in it, accumulate and return -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
        # Check left-child then right-child
        vl = self._bisect_forward(x, start, 2*k + 1)
        if vl != -1:
            return vl
        return self._bisect_forward(x, start, 2*k + 2)
    
    # Returns min index s.t. start <= index and satisfy check(data[start:idx)) = True
    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):
        # When segment-k is at the bottom, accumulate and return.
        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 
        # When right-child isn't in range, just look at right-child. 
        if mid >= start:
            return self._bisect_backward(x, start, 2*k + 1)
        # When segment-k is in range and has no answer in it, accumulate and return -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
        # Check right-child then left-child
        vl = self._bisect_backward(x, start, 2*k + 2)
        if vl != -1:
            return vl
        return self._bisect_backward(x, start, 2*k + 1)
    
    # Returns max index s.t. index < start and satisfy check(data[idx:start)) = True
    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)
if max(ans) >= 3:
    print("NO")
    return
print("YES")
print("".join([str(item - 1) for item in ans]))