//package ecr104;

import java.io.*;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Queue;

public class F {
	InputStream is;
	FastWriter out;
//	String INPUT = "11451481091145148109114514810911451481091145148109";
//	String INPUT = "99999999999999999999999999999999999999999999999999";
//	String INPUT = "37373737373737373737373737373737373737373737373737";
	String INPUT = "";

	void solve()
	{
		char[] N = ("000" + ns()).toCharArray();
		int n = N.length;
		final int D = 50;
		final int B = 1200;
		int[][] dp = new int[D][B]; // delta from ideal, previous balance = #
		final int O = 500;
		final int Q = 25;
		final int I = 9999999;
		for(int i = 0;i < D;i++)Arrays.fill(dp[i], I);
		dp[Q][O] = 0;
		for(int d = 0;d < n;d++){
			int[][] ndp = new int[D][B]; // delta from ideal, previous balance = #
			for(int i = 0;i < D;i++)Arrays.fill(ndp[i], I);

			for(int i = 0;i < D;i++) {
				for (int j = 0; j < B; j++) {
					if (dp[i][j] >= I) continue;
					int del = (i - Q) * 10 + j - O - (N[d] - '0');
					for (int k = -11; k <= 11; k++) {
						if (0 <= del + k + Q && del + k + Q < D) {
							ndp[del + k + Q][j + k] = Math.min(ndp[del + k + Q][j + k],
									dp[i][j] + Math.abs(k) * (n - d));
						}
					}
				}

			}

			dp = ndp;
		}

		int ans = Integer.MAX_VALUE;
		for(int j = 0;j < B;j++){
			ans = Math.min(ans, dp[Q][j]);
		}
		out.println(ans);
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new FastWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new F().run(); }

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private long[] nal(int n)
	{
		long[] a = new long[n];
		for(int i = 0;i < n;i++)a[i] = nl();
		return a;
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[][] nmi(int n, int m) {
		int[][] map = new int[n][];
		for(int i = 0;i < n;i++)map[i] = na(m);
		return map;
	}

	private int ni() { return (int)nl(); }

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	public static class FastWriter
	{
		private static final int BUF_SIZE = 1<<13;
		private final byte[] buf = new byte[BUF_SIZE];
		private final OutputStream out;
		private int ptr = 0;

		private FastWriter(){out = null;}

		public FastWriter(OutputStream os)
		{
			this.out = os;
		}

		public FastWriter(String path)
		{
			try {
				this.out = new FileOutputStream(path);
			} catch (FileNotFoundException e) {
				throw new RuntimeException("FastWriter");
			}
		}

		public FastWriter write(byte b)
		{
			buf[ptr++] = b;
			if(ptr == BUF_SIZE)innerflush();
			return this;
		}

		public FastWriter write(char c)
		{
			return write((byte)c);
		}

		public FastWriter write(char[] s)
		{
			for(char c : s){
				buf[ptr++] = (byte)c;
				if(ptr == BUF_SIZE)innerflush();
			}
			return this;
		}

		public FastWriter write(String s)
		{
			s.chars().forEach(c -> {
				buf[ptr++] = (byte)c;
				if(ptr == BUF_SIZE)innerflush();
			});
			return this;
		}

		private static int countDigits(int l) {
			if (l >= 1000000000) return 10;
			if (l >= 100000000) return 9;
			if (l >= 10000000) return 8;
			if (l >= 1000000) return 7;
			if (l >= 100000) return 6;
			if (l >= 10000) return 5;
			if (l >= 1000) return 4;
			if (l >= 100) return 3;
			if (l >= 10) return 2;
			return 1;
		}

		public FastWriter write(int x)
		{
			if(x == Integer.MIN_VALUE){
				return write((long)x);
			}
			if(ptr + 12 >= BUF_SIZE)innerflush();
			if(x < 0){
				write((byte)'-');
				x = -x;
			}
			int d = countDigits(x);
			for(int i = ptr + d - 1;i >= ptr;i--){
				buf[i] = (byte)('0'+x%10);
				x /= 10;
			}
			ptr += d;
			return this;
		}

		private static int countDigits(long l) {
			if (l >= 1000000000000000000L) return 19;
			if (l >= 100000000000000000L) return 18;
			if (l >= 10000000000000000L) return 17;
			if (l >= 1000000000000000L) return 16;
			if (l >= 100000000000000L) return 15;
			if (l >= 10000000000000L) return 14;
			if (l >= 1000000000000L) return 13;
			if (l >= 100000000000L) return 12;
			if (l >= 10000000000L) return 11;
			if (l >= 1000000000L) return 10;
			if (l >= 100000000L) return 9;
			if (l >= 10000000L) return 8;
			if (l >= 1000000L) return 7;
			if (l >= 100000L) return 6;
			if (l >= 10000L) return 5;
			if (l >= 1000L) return 4;
			if (l >= 100L) return 3;
			if (l >= 10L) return 2;
			return 1;
		}

		public FastWriter write(long x)
		{
			if(x == Long.MIN_VALUE){
				return write("" + x);
			}
			if(ptr + 21 >= BUF_SIZE)innerflush();
			if(x < 0){
				write((byte)'-');
				x = -x;
			}
			int d = countDigits(x);
			for(int i = ptr + d - 1;i >= ptr;i--){
				buf[i] = (byte)('0'+x%10);
				x /= 10;
			}
			ptr += d;
			return this;
		}

		public FastWriter write(double x, int precision)
		{
			if(x < 0){
				write('-');
				x = -x;
			}
			x += Math.pow(10, -precision)/2;
			//		if(x < 0){ x = 0; }
			write((long)x).write(".");
			x -= (long)x;
			for(int i = 0;i < precision;i++){
				x *= 10;
				write((char)('0'+(int)x));
				x -= (int)x;
			}
			return this;
		}

		public FastWriter writeln(char c){
			return write(c).writeln();
		}

		public FastWriter writeln(int x){
			return write(x).writeln();
		}

		public FastWriter writeln(long x){
			return write(x).writeln();
		}

		public FastWriter writeln(double x, int precision){
			return write(x, precision).writeln();
		}

		public FastWriter write(int... xs)
		{
			boolean first = true;
			for(int x : xs) {
				if (!first) write(' ');
				first = false;
				write(x);
			}
			return this;
		}

		public FastWriter write(long... xs)
		{
			boolean first = true;
			for(long x : xs) {
				if (!first) write(' ');
				first = false;
				write(x);
			}
			return this;
		}

		public FastWriter writeln()
		{
			return write((byte)'\n');
		}

		public FastWriter writeln(int... xs)
		{
			return write(xs).writeln();
		}

		public FastWriter writeln(long... xs)
		{
			return write(xs).writeln();
		}

		public FastWriter writeln(char[] line)
		{
			return write(line).writeln();
		}

		public FastWriter writeln(char[]... map)
		{
			for(char[] line : map)write(line).writeln();
			return this;
		}

		public FastWriter writeln(String s)
		{
			return write(s).writeln();
		}

		private void innerflush()
		{
			try {
				out.write(buf, 0, ptr);
				ptr = 0;
			} catch (IOException e) {
				throw new RuntimeException("innerflush");
			}
		}

		public void flush()
		{
			innerflush();
			try {
				out.flush();
			} catch (IOException e) {
				throw new RuntimeException("flush");
			}
		}

		public FastWriter print(byte b) { return write(b); }
		public FastWriter print(char c) { return write(c); }
		public FastWriter print(char[] s) { return write(s); }
		public FastWriter print(String s) { return write(s); }
		public FastWriter print(int x) { return write(x); }
		public FastWriter print(long x) { return write(x); }
		public FastWriter print(double x, int precision) { return write(x, precision); }
		public FastWriter println(char c){ return writeln(c); }
		public FastWriter println(int x){ return writeln(x); }
		public FastWriter println(long x){ return writeln(x); }
		public FastWriter println(double x, int precision){ return writeln(x, precision); }
		public FastWriter print(int... xs) { return write(xs); }
		public FastWriter print(long... xs) { return write(xs); }
		public FastWriter println(int... xs) { return writeln(xs); }
		public FastWriter println(long... xs) { return writeln(xs); }
		public FastWriter println(char[] line) { return writeln(line); }
		public FastWriter println(char[]... map) { return writeln(map); }
		public FastWriter println(String s) { return writeln(s); }
		public FastWriter println() { return writeln(); }
	}

	public void trnz(int... o)
	{
		for(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+":"+o[i]+" ");
		System.out.println();
	}

	// print ids which are 1
	public void trt(long... o)
	{
		Queue<Integer> stands = new ArrayDeque<>();
		for(int i = 0;i < o.length;i++){
			for(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));
		}
		System.out.println(stands);
	}

	public void tf(boolean... r)
	{
		for(boolean x : r)System.out.print(x?'#':'.');
		System.out.println();
	}

	public void tf(boolean[]... b)
	{
		for(boolean[] r : b) {
			for(boolean x : r)System.out.print(x?'#':'.');
			System.out.println();
		}
		System.out.println();
	}

	public void tf(long[]... b)
	{
		if(INPUT.length() != 0) {
			for (long[] r : b) {
				for (long x : r) {
					for (int i = 0; i < 64; i++) {
						System.out.print(x << ~i < 0 ? '#' : '.');
					}
				}
				System.out.println();
			}
			System.out.println();
		}
	}

