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.util.ArrayList;
public class LongestDecreasingSubSequence {
     public static void main (String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        /*String[] str = br.readLine().split(" ");
        int[] inp =  new int[str.length];
        for (int i = 0;i<inp.length ;i++ ) {
            inp[i] = Integer.valueOf(str[i]);
        }*/
        int n1 = Integer.valueOf(br.readLine());
        String str = br.readLine();
        
        int n = str.length();
        int[] inp = new int[n];
        for (int i = 0; i < n; i++) {
			inp[i] = str.charAt(i) -'a';
		}
        Arr a = new Arr(inp);
        a.longestDecreasingSubsequence();
        //System.out.println(a.longestDecreasingSubsequence());
     }
}
class Arr{
    private int[] inp;
    public Arr(int[] inp) {
        this.inp = inp;
    }
    public int longestDecreasingSubsequenceLog(){
       int[] lElem = new int[inp.length] ;
       int[] lis = new int[inp.length];
       int[] dp = new int[inp.length];
       int maxL = -1;
       for (int i =0; i<inp.length; i++) {
            int start = 0;
            int end = maxL;//lelem is sorted decreasingly
            int elem = inp[i];
            while(start<=end) {
               int mid = start + (end-start )/2;
               if(inp[lElem[mid]]> elem){
                   start = mid+1;
               } else if(inp[lElem[mid]]<elem){
                   end = mid-1;
               } else {//equal found
                   break; // found no action required
               }
            }
            if(start>maxL){
            	if(maxL != -1) {	

                    lis[maxL] = lElem[maxL];
            	}
                maxL = maxL +1;
                lElem[maxL] = i ;
            } else{
                lElem[start] = i;
            }
            dp[i] = maxL+1;
       }

        for (int j = 0; j < maxL; j++) {
			System.out.print(inp[lis[j]]);
				System.out.print(" ");
		}

        System.out.println(inp[lElem[maxL]]);
        for (int j = 0; j < inp.length; j++) {
			System.out.print(dp[j]);
				System.out.print(" ");
		}
        System.out.println();
        return maxL+1;
    }
        
    public int longestIncreasingSubsequenceLog() {
        int[] sElem = new int[inp.length];//index of the smallest elem if duplicates exist
        //even if inp has multiple duplicates this will always have distinct elems
        int[] lis = new int[inp.length];
        int maxL = -1;
        for (int i =0; i<inp.length; i++) {
            //binary search the samllest elem
            int start = 0;
            int end = maxL;
            int found = -1;
            int elem = inp[i];
            while(start<=end){
            	
                int mid =start+ (end -start)/2; 
                /*if(start == end) {
                	//mid will be start
                	System.out.println("equal: elem "+ elem  );
            		System.out.println(start + " " + inp[sElem[start]]);
            	}*/
                if (inp[sElem[mid]]>elem){
                    end = mid-1;
                }else if(inp[sElem[mid]]<elem){
                    start = mid +1;
                }else if(inp[sElem[mid]]==elem){
                    found = mid;
                    break;
                }
            }
            if(start>maxL){ //greateer than all add a new LIS and extend
                sElem[maxL +1] = i; //index of curr elem
                maxL = maxL +1;
                if(maxL >0) {
                    lis[maxL-1] = sElem[maxL -1];
                }
            }else if(found!= -1) {
            	continue;
            }
            else{//replace start -1 vs end +1 inplies it is 
            	/* not found impleies it was in a one elem situation can be
            	 * start = end
            	 */

                sElem[start] = i;
            }
            /*for (int j = 0; j <=maxL; j++) {
				System.out.print(inp[sElem[j]] + " ");
			}
            System.out.println();*/
            
        }
        /*for (int j = 0; j < maxL; j++) {
			System.out.print(inp[lis[j]]);
				System.out.print(" ");
		}

        System.out.println(inp[sElem[maxL]]);*/
        return maxL+1;
        //index is the length   
    }
    public int binarySearch(int[] arr, int  l, int elem ){
        //this will not suffice as there is a swap required
        int start = 0;
        int end = l;
        int found = -1;
        while(start<=end){// <= becasue the if one elem also we need to see and then start will be end
            int mid =start+ (end -start)/2;  // do cases for mid if l is odd if l is even 
            /*
             * l = 5 start = 0 end = 4 0 + 4 -0/2 = 2 right
             * l = 4 start = 0 end = 3 0 +3/2  = 1 this is also fine
             * l = 8 star = 5 end = 8 5 + (0 +3/2) = 6
             *      5+8/2 = 11
             *  upper of 5+8/2 does it  but go with your intuitive way alwasy
             *  best way to analyse mids is to actually print it for various array lengths that way you know whether you are correct or not
             */
            if (inp[arr[mid]]>elem){// three cases less greater and equals
                end = mid-1;
            }else if(inp[arr[mid]]<elem){
                start = mid +1;
            }else if(inp[arr[mid]]==elem){
                found = mid;
                break;
            }
            /*
             * need to analyse what happens to start end if not found which is the smalles number less than elem
             * start always
             * think why
             */
        }
        return found;
    }

