This is a hard 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 the minimum number of 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 find the minimum number of colors which you have to color the given string in 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 ≤ n ≤ 2 ⋅ 10^5) — the length of s.

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

Output

In the first line print one integer res (1 ≤ res ≤ n) — the minimum number of colors in which you have to color the given string so that after coloring it can become sorted by some sequence of swaps.

In the second line print any possible coloring that can be used to sort the string using some sequence of swaps described in the problem statement. The coloring is the array c of length n, where 1 ≤ c_i ≤ res and c_i means the color of the i-th character.

Examples

Input


9
abacbecfd


Output


2
1 1 2 1 2 1 2 1 2 


Input


8
aaabbcbb


Output


2
1 2 1 2 1 2 1 1


Input


7
abcdedc


Output


3
1 1 1 1 1 2 3 


Input


5
abcde


Output


1
1 1 1 1 1 
import java.io.*;
import java.io.IOException;

import java.util.*;
//import javafx.util.Pair; 
//import java.util.concurrent.LinkedBlockingDeque;

//import sun.net.www.content.audio.wav;



    
   public  class Codeforces {
        
        public static long mod = (long)Math.pow(10, 9)+7 ;
        public static double epsilon=0.00000000008854;//value of epsilon
        public static InputReader sc = new InputReader(System.in);
        public static PrintWriter pw = new PrintWriter(System.out);
        
        public static long gcd(long a,long b){
            while(b>0){
                long t=b;
                b=a%b;
                a=t;
            }
            return a;
        }
        public static int fun(int n,int h,int th,int dp[][],int a[],int l,int r){
            if(n==a.length){
                if(l<=h&&r>=h)
                return 1;
                else return 0;
            }
            if(dp[n][h]>-1){
                return dp[n][h];
            }
            if(n>0&&l<=h&&r>=h){
                //pw.println(h);
                dp[n][h]=1;
            }
            else dp[n][h]=0;
            //pw.println(n+" "+(h+a[n]+th)%th+" "+(h+a[n]-1+th)%th);
            return dp[n][h]+=Math.max(fun(n+1, (h+a[n]+th)%th, th, dp, a,l,r),fun(n+1, (h+a[n]-1+th)%th, th, dp, a,l,r));
        }
        public static ArrayList<ArrayList <Integer>> GetGraph(int n,int m){
            ArrayList<ArrayList <Integer>> a=new ArrayList<>();
            for(int i=0;i<n;i++){
                a.add(new ArrayList<>());
            }
            for(int i=0;i<m;i++){
                int u=sc.nextInt()-1;
                int v=sc.nextInt()-1;
                a.get(u).add(v);
                a.get(v).add(u);
            } 
            return a;
        }
        static int dfs(int src, ArrayList<ArrayList<Integer>> list, int vis[],int dp[],int p[])
            {
                //Here 0-white,1-gray & 2-black;
            // Time complexity O(n+m)
            
            vis[src]=1;
            for(int i=0;i<list.get(src).size();i++){
                int v=list.get(src).get(i);
                if(vis[v]==0){
                    p[v]=src;
                  dp[src] += Math.max(dfs(v, list, vis, dp, p), 0);
                }
            }
            vis[src]=2;
            return dp[src];

            }

            static void dfs1(int src, ArrayList<ArrayList<Integer>> list, int vis[],int dp[],int p[])
            {
                //Here 0-white,1-gray & 2-black;
            // Time complexity O(n+m)
            
            vis[src]=1;
            
            for(int i=0;i<list.get(src).size();i++){
                int v=list.get(src).get(i);
                if(vis[v]==0){
                    //p[v]=src;
                    if(dp[v]>=0){
                        int pv=dp[src]-dp[v];
                        dp[v]+=Math.max(pv, 0);
                    }
                    else{
                        dp[v]+=Math.max(dp[src], 0);
                    }
                    dfs1(v, list, vis, dp, p);
                }
            }
            vis[src]=2;
            //return dp[src];

            }
        public static void main(String[] args) {
            // code starts..
            int n=sc.nextInt();
            String s=sc.nextLine();
            TreeSet<Integer> tr=new TreeSet<>();
            int val[]=new int[100000];
            int ans[]=new int[n];
            for(int i=0;i<n;i++){
                int v=s.charAt(i);
                Integer t=tr.floor(v);
                if(t==null){
                    tr.add(v);
                    ans[i]=tr.size();
                    val[v]=tr.size();
                }
                else{
                    ans[i]=val[t];
                    val[v]=val[t];
                    tr.remove(t);
                    tr.add(v);
                }
                
            }
            pw.println(tr.size());
            for(int i=0;i<n;i++){
                pw.print(ans[i]+" ");
            }
            
            // Code ends...
            pw.flush();
            pw.close();
        }
       
        public static Comparator<Integer[]> column(int i){
            return 
            new Comparator<Integer[]>() {
                @Override
                public int compare(Integer[] o1, Integer[] o2) {
                    return o1[i].compareTo(o2[i]);//for ascending
                    //return o2[i].compareTo(o1[i]);//for descending
                }
            };
        }
        public static String reverseString(String s){
            StringBuilder input1 = new StringBuilder(); 
            input1.append(s);  
            input1 = input1.reverse();
            return input1.toString();
        }
        public static int[] scanArray(int n){
            int a[]=new int [n];
            for(int i=0;i<n;i++)
            a[i]=sc.nextInt();
    
            return a;
        }
        public static long[] scanLongArray(int n){
            long a[]=new long [n];
            for(int i=0;i<n;i++)
            a[i]=sc.nextLong();
    
            return a;
        }
        public static String [] scanStrings(int n){
            String a[]=new String [n];
            for(int i=0;i<n;i++)
            a[i]=sc.nextLine();
    
            return a;
        }
        
    }
    
    class InputReader {
    
            private final InputStream stream;
            private final byte[] buf = new byte[8192];
            private int curChar, snumChars;
            private SpaceCharFilter filter;
    
            public InputReader(InputStream stream) {
                this.stream = stream;
            }
    
            public int snext() {
                if (snumChars == -1)
                    throw new InputMismatchException();
                if (curChar >= snumChars) {
                    curChar = 0;
                    try {
                        snumChars = stream.read(buf);
                    } catch (IOException e) {
                        throw new InputMismatchException();
                    }
                    if (snumChars <= 0)
                        return -1;
                }
                return buf[curChar++];
            }
    
            public int nextInt() {
                int c = snext();
                while (isSpaceChar(c)) {
                    c = snext();
                }
                int sgn = 1;
                if (c == '-') {
                    sgn = -1;
                    c = snext();
                }
                int res = 0;
                do {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = snext();
                } while (!isSpaceChar(c));
                return res * sgn;
            }
    
            public long nextLong() {
                int c = snext();
                while (isSpaceChar(c)) {
                    c = snext();
                }
                int sgn = 1;
                if (c == '-') {
                    sgn = -1;
                    c = snext();
                }
                long res = 0;
                do {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = snext();
                } while (!isSpaceChar(c));
                return res * sgn;
            }
    
            public int[] nextIntArray(int n) {
                int a[] = new int[n];
                for (int i = 0; i < n; i++) {
                    a[i] = nextInt();
                }
                return a;
            }
    
            public String readString() {
                int c = snext();
                while (isSpaceChar(c)) {
                    c = snext();
                }
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = snext();
                } while (!isSpaceChar(c));
                return res.toString();
            }
    
            public String nextLine() {
                int c = snext();
                while (isSpaceChar(c))
                    c = snext();
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = snext();
                } while (!isEndOfLine(c));
                return res.toString();
            }
    
            public boolean isSpaceChar(int c) {
                if (filter != null)
                    return filter.isSpaceChar(c);
                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
            }
    
            private boolean isEndOfLine(int c) {
                return c == '\n' || c == '\r' || c == -1;
            }
    
            public interface SpaceCharFilter {
                public boolean isSpaceChar(int ch);
            }
        }
        class pair implements Comparable<pair> {
            int val=0,c=0;
            pair(int v,int col){
                val=v;
                c=col;
            }
            public int compareTo(pair m) 
            { 
                return this.val - m.val; 
            } 
        }
        