	public void tf(long... b)
	{
		if(INPUT.length() != 0) {
			for (long x : b) {
				for (int i = 0; i < 64; i++) {
					System.out.print(x << ~i < 0 ? '#' : '.');
				}
			}
			System.out.println();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.Vector;

public class Test {

	static int getCount(char[] c)
	{
//		for(int i = 0; i < c.length; i++) System.out.print(c[i]+"");
//		System.out.println();
		int count = 0;
		int n = c.length;
		for(int i = 0; i < n; i++)
		{
			boolean neg_check = false;
			int ct = 0;
			for(int j = i; j < n; j++)
			{
				if(c[j] == '(') ct++;
				else
				{
					ct--;
					if(ct < 0) neg_check = true;
				}
			}
			for(int j = 0; j < i; j++)
			{
				if(c[j] == '(') ct++;
				else
				{
					ct--;
					if(ct < 0) neg_check = true;
				}
			}
			if(ct != 0) neg_check = true;
			if(!neg_check)
			{
				//System.out.print(i+" ");
				count++;
			}
		}
		//System.out.println();
		//System.out.println(count);
		return count;
	}

	public static void main(String[] args) throws Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter writer = new PrintWriter(System.out);
		int n = Integer.parseInt(br.readLine());
		String s = br.readLine();
		char[] c = s.toCharArray();
		int count = 0;
		int ind_i = 0;
		int ind_j = 0;
		char[] c1 = new char[c.length];
		for(int k = 0; k < c.length; k++) c1[k] = c[k];
		for(int i = 0; i < n-1; i++)
		{
			for(int j = i+1; j < n; j++)
			{
				char temp = c1[i];
				c1[i] = c1[j];
				c1[j] = temp;
				int gc = getCount(c1);
				if(count < gc)
				{
					count = gc;
					ind_i = i;
					ind_j = j;
				}
				for(int k = 0; k < c.length; k++) c1[k] = c[k];
			}
		}
		ind_i++;
		ind_j++;
		writer.println(count);
		writer.println(ind_i + " " + ind_j);
		br.close();
		writer.close();
	}

}


import java.io.BufferedOutputStream;
import java.io.Closeable;
import java.io.DataInputStream;
import java.io.Flushable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.function.Function;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	static class TaskAdapter implements Runnable {
		@Override
		public void run() {
			InputStream inputStream = System.in;
			OutputStream outputStream = System.out;
			FastReader in = new FastReader(inputStream);
			Output out = new Output(outputStream);
			D1TheWorldIsJustAProgrammingTaskEasyVersion solver = new D1TheWorldIsJustAProgrammingTaskEasyVersion();
			solver.solve(1, in, out);
			out.close();
		}
	}

	public static void main(String[] args) throws Exception {
		Thread thread = new Thread(null, new TaskAdapter(), "", 1<<28);
		thread.start();
		thread.join();
	}
	static class D1TheWorldIsJustAProgrammingTaskEasyVersion {
		int n;

		public D1TheWorldIsJustAProgrammingTaskEasyVersion() {
		}

		public int solve(int[] arr) {
			int[] psum = new int[n+1];
			for(int i = 0; i<n; i++) {
				psum[i+1] = psum[i]+arr[i];
			}
			SparseTable rmq = new SparseTable(psum);
			if(rmq.min(0, n)<0) {
				for(int i = 0; i<=n; i++) {
					if(i==n) {
						return 0;
					}
					if(psum[n]-psum[i+1]+rmq.min(0, i+1)>=0&&(i<n-1 ? rmq.min(i+2, n) : 0)-psum[i+1]>=0) {
						Utilities.leftShift(arr, i+1);
						break;
					}
				}
			}
			int cnt = 0, sum = 0;
			for(int i = 0; i<n; i++) {
				if((sum += arr[i])==0) {
					cnt++;
				}
			}
			return cnt;
		}

		public void solve(int kase, InputReader in, Output pw) {
			n = in.nextInt();
			int[] arr = in.nextIntChar(o -> o=='(' ? 1 : -1);
			int sum = 0;
			for(int i = 0; i<n; i++) {
				sum += arr[i];
			}
			if(sum!=0) {
				pw.println("0\n1 1");
				return;
			}
			int ans = solve(arr.clone()), l = 0, r = 0;
			for(int i = 0; i<n; i++) {
				for(int j = i+1; j<n; j++) {
					Utilities.Debug.dbg(arr);
					if(arr[i]!=arr[j]) {
						Utilities.swap(arr, i, j);
						int cnt = solve(arr.clone());
						if(cnt>ans) {
							ans = cnt;
							l = i;
							r = j;
						}
						Utilities.swap(arr, i, j);
					}
				}
			}
			pw.println(ans);
			pw.println(l+1, r+1);
		}

	}

	static class Utilities {
		public static void swap(int[] arr, int i, int j) {
			if(i!=j) {
				arr[i] ^= arr[j];
				arr[j] ^= arr[i];
				arr[i] ^= arr[j];
			}
		}

		public static void leftShift(int[] arr, int offSet) {
			int[] tmp = new int[offSet];
			System.arraycopy(arr, 0, tmp, 0, offSet);
			System.arraycopy(arr, offSet, arr, 0, arr.length-offSet);
			System.arraycopy(tmp, 0, arr, arr.length-offSet, offSet);
		}

		public static class Debug {
			public static final boolean LOCAL = System.getProperty("ONLINE_JUDGE")==null;

			private static <T> String ts(T t) {
				if(t==null) {
					return "null";
				}
				try {
					return ts((Iterable) t);
				}catch(ClassCastException e) {
					if(t instanceof int[]) {
						String s = Arrays.toString((int[]) t);
						return "{"+s.substring(1, s.length()-1)+"}";
					}else if(t instanceof long[]) {
						String s = Arrays.toString((long[]) t);
						return "{"+s.substring(1, s.length()-1)+"}";
					}else if(t instanceof char[]) {
						String s = Arrays.toString((char[]) t);
						return "{"+s.substring(1, s.length()-1)+"}";
					}else if(t instanceof double[]) {
						String s = Arrays.toString((double[]) t);
						return "{"+s.substring(1, s.length()-1)+"}";
					}else if(t instanceof boolean[]) {
						String s = Arrays.toString((boolean[]) t);
						return "{"+s.substring(1, s.length()-1)+"}";
					}
					try {
						return ts((Object[]) t);
					}catch(ClassCastException e1) {
						return t.toString();
					}
				}
			}

			private static <T> String ts(T[] arr) {
				StringBuilder ret = new StringBuilder();
				ret.append("{");
				boolean first = true;
				for(T t: arr) {
					if(!first) {
						ret.append(", ");
					}
					first = false;
					ret.append(ts(t));
				}
				ret.append("}");
				return ret.toString();
			}

			private static <T> String ts(Iterable<T> iter) {
				StringBuilder ret = new StringBuilder();
				ret.append("{");
				boolean first = true;
				for(T t: iter) {
					if(!first) {
						ret.append(", ");
					}
					first = false;
					ret.append(ts(t));
				}
				ret.append("}");
				return ret.toString();
			}

			public static void dbg(Object... o) {
				if(LOCAL) {
					System.err.print("Line #"+Thread.currentThread().getStackTrace()[2].getLineNumber()+": [");
					for(int i = 0; i<o.length; i++) {
						if(i!=0) {
							System.err.print(", ");
						}
						System.err.print(ts(o[i]));
					}
					System.err.println("]");
				}
			}

		}

	}

	static class Output implements Closeable, Flushable {
		public StringBuilder sb;
		public OutputStream os;
		public int BUFFER_SIZE;
		public boolean autoFlush;
		public String lineSeparator;

		public Output(OutputStream os) {
			this(os, 1<<16);
		}

		public Output(OutputStream os, int bs) {
			BUFFER_SIZE = bs;
			sb = new StringBuilder(BUFFER_SIZE);
			this.os = new BufferedOutputStream(os, 1<<17);
			autoFlush = false;
			lineSeparator = System.lineSeparator();
		}

		public void print(String s) {
			sb.append(s);
			if(autoFlush) {
				flush();
			}else if(sb.length()>BUFFER_SIZE >> 1) {
				flushToBuffer();
			}
		}

		public void println(int i) {
			println(String.valueOf(i));
		}

		public void println(Object... o) {
			for(int i = 0; i<o.length; i++) {
				if(i!=0) {
					print(" ");
				}
				print(String.valueOf(o[i]));
			}
			println();
		}

		public void println(String s) {
			sb.append(s);
			println();
			if(autoFlush) {
				flush();
			}else if(sb.length()>BUFFER_SIZE >> 1) {
				flushToBuffer();
			}
		}

		public void println() {
			sb.append(lineSeparator);
		}

		private void flushToBuffer() {
			try {
				os.write(sb.toString().getBytes());
			}catch(IOException e) {
				e.printStackTrace();
			}
			sb = new StringBuilder(BUFFER_SIZE);
		}

		public void flush() {
			try {
				flushToBuffer();
				os.flush();
			}catch(IOException e) {
				e.printStackTrace();
			}
		}

		public void close() {
			flush();
			try {
				os.close();
			}catch(IOException e) {
				e.printStackTrace();
			}
		}

	}

	static class SparseTable {
		public int[][] dmax;
		public int[][] dmin;

		public SparseTable(int[] arr) {
			int n = arr.length;
			dmin = new int[32][n];
			dmax = new int[32][n];
			dmin[0] = arr.clone();
			dmax[0] = arr.clone();
			for(int i = 1; 1<<i<=n; i++) {
				for(int j = 0; j+(1<<i)-1<n; j++) {
					dmin[i][j] = Math.min(dmin[i-1][j], dmin[i-1][j+(1<<i-1)]);
					dmax[i][j] = Math.max(dmax[i-1][j], dmax[i-1][j+(1<<i-1)]);
				}
			}
		}

		public int min(int i, int j) {
			if(i==j) {
				return dmin[0][i];
			}
			int k = 31-Integer.numberOfLeadingZeros(j-i);
			return Math.min(dmin[k][i], dmin[k][j-(1<<k)+1]);
		}

	}

	static class FastReader implements InputReader {
		final private int BUFFER_SIZE = 1<<16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer;
		private int bytesRead;

		public FastReader(InputStream is) {
			din = new DataInputStream(is);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String next() {
			StringBuilder ret = new StringBuilder(64);
			byte c = skip();
			while(c!=-1&&!isSpaceChar(c)) {
				ret.appendCodePoint(c);
				c = read();
			}
			return ret.toString();
		}

		public int nextInt() {
			int ret = 0;
			byte c = skipToDigit();
			boolean neg = (c=='-');
			if(neg) {
				c = read();
			}
			do {
				ret = ret*10+c-'0';
			} while((c = read())>='0'&&c<='9');
			if(neg) {
				return -ret;
			}
			return ret;
		}

		private boolean isSpaceChar(byte b) {
			return b==' '||b=='\r'||b=='\n'||b=='\t'||b=='\f';
		}

		private byte skip() {
			byte ret;
			while(isSpaceChar((ret = read()))) ;
			return ret;
		}

		private boolean isDigit(byte b) {
			return b>='0'&&b<='9';
		}

		private byte skipToDigit() {
			byte ret;
			while(!isDigit(ret = read())&&ret!='-') ;
			return ret;
		}

		private void fillBuffer() {
			try {
				bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			}catch(IOException e) {
				e.printStackTrace();
				throw new InputMismatchException();
			}
			if(bytesRead==-1) {
				buffer[0] = -1;
			}
		}

		private byte read() {
			if(bytesRead==-1) {
				throw new InputMismatchException();
			}else if(bufferPointer==bytesRead) {
				fillBuffer();
			}
			return buffer[bufferPointer++];
		}

	}

	static interface InputReader {
		String next();

		int nextInt();

		default int[] nextIntChar(Function<Character, Integer> f) {
			String s = next();
			int[] ret = new int[s.length()];
			for(int i = 0; i<s.length(); i++) {
				ret[i] = f.apply(s.charAt(i));
			}
			return ret;
		}

	}
}


import java.io.*;
import java.util.*;

public class  Main{
	static class tri{
		int l,r,v;
		tri(int x,int y,int z){
			l=x;r=y;v=z;
		}
		public String toString() {
			return l+" "+r+" "+v;
		}
	}
	public static void main(String[] args) throws Exception{
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();
		String x=sc.nextLine();
		int sum=0;
		int shift=0;
		for(int i=0;i<n;i++) {
			if(x.charAt(i)=='(')sum++;
			else {
				sum--;
				if(sum<0) {
					shift=i;
				}
			}
		}
		if(sum!=0) {
			pw.println(0);
			pw.println(1+" "+1);
			pw.flush();
			return;
		}
		StringBuilder sb=new StringBuilder();
		StringBuilder sb2=new StringBuilder();

		char[]in;

			int j=0;
			while(j<=shift) {
				sb.append(x.charAt(j));j++;
			}
			while(j<n) {
				sb2.append(x.charAt(j));j++;
			}
			StringBuilder res =(sb2.append(sb));

			in=res.toString().toCharArray();
			int i=0;
			LinkedList<Integer>l=new LinkedList<Integer>();
			LinkedList<tri>ranges=new LinkedList<Main.tri>();
			while(i<n) {
				if(in[i]=='(') {
					l.add(i);
				}
				else {
					int o=l.pollLast();
					ranges.add(new tri(o, i, i-o));
				}
				i++;
			}
			int prev=ranges.getFirst().v;
			boolean alle=true;
			for(tri o:ranges) {
				if(o.v!=prev) {
					alle=false;break;
				}
			}
			if(alle) {
				int ans=0;
				int s=0;
				for(int k=0;k<n;k++) {
					if(in[k]=='(') {
						s++;
					}
					else {
						s--;
						if(s==0) {
							ans++;
						}
					}
				}
				pw.println(ans);
				pw.println(1+" "+1);
				pw.flush();return;
			}
			tri max=new tri(1,1,-1);
			for(tri o:ranges) {
				if(o.v>max.v) {
					max=new tri(o.l,o.r,o.v);
				}
			}
			int le=max.l;int r=max.r;
			in[le]=')';in[r]='(';
			if(le==0) {
				res=new StringBuilder();
				for(int k=1;k<n;k++)res.append(in[k]);
				res.append(in[0]);
				in=res.toString().toCharArray();
			}
			int ans=0;
			int s=0;
			for(int k=0;k<n;k++) {
				if(in[k]=='(') {
					s++;
				}
				else {
					s--;
					if(s==0) {
						ans++;
					}
				}
			}
			pw.println(ans);
			int pre=shift+1;
			int rest=n-shift-1;
			if(max.l<=shift) {
				pw.print(pre+max.l+1);
			}
			else {
				pw.print(max.l-rest+1);
			}
			pw.print(" ");
			if(max.r<=shift) {
				pw.print(pre+max.r+1);
			}
			else {
				pw.print(max.r-rest+1);
			}

		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] takearr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] takearrl(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public Integer[] takearrobj(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] takearrlobj(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


import java.util.*;
import java.lang.*;
// StringBuilder uses java.lang

public class mainClass {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int si = sc.nextInt();
        String brack = sc.next();
        int[] bInts = new int[si];
        int s = 0;
        for (int i=0;i<si;i++) {
            if (brack.substring(i,i+1).equals("(")) {
                bInts[i]=1;
                s++;
            } else {
                bInts[i]=-1;
                s--;
            }
        }
        if (s!=0) {
            System.out.println(0);
            System.out.println("1 1");
        } else {
            int maxAns = countConcat(bInts);
            int left = 1;
            int right = 1;
            for (int i=0;i<n;i++) {
                for (int j=i+1;j<n;j++) {
                    if (bInts[i]!=bInts[j]) {
                        bInts[i]*=-1;
                        bInts[j]*=-1;
                        int l = countConcat(bInts);
                        if (l>maxAns) {
                            left=i+1;
                            right=j+1;
                            maxAns=l;
                        }
                        bInts[i]*=-1;
                        bInts[j]*=-1;
                    }
                }
            }
            System.out.println(maxAns);
            System.out.println(left+" "+right);
        }
    }
    public static int countConcat(int[] r) {
        int ans = 0;
        int d = 0;
        int at = 0;
        for (int i=0;i<r.length;i++) {
            at+=r[i];
            if (at==d) {
                ans++;
            } else if (at<d) {
                d=at;
                ans=1;
            }
        }
        return ans;
    }
    public static long fastPow(int base,long exp,int mod) {
        if (exp==0) {
            return 1;
        } else {
            if (exp % 2 == 1) {
                long z = fastPow(base,(exp-1)/2,mod);
                return ((((z*base) % mod) * z) % mod);
            } else {
                long z = fastPow(base,exp/2,mod);
                return ((z*z) % mod);
            }
        }
    }
}


import java.util.Scanner;
public class driver {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        for(int i = 1; i<n; i++){
            System.out.print(i);
            for(int o = 1; o<n; o++){
                Integer p = i*o;
                String q = Integer.toString(p, n);
                System.out.print(q);
            }
            System.out.println();
        }
    }
}


import java.util.Scanner;

/**
 * Created by max_b on 2/1/2017.
 */
public class driver {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        for(int i = 1; i<n; i++){

            for(int o = 1; o<n; o++){
                Integer p = i*o;
                String q = Integer.toString(p, n);
                System.out.print(q);
            }
            System.out.println();
        }
    }
}


import java.util.Scanner;
public class MultiplicationTable {

