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.math.BigInteger;
import java.util.*;
 
public class test {
	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		PrintWriter out = new PrintWriter(outputStream);
		InputReader in = new InputReader(inputStream);
		
//		for(int i=4;i<=4;i++) {
//			InputStream uinputStream = new FileInputStream("milkvisits.in");
//			String f = i+".in";
//			InputStream uinputStream = new FileInputStream(f);
//			InputReader in = new InputReader(uinputStream);
//			PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("milkvisits.out")));
//		}
		Task t = new Task();
		t.solve(in, out);
		out.close();
	}	
	
	static class Task{
		public void solve(InputReader in, PrintWriter out) throws IOException {
			int n = in.nextInt();
			char arr[] = in.next().toCharArray();
			int c[] = new int[26];
			int ret[] = new int[n];
			ret[n-1] = 1;
			c[arr[n-1]-'a'] = 1;
			int max = 1;
			for(int i=n-2;i>=0;i--) {
				int v = 0;
				for(int j=(arr[i]-'a')-1;j>=0;j--) {
					if(c[j]>v) v=c[j];
				}
				v++;
				ret[i] = v;
				if(v>c[arr[i]-'a']) c[arr[i]-'a'] = v;
				if(v>max) max = v;
			}
			out.println(max);
			for(int i:ret) out.print(i+" ");
			out.println();
			
//			char arr[][] = {
//					{'.','.','#','#'},
//					{'.','#','.','.'},
//					{'#','.','.','#'},
//					{'#','#','#','.'}
//			};
			//Dumper.print(maxStudents(arr));
		}
	    public int maxStudents(char[][] seats) {
	    	//Dumper.print(3&1<<1);
	        int n = seats.length;
	        int m = seats[0].length;
	        int arr[][] = new int[m][n];
	        for(int i=0;i<n;i++) {
	        	for(int j=0;j<m;j++) {
	        		if(seats[i][j]=='#') arr[j][i] = 1;	        		
	        	}
	        }
	        int tmp = n;
	        n=m;m=tmp;
	        if(n==1) return find(0,0,arr[0]);
	        else if(n==2) {
	        	int max = 0;
	        	for(int i=0;i<1<<m;i++) {
	        		if(i==5) {
	        			//Dumper.print("here");
	        		}	        		
	        		int t = can(i,arr[1]);
	        		if(t==-1) continue;

	        		int p = find(0,i,arr[0]);
	        		if(p+t>max) max = p+t;
	        	}
	        	return max;
	        }else if(n==3) {
	        	int max = 0;
	        	for(int i=0;i<1<<m;i++) {	        		
	        		int t = can(i,arr[1]);
	        		if(t==-1) continue;
	        		int p1 = find(0,i,arr[0]);
	        		int p2 = find(0,i,arr[2]);
	        		if(p1+p2+t>max) max = p1+p2+t;
	        	}
	        	return max;
	        }
	        else {
	        	int l[] = new int[1<<m];
	        	int r[] = new int[1<<m];
	        	int low = n/2-1;
	        	int high = n/2;
	        	for(int i=0;i<1<<m;i++) {
	        		int ta = can(i,arr[high]);
	        		if(ta==-1) continue;
	        		int max = 0;
	        		if(high+2<n) {
	        			for(int j=0;j<1<<m;j++) {
	        				int tb = can(j,arr[high+2]);
	        				if(tb==-1) continue;
	        				int v = find(i,j,arr[high+1]);
	        				int v2 = 0;
	        				if(high+3<n) v2 = find(0,j,arr[high+3]);
	        				if(v+ta+tb+v2>max) max=v+ta+tb+v2;
	        			}
	        		}else if(high+1<n){
	        			int v = find(i,0,arr[high+1]);
	        			if(v+ta>max) max = v+ta;
	        		}
	        		r[i] = max;
	        	}
	        	for(int i=0;i<1<<m;i++) {
	        		int ta = can(i,arr[low]);
	        		if(ta==-1) continue;
	        		int max = 0;
	        		if(low-2>=0) {
	        			for(int j=0;j<1<<m;j++) {
	        				int tb = can(j,arr[low-2]);
	        				if(tb==-1) continue;
	        				int v = find(i,j,arr[low-1]);
	        				int v2 = 0;
	        				if(low-3>=0) v2 = find(0,j,arr[low-3]);
	        				if(v+v2+ta+tb>max) max = v+v2+ta+tb;
	        			}
	        		}else if(low-1>=0) {
	        			int v = find(i,0,arr[low-1]);
	        			if(v+ta>max) max = v+ta;
	        		}
	        		l[i] = max;
	        	}
	        	int ret = 0;
	        	for(int i=0;i<1<<m;i++) {
	        		for(int j=0;j<1<<m;j++) {
	        			if(can(i,j,m)) {
	        				if(l[i]+r[j]>ret) {
	        					ret = l[i]+r[j];
	        					//Dumper.print(i+" "+j);
	        				}
	        			}
	        		}
	        	}
	        	return ret;
	        }
	    }
	    int can(int k, int arr[]) {
	    	int n = arr.length;
	    	int x = 0;
	    	for(int i=0;i<n;i++) {
	    		if((k&1<<i)!=0&&arr[i]==1) return -1;
	    		if((k&1<<i)!=0) x++;
	    	}
	    	return x;
	    }
	    boolean can(int l, int r,int n) {
	    	for(int i=0;i<n;i++) {
	    		if((l&1<<i)!=0) {
	    			if((r&1<<i)!=0) return false;
	    			if((r&(1<<(i+1)))!=0) return false;
	    			if(i>0&&(r&1<<(i-1))!=0) return false;	    			
	    		}
	    	}
	    	return true;
	    }
	    int find(int l, int r, int arr[]) {
	    	int n = arr.length;
	    	int x = 0;
	    	for(int i=0;i<n;i++) {
	    		if(arr[i]==1) continue;
	    		if((l&1<<i+1)!=0) continue;
	    		if((r&1<<i+1)!=0) continue;
	    		if((l&(1<<i-1))!=0) continue;
	    		if((r&(1<<(i-1)))!=0) continue;
	    		if((l&(1<<i))!=0) continue;
	    		if((r&(1<<i))!=0) continue;
	    		x++;
	    	}
	    	return x;
	    }
	    
	    public int maxValueAfterReverse(int[] nums) {
	    	int n = nums.length;
	    	ArrayList<pair> arr = new ArrayList<pair>();
	    	int c = 0;
	    	for(int i=0;i<n-1;i++) {
	    		arr.add(new pair(nums[i],nums[i+1]));
	    		c+=Math.abs(nums[i+1]-nums[i]);
	    	}
	    	Collections.sort(arr);
	    	//c += Math.abs(arr.get(0).x-arr.get(n-2).x) + Math.abs(arr.get(0).y-arr.get(n-2).y);
	    	//c -= Math.abs(arr.get(0).x-arr.get(0).y) + Math.abs(arr.get(n-2).x-arr.get(n-2).y);
	    	return c;
	    }
 
		class edge {
			int f,t,len;
			public edge(int a, int b, int c) {
				f=a;t=b;len=c;
			}
		}
	
		class pair implements Comparable<pair>{
			int val,idx;
			public pair(int a, int b) {
				val = a;
				idx = b;
			}
			@Override
			public int compareTo(pair t) {
				return t.val-this.val;
			}
		}
		  
	    class sgt{
	    	sgt lt;
	    	sgt rt;
	    	int l,r;
	    	long sum, max, min, lazy;
	    	public sgt(int L, int R, int arr[]) {
	    		l=L;r=R;
	    		if(l==r-1) {
	    			sum = max = min = arr[l];
	    			lazy = 0;
	    			return;
	    		}
	    		lt = new sgt(l, l+r>>1, arr);
	    		rt = new sgt(l+r>>1, r, arr);
	    		pop_up();
	    	}
	    	void pop_up() {
	    		this.sum = lt.sum + rt.sum;
	    		this.max = Math.max(lt.max, rt.max);
	    		this.min = Math.min(lt.min, rt.min);
	    	}
	    	void push_down() {
	    		if(this.lazy!=0) {
	    			lt.sum+=lazy;
	    			rt.sum+=lazy;
	    			lt.max+=lazy;
	    			lt.min+=lazy;
	    			rt.max+=lazy;
	    			rt.min+=lazy;
	    			lt.lazy+=this.lazy;
	    			rt.lazy+=this.lazy;
	    			this.lazy = 0;
	    		}
	    	}
	    	void change(int L, int R, int v) {
	    		if(R<=l||r<=L) return;
	    		if(L<=l&&r<=R) {
	    			this.max+=v;
	    			this.min+=v;
	    			this.sum+=v*(r-l);
	    			this.lazy+=v;
	    			return;
	    		}
	    		push_down();
	    		lt.change(L, R, v);
	    		rt.change(L, R, v);
	    		pop_up();
	    	}
	    	long query_max(int L, int R) {
	    		if(L<=l&&r<=R) return this.max;
	    		if(r<=L||R<=l) return Long.MIN_VALUE;
	    		push_down();
	    		return Math.max(lt.query_max(L, R), rt.query_max(L, R));	    		
	    	}
	    	long[] query_min(int L, int R) {
	    		if(L<=l&&r<=R) return new long[] {this.min, this.l};
	    		if(r<=L||R<=l) return new long[] {Long.MAX_VALUE, 99999999};
	    		push_down();
	    		long a[] = lt.query_min(L, R);
	    		long b[] = rt.query_min(L, R);
	    		if(a[0]<b[0]) return a;
	    		else if(a[0]>b[0]) return b;
	    		else return new long[] {a[0], Math.min(a[1], b[1])};
	    		//return Math.min(lt.query_min(L, R), rt.query_min(L, R));	
	    	}
	    	long query_sum(int L, int R) {
	    		if(L<=l&&r<=R) return this.sum;
	    		if(r<=L||R<=l) return 0;
	    		push_down();
	    		return lt.query_sum(L, R) + rt.query_sum(L, R);
	    	}
	    }	   
			    	
		List<List<String>> convert(String arr[][]){
			int n = arr.length;
			List<List<String>> ret = new ArrayList<>();
			for(int i=0;i<n;i++) {
				ArrayList<String> tmp = new ArrayList<String>();
				for(int j=0;j<arr[i].length;j++) tmp.add(arr[i][j]);
				ret.add(tmp);
			}
			return ret;
		}
		
		public class TreeNode {
			int val;
			TreeNode left;
			TreeNode right;
			TreeNode(int x) { val = x; }
		}
	
		public int GCD(int a, int b) {
		   if (b==0) return a;
		   return GCD(b,a%b);
		}
		public long GCD(long a, long b) {
			   if (b==0) return a;
			   return GCD(b,a%b);
		}		
	}
	
	
    static class ArrayUtils {
        static final long seed = System.nanoTime();
        static final Random rand = new Random(seed);
 
        public static void sort(int[] a) {
            shuffle(a);
            Arrays.sort(a);
        }
 
        public static void shuffle(int[] a) {
            for (int i = 0; i < a.length; i++) {
                int j = rand.nextInt(i + 1);
                int t = a[i];
                a[i] = a[j];
                a[j] = t;
            }
        }
 
    }	
	static class BIT{
		int arr[];
		int n;
		public BIT(int a) {
			n=a;
			arr = new int[n];
		}
		int sum(int p) {
			int s=0;
			while(p>0) {
				s+=arr[p];
				p-=p&(-p);
			}
			return s;
		}
		void add(int p, int v) {
			while(p<n) {
				arr[p]+=v;
				p+=p&(-p);
			}
		}
	}
	static class DSU{
		int[] arr;
		int[] sz;
		public DSU(int n) {
			arr = new int[n];
			sz = new int[n];
			for(int i=0;i<n;i++) arr[i] = i;
			Arrays.fill(sz, 1);
		}
		public int find(int a) {
			if(arr[a]!=a) arr[a] = find(arr[a]);
			return arr[a];
		}
		public void union(int a, int b) {
			int x = find(a);
			int y = find(b);
			if(x==y) return;
			arr[y] = x;
			sz[x] += sz[y];
		}
		public int size(int x) {
			return sz[find(x)];
		}
	}	
	static class MinHeap<Key> implements Iterable<Key> {
		private int maxN;
		private int n;
		private int[] pq;
		private int[] qp;
		private Key[] keys;
		private Comparator<Key> comparator;
		
		public MinHeap(int capacity){
			if (capacity < 0) throw new IllegalArgumentException();
			this.maxN = capacity;
			n=0;
			pq = new int[maxN+1];
			qp = new int[maxN+1];
			keys = (Key[]) new Object[capacity+1];
			Arrays.fill(qp, -1);
		}
		
		public MinHeap(int capacity, Comparator<Key> c){
			if (capacity < 0) throw new IllegalArgumentException();
			this.maxN = capacity;
			n=0;
			pq = new int[maxN+1];
			qp = new int[maxN+1];
			keys = (Key[]) new Object[capacity+1];
			Arrays.fill(qp, -1);
			comparator = c;
		}			
		public boolean isEmpty()	{ return n==0; 	}
		public int size()			{ return n;		}
		public boolean contains(int i) {
	        if (i < 0 || i >= maxN) throw new IllegalArgumentException();
	        return qp[i] != -1;
		}	
		public int peekIdx() {
	        if (n == 0) throw new NoSuchElementException("Priority queue underflow");
	        return pq[1];		
		}	
		public Key peek(){
			if(isEmpty()) throw new NoSuchElementException("Priority queue underflow");
			return keys[pq[1]];
		}
		public int poll(){
			if(isEmpty()) throw new NoSuchElementException("Priority queue underflow");
			int min = pq[1];
			exch(1,n--);
			down(1);
			assert min==pq[n+1];
			qp[min] = -1;
			keys[min] = null;		
			pq[n+1] = -1;
			return min;
		}
	    public void update(int i, Key key) {
	        if (i < 0 || i >= maxN) throw new IllegalArgumentException();
	        if (!contains(i)) {
	        	this.add(i, key);
	        }else {
	        	keys[i] = key;
	        	up(qp[i]);
	        	down(qp[i]);
	        }
	    }	
		private void add(int i, Key x){
	        if (i < 0 || i >= maxN) throw new IllegalArgumentException();
	        if (contains(i)) throw new IllegalArgumentException("index is already in the priority queue");
	        n++;
	        qp[i] = n;
	        pq[n] = i;
	        keys[i] = x;
	        up(n);
		}
		private void up(int k){
			while(k>1&&less(k,k/2)){
				exch(k,k/2);
				k/=2;
			}
		}
		private void down(int k){
			while(2*k<=n){
				int j=2*k;
				if(j<n&&less(j+1,j)) j++;
				if(less(k,j)) break;
				exch(k,j);
				k=j;
			}
		}
		
		public boolean less(int i, int j){
	        if (comparator == null) {
	            return ((Comparable<Key>) keys[pq[i]]).compareTo(keys[pq[j]]) < 0;
	        }
	        else {
	            return comparator.compare(keys[pq[i]], keys[pq[j]]) < 0;
	        }
		}
 
		public void exch(int i, int j){
	        int swap = pq[i];
	        pq[i] = pq[j];
	        pq[j] = swap;
	        qp[pq[i]] = i;
	        qp[pq[j]] = j;
		}
 
		@Override
		public Iterator<Key> iterator() {
			// TODO Auto-generated method stub
			return null;
		}
	}  	
 
    private static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int zcurChar;
        private int znumChars;
        private SpaceCharFilter filter;
 
        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }
 
        public int read()
        {
            if (znumChars == -1)
                throw new InputMismatchException();
            if (zcurChar >= znumChars)
            {
            	zcurChar = 0;
                try
                {
                    znumChars = stream.read(buf);
                } catch (IOException e)
                {
                    throw new InputMismatchException();
                }
                if (znumChars <= 0)
                    return -1;
            }
            return buf[zcurChar++];
        }
 
        public int nextInt()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
 
        public String nextString()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
 
        public double nextDouble()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.')
            {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.')
            {
                c = read();
                double m = 1;
                while (!isSpaceChar(c))
                {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }
 
        public long nextLong()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do
            {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
 
        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
 
        public String next()
        {
            return nextString();
        }
 
        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
        public int[] readIntArray(int n) {
            int[] ret = new int[n];
            for (int i = 0; i < n; i++) {
                ret[i] = nextInt();
            }
            return ret;
        }        
    }    
 
	static class Dumper {
		static void print_int_arr(int[] arr) {
			for (int i = 0; i < arr.length; i++) {
				System.out.print(arr[i] + " ");
			}
			System.out.println();
			System.out.println("---------------------");
		}
 
		static void print_char_arr(char[] arr) {
			for (int i = 0; i < arr.length; i++) {
				System.out.print(arr[i] + " ");
			}
			System.out.println();
			System.out.println("---------------------");
		}
 
		static void print_double_arr(double[] arr) {
			for (int i = 0; i < arr.length; i++) {
				System.out.print(arr[i] + " ");
			}
			System.out.println();
			System.out.println("---------------------");
		}
 
		static void print_2d_arr(int[][] arr, int x, int y) {
			for (int i = 0; i < x; i++) {
				for (int j = 0; j < y; j++) {
					System.out.print(arr[i][j] + " ");
				}
				System.out.println();
			}
			System.out.println();
			System.out.println("---------------------");
		}
 
		static void print_2d_arr(boolean[][] arr, int x, int y) {
			for (int i = 0; i < x; i++) {
				for (int j = 0; j < y; j++) {
					System.out.print(arr[i][j] + " ");
				}
				System.out.println();
			}
			System.out.println();
			System.out.println("---------------------");
		}
 
		static void print(Object o) {
			System.out.println(o.toString());
		}
 
		static void getc() {
			System.out.println("here");
		}
	}
}