    public int longestincreasingsubsequence(){
        int[] l = new int[inp.length];
        int[] m = new int[inp.length];
        int pm = 0;
        for (int i = 0;i<inp.length ; i++) {
            if(i==0){
               l[i]  = 1;
                m[pm] = -1;
                pm++;
            }else{
                int max = 0;
                int matchj = 0;
                for (int j= 0;j<i ;j++ ) {
                    if(inp[j]<inp[i]){
                        if(l[j]> max){
                            max = l[j];
                            matchj = j;
                        }
                    }
                }
                if(max!=0){
                    l[i] = max +1;
                    m[pm] = matchj;
                    pm++;
                }else{
                    l[i] = 1;
                    m[pm] = -1;
                    pm++;
                }                
            }
        }
        int maxlength = 0;
        int index = -1;
        for (int i = 0; i < l.length; i++) {
			if(l[i]>maxlength) {
				maxlength = l[i];
				index = i;
			}
		}
        //printsubseq(m,index);
        return maxlength;

    }
    public int longestDecreasingSubsequence(){
        int[] l = new int[inp.length];
        int[] m = new int[inp.length];
        int[] redL = new int[26];//reduced L owing to only 26 possiblilties
        int pm = 0;
        for (int i = 0;i<inp.length ; i++) {
            if(i==0){
               l[i]  = 1;

               redL[inp[i]] = 1;
                m[pm] = -1;
                pm++;
            }else{
                int max = 0;
                int matchj = 0;
                for (int j= inp[i]+1 ;j<26 ;j++ ) {//Decreasing
                    if(redL[j]>max){
                         max = redL[j];
                         matchj = j;
                    }
                }
                if(max!=0){
                    l[i] = max +1;
                    redL[inp[i]] = max +1;
                    m[pm] = matchj;
                    pm++;
                }else{
                    l[i] = 1;
                    redL[inp[i]] = 1;
                    m[pm] = -1;
                    pm++;
                }                
            }
        }
        int maxlength = 0;
        int index = -1;
        for (int i = 0; i < l.length; i++) {
			if(l[i]>maxlength) {
				maxlength = l[i];
				index = i;
			}
		}
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < l.length; i++) {
			sb.append(l[i]);
			if(i<l.length) {
				sb.append(" ");
			}
		}
        System.out.println(maxlength);
        System.out.println(sb.toString());
        //printsubseq(m,index);
        return maxlength;

    }
    public int max(int a, int b) {
    	return a>b?a:b;
    }
    public void printsubseq(int[] m, int start) {
    	StringBuilder sb = new StringBuilder();
    	ArrayList<Integer> ar = new ArrayList<Integer>();
    	int i = start;
    	while(i>=0 ) {
    		ar.add(inp[i]);
            i = m[i];
    	}
    	int n = ar.size();
    	for (int j = n-1; j >=0; j--) {
			sb.append(ar.get(j));
			if(j!=0) {
				sb.append(" ");
			}
		}
    	System.out.println(sb.toString());
    }
}