    public static void main(String[] args)
    {
       Scanner scan = new Scanner(System.in);
       int x = scan.nextInt();

       for (int i=1; i<x ; i++)
       {
           for (int j=1; j<x;j++)
           {
               System.out.print((i*j/x)*10 + (i*j%x));
           }
           System.out.println("  ");
       }
    }

}


import java.util.Scanner;
public class multiplicationTable {
    public static void main(String[] args) {
        Integer.toString(3, 4); //to convert bases
        Scanner in = new Scanner(System.in);
        int tableSize = in.nextInt();
        in.nextLine();

        System.out.println(" ");

        for (int i = 1; i < tableSize; i++) {
            for (int j = 1; j < tableSize; j++) {
                System.out.print(Integer.toString(i*j, tableSize) + " ");
            }
            System.out.println(" ");
        }

    }
}


import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
public class Main {

    public void sort(long b[]){
        Random rd = new Random();
        for(int i=1;i<b.length;++i){
            int c = rd.nextInt(i);
            long v = b[c];
            b[c] = b[i];
            b[i] = v;
        }
        Arrays.sort(b);
    }
    public void sort(int b[]){
        Random rd = new Random();
        for(int i = 1;i<b.length;++i){
            int c = rd.nextInt(i);
            int v = b[c];
            b[c]= b[i];
            b[i] = v;
        }
        Arrays.sort(b);
    }

    static int groups = 0;
    static int[] fa;
    static int[] sz;

    static void init(int n) {
        groups = n;
        fa = new int[n];
        for (int i = 1; i < n; ++i) {
            fa[i] = i;
        }
        sz = new int[n];
        Arrays.fill(sz, 1);
    }

    static int root(int p) {
        while (p != fa[p]) {
            fa[p] = fa[fa[p]];
            p = fa[p];
        }
        return p;
    }

    static void combine(int p, int q) {
        int i = root(p);
        int j = root(q);
        if (i == j) {
            return;
        }
        if (sz[i] < sz[j]) {
            fa[i] = j;
            sz[j] += sz[i];
        } else {
            fa[j] = i;
            sz[i] += sz[j];
        }
        groups--;
    }

    class Pair {
        long x;long y;
        Pair(long xx,long yy){
            x = xx;y= yy;
            long g = gcd(Math.abs(x),Math.abs(y));
            if(xx*yy>=0){
                x = Math.abs(x)/g;
                y = Math.abs(y)/g;
            }else{
                x = -Math.abs(x)/g;
                y = Math.abs(y)/g;
            }
        }

        public boolean equals(Object fk){
            Pair p = (Pair)fk;
            return x == p.x && y== p.y;
        }

        public int hashCode(){
            return (int)(x*37+y);
        }

    }

    void dfs(int g, List<Integer> go[],boolean vis[]){
        vis[g] = true;
        for(int u: go[g]){
            int to = u;
            if(!vis[to]) {
                dfs(to, go, vis);
            }
        }

    }

    public static void main(String[] args) throws Exception {
        new Main().run();}

    TreeMap<Integer,Integer> tmp = new TreeMap<>();

    void remove(int u){
        int v = tmp.get(u);
        if(v==1){
            tmp.remove(u);
        }else{
            tmp.put(u,v-1);
        }
    }

    private int len(long i) {
        int ans = 0;
        while (i > 0) {
            i /= 10;
            ans++;
        }
        return ans;
    }
    long len[] = new long[100000000];

    long go(long a,long tot){
        int p = 0;
        for(int i=1;i*i<=a;++i){
            if(a%i==0){
                len[p++] = i;
            }
        }
        int g = -1;
        long ans = tot*2+2;
        for(int i=1;i*i<=(tot);++i){
            if(tot%i==0){
                while(g+1<p&&len[g+1]<=i) g++;
                if(tot/i >= a/len[g] ){
                    ans = Math.min(ans, 2*(i+tot/i));
                }

            }
        }
        return ans;

    }

    void solve(){

        long a = nl();
        long b = nl();
        long tot = a+b;

    println(Math.min(go(a,tot),go(b,tot)));

//         PriorityQueue<int[]> q= new PriorityQueue<>((x,y)->{return x[0]-y[0];});
//
//         q.offer(new int[]{0,0});
//         boolean inq[] = new boolean[n];
//         while(q.size()>0){
//             int c[]= q.poll();
//             for(int i=h[c[1]];i!=-1;i=ne[i]){
//                 if(!inq[to[i]]) {
//                     q.offer(new int[]{ wt[i], to[i]});
//                     inq[to[i]] = true;
//                 }
//             }
//         }

    }

    int err = 0;

    void go(int rt,int pt,int fa) {
        stk[rt] = pt;
        for(int i=h[rt];i!=-1;i=ne[i]) {
            if(to[i]==pt||to[i]==fa) continue;
            go(to[i],pt,rt);
        }
    }

    int ct = 0;
    void add(int u,int v){
        to[ct] = v;

        ne[ct] = h[u];
        h[u] = ct++;
//
//        to1[ct] = u;
//        wt1[ct] = w;
//        ne1[ct] = h1[v];
//        h1[v] = ct++;
    }
    int []h,ne,to,wt,qt,stk;

    long inv(long a, long MOD) {
        //return fpow(a, MOD-2, MOD);
        return a==1?1:(long )(MOD-MOD/a)*inv(MOD%a, MOD)%MOD;
    }

    void inverse(){
        int MAXN = 10000;
        long inv[] = new long[MAXN+1];
        inv[1] = 1; //注意初始化
        long mod = 1000000007;
        for (int i=2; i<=MAXN; ++i) {
            inv[i] = (mod - mod / i) * inv[(int) (mod % i)] % mod;
        }
    }

    // 计算某个特别大的组合数
    long C(long n,long m, long MOD) {
        if(m+m>n)m=n-m;
        long up=1,down=1;
        for(long i=0;i<m;i++)
        {
            up=up*(n-i)%MOD;
            down=down*(i+1)%MOD;
        }
        return up*inv(down, MOD)%MOD;
    }

    void solve2() {

        int n = ni();
        String s=  ns();
        int g[][] = new int[3][3];
        for(int i = 0;i<n;++i){
            char c = s.charAt(i);
            int idx = 0;
            if(c=='G'){
                idx =1;
            }else if(c=='B'){
                idx =2;
            }
            g[c][i%3]++;
        }

    }

//    int []h,to,ne,wt;

    long t1[];
    //    long t2[];
    void update(long[] t,int i,long v){
        for(;i<t.length;i+=(i&-i)){
            t[i] += v;
        }
    }
    long get(long[] t,int i){
        long s = 0;
        for(;i>0;i-=(i&-i)){
            s += t[i];
        }
        return s;
    }

    int equal_bigger(long t[],long v){
        int s=0,p=0;
        for(int i=Integer.numberOfTrailingZeros(Integer.highestOneBit(t.length));i>=0;--i) {
            if(p+(1<<i)< t.length && s + t[p+(1<<i)] < v){
                v -= t[p+(1<<i)];
                p |= 1<<i;
            }
        }
        return p+1;
    }

    long gcd(long a,long b){ return b==0?a: gcd(b,a%b);}
    InputStream is;PrintWriter out;
    void run() throws Exception {is = System.in;
        //  is = new FileInputStream("C:\\Users\\Luqi\\Downloads\\P1600_2.in");

        out = new PrintWriter(System.out);solve();out.flush();}
    private byte[] inbuf = new byte[2];
    public int lenbuf = 0, ptrbuf = 0;
    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {lenbuf = is.read(inbuf);} catch (IOException e) {throw new InputMismatchException();}
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];}
    private boolean isSpaceChar(int c) {return !(c >= 33 && c <= 126);}
    private int skip() {int b;while((b = readByte()) != -1 && isSpaceChar(b));return b;}
    private double nd() {return Double.parseDouble(ns());}
    private char nc() {return (char) skip();}
    private char ncc() {int b;while((b = readByte()) != -1 && !(b >= 32 && b <= 126));return (char)b;}
    private String ns() {int b = skip();StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);b = readByte(); }
        return sb.toString();}
    private char[] ns(int n) {char[] buf = new char[n];int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b;b = readByte(); }
        return n == p ? buf : Arrays.copyOf(buf, p);}
    private String nline() {int b = skip();StringBuilder sb = new StringBuilder();
        while (!isSpaceChar(b) || b == ' ') { sb.appendCodePoint(b);b = readByte(); }
        return sb.toString();}
    private char[][] nm(int n, int m) {char[][] a = new char[n][];for (int i = 0; i < n; i++) a[i] = ns(m);return a;}
    private int[] na(int n) {int[] a = new int[n];for (int i = 0; i < n; i++) a[i] = ni();return a;}
    private long[] nal(int n) { long[] a = new long[n];for (int i = 0; i < n; i++) a[i] = nl();return a;}
    private int ni() { int num = 0, b; boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')){};
        if (b == '-') { minus = true; b = readByte(); }
        while (true) {
            if (b >= '0' && b <= '9') num = (num << 3) + (num << 1) + (b - '0');
            else return minus ? -num : num;
            b = readByte();}}
    private long nl() { long num = 0; int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')){};
        if (b == '-') { minus = true; b = readByte(); }
        while (true) {
            if (b >= '0' && b <= '9')  num = num * 10 + (b - '0');
            else return minus ? -num : num;
            b = readByte();}}
    void print(Object obj){out.print(obj);}
    void println(Object obj){out.println(obj);}
    void println(){out.println();}
}


/**
 * BaZ :D
 */
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main
{
    static Reader scan;
    static PrintWriter pw;
    public static void main(String[] args) {
        new Thread(null,null,"BaZ",1<<25)
        {
           public void run()
           {
               try
               {
                   solve();
               }
               catch(Exception e)
               {
                   e.printStackTrace();
                   System.exit(1);
               }
           }
        }.start();
    }
    static void solve() throws IOException
    {
        scan = new Reader();
        pw = new PrintWriter(System.out,true);
        StringBuilder sb = new StringBuilder();
        int t = 1;
        while(t-->0)
        {
           long a = nl();
           long b = nl();
           long a1[] = new long[10000000];
           long a2[] = new long[10000000];
           long b1[] = new long[10000000];
           long b2[] = new long[10000000];
           int na = 0,nb = 0;
           for(long i=1;i*i<=a;++i) {
               if(a%i==0){
                    a1[na] = i;
                    a2[na++] = a/i;
               }
           }
           for(long i=1;i*i<=b;++i) {
               if(b%i==0) {
                   b1[nb] = i;
                   b2[nb++] = b/i;
               }
           }
//           pl("na : "+na);
//           for(int i=0;i<na;++i)
//               p(a1[i]+","+a2[i]);
//           pl();
//           pl("nb : "+nb);
//           for(int i=0;i<nb;++i)
//               p(b1[i]+","+b2[i]);
//           pl();
           int idx1 = -1,idx2 = -1;
           long N = a+b;
           long ans = Long.MAX_VALUE;
           for(int i=1;i*i<=N;++i) {
               if(N%i==0) {
                   long bc = N/i;
                   while(idx1+1<na && a1[idx1+1]<=i)
                       idx1++;
                   while(idx2+1<nb && b1[idx2+1]<=i)
                       idx2++;
                   if(idx1!=-1) {
                       if(a2[idx1]<=bc) {
                           ans = min(ans, (i+bc)<<1);
                       }
                   }
                   if(idx2!=-1) {
                       if(b2[idx2]<=bc) {
                           ans = min(ans, (i+bc)<<1);
                       }
                   }
               }
           }
           pl(ans);
        }
        pw.flush();
        pw.close();
    }
    static int ni() throws IOException
    {
        return scan.nextInt();
    }
    static long nl() throws IOException
    {
        return scan.nextLong();
    }
    static double nd() throws IOException
    {
        return scan.nextDouble();
    }
    static void pl()
    {
        pw.println();
    }
    static void p(Object o)
    {
        pw.print(o+" ");
    }
    static void pl(Object o)
    {
        pw.println(o);
    }
    static void psb(StringBuilder sb)
    {
        pw.print(sb);
    }
    static void pa(String arrayName, Object arr[])
    {
        pl(arrayName+" : ");
        for(Object o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, int arr[])
    {
        pl(arrayName+" : ");
        for(int o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, long arr[])
    {
        pl(arrayName+" : ");
        for(long o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, double arr[])
    {
        pl(arrayName+" : ");
        for(double o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, char arr[])
    {
        pl(arrayName+" : ");
        for(char o : arr)
            p(o);
        pl();
    }
    static void pa(String listName, List<Object> list)
    {
        pl(listName+" : ");
        for(Object o : list)
            p(o);
        pl();
    }
    static class Reader {
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader() {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException {
        byte[] buf = new byte[64];
        int cnt = 0, c;
        while ((c = read()) != -1) {
            if (c == '\n') break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException {
        int ret = 0;
        byte c = read();
        while (c <= ' ') c = read();
        boolean neg = (c == '-');
        if (neg) c = read();
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0' && c <= '9');
        if (neg) return -ret;
        return ret;
    }

    public long nextLong() throws IOException {
        long ret = 0;
        byte c = read();
        while (c <= ' ') c = read();
        boolean neg = (c == '-');
        if (neg) c = read();
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0' && c <= '9');
        if (neg) return -ret;
        return ret;
    }

    public double nextDouble() throws IOException {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ') c = read();
        boolean neg = (c == '-');
        if (neg) c = read();
        do {
            ret = ret * 10 + c - '0';
        } while ((c = read()) >= '0' && c <= '9');
        if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);
        if (neg) return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1) buffer[0] = -1;
    }

    private byte read() throws IOException {
        if (bufferPointer == bytesRead) fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException {
        if (din == null) return;
        din.close();
    }
}
}


import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.InputMismatchException;

public class F1029 {
	static class Solver {

		long A, B, C;

		void solve(FastScanner s, PrintWriter out) {
			A = s.nextLong();
			B = s.nextLong();
			C = A + B;
			long best = (long) 1e18;
			long p = 1, q, a = 1, b = 1;
			while (p * p <= C) {
				if (C % p != 0) {
					p++;
					continue;
				}
				q = C / p;
				while (a * a <= A && ((A > q * a) || A % a != 0))
					a++;
				while (b * b <= B && ((B > q * b) || B % b != 0))
					b++;
				if (a * a <= A || b * b <= B)
					best = Math.min(best, 2 * (p + q));
				p++;
			}
			out.println(best);
		}

	}

	public static void main(String[] args) {

		FastScanner s = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		Solver solver = new Solver();
		solver.solve(s, out);

		out.close();

	}

	static int swap(int a, int b) {
		return a;
	}

	static Object swap(Object a, Object b) {
		return a;
	}

	static String ts(Object... o) {
		return Arrays.deepToString(o);
	}

	static class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
		}

		public FastScanner(File f) throws FileNotFoundException {
			this(new FileInputStream(f));
		}

		public FastScanner(String s) {
			this.stream = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));
		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String next() {
			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 String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}

		// Jacob Garbage

		public int[] nextIntArray(int N) {
			int[] ret = new int[N];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextInt();
			return ret;
		}

		public int[][] next2DIntArray(int N, int M) {
			int[][] ret = new int[N][];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextIntArray(M);
			return ret;
		}

		public long[] nextLongArray(int N) {
			long[] ret = new long[N];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextLong();
			return ret;
		}

		public long[][] next2DLongArray(int N, int M) {
			long[][] ret = new long[N][];
			for (int i = 0; i < N; i++)
				ret[i] = nextLongArray(M);
			return ret;
		}

		public double[] nextDoubleArray(int N) {
			double[] ret = new double[N];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextDouble();
			return ret;
		}

		public double[][] next2DDoubleArray(int N, int M) {
			double[][] ret = new double[N][];
			for (int i = 0; i < N; i++)
				ret[i] = this.nextDoubleArray(M);
			return ret;
		}

	}
}


import java.util.Scanner;

public class MultiColoredMarkers {

    public static boolean checkSmallRectangleCanBePlacedIntoBigRectangle(long smallRectangleSide, long a, long BigRectangleSide, long s){
        return ((smallRectangleSide <= BigRectangleSide) && ((a / smallRectangleSide) <= (s / BigRectangleSide)));
    }

    public static void getDividersPerValue(long n, long[] dividers){
        long sqrtOfN = (int) Math.sqrt(n);

        int i = 0;
        for (long divider = sqrtOfN; divider > 0;  divider--){
            if (n % divider == 0) {
                dividers[i++] = divider;
            }
        }
        dividers[i] = 0;
    }

    public static long checkDividers(long[] dividersForInnerRectangle, long[] dividersForExternalRectangle,
                                     long innerRectangleS, long ExternalRectangleS, long bestP){
        long newBestP = bestP;
        for (long dividerExternal : dividersForExternalRectangle){
            if (dividerExternal == 0){
                break;
            }
            for (long dividerInner : dividersForInnerRectangle){
                if (dividerInner == 0){
                    break;
                }
                if (checkSmallRectangleCanBePlacedIntoBigRectangle(dividerInner, innerRectangleS, dividerExternal, ExternalRectangleS)){
                    newBestP = Math.min(bestP, 2 * (dividerExternal + ExternalRectangleS/dividerExternal));
                    return newBestP;
                }
            }
        }
        return newBestP;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long s = a + b;
        long bestP = 2*s + 2;

        long[] dividersInner = new long[1000*1000];
        getDividersPerValue(a, dividersInner);
        long[] dividersS = new long[1000*1000];
        getDividersPerValue(s, dividersS);
        bestP = Math.min(bestP, checkDividers(dividersInner,dividersS,a,s,bestP));

        getDividersPerValue(b, dividersInner);
        bestP = Math.min(bestP, checkDividers(dividersInner,dividersS,b,s,bestP));
        System.out.println(bestP);
    }


import java.io.*;
import java.util.*;

public class D {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	static class Olymp {
		int id;
		String s;

		public Olymp(int id, String s) {
			this.id = id;
			this.s = s;
		}
	}

	void solve() throws IOException {
		int n = nextInt();
		for (int i = 0; i < n; i++) {
			String s = nextToken();
			s = s.substring(4);
			int len = s.length();
			long tail = Integer.parseInt(s);

			long start = 1989;
			long pw = 10;
			for (int j = 1; j < len; j++) {
				start += pw;
				pw *= 10;
			}

			long res = ((start - 1 - tail) / pw + 1) * pw + tail;
			out.println(res);

		}

	}

	D() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new D();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}


import java.util.*;
public class InternationalOlympiad
{
	public static final long INFINITY = 1000000000;

	public static HashSet<Long> used;
	public static HashMap<Long, Long> map;

	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);

		used = new HashSet<Long>();
		map = new HashMap<Long, Long>();

		ArrayDeque<Long> queue = new ArrayDeque<Long>();
		for(long x = 0; x < 1989; x++)
		{
			queue.add(x);
		}

		while(queue.size() > 0)
		{
			long num = queue.remove();

			long next = next(num);
			map.put(num, next);
			used.add(next);

			if(next < INFINITY)
			{
				queue.add(next);
			}
		}

		int n = in.nextInt();
		for(int y = 0; y < n; y++)
		{
			long abbr = Long.parseLong(in.next().substring(4));

			if(map.containsKey(abbr))
			{
				System.out.println(map.get(abbr));
			}
			else
			{
				System.out.println(abbr);
			}
		}
	}

	public static long next(long num)
	{
		int shift = ("" + num).length();
		long pow = 1;
		for(int i = 0; i < shift; i++)
		{
			pow *= 10;
		}

		long left = 1 * pow;
		while(true)
		{
			if(left + num >= 1989 && !used.contains(left + num))
			{
				return left + num;
			}

			left += pow;
		}
	}
}


/*
 * Code Author: Jayesh Udhani
 * Institute  : DA-IICT
 * 3rd year BTech ICT Student
 */

import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class CROC2016D
{
	static class Pair
	{
		private String first;
		private String second;
		public Pair(String i, String j)
		{
			this.first = i;
			this.second = j;
		}
		public String getFirst() { return first; }
		public String getSecond() { return second ;}
	}
	private static Pair solverUtil(String s)
	{
		int n=s.length();
		if(n==1)
			return new Pair("1989", "1998");
		else if(n==2)
			return new Pair("1999", "2098");
		else if(n==3)
			return new Pair("2099", "3098");
		else
		{
			StringBuilder sb1=new StringBuilder();
			StringBuilder sb2=new StringBuilder();
			int i=0;
			for(;i<n-4;i++)
				sb1.append("1");
			for(i=0;i<n-3;i++)
				sb2.append("1");
			sb1.append("3099");
			sb2.append("3098");
			return new Pair(new String(sb1), new String(sb2));
		}
	}
	private static String solver(String s)
	{
		Pair p=solverUtil(s);
		int n=s.length();
		BigInteger b1=new BigInteger(p.getFirst());
		BigInteger b2=new BigInteger(p.getSecond());
		if(n==1 || n==2)
		{
			while(b1.compareTo(b2)<0)
			{
				if(b1.toString().endsWith(s))
					return b1.toString();
				b1=b1.add(new BigInteger("1"));
			}
		}
		else
		{
			BigInteger t=new BigInteger(s);
			if(t.compareTo(b1)>=0 && t.compareTo(b2)<=0)
				return s;
			for(int i=1;i<=9;i++)
			{
				BigInteger t1=new BigInteger(i+s);
				if(t1.compareTo(b1)>=0 && t1.compareTo(b2)<=0)
					return i+s;
			}
		}
		return null;
	}
	public static void main(String args[])
	{
		InputReader in = new InputReader(System.in);
		OutputStream outputStream = System.out;
		PrintWriter out = new PrintWriter(outputStream);
		int n=in.nextInt(),i=0;
		for(;i<n;i++)
			System.out.println(solver(in.next().substring(4)));
		out.close();
	}
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream inputstream) {
			reader = new BufferedReader(new InputStreamReader(inputstream));
			tokenizer = null;
		}

		public String nextLine(){
			String fullLine=null;
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					fullLine=reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            for (int i = 0; i < N; i++) {
                String abr = in.next();
                int year = Integer.parseInt(abr.substring(4));
                int K = (year + "").length();
                int F = 0;
                int ten = 10;
                for (int j = 1; j < K; j++) {
                    F += ten;
                    ten *= 10;
                }

                while (year < 1989 + F) year += ten;

                out.println(year);
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class R243qESerejaAndSets {

	static final int mod = (int)1e9 + 7;
	static long pow2[];
	static int N,K;
	static int dp[][][];

	public static void main(String args[]) {
		InputReader in = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);

		pow2 = new long[551];
		pow2[0] = 1;
		for(int i=1;i<=550;i++)
			pow2[i] = (pow2[i-1] * 2) % mod;

		N = in.nextInt();
		K = in.nextInt();

		dp = new int[N + 2][K + 1][N + 1];
		for(int i=0;i<=N;i++)
			dp[N+1][K][i] = 1;

		for(int curr=N;curr>=1;curr--){
			int t = Math.min(K, curr-1);
			for(int count=0;count<=t;count++){
				for(int last=0;last<=curr;last++){
					long ans = 0;
					if(count != K)
						ans = (dp[curr+1][count+1][curr] * (pow2[curr] - pow2[last] + mod));
					ans = (ans + dp[curr+1][count][last] * pow2[last]) % mod;
					dp[curr][count][last] = (int)ans;
				}
			}
		}

		w.println(dp[1][0][0]);
		w.close();
	}

	static class InputReader {

		private InputStream stream;
		private byte[] buf = new byte[8192];
		private int curChar;
		private int 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 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 boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}
}


import java.io.*;
import java.util.*;
import java.math.BigInteger;
import java.util.Collections.*;
import static java.lang.Math.*;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.util.Arrays.*;
import static java.math.BigInteger.*;

public class Main{

    void run(){
        Locale.setDefault(Locale.US);
        boolean my;
        try {
            my = System.getProperty("MY_LOCAL") != null;
        } catch (Exception e) {
            my = false;

        }
        try{
            err = System.err;
            if( my ){
                sc  = new FastScanner(new BufferedReader(new FileReader("input.txt")));
//                sc  = new FastScanner(new BufferedReader(new FileReader("C:\\myTest.txt")));
                out = new PrintWriter   (new FileWriter("output.txt"));
            }
            else {
                sc = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }
//            out = new PrintWriter(new OutputStreamWriter(System.out));
        }catch(Exception e){
            MLE();
        }
        if( my )
            tBeg = System.currentTimeMillis();
        solve();
        if( my )
            err.println( "TIME: " + (System.currentTimeMillis() - tBeg ) / 1e3 );
        exit(0);
    }

    void exit( int val ){
        err.flush();
        out.flush();
        System.exit(val);
    }

    double tBeg;
    FastScanner sc;
    PrintWriter out;
    PrintStream err;

    class FastScanner{

        StringTokenizer st;
        BufferedReader br;

        FastScanner( BufferedReader _br ){
            br = _br;
        }

        String readLine(){
            try {
                return br.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        String next(){
            while( st==null || !st.hasMoreElements() )
                st = new StringTokenizer(readLine());
            return st.nextToken();
        }

        int nextInt(){ return Integer.parseInt(next()); }
        long nextLong(){ return Long.parseLong(next()); }
        double nextDouble(){ return Double.parseDouble(next()); }
    }

    void MLE(){
        int[][] arr = new int[1024*1024][]; for( int i = 0; i < 1024*1024; ++i ) arr[i] = new int[1024*1024];
    }

    void MLE( boolean doNotMLE ){ if( !doNotMLE ) MLE(); }

    void TLE(){
        for(;;);
    }

    public static void main(String[] args) {
        new Main().run();
//        new Thread( null, new Runnable() {
//            @Override
//            public void run() {
//                new Main().run();
//            }
//        }, "Lolka", 256_000_000L ).run();
    }

    ////////////////////////////////////////////////////////////////

    final long mod = (int)1e9 + 7;
    int n, k;
    Long[][] dp0, dp1;
    long[] pow2 = new long[1000];
    {
        pow2[0] = 1;
        for (int i = 1; i < pow2.length; i++) {
            pow2[i] = (pow2[i-1] * 2) % mod;
        }
    }

    void solve(){
        n = sc.nextInt();
        k = sc.nextInt();
        dp0 = new Long[k+1][n+1];
        for (Long[] val : dp0) fill(val, 0L);

        for (int sz = 1; sz <= n; sz++) {
            dp1  = new Long[k+1][n+1];

            for (int cnt  = 0; cnt <= k; cnt++) {
            for (int last = 0; last <= sz; last++) {
                if( cnt == 0 ){
                    if( last == 0 ) dp1[cnt][last] = 1L;
                    else dp1[cnt][last] = 0L;
                }
                else if( sz == last ){
                    if( cnt == 1 ){
                        dp1[cnt][last] = (pow2[last]-1);
                    }
                    else{
                        dp1[cnt][last] = 0L;
                        for (int l = 1; l <= sz - 1; l++) {
                            dp1[cnt][last] += (dp1[cnt-1][l] * (pow2[sz-l]-1)) % mod;
                        }
                    }
                }
                else{
                    dp1[cnt][last] = dp0[cnt][last] * pow2[last];
                }
                dp1[cnt][last] = ( dp1[cnt][last]%mod + mod ) % mod;
            }
            }
            //
            dp0 = dp1;
        }
        long ans = 0;
        for (int last = 0; last <= n; last++) {
            ans += dp0[k][last];
        }
        ans %= mod;
        out.println( ans );
    }

}


import java.io.*;
import java.util.*;
import java.math.BigInteger;
import java.util.Collections.*;
import static java.lang.Math.*;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.util.Arrays.*;
import static java.math.BigInteger.*;

public class Main{

    void run(){
        Locale.setDefault(Locale.US);
        boolean my;
        try {
            my = System.getProperty("MY_LOCAL") != null;
        } catch (Exception e) {
            my = false;

        }
        try{
            err = System.err;
            if( my ){
                sc  = new FastScanner(new BufferedReader(new FileReader("input.txt")));
//                sc  = new FastScanner(new BufferedReader(new FileReader("C:\\myTest.txt")));
                out = new PrintWriter   (new FileWriter("output.txt"));
            }
            else {
                sc = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }
//            out = new PrintWriter(new OutputStreamWriter(System.out));
        }catch(Exception e){
            MLE();
        }
        if( my )
            tBeg = System.currentTimeMillis();
        solve();
        if( my )
            err.println( "TIME: " + (System.currentTimeMillis() - tBeg ) / 1e3 );
        exit(0);
    }

    void exit( int val ){
        err.flush();
        out.flush();
        System.exit(val);
    }

    double tBeg;
    FastScanner sc;
    PrintWriter out;
    PrintStream err;

    class FastScanner{

        StringTokenizer st;
        BufferedReader br;

        FastScanner( BufferedReader _br ){
            br = _br;
        }

        String readLine(){
            try {
                return br.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        String next(){
            while( st==null || !st.hasMoreElements() )
                st = new StringTokenizer(readLine());
            return st.nextToken();
        }

        int nextInt(){ return Integer.parseInt(next()); }
        long nextLong(){ return Long.parseLong(next()); }
        double nextDouble(){ return Double.parseDouble(next()); }
    }

    void MLE(){
        int[][] arr = new int[1024*1024][]; for( int i = 0; i < 1024*1024; ++i ) arr[i] = new int[1024*1024];
    }

    void MLE( boolean doNotMLE ){ if( !doNotMLE ) MLE(); }

    void TLE(){
        for(;;);
    }

    public static void main(String[] args) {
        new Main().run();
//        new Thread( null, new Runnable() {
//            @Override
//            public void run() {
//                new Main().run();
//            }
//        }, "Lolka", 256_000_000L ).run();
    }

    ////////////////////////////////////////////////////////////////

    final long mod = (int)1e9 + 7;
    int n, k;
    long[][] dp0, dp1;
    long[] pow2 = new long[600];
    long[] pow2Inv = new long[600];
    {
        pow2[0] = 1;
        for (int i = 1; i < pow2.length; i++) {
            pow2[i] = (pow2[i-1] * 2) % mod;
        }
        for (int i = 0; i < pow2Inv.length; i++) {
            pow2Inv[i] = valueOf(pow2[i]).modInverse(valueOf(mod)).intValue();
        }
    }

    long add( long a, long b ){
        long c = a + b;
        if( mod <= c ) c -= mod;
        return c;
    }

    void solve(){
        n = sc.nextInt();
        k = sc.nextInt();
        dp0 = new long[k+1][n+1];
        for (long[] val : dp0) fill(val, 0L);

        for (int sz = 1; sz <= n; sz++) {
            dp1  = new long[k+1][n+1];

            long[] sumDiv = null;// = new long[sz+1];
            long[] sum = null; // = new long[sz+1];
            for (int cnt  = 0; cnt <= k; cnt++) {
                long[] newSumDiv = new long[sz+1];
                long[] newSum = new long[sz+1];
                for (int last = 0; last <= sz; last++) {
                    if( cnt == 0 ){
                        if( last == 0 ) dp1[cnt][last] = 1L;
                        else dp1[cnt][last] = 0L;
                    }
                    else if( sz == last ){
                        if( cnt == 1 ){
                            dp1[cnt][last] = (pow2[last]-1);
                        }
                        else{
                            dp1[cnt][last] = 0L;
                            dp1[cnt][last] += sumDiv[sz-1]*pow2[sz] - sum[sz-1];
                        }
                    }
                    else{
                        dp1[cnt][last] = dp0[cnt][last] * pow2[last];
                    }
                    dp1[cnt][last] = ( dp1[cnt][last]%mod + mod ) % mod;

                    if( 1 <= last ){
                        newSumDiv[last] = (dp1[cnt][last] * pow2Inv[last]) % mod;
                        newSum[last] = dp1[cnt][last];
                    }
                }

                for (int i = 1; i < newSum.length; i++) {
                    newSum[i] = add( newSum[i], newSum[i-1] );
                    newSumDiv[i] = add( newSumDiv[i], newSumDiv[i-1] );
                }
                sum = newSum;
                sumDiv = newSumDiv;
            }
           //
            dp0 = dp1;
        }
        long ans = 0;
        for (int last = 0; last <= n; last++) {
            ans += dp0[k][last];
        }
        ans %= mod;
        out.println( ans );
    }

}


//package round243;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class E4 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	/*
[[1, 0, 0, 0, 0]]
[[0, 8, 48, 56, 15]]
[[0, 0, 32, 192, 256]]
[[0, 0, 0, 64, 288]]
[[0, 0, 0, 0, 64]]	 *
	 */
	void solve()
	{
		int n = ni(), K = ni();
		int mod = 1000000007;
		int[][] dp = new int[K+1][n+1];
		dp[0][0] = 1;
		long two0 = 1;
		for(int end = 1;end <= n;end++){
			two0 *= 2;
			if(two0 >= mod)two0 -= mod;
			for(int k = K;k >= 0;k--){
				int two = 1;
				long lsum = 0;
				for(int l = 0;l <= end-1;l++){
					lsum += dp[k][l] * (two0-two)%mod;
					if(lsum >= mod)lsum -= mod;
					if(lsum < 0)lsum += mod;
					dp[k][l] = (int)((long)dp[k][l] * two % mod);
					two *= 2;
					if(two >= mod)two -= mod;
				}
				if(k+1 <= K)dp[k+1][end] = (int)lsum;
			}
		}
//		for(int i = 0;i <= K;i++){
//			tr(dp[i]);
//		}
		long ret = 0;
		for(int j = 0;j <= n;j++){
			ret += dp[K][j];
		}
		out.println(ret%mod);
	}

	public static long pow(long a, long n, long mod) {
		//		a %= mod;
		long ret = 1;
		int x = 63 - Long.numberOfLeadingZeros(n);
		for (; x >= 0; x--) {
			ret = ret * ret % mod;
			if (n << 63 - x < 0)
				ret = ret * a % mod;
		}
		return ret;
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new E4().run(); }

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;

public class Main {
    void solve() {
        long MX=(long)1e18;
        long l=nl(),r=nl();
        if(l==MX && r==MX){
            pw.println("1");
            return;
        }
        long rr=r;

        if(rr==MX) rr--;
        a=convert(l);
        b=convert(rr);
      //  for(int i=0;i<18;i++) System.out.print(a[i]+" ");

        cc=new int[10];
        c=new int[10];
        generate(18,0);

       // pw.println(id);
//
//        for(int i=0;i<id;i++){
//            for(int j=0;j<10;j++) cc[j]=c[i][j];
//
//            if(go(0,1,1)) {
//                ans++;
//
//            }
//        }
//        Arrays.fill(cc,0);
        //cc[7]=18;
      //  pw.println(go(0,1,1));

      //  if(r==MX) ans++;
        pw.println(ans);
    }
    int a[],b[];
    int c[];
    int cc[];
    int id=0;
    int ans=0;
    boolean go(int i,int t1,int t2){
        if(i>=18) return true;
        int st=0,ed=9;

        if(t1==1 && t2==1){
             st=a[i]; ed=b[i];
           //  if(i==16) pw.println("YES"+" "+st+" "+ed);
             for(int j=st+1;j<ed;j++){

                 if(cc[j]>0){

                     return true;
                 }
             }

             if(st==ed){

                 if(cc[st]>0){
                     cc[st]--;
                     if(go(i+1,1,1)) return true;
                     cc[st]++;

                 }
             }else {
                 if(cc[st]>0){
                     cc[st]--;
                     if(go(i+1,1,0)) return true;
                     cc[st]++;
                 }
                 if(cc[ed]>0){
                     cc[ed]--;
                     if(go(i+1,0,1)) return true;

                     cc[ed]++;
                 }
             }

        }else if(t1==1){
            st=a[i];
            for(int j=st+1;j<=ed;j++){
                if(cc[j]>0) return true;
            }
            if(cc[st]>0){
                cc[st]--;
                if(go(i+1,1,0)) return true;
                cc[st]++;
            }

        }else if(t2==1){
            ed=b[i];
            for(int j=st;j<ed;j++) if(cc[j]>0) return true;
            if(cc[ed]>0){
                cc[ed]--;
                if(go(i+1,0,1)) return true;
                cc[ed]++;
            }
        }else {
            return true;
        }
        return false;
    }

    void generate(int i,int digit){

        if(i==0){

            for(int j=0;j<10;j++) cc[j]=c[j];

            if(go(0,1,1)) ans++;
            return;
        }
        if(digit>9) return;
        for(int j=0;j<=i;j++){
            c[digit]=j;
            generate(i-j,digit+1);
            c[digit]=0;

        }

    }
    int []convert(long n){
        int a[]=new int[18];
        int id=17;
        while(n>0){

            a[id]=(int)(n%10);
           // if(a[id]<0) System.out.println("YES");
            id--;
            n/=10;
        }
        return a;
    }

    long M=(long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");

    }

    public static void main(String[] args) throws Exception { new Main().run(); }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
    private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        long min;
        int[] minDigits;
        int[] maxDigits;
        long max;
        long res;
        long[][] comb;
        int[] cnt;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            comb = new long[20][20];
            comb[0][0] = 1;
            for (int i = 1; i < comb.length; ++i) {
                comb[i][0] = 1;
                for (int j = 1; j < comb.length; ++j) {
                    comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
                }
            }
            min = in.nextLong() - 1;
            max = in.nextLong() + 1;
            minDigits = makeDigits(min);
            maxDigits = makeDigits(max);
            int[] cnt = new int[10];
            this.cnt = new int[10];
            res = 0;
            int[] p = new int[10];
            generate(18, 1, cnt);
            out.println(res);
        }

        private int[] makeDigits(long min) {
            int[] res = new int[19];
            for (int i = 0; i < res.length; ++i) {
                res[res.length - 1 - i] = (int) (min % 10);
                min /= 10;
            }
            return res;
        }

        private void generate(int max, int at, int[] cnt) {
            if (at >= 10) {
            /*long n1 = count(cnt, min, minDigits);
            long n2 = count(cnt, max, maxDigits);
            if (n1 < n2) {
                ++res;
            }*/
                if (isAny(cnt)) {
                    ++res;
                }
                return;
            }
            for (int x = 0; x <= max; ++x) {
                cnt[at] = x;
                generate(max - x, at + 1, cnt);
            }
        }

        private boolean isAny(int[] origCnt) {
            System.arraycopy(origCnt, 0, cnt, 0, 10);
            cnt[0] = maxDigits.length;
            for (int x : origCnt) cnt[0] -= x;
            int[] p = new int[10];
            for (int i = 0; i < p.length; ++i) p[i] = i - 1;
            boolean alreadyGreater = false;
            for (int pos = 0; pos < maxDigits.length; ++pos) {
                int cur = maxDigits[pos];
                int got = p[cur];
                while (got >= 0 && cnt[got] == 0) {
                    got = p[got];
                }
                int tmp = cur;
                while (tmp != got) {
                    int z = p[tmp];
                    p[tmp] = got;
                    tmp = z;
                }
                if (got >= 0 && got < cur) {
                    if (alreadyGreater || got > minDigits[pos]) {
                        return true;
                    }
                    if (got == minDigits[pos]) {
                        --cnt[got];
                        int at = pos + 1;
                        int coming;
                        outer:
                        for (coming = 9; coming >= 0; --coming) {
                            for (int i = cnt[coming]; i > 0; --i) {
                                if (minDigits[at] < coming) {
                                    return true;
                                }
                                if (minDigits[at] > coming) break outer;
                                ++at;
                            }
                        }
                        if (coming < 0) {
                            if (at != minDigits.length)
                                throw new RuntimeException();
                        }
                        ++cnt[got];
                    }
                }
                --cnt[cur];
                if (cnt[cur] < 0) return false;
                if (cur > minDigits[pos]) alreadyGreater = true;
            }
            return false;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public long a;
        public long b;
        public int pt;
        public int[] l;
        public int[] r;
        public int[] arr;
        public int ans;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            a = in.nextLong();
            b = in.nextLong();
            String sa = String.valueOf(a), sb = String.valueOf(b);
            while (sa.length() < sb.length()) sa = "0" + sa;
            l = new int[sa.length()];
            r = new int[sb.length()];
            for (int i = 0; i < sa.length(); i++) l[i] = sa.charAt(i) - '0';
            for (int i = 0; i < sb.length(); i++) r[i] = sb.charAt(i) - '0';
            arr = new int[10];
            long[] pow10 = new long[sb.length() + 1];
            pow10[0] = 1;
            for (int i = 1; i < pow10.length; i++) pow10[i] = pow10[i - 1] * 10;
            pt = 0;
            while (pt < sa.length() && l[pt] == r[pt]) {
                a -= pow10[sb.length() - pt - 1] * l[pt];
                b -= pow10[sb.length() - pt - 1] * l[pt];
                pt++;
            }
            if (pt == sb.length()) {
                out.println(1);
                return;
            }
            dfs(0, r.length - pt);
            out.println(ans);
        }

        public void dfs(int num, int left) {
            if (num == 9) {
                arr[9] = left;
                if (ok(arr)) {
                    ans++;
                }
            } else {
                for (int i = 0; i <= left; i++) {
                    arr[num] = i;
                    dfs(num + 1, left - i);
                }
            }
        }

        public boolean ok(int[] arr) {
            if (arr[r[pt]] > 0) {
                arr[r[pt]] -= 1;
                long g = r[pt];
                for (int dd = 0; dd <= 9; dd++) for (int k = 0; k < arr[dd]; k++) g = g * 10 + dd;
                arr[r[pt]]++;
                if (g <= b) {
                    return true;
                }
            }

            for (int cdig = r[pt] - 1; cdig >= l[pt]; cdig--) {
                if (arr[cdig] > 0) {
                    arr[cdig]--;
                    if (cdig == l[pt]) {
                        long c1 = cdig;
                        for (int dd = 9; dd >= 0; dd--) {
                            for (int k = 0; k < arr[dd]; k++) c1 = c1 * 10 + dd;
                        }
                        if (c1 < a) {
                            arr[cdig]++;
                            if (c1 > b) {
                                System.out.println("BAD!");
                                System.out.println(Arrays.toString(arr) + " " + c1);
                            }
                            return false;
                        }
                    }
                    arr[cdig]++;
                    return true;
                }
            }
            return false;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (this.numChars == -1) {
                throw new InputMismatchException();
            } else {
                if (this.curChar >= this.numChars) {
                    this.curChar = 0;

                    try {
                        this.numChars = this.stream.read(this.buf);
                    } catch (IOException var2) {
                        throw new InputMismatchException();
                    }

                    if (this.numChars <= 0) {
                        return -1;
                    }
                }

                return this.buf[this.curChar++];
            }
        }

        public long nextLong() {
            int c;
            for (c = this.read(); isSpaceChar(c); c = this.read()) {
                ;
            }

            byte sgn = 1;
            if (c == 45) {
                sgn = -1;
                c = this.read();
            }

            long res = 0L;

            while (c >= 48 && c <= 57) {
                res *= 10L;
                res += (long) (c - 48);
                c = this.read();
                if (isSpaceChar(c)) {
                    return res * (long) sgn;
                }
            }

            throw new InputMismatchException();
        }

        public static boolean isSpaceChar(int c) {
            return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;
        }

    }
}


import java.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;

public class Main {
    void solve() {
        long MX=(long)1e18;
        long l=nl(),r=nl();
        if(l==MX && r==MX){
            pw.println("1");
            return;
        }
        long rr=r;

        if(rr==MX) rr--;
        a=convert(l);
        b=convert(rr);

        cc=new int[10];
        c=new int[10];
        generate(18,0);

       // pw.println(id);
//
//        for(int i=0;i<id;i++){
//            for(int j=0;j<10;j++) cc[j]=c[i][j];
//
//            if(go(0,1,1)) {
//                ans++;
//
//            }
//        }
//        Arrays.fill(cc,0);
//        cc[0]=17;cc[5]=1;
//        pw.println(go(0,1,1));

        if(r==MX) ans++;
        pw.println(ans);
    }
    int a[],b[];
    int c[];
    int cc[];
    int id=0;
    int ans=0;
    boolean go(int i,int t1,int t2){
        if(i>=18) return true;
        int st=0,ed=9;

        if(t1==1 && t2==1){
             st=a[i]; ed=b[i];
           //  if(i==16) pw.println("YES"+" "+st+" "+ed);
             for(int j=st+1;j<ed;j++){

                 if(cc[j]>0){

                     return true;
                 }
             }

             if(st==ed){
                 if(cc[st]>0){
                     cc[st]--;
                     if(go(i+1,1,1)) return true;
                     cc[st]++;

                 }
             }else {
                 if(cc[st]>0){
                     cc[st]--;
                     if(go(i+1,1,0)) return true;
                     cc[st]++;
                 }
                 if(cc[ed]>0){
                     cc[ed]--;
                     if(go(i+1,0,1)) return true;

                     cc[ed]++;
                 }
             }

        }else if(t1==1){
            st=a[i];
            for(int j=st+1;j<=ed;j++){
                if(cc[j]>0) return true;
            }
            if(cc[st]>0){
                cc[st]--;
                if(go(i+1,1,0)) return true;
                cc[st]++;
            }

        }else if(t2==1){
            ed=b[i];
            for(int j=st;j<ed;j++) if(cc[j]>0) return true;
            if(cc[ed]>0){
                cc[ed]--;
                if(go(i+1,0,1)) return true;
                cc[ed]++;
            }
        }else {
            return true;
        }
        return false;
    }

    void generate(int i,int digit){

        if(i==0){

            for(int j=0;j<10;j++) cc[j]=c[j];
            if(go(0,1,1)) ans++;
            return;
        }
        if(digit>9) return;
        for(int j=0;j<=i;j++){
            c[digit]=j;
            generate(i-j,digit+1);
            c[digit]=0;

        }

    }
    int []convert(long n){
        int a[]=new int[18];
        int id=17;
        while(n>0){
            a[id]=(int)n%10;
            id--;
            n/=10;
        }
        return a;
    }

    long M=(long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");

    }

    public static void main(String[] args) throws Exception { new Main().run(); }

    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }
    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
    private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}


import java.util.Arrays;
import java.util.Scanner;

public class E {
    static double DP[][][][];
    static double p;
    static int screen = (1 << 8) - 1;

    public static double get(int index, int mask, int ninth, int cnt) {
        if (index == 0) {
            int res = 0;
            while ((mask & 1) == 0) {
                res++;
                mask >>= 1;
            }
            if (res == 8 && ninth == 0)
                res += cnt * ninth;
            return res;
        }
        if (DP[index][mask][ninth][cnt] != -1)
            return DP[index][mask][ninth][cnt];
        double res = 0;
        int nextBit = (mask & (1 << 7)) == 0 ? 0 : 1;
        int nextCnt = nextBit == ninth ? (cnt + 1) : 1;
        int nextMask = (mask << 1);
        res += p * get(index - 1, nextMask & screen, nextBit, nextCnt);

        nextMask = mask + 1;
        nextBit = (nextMask & (1 << 8)) == 0 ? ninth : 1;
        nextCnt = nextBit == 0 ? cnt : 1;
        res += (1 - p) * get(index - 1, nextMask & screen, nextBit, nextCnt);
        return DP[index][mask][ninth][cnt] = res;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int k = in.nextInt();
        p = in.nextDouble() / 100;
        DP = new double[k + 1][1 << 8][2][250];
        for (int i = 0; i < DP.length; i++)
            for (int j = 0; j < DP[0].length; j++)
                for (int l = 0; l < DP[0][0].length; l++)
                    Arrays.fill(DP[i][j][l], -1);
        int mask = x & screen;
        int ninth = (x & (1 << 8)) == 0 ? 0 : 1;
        int cnt = 0;
        x >>= 8;
        while ((x & 1) == ninth && x > 0) {
            cnt++;
            x >>= 1;
        }
        System.out.println(get(k, mask, ninth, cnt));
    }
}