import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class vc3{
public static int can[];
public static boolean dp[][][];
public static boolean use[][][];
public static long mod = 1000000007;
public static void main(String args[]) throws IOException{
BufferedReader lector = new BufferedReader(new InputStreamReader(System.in));
lector.readLine();
String tmp = lector.readLine();
String tal="BGR";
can = new int[3];
for(int n = 0;n<tmp.length();n++)
can[tal.indexOf(tmp.charAt(n))]++;
String res = "";
for(int n = 0;n<3;n++){
dp = new boolean[401][401][401];
use = new boolean[401][401][401];
if(pos(can[0],can[1],can[2],n))res+=tal.charAt(n);
}
System.out.println(res);
}
public static boolean pos(int a,int b,int c,int d){
int s = a+b+c;
int r[]={a,b,c};
for(int n = 0;n<3;n++)if(r[n]<0)return false;
if(use[a][b][c])return dp[a][b][c];
//System.out.println(a+" "+b+" "+c);
if(s==1)
return r[d]==1;
boolean tal = false;
for(int n = 0;n<3;n++)
for(int m = 0;m<=n;m++){
if(n==m && r[n]<2)continue;
if(n==m)r[n]--;
else{
for(int k = 0;k<3;k++)
if(k!=n && k!=m)
r[k]++;
r[n]--;
r[m]--;
}
tal|=pos(r[0],r[1],r[2],d);
if(n==m)r[n]++;
else{
for(int k = 0;k<3;k++)
if(k!=n && k!=m)
r[k]--;
r[n]++;
r[m]++;
}
}
use[a][b][c]=true;
dp[a][b][c]=tal;
return tal;
}
}
class p implements Comparable{
public int a;
public p(int a){
this.a = a;
}
public String toString(){
return "";
}
public int compareTo(Object o){
p pp = (p)o;
return (int)Math.signum(a-pp.a);
}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class solve {

	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));
		int n = sc.nextInt();
		String ss = sc.next();
		Set<String> set = new HashSet<String>();
		set.add(ss);
		boolean flag = true;
		while (flag) {
			Set<String> tset = new HashSet<String>();
			for (String s : set) {
				StringBuilder b = new StringBuilder(s);
				for (int i = 0; i < b.length(); i++)
					for (int j = i + 1; j < b.length(); j++) {
						char ci = b.charAt(i);
						char cj = b.charAt(j);
						char c = move(ci, cj);
						StringBuilder t = new StringBuilder(b.toString());
						flag = true;
						tset.add(t.replace(i, i + 1, c+"").replace(j, j + 1, "").toString());
					}
			}
			if (tset.isEmpty())
				break;
			set = tset;
		}
		Set<String> sort = new TreeSet<String>(set);
		String o = "";
		for (String t : sort)
			o += t;
		out.println(o);
		out.close();
	}

	static char move(char a, char b) {
		if (a == b)
			return a;
		else
			return "RGB".replace(a + "", "").replace(b + "", "").charAt(0);
	}

	// -----------PrintWriter for faster output---------------------------------
	public static PrintWriter out;

	// -----------MyScanner class for faster input----------
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
	// --------------------------------------------------------
}


import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

public class CodeforcesCom {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        int n = in.readInt();
        int a = in.readInt();
        int b = in.readInt();
        int k = in.readInt();
        long[][]dp = new long[5009][5009];
        dp[0][a]=1;
        for(int i=1;i<=n;i++)dp[0][i]+=dp[0][i-1];
        for(int i=1;i<=k;i++){
            for(int j=1;j<=n;j++){
                if(j==b){
                    dp[i][j]+=dp[i][j-1];
                }
                else if( j<b ){
                    dp[i][j]=1000000007+dp[i-1][(j+b)/2-((b-j)%2==0?1:0)]-dp[i-1][j]+dp[i-1][j-1];
                    dp[i][j]+=dp[i][j-1];
                    dp[i][j]%=1000000007;
                }
                else {
                    dp[i][j]=1000000007+dp[i-1][n]-dp[i-1][(b+j)/2]-dp[i-1][j]+dp[i-1][j-1];
                    dp[i][j]+=dp[i][j-1];
                    dp[i][j]%=1000000007;
                }
            }
        }
        System.out.print(dp[k][n]+"\n");
    }

}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1000];
    private int curChar, numChars;

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

    private 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++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

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

    private String readLine0() {
        StringBuffer buf = new StringBuffer();
        int c = read();
        while (c != '\n' && c != -1) {
            buf.appendCodePoint(c);
            c = read();
        }
        return buf.toString();
    }

    public String readLine() {
        String s = readLine0();
        while (s.trim().length() == 0)
            s = readLine0();
        return s;
    }

    public String readLine(boolean ignoreEmptyLines) {
        if (ignoreEmptyLines)
            return readLine();
        else
            return readLine0();
    }

    public char readCharacter() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        return (char) c;
    }

    public double readDouble() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        double res = 0;
        while (!isSpaceChar(c) && c != '.') {
            if (c == 'e' || c == 'E')
                return res * Math.pow(10, readInt());
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        }
        if (c == '.') {
            c = read();
            double m = 1;
            while (!isSpaceChar(c)) {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, readInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                m /= 10;
                res += (c - '0') * m;
                c = read();
            }
        }
        return res * sgn;
    }
}


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

public class marte{

private int contor=0;

public static void main (String args[]) throws Exception{

Scanner input=new Scanner(System.in);

HashMap<String, Integer> map= new HashMap<String, Integer>();
HashMap<String, Integer> map2= new HashMap<String, Integer>();
HashMap<Integer, Integer> finish= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> maxime= new HashMap<Integer, Integer>();

	String str=input.next();
	String alfa="abcdefghijklmnopqrstuvwxyz";

	for(int i=0;i<alfa.length();i++)
	map.put(alfa.substring(i,i+1),i+1);
	int max=0;
	int diferite=0;

	for(int i=0;i<str.length();i++)
	if(!map2.containsKey(str.substring(i,i+1))) {diferite++;
	map2.put(str.substring(i,i+1),1);

	max=Math.max(max,map.get(str.substring(i,i+1)));}

	int y=0;
	int []v=new int[27];
//	System.out.println(map.get("z"));

	for(int i=0;i<str.length();i++)
{	v[map.get(str.substring(i,i+1))]++;
	if(v[map.get(str.substring(i,i+1))]==1 && map.get(str.substring(i,i+1))>1 &&
	v[map.get(str.substring(i,i+1))-1]==0) y=1;}

	for(int i=1;i<diferite;i++)
	if(v[i]<v[i+1]) y=1;

	if(diferite<max || y==1) System.out.println("NO");
	else System.out.println("YES");

	}

}


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

public class CF1206F extends PrintWriter {
	CF1206F() { super(System.out); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1206F o = new CF1206F(); o.main(); o.flush();
	}

	int[] next, jj; int l_ = 1;
	int link(int l, int j) { next[l_] = l; jj[l_] = j; return l_++; }
	int[] ao; int n;
	int[] cc;
	void init() {
		int m = n - 1;
		next = new int[1 + m * 2];
		jj = new int[1 + m * 2];
		ao = new int[n];
		cc = new int[n];
	}
	int n_, i_, j_;
	int dfs(int p, int i) {
		int k = 1;
		for (int l = ao[i]; l != 0; l = next[l]) {
			int j = jj[l];
			if (j != p)
				k += dfs(i, j);
		}
		int k_ = Math.min(k, n - k);
		if (n_ < k_) {
			n_ = k_;
			if (k <= n - k) {
				i_ = i;
				j_ = p;
			} else {
				i_ = p;
				j_ = i;
			}
		}
		return k;
	}
	int a, b;
	void dfs_(int p, int i, int c) {
		for (int l = ao[i]; l != 0; l = next[l]) {
			int j = jj[l];
			if (j != p) {
				cc[j] = a;
				println((i + 1) + " " + (j + 1) + " " + (a - c));
				a += b;
			}
		}
		for (int l = ao[i]; l != 0; l = next[l]) {
			int j = jj[l];
			if (j != p)
				dfs_(i, j, cc[j]);
		}
	}
	void main() {
		n = sc.nextInt();
		if (n == 1)
			return;
		init();
		for (int h = 0; h < n - 1; h++) {
			int i = sc.nextInt() - 1;
			int j = sc.nextInt() - 1;
			ao[i] = link(ao[i], j);
			ao[j] = link(ao[j], i);
		}
		dfs(-1, 0);
		a = 1; b = 1;
		dfs_(i_, j_, 0);
		a = (n - n_) * 2; b = n - n_;
		println((j_ + 1) + " " + (i_ + 1) + " " + (n - n_));
		dfs_(j_, i_, n - n_);
	}
}


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

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

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

		public 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++];
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			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 boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next() {
			return readString();
		}

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

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 print(Object...objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0)
					writer.print(' ');
				writer.print(objects[i]);
			}
		}

		public void printLine(Object...objects) {
			print(objects);
			writer.println();
		}

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

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

		}

    static class IOUtils {

		public static int[] readIntArray(InputReader in, int size) {
			int[] array = new int[size];
			for (int i = 0; i < size; i++)
				array[i] = in.readInt();
			return array;
		}
    }
    // count;
    static int[] init, goal;
    static boolean[] visited;
    static ArrayList<ArrayList<Integer>> lists;
    static int mod = 1000000007;
    static OutputWriter out;
    static InputReader in;
    static ArrayList<Integer> abc;
    public static void main (String[] args) throws java.lang.Exception
	{
	    out = new OutputWriter(System.out);
            in = new InputReader(System.in);
	    long n = Long.parseLong(in.readString()); long k = Long.parseLong(in.readInt());
            long w = n/2;
            w = w-w%(k+1);
            long d = w/(k+1);
            long c = k*d;
            long x = n - c - d;
            out.print(d+" "+c+" "+x);
	    /*int[] a = new int[n];
	    for(int i=0; i<n; i++)a[i] = in.readInt();
	    TreeSet<Integer> hill = new TreeSet<Integer>();
	    TreeSet<Integer> valley = new TreeSet<Integer>();
	    int i = 1;
        for(i=1; i<n; i++)if(a[i]!=a[i-1])break;
        boolean inc = (a[i]>a[i-1]?true:false);
        i++;
        for(; i<n; i++){
            if(inc && a[i]<a[i-1]){hill.add(i); inc = false;}
            else if(!inc && a[i]>a[i-1]){valley.add(i); inc = true;}
        }
        for(int i=0; i<m; i++){
            int l = in.readInt();
            int r = in.readInt()-1;
            if(valley.subSet(l, r).size()>0)out.printLine("No");
            else out.printLine("Yes");
        }*/
            i
	    out.flush();
            out.close();
	}

	public static void dfs(int start, int d1, int d2){
	    visited[start] = true;
    int x = Math.abs(init[start]-goal[start]);
	    ArrayList<Integer> list = lists.get(start);
	    for(int i=0; i<list.size(); i++){
	        if(!visited[list.get(i)]){
        	    if((x+d2)%2==1){
	                count++; abc.add(start);
	                dfs(list.get(i), 1, d1);
	            }else dfs(list.get(i), 0, d1);
	        }
	    }
	}
   public static int gcd(int aaa, int bbb){
        //b is greater
        if(aaa>bbb){int temp = aaa; aaa = bbb; bbb = temp;}
        if(bbb%aaa==0)return aaa;
        return gcd(bbb%aaa, aaa);
    }
	public static void add(int index, int value, int[] b){
	    while(index < b.length){
	        b[index] += value;
	        index = index + (index & (-index));
	    }
	}

	public static int getSum(int index, int [] b){
	    int sum = 0;
	    while(index > 0){
	        sum += b[index];
	        index = index - (index&(-index));
	    }
	    return sum;
	}

	public static void printArray(int[] a){
	    for(int i=1; i<a.length; i++)out.print(a[i]+" ");
	    out.printLine("---------");
	}

	static class Pair implements Comparable<Pair>{
	    int s;
	    //int d;
	    int len;
	    public Pair(int a, int c){
	        s = a; len = c;
	    }
	    public int compareTo(Pair p){
	        if(this.len > p.len)return 1;
	        else if(this.len < p.len)return -1;
	        return 0;
	    }
	}
}


import java.util.*;

public class Main {

    final static Map<String, Integer> map =new HashMap<>();
    final static Map<String, String> set = new HashMap<>();
    public static void main(String[] args) {
        map.put("A<B", 10);
        map.put("B<A", 100);
        map.put("A<C", 1);
        map.put("C<A", 100);
        map.put("C<B", 10);
        map.put("B<C", 1);
        map.put("B>A", 10);
        map.put("A>B", 100);
        map.put("C>A", 1);
        map.put("A>C", 100);
        map.put("B>C", 10);
        map.put("C>B", 1);

        set.put("12", "CBA");
        set.put("21", "BCA");
        set.put("102", "CAB");
        set.put("120", "BAC");
        set.put("201", "ACB");
        set.put("210", "ABC");

        Scanner scanner = new Scanner(System.in);
        int ABC = 0;
        for(int i = 0; i < 3; ++i)
            ABC += map.get(scanner.nextLine());

        if(set.containsKey(String.valueOf(ABC)))
            System.out.println(new StringBuilder(set.get(String.valueOf(ABC))).reverse().toString());
        else
            System.out.println("Impossible");
    }
}
import java.util.*;

public class Main {

    final static Map<String, Integer> map =new HashMap<>();
    final static Map<String, String> set = new HashMap<>();
    public static void main(String[] args) {
        map.put("A<B", 10);
        map.put("B<A", 100);
        map.put("A<C", 1);
        map.put("C<A", 100);
        map.put("C<B", 10);
        map.put("B<C", 1);
        map.put("B>A", 10);
        map.put("A>B", 100);
        map.put("C>A", 1);
        map.put("A>C", 100);
        map.put("B>C", 10);
        map.put("C>B", 1);

        set.put("12", "CBA");
        set.put("21", "BCA");
        set.put("102", "CAB");
        set.put("120", "BAC");
        set.put("201", "ACB");
        set.put("210", "ABC");

        Scanner scanner = new Scanner(System.in);
        int ABC = 0;
        for(int i = 0; i < 3; ++i)
            ABC += map.get(scanner.nextLine());

        if(set.containsKey(String.valueOf(ABC)))
            System.out.println(new StringBuilder(set.get(String.valueOf(ABC))).reverse().toString());
        else
            System.out.println("Impossible");
    }
}


package testinggg;

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

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

    static class coins {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            String arr[] = new String[3];
            Integer letter[] = new Integer[3];
            for (int i = 0; i < 3; i++) {
                arr[i] = in.next();
                letter[i] = 0;
            }

            for (int i = 0; i < 3; i++) {
                if (arr[i].charAt(1) == '>') {
                    letter[(int) (arr[i].charAt(0)) % 65] += 1;
                    letter[(int) (arr[i].charAt(2)) % 65] -= 1;
                } else {
                    letter[(int) (arr[i].charAt(0)) % 65] -= 1;
                    letter[(int) (arr[i].charAt(2)) % 65] += 1;
                }

            }
            //out.println("letter 0 is "+letter[0]+"letter 1 is "+letter[1]);
            if (Math.abs(letter[0]) + Math.abs(letter[1]) + Math.abs(letter[2]) == 4) {
                String ans = Arrays.toString(letter);
                //out.println(ans);
                if (ans.equals("[2, 0, -2]")) out.println("CBA");
                else if (ans.equals("[2, -2, 0]")) out.print("BCA");
                else if (ans.equals("[-2, 0, 2]")) out.print("ABC");
                else if (ans.equals("[-2, 2, 0]")) out.print("ACB");
                else if (ans.equals("[0, 2, -2]")) out.print("CAB");
                else if (ans.equals(["0, -2, 2]")) out.print("BAC");
            } else {
                out.print("Impossible");
            }
        }

    }
}


import java.util.*;
public class x399A {

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

		int n=sc.nextInt();
		int p=sc.nextInt();
		int k=sc.nextInt();
		int k1,k2;
		k1=k2=k;
		if(p-k>1)
			System.out.print("<<");
		while(k1!=0)
		{
			if(p-k1>0)
			{
				System.out.print(" "+(p-k1));
			}
			k1--;
		}
		System.out.print(" ("+p+")");

		//System.out.println(p+" "+k+" "+n);
		if(p+k>=n)
		{
			//System.out.print("Hello");
			int x=p+1;
			System.out.print(" "+x);
			while(x!=n)
			{
				x++;
				System.out.print(" "+x);
			}
		}
		else
		{
			int y=p+1;
			//System.out.print(y);
			System.out.print(" "+y);
			k2=k-1;
			while(k2!=0)
			{
				y++;
				System.out.print(" "+y);
				k2--;
			}
			System.out.print(" >>");
		}
	}

}


import java.util.*;
public class Game
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int n1 = sc.nextInt();
int n2 = sc.nextInt();
int k1 = sc.nextInt();
int k2 = sc.nextInt();
while(n1 > 0 && n2 > 0)
{
 if(n1-1>0)
 {
       k1--;
       n1 -= 1;
 }
 else
 {
       System.out.println("First");
 }
 if(n2 - 1 > 0)
 {
       k2--;
       n2 -= 1;
 }
 else
 {
       System.out.println("Second");
 }
}
}
}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 *
 * @author mav3n
 */
public class B272 {

    public static int strValue(String s){
        int n=0;
        int l = s.length();
        for(int i=0;i<l;i++){
            if(s.charAt(i)=='+')
                n++;
            else if(s.charAt(i)=='-')
                n--;
        }
        return n;
    }

    public static void main(String... arg){
                Scanner sc = new Scanner(System.in);
                String s1 = sc.nextLine();
                String s2 = sc.nextLine();
                int n1=0,n2=0,x=0;
                int l = s1.length();
                for(int i=0;i<l;i++){
                    if(s1.charAt(i)=='+')
                        n1++;
                    else if(s1.charAt(i)=='-')
                        n1--;

                    if(s2.charAt(i)=='+')
                        n2++;
                    else if(s2.charAt(i)=='-')
                        n2--;
                    else if(s2.charAt(i)=='?')
                        x++;
                }
                double result = 0.0;

                if(x>0){
                    int diff=n1-n2;
                    double fc = 0.0;
                    List<String> cases = new ArrayList<String>();
                    //String[] cases = new String[(int)Math.pow(2, x)];
                    //cases[0]="+";cases[x/2]="-";
                    cases.add("+");cases.add("-");
                    int len=cases.size();
                    int tc = (int)Math.pow(x,2);
                    while(true){
                        len = cases.size();
                        for(int j=0;j<len;j++){
                            String temp = cases.get(j);
                            //System.out.println("temp :: "+temp+"  len :: "+len);
                            cases.add(temp+"+");
                            cases.add(temp+"-");
                        }
                        cases = cases.subList(len,cases.size());
                        if(cases.size()==tc)
                            break;
                    }
                    for(int i=0;i<cases.size();i++){
                        //System.out.println(cases.get(i));
                        if(strValue(cases.get(i))==diff)
                            fc++;
                    }

                    result=fc/tc;
                    //System.out.println(fc+" "+tc+ " "+ result);
                }
                else if(x==0){
                    if(n1==n2)
                        result=1.0;
                    else
                        result=0.0;
                }
                System.out.println(String.format( "%.9f", result ));
    }
}


import java.util.*;
import java.io.*;
public class A
{
      public static void main(String ar[]) throws Exception
      {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            String s1[]=br.readLine().split(" ");
            long a=Long.parseLong(s1[0]);
            long b=Long.parseLong(s1[1]);
            long S=0;

            while(a>1 && b>1)
            {
                if(a<b)
                { S++; b=b-a; }
                else
                { S+=a/b; a=a%b; }
            }

            if(a==1)
             S+=b;
            else if(b==1)
             S+=a;
            System.out.println(S);
      }
}


import java.util.Arrays;
import java.util.Scanner;
public class New {

    public static void main( String [] args)
    {
        Scanner sc = new Scanner(System.in);
        int total, rslt=0,i, j, type=4;
        int arr[] = new int[type];
        for (i=0; i<type; i++)
        {
            arr[i]=sc.nextInt();
            for(j=1; j<i; j++)
            {
                if(arr[j]%arr[i]==0)
                {
                    --type;
                    --i;
                }
            }
        }
        int size=type;
        int arr2[];
        arr2= Arrays.copyOf(arr, size);
        Arrays.sort(arr2);
        total=sc.nextInt();

        if (type==1)
        {
                rslt=total/arr2[0];
        }
        else
        {
            boolean [] array = new boolean[total];
            for(i=0; i<size; i++)
            {

                for (j=1; j*arr2[i]<= total; j++)
                {
                    if (!array[j*arr2[i]])
                    {
                        array[j*arr2[i]]=true;
                        rslt++;
                    }
                }

            }
        }

        System.out.println(rslt);

    }
}


import java.util.*;
public class divmod
{
    public static void main(String args[])
    {
        Scanner in=new Scanner(System.in);
        long n,k,x;
        n=in.nextLong();
        k=in.nextLong();
        for(x=1;x>0;x++)
        {
            if((x%k)*(x/k)==n)
            {
                System.out.println(x);
                System.exit(0);
            }
        }
    }
}


import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    static long min , max;
    public static void search (long arr [] , int idx , int rem)
    {
        if (idx == 2)
        {
            arr[2] = rem;
            long first = (arr[0] + 1) * (arr[1] + 2) * (arr[2] + 2);
            long second = (arr[0] + 2) * (arr[1] + 1) * (arr[2] + 2);
            long third = (arr[0] + 2) * (arr[1] + 2) * (arr[2] + 1);

            min = Math.min(min , Math.min(first , Math.min(second , third)));
            max = Math.max(max , Math.max(first , Math.max(second , third)));
            return;
        }

        for (int i = 1 ; i * i <= rem ; ++i)
            if (rem % i == 0)
            {
                arr[idx] = i;
                search(arr , idx + 1 , rem / i);
                if (rem / i != i)
                {
                    arr[idx] = rem / i;
                    search(arr , idx + 1 , i);
                }
            }

    }
    public static void main(String[]args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        StringBuilder sb = new StringBuilder();
        int n = sc.nextInt();
        min = Long.MAX_VALUE;
        max = Long.MIN_VALUE;
        search(new int[3] , 0 , n);
        out.printf("%d %d" , min - n , max - n );
        out.flush();
        out.close();
    }

    static  class Scanner
    {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

        public String next() throws IOException
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {return br.readLine();}

        public double nextDouble() throws IOException
        {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if(x.charAt(0) == '-')
            {
                neg = true;
                start++;
            }
            for(int i = start; i < x.length(); i++)
                if(x.charAt(i) == '.')
                {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                }
                else
                {
                    sb.append(x.charAt(i));
                    if(dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg?-1:1);
        }

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

    }

}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package graphapi;

/**
 *
 * @author hussienalbared
 */
public class Graph {

}


import java.io.*;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {

    static MyScanner   in;
    //    static Timer timer = new Timer();
    static PrintWriter out;

    static String number;

    public static void main(String[] args) throws IOException {
        in = new MyScanner();
        out = new PrintWriter(System.out, true);

        long n = in.nextInt();
        number = in.next();

        ArrayList<Long> list = new ArrayList<>();
        while (number != null)
            list.add(takeMax(n));

        long ans = 0;
        long sch = 1;

        for (long a : list) {
            ans += a * sch;
            sch *= n;
        }

        out.println(ans);
    }

    static long takeMax(long n) {
        if (number.length() < 11 && Long.parseLong(number) < n) {
            long ans = Long.parseLong(number);
            number = null;
            return ans;
        }

        int lastIndex = number.length() - 1;

        for (int i = number.length() - 1; i >= 0; i--) {
            if (number.charAt(i) == '0')
                continue;

            try {
                long num = Long.parseLong(number.substring(i));
                if (num > n) {
                    num = Long.parseLong(number.substring(lastIndex));
                    number = number.substring(0, lastIndex);
                    return num;
                }
                lastIndex = i;
            }
            catch (Exception e) {
                long num = Long.parseLong(number.substring(lastIndex));
                number = number.substring(0, lastIndex);
                return num;
            }

        }

        return 0;
    }

}

class MyScanner implements Closeable {

    public static final String CP1251 = "cp1251";

    private final BufferedReader  br;
    private       StringTokenizer st;
    private       String          last;

    public MyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    public MyScanner(String path) throws IOException {
        br = new BufferedReader(new FileReader(path));
    }

    public MyScanner(String path, String decoder) throws IOException {
        br = new BufferedReader(new InputStreamReader(new FileInputStream(path), decoder));
    }

    public void close() throws IOException {
        br.close();
    }

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

    public String next(String delim) throws IOException {
        while (st == null || !st.hasMoreElements())
            st = new StringTokenizer(br.readLine());
        last = null;
        return st.nextToken(delim);
    }

    public String nextLine() throws IOException {
        st = null;
        return (last == null) ? br.readLine() : last;
    }

    public boolean hasNext() {
        if (st != null && st.hasMoreElements())
            return true;

        try {
            while (st == null || !st.hasMoreElements()) {
                last = br.readLine();
                st = new StringTokenizer(last);
            }
        }
        catch (Exception e) {
            return false;
        }

        return true;
    }

    public String[] nextStrings(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = next();
        return arr;
    }

    public String[] nextLines(int n) throws IOException {
        String[] arr = new String[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLine();
        return arr;
    }

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

    public int[] nextInts(int n) throws IOException {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    public Integer[] nextIntegers(int n) throws IOException {
        Integer[] arr = new Integer[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextInt();
        return arr;
    }

    public int[][] next2Ints(int n, int m) throws IOException {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextInt();
        return arr;
    }

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

    public long[] nextLongs(int n) throws IOException {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++)
            arr[i] = nextLong();
        return arr;
    }

    public long[][] next2Longs(int n, int m) throws IOException {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextLong();
        return arr;
    }

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

    public double[] nextDoubles(int size) throws IOException {
        double[] arr = new double[size];
        for (int i = 0; i < size; i++)
            arr[i] = nextDouble();
        return arr;
    }

    public double[][] next2Doubles(int n, int m) throws IOException {
        double[][] arr = new double[n][m];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                arr[i][j] = nextDouble();
        return arr;
    }

    public boolean nextBool() throws IOException {
        String s = next();
        if (s.equalsIgnoreCase("true") || s.equals("1"))
            return true;

        if (s.equalsIgnoreCase("false") || s.equals("0"))
            return false;

        throw new IOException("Boolean expected, String found!");
    }
}


import java.util.*;

public class Ideone {
	public static ArrayList<String> Data = new ArrayList<String>();

	public static long fact (int n) {
		if (n <= 1) return 1;
		else {
			long rez = 1;
			for (int i = 2; i <= n; i++) rez *= i;
			return rez;
		}
	}

	public static long P (int[] count) {
		int n = 0;
		for (int i = 0; i < 10; i++) n += count[i];
		long rez = fact(n);
		for (int i = 0; i < 10; i++) rez /= fact(count[i]);
		if (count[0] >= 1) {
			long dif = fact(n-1);
			dif /= fact(count[0]-1);
			for (int i = 1; i < 10; i++) dif /= fact(count[i]);
			rez -= dif;
		}
		return rez;
	}

	public static long Calc (int[] count) {
		long rez = P(count);
		int[][] counts  = new int[10][10];
		for (int i = 0; i < 10; i++) {
			if(count[i] != 0 && count[i] != 1) {
				for (int j = 0; j < 10; j++) counts[i][j] = count[j];
				counts[i][i]--;
				String str = "";
				for (int j = 0; j < 10; j++) str += counts[i][j] + '0';
				boolean contains = false;
				for (int j = 0; j < Data.size() && !contains; j++) if (Data.get(j) == str) contains = true;
				if (!contains) {
					Data.add(str);
					rez += Calc(counts[i]);
				}
			}
		}
		return rez;
	}

	public static void main (String[] args) {
		int count[] = {0,0,0,0,0,0,0,0,0,0};
		String str;
		Scanner imput = new Scanner(System.in);
		str = imput.nextLine();
		for (char a: str.toCharArray()) count[a-'0']++;
		System.out.print(Calc(count));
	}
}


import java.util.*;

//http://codeforces.com/contest/991/problem/E
public class BusNumber {
    private static Map<ArrayList<Integer>, Long> memo = new HashMap<>();
    private static long[] fact = new long[20];

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        fact[0] = 1;
        for (int i = 1; i < fact.length; i++) {
            fact[i] = i * fact[i - 1];
        }
        char[] num = sc.nextLine().toCharArray();
        Map<Character, Integer> countMap = new HashMap<>();
        for (char c : num) {
            countMap.put(c, countMap.getOrDefault(c, 0) + 1);
        }
        int zeroCount = -1;
        if (countMap.containsKey('0')) {
            zeroCount = countMap.get('0');
            countMap.remove('0');
        }
        ArrayList<Integer> counts = new ArrayList<>();
        for (Integer i : countMap.values()) {
            counts.add(i);
        }
        System.out.println(solve(zeroCount, counts));
    }

    private static long solve(int zeros, ArrayList<Integer> dCounts) {
        Collections.sort(dCounts);
        if (zeros == 0 || dCounts.get(0) == 0) {
            return 0;
        } else if (memo.containsKey(dCounts)) {
            return memo.get(dCounts);

        }
        //count num digits
        int sum = Math.max(0, zeros);
        for (int i : dCounts) {
            sum += i;
        }

        //calc ways for this permutation
        long ways = fact[sum];
        for (int i : dCounts) {
            ways /= fact[i];
        }
        if (zeros != -1) {
            ways /= zeros;
            ways *= (sum - zeros);
            ways /= sum;
        }

        //
        for (int i = 0; i < dCounts.size(); i++) {
            ArrayList<Integer> copy = new ArrayList<>(dCounts.size());
            for (int j = 0; j < dCounts.size(); j++) {
                copy.add(dCounts.get(j));
            }
            copy.set(i, copy.get(i) - 1);
            ways += solve(zeros, copy);
        }
        if (zeros > -1) {
            ways += solve(zeros - 1, dCounts);
        }
        //subtract double-counts
        if (dCounts.size() > 1) {
            for (int i = 0; i < dCounts.size(); i++) {
                ArrayList<Integer> copy = new ArrayList<>(dCounts.size());
                for (int j = 0; j < dCounts.size(); j++) {
                    copy.add(dCounts.get(j) - 1);
                }
                copy.set(i, copy.get(i) + 1);
                ways -= solve(zeros - 1, copy);
            }
        }
        ArrayList<Integer> copy = new ArrayList<>(dCounts.size());
        if (zeros > -1) {
            for (int j = 0; j < dCounts.size(); j++) {
                copy.add(dCounts.get(j) - 1);
            }
            ways -= solve(zeros, copy);
        }

        //add the small part
        for (int j = 0; j < dCounts.size(); j++) {
            copy.add(dCounts.get(j) - 1);
        }
        ways += solve(zeros - 1, copy);
        return ways;
    }

}


import org.w3c.dom.ls.LSOutput;

import java.util.*;
import java.lang.*;

public class Main {
    static final int INF = 1000 * 1000 * 1000;

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

        int ans = 1;
        for (int i = 1; i < a + b; ++i) {
            if (a / i + b / i >= n) {
                ans = i;
            }
        }

        System.out.println(Math.min(ans, Math.min(a, b));
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    static BufferedReader br;
    static int[] f;
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        //br = new BufferedReader(new FileReader("src/march_circuits/input.txt"));
        f = new int[100000000];
        Arrays.fill(f, Integer.MAX_VALUE);
        prePro();
        long n = Long.parseLong(rl());
        if(n>1e8) {
            while(true);
        } else {
            System.out.println(f[(int) n]);
        }
    }

    private static void prePro() {
        f[0]=0;f[1]=1;f[2]=1;f[3]=1;f[4]=1;f[5]=1;f[6]=1;f[7]=1;f[8]=1;f[9]=1;
        for(int i=10;i<f.length;i++) {
          int dupI = i;
          int smallest = Integer.MAX_VALUE;
          while(dupI>0) {
              int rem = dupI % 10;
              int res = f[i - rem] + f[rem];
              if(res<smallest)smallest=res;
              dupI/=10;
          }
          f[i] = smallest;
        }
    }

    private static String rl() throws IOException { return br.readLine();}
    private static int ri() throws IOException { return Integer.parseInt(rl());}
    private static int[] ria() throws IOException {
        String[] line = rl().split(" ");
        int[] ar = new int[line.length];
        for(int i=0;i<line.length;i++) {
            ar[i] = Integer.parseInt(line[i]);
        }
        return ar;
    }
    private static long[] rla() throws IOException {
        String[] line = rl().split(" ");
        long[] ar = new long[line.length];
        for(int i=0;i<line.length;i++) {
            ar[i] = Integer.parseInt(line[i]);
        }
        return ar;
    }

}


import java.io.*;
import java.util.*;
public class A68 {
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] in = br.readLine().split(" ");
        int a = Integer.parseInt(in[4]);
        int b = Integer.parseInt(in[5]);
        int[] p = new int[4];
        for(int i=0;i<4;i++)
            p[i] = Integer.parseInt(in[i]);
        Arrays.sort(p);
        int t = Math.min(b, p[0]);
        int res = t-a;
        if(res<0)
            System.out.println(0);
        else
        System.out.println(res);
    }
}


import java.io.*;
import java.util.*;
/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
 */
public class Main
{
	static final long mod=1000000007;
	static final double eps=1e-8;
	static final long inf=100000000000000000L;
	static final boolean debug=true;
	static Reader in=new Reader();
	public static void main(String[] args) throws IOException
	{
		int a=ni(),b=ni(),k=ni(),t=ni();
		long dp[][]=new long[2*t+1][4*k*t+1];
		dp[0][2*t*k]=1;
		for(int i=1; i<=2*t; i++)
		{
			for(int j=0; j<k; j++)
			{
				dp[i][0]=(dp[i][0]+dp[i-1][j])%mod;
				dp[i][j+k+1]=(dp[i][j+k+1]-dp[i-1][j])%mod;
			}
			for(int j=k; j<4*k*t-k; j++)
			{
				dp[i][j-k]=(dp[i][j-k]+dp[i-1][j])%mod;
				dp[i][j+k+1]=(dp[i][j+k+1]-dp[i-1][j])%mod;
			}
			for(int j=4*k*t-k; j<=4*k*t; j++)
				dp[i][j-k]=(dp[i][j-k]+dp[i-1][j])%mod;
			for(int j=1; j<=4*k*t; j++)
				dp[i][j]=(dp[i][j-1]+dp[i][j])%mod;
		}
		long an=0;
		for(int i=b-a+1+2*t*k; i<=4*k*t; i++)
		{
			an=(an+dp[2*t][i])%mod;
		}
		pr((an+mod)%mod);
		System.out.println(ans);
	}
	static StringBuilder ans=new StringBuilder();
	static long powm(long a, long b, long m)
	{
		long an=1;
		long c=a;
		while(b>0)
		{
			if(b%2==1)
				an=(an*c)%m;
			c=(c*c)%m;
			b>>=1;
		}
		return an;
	}
	static void pd(){if(debug)ans.append("hola");}
	static void pd(Object a){if(debug)ans.append(a+"\n");}
	static void pr(Object a){ans.append(a+"\n");}
	static void pr(){ans.append("\n");}
	static void p(Object a){ans.append(a);}
	static int ni(){return in.nextInt();}
	static long nl(){return in.nextLong();}
	static String ns(){return in.next();}
	static double nd(){return in.nextDouble();}
	static String pr(String a, long b)
	{
		String c="";
		while(b>0)
		{
			if(b%2==1)
				c=c.concat(a);
			a=a.concat(a);
			b>>=1;
		}
		return c;
	}
	static class Reader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public Reader() {
            reader = new BufferedReader(new InputStreamReader(System.in), 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());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
    }
}


import java.util.Scanner;
import java.lang.Math;
public class main8{
public static void main(String arg[])
{
	Scanner s=new Scanner(System.in);
	int x=s.nextInt();
	int y=s.nextInt();
	int z=s.nextInt();
	int t1=s.nextInt();
	int t2=s.nextInt();
	int t3=s.nextInt();
	int ts=0,te=0;
	//Time taken by stairs
	ts=(Math.abs(x-y))*t1;
	//Time taken by elevator
	te=((Math.abs(z-x))*t2)+(3*t3)+(Math.abs(x-y))*t2;
	if(te=<ts)
	{
		System.out.println("YES");
	}
	else
		System.out.println("NO");
}
}


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

public class C implements Runnable
{
    String file = "input";

    boolean TEST = false;

    void solve() throws IOException
    {
        long xa = nextInt(), ya = nextInt(),
        xb = nextInt(), yb = nextInt(),
        xc = nextInt(), yc = nextInt();

        boolean ok = false;
        ok |= canSolve(xc, -yc, xb - xa, yc, xc, yb - ya);
        ok |= canSolve(xc, -yc, xb + ya, yc, xc, yb - xa);
        ok |= canSolve(xc, -yc, xb + xa, yc, xc, yb + ya);
        ok |= canSolve(xc, -yc, xb - ya, yc, xc, yb + xa);
        if(ok) out.println("YES");
        else out.println("NO");
    }

    boolean canSolve(long a1, long b1, long c1, long a2, long b2, long c2)
    {
        if(a1 == 0)
        {
            if(b1 == 0) return c1 == 0;
            if(c1 % b1 != 0) return false;
            long y = c1 / b1;
            long ly = c2 - b2 * y;
            if(a2 == 0) return ly == 0;
            if(ly % a2 != 0) return false;
            return true;
        }
        if(a2 == 0)
        {
            if(b2 == 0) return c2 == 0;
            if(c2 % b2 != 0) return false;
            long y = c2 / b2;
            long ly = c1 - b1 * y;
            if(a1 == 0) return ly == 0;
            if(ly % a2 != 0) return false;
            return true;
        }

        long det = a2 * b1 - a1 * b2;
        long fy = c1 * a2 - c2 * a1;
        long fx = c1 * b2 - c2 * b1;

        //print(a1, b1, c1, a2, b2, c2, det, fy, fx);

        if(det == 0)
        {
            if(fy != 0 || fx != 0) return false;
            return true;
        }

        if(fy % det != 0) return false;
        if(fx % det != 0) return false;

        return true;
    }

    String next() throws IOException
    {
        while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(input.readLine());
        return st.nextToken();
    }

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

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

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

    void print(Object... o)
    {
        System.out.println(deepToString(o));
    }

    void gcj(Object o)
    {
        String s = String.valueOf(o);
        out.println("Case #" + test + ": " + s);
        System.out.println("Case #" + test + ": " + s);
    }

    BufferedReader input;
    PrintWriter out;
    StringTokenizer st;
    int test;

    void init() throws IOException
    {
        if(TEST) input = new BufferedReader(new FileReader(file + ".in"));
        else input = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new BufferedOutputStream(System.out));
    }

    public static void main(String[] args) throws IOException
    {
        new Thread(null, new C(), "", 1 << 20).start();
    }

    public void run()
    {
        try
        {
            init();
            if(TEST)
            {
                int runs = nextInt();
                for(int i = 0; i < runs; i++) solve();
            }
            else solve();
            out.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
            System.exit(1);
        }
    }
}


import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: Lenovo
 * Date: 12-4-10
 * Time: 下午11:20
 * To change this template use File | Settings | File Templates.
 */
public class Main {
    private static long gcd(long a,long b)
    {
        return b==0 ? a : gcd(b,a%b);
    }
    private static boolean can(long a,long b,long c,long d,long e,long f)
    {
        long s=a*e-b*d;
        if (s!=0)
        {
            return (c*e-b*f)%s==0 && (a*f-c*d)%s==0;
        }
        else return (c*e==b*f && a*f==c*d && c%gcd(Math.abs(a),Math.abs(b))==0);
    }
    public static void main(String[] args)
    {
        long x1,y1,x2,y2,x3,y3;
        Scanner scan = new Scanner(System.in);
        x1=scan.nextLong();
        y1=scan.nextLong();
        x3=scan.nextLong();
        y3=scan.nextLong();
        x2=scan.nextLong();
        y2=scan.nextLong();
        System.out.println((can(x2,y2,x1-x3,y2,x2,y1-y3)
                || can(x2,y2,x1+x3,y2,x2,y1+y3)
                || can(x2,y2,x1-y3,y2,x2,y1-x3)
                || can(x2,y2,x1+y3,y2,x2,y1+x3)) ? "YES" : "NO");
    }
}


import java.util.*;
import java.math.*;

public class Main{
    public static void main(String [] args)
    {
        Scanner scan=new Scanner(System.in);
        int x1[]=new int[4];
        int y1[]=new int[4];
        int x2[]=new int[4];
        int y2[]=new int[4];
        int hor=0;
        int ver=0;

        for(int i=0 ; i<4; i++)
        {
            x1[i]=scan.nextInt();
            y1[i]=scan.nextInt();
            x2[i]=scan.nextInt();
            y2[i]=scan.nextInt();
        }
        int count=0;
        for(int i=0; i< 3; i++)
        {
            for(int j=i+1 ; j<4 ; j++)
            {
                if(x1[i]==x1[j] && y1[i]==y1[j])
                    count++;
                if(x2[i]==x2[j] && y2[i]==y2[j])
                    count++;
                if(x1[i]==x2[j] && y1[i]==y2[j])
                    count++;
                if(x2[i]==x1[j] && y2[i]==y1[j])
                    count++;
            }
        }
        if(hor==2 && ver==2 && count==4)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}


import java.util.*;
import static java.lang.Math.*;

public class E {
    static void p(Object ...args) {System.out.println(Arrays.deepToString(args));}
    static long MOD = 1_000_000_007;

    /*static int score(int a, int k) {
        int ans = 0;
        while( a > 0) {
            ans += a % k;
            a /= k;
        }
        return ans % k;
    }

    public static long slow(int N, int K) {
        long[] V = new long[N+1];
        for (int i = 0; i <= N; i++)
            V[i] = score(i, K);
        long[] dp = new long[N+1];
        for (int i = 0; i <= N; i++) {
            for (int j = 0; j < K; j++) {
                for (int a = i - 1; a >= 0; a--) {
                    if (V[a] == j) {
                        dp[i] += dp[a];
                        break;
                    }
                }
            }
            dp[i] += 1;
            dp[i] %= MOD;
        }
        return dp[N];
    }*/
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long N = in.nextLong();
        int K = in.nextInt();

        long[][][] M = new long[70][][];
        for (int i = 2; i < M.length; i++)
            M[i] = makeMatrix(K, i);

        /*p("M[2]");
        for (int i = 0; i < M[2].length; i++)
            p(M[2][i]);
        p("M[3]");
        for (int i = 0; i < M[3].length; i++)
            p(M[3][i]);*/

        long[][][] moveBy = new long[70][][];
        long[][][] moveByK = new long[70][][];
        for (int i = 1; i < moveBy.length - 1; i++) {
            long[][] ans = new long[K+1][K+1];
            for (int j = 0; j < ans.length; j++)
                ans[j][j] = 1;
            for (int j = i - 1; j >= 1; j--)
                ans = multiply(ans, moveByK[j]);

            ans = multiply(ans, M[i+1]);
            moveBy[i] = ans;
            moveByK[i] = new long[K+1][K+1];
            for (int j = 0; j <= K; j++)
                moveByK[i][j][j] = 1;
            for (int j = 0; j < K-1; j++)
                moveByK[i] = multiply(moveByK[i], moveBy[i]);
        }
        /*p("moveBy[2]");
        for (int i = 0; i <= K; i++)
            p(moveBy[2][i]);*/

        long at = 0;
        long[][] f = new long[K+1][K+1];
        for (int i = 0; i < f.length; i++)
            f[i][i] = 1;
        //f = multiply(f, M[2]);
        //f = multiply(f, M[3]);
        long temp = N / K;
        for (int i = 1; temp > 0; i++) {
            for (int j = 0; j < temp % K; j++) {
                //p("mult by", i);
                f = multiply(moveBy[i], f);
            }
            temp /= K;
        }
        /*p("f");
        for (int i = 0; i < K+1; i++)
            p(f[i]);*/
        long[] start = new long[K+1];
        for (int i = 0; i < start.length; i++)
            start[i] = (1L<<(i)) % MOD;
        start[K] = 1;

        int position = (int)(N % K);
        //p("taking: ", position);
        long ans = 0;
        for (int i = 0; i < start.length; i++)
            ans += (start[i] * f[i][position]) % MOD;
        ans %= MOD;

        /*long a2 = slow((int)N, K);
        if (ans != a2) {
            p(ans, a2);
            throw new RuntimeException();
        }*/
        System.out.println(ans);
    }
    static long[][] makeMatrix(int K, int a) {
        long[][] res = new long[K+1][K+1];

        int[] v = new int[2*K];
        v[2*K-1] = 0;
        for (int i = 2*K-2; i >= 0; i--) {
            if (i == K-1) {
                v[i] = (K + (K-a + v[i+1]) % K) % K;
            } else {
                v[i] = (K + (K-1 + v[i+1]) % K) % K;
            }
        }
        /*if (a == 2 || a == 3) {
            p(a, v);
        }*/
        for (int i = 0; i <= K; i++)
            res[K][i]++;
        for (int c = 0; c < K; c++) {
            for (int i = 0; i < K; i++) {
                boolean found = false;
                for (int j = c - 1 + K; j >= 0; j--) {
                    if (v[j] == i) {
                        found = true;
                        if (j < K) {
                            res[j][c] += 1;
                        } else {
                            for (int b = 0; b <= K; b++)
                                res[b][c] += res[b][j-K];
                        }
                        break;
                    }
                }
                if (!found) {
                    p(c, i, v);
                    throw new RuntimeException();
                }
            }
        }
        return res;
    }
    static long[][] multiply(long[][] A, long[][] B) {
        long[][] res = new long[A.length][A.length];
        for (int r = 0; r < A.length; r++)
            for (int c = 0; c < A.length; c++) {
                for (int i = 0; i < A.length; i++)
                    res[r][c] += (A[r][i] * B[i][c]) % MOD;
                res[r][c] %= MOD;
            }
        return res;
    }
 }


/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
	     Scanner in=new Scanner(System.in);
	     long a,b,c,d,i,j;
	     a=in.nextLong();
	     b=in.nextLong();
	     c=in.nextLong();
	     d=in.nextLong();
	     if(c%2==0 && d%2==0 && b%2!=0 && a%2==0 )
	          System.out.println("-1");
	     else if(d%2!=0 && c%2==0 && a%2==0 && b%2==0)
	          System.out.println("-1");
	     else {
	     for(i=b;i<100000;i+=a)
	     {
	          for(j=d;j<=i;j+=c)
	          {
	               if(j==i)
	               {    System.out.println(j);
	                    break;}
	          }
	          if(j==i)
	          break;
	     }
	     if(j!=i)
	          System.out.println("-1");
	     }
	}
}


/**
 * @author derrick20
 */

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

public class ShovelSale {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

//        for (int N = 1; N <= 100; N++) {
        String s = sc.next();
        int N = Integer.parseInt(s);
        int S = 2 * N - 1;
        int max = 0;
        long x = 0;
        long sum = 0;
        while ((10 * x + 9) <= S) {
            max++;
            x = 10 * x + 9;
        }
        sum = x;
        x = 1;
        for (int i = 0; i < max; i++) {
            x *= 10;
        }
        while (sum + x <= S) {
            sum += x;
        }

        int bruteans = brute(N, max);
//        System.out.println("Brute for " + N + " and max of " + max + ": " + bruteans);

        long ans = 0;
        if (max == 0) {
            ans = N * (N - 1) / 2;
        }
        else {
            while (sum >= x) {
                ans += (N >= sum ? (sum) / 2 : (N - (sum - N) + 1) / 2);
                sum -= x;
            }
            ans += (N >= sum ? (sum) / 2 : (N - (sum - N) + 1) / 2);
        }
//            System.out.println(ans);
//            if (bruteans != ans) {
//                System.exit(0);
//            }
//        }
        out.println(bruteans);
        out.close();
    }

    static int brute(int N, int max) {
        int res = 0;
        for (int i = 1; i <= N; i++) {
            for (int j = i + 1; j <= N; j++) {
                int sum = i + j;
                int ct = 0;
                while (sum > 0) {
                    if (sum % 10 == 9) {
                        ct++;
                    }
                    else {
                        break;
                    }
                    sum /= 10;
                }
                if (ct == max) {
//                    System.out.println(i + j);
                    res++;
                }
            }
        }
        return res;
    }

    static class FastScanner {
        private int BS = 1 << 16;
        private char NC = (char) 0;
        private byte[] buf = new byte[BS];
        private int bId = 0, size = 0;
        private char c = NC;
        private double cnt = 1;
        private BufferedInputStream in;

        public FastScanner() {
            in = new BufferedInputStream(System.in, BS);
        }

        public FastScanner(String s) {
            try {
                in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
            } catch (Exception e) {
                in = new BufferedInputStream(System.in, BS);
            }
        }

        private char getChar() {
            while (bId == size) {
                try {
                    size = in.read(buf);
                } catch (Exception e) {
                    return NC;
                }
                if (size == -1) return NC;
                bId = 0;
            }
            return (char) buf[bId++];
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public int[] nextInts(int N) {
            int[] res = new int[N];
            for (int i = 0; i < N; i++) {
                res[i] = (int) nextLong();
            }
            return res;
        }

        public long[] nextLongs(int N) {
            long[] res = new long[N];
            for (int i = 0; i < N; i++) {
                res[i] = nextLong();
            }
            return res;
        }

        public long nextLong() {
            cnt = 1;
            boolean neg = false;
            if (c == NC) c = getChar();
            for (; (c < '0' || c > '9'); c = getChar()) {
                if (c == '-') neg = true;
            }
            long res = 0;
            for (; c >= '0' && c <= '9'; c = getChar()) {
                res = (res << 3) + (res << 1) + c - '0';
                cnt *= 10;
            }
            return neg ? -res : res;
        }

        public double nextDouble() {
            double cur = nextLong();
            return c != '.' ? cur : cur + nextLong() / cnt;
        }

        public String next() {
            StringBuilder res = new StringBuilder();
            while (c <= 32) c = getChar();
            while (c > 32) {
                res.append(c);
                c = getChar();
            }
            return res.toString();
        }

        public String nextLine() {
            StringBuilder res = new StringBuilder();
            while (c <= 32) c = getChar();
            while (c != '\n') {
                res.append(c);
                c = getChar();
            }
            return res.toString();
        }

        public boolean hasNext() {
            if (c > 32) return true;
            while (true) {
                c = getChar();
                if (c == NC) return false;
                else if (c > 32) return true;
            }
        }
    }
}


//package com.company;

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

public class Main {
    public static class Task {
        public class Number {
            int factNum;
            int[] primeFactorCounts;
            int largestFactor;
            int S = 0;
            public Number(int f, int[] primeFactorCounts) {
                this.factNum = f;
                this.primeFactorCounts = primeFactorCounts;
                for (largestFactor = primeFactorCounts.length - 1; largestFactor >= 0; largestFactor--) {
                    if (primeFactorCounts[largestFactor] != 0) break;
                }
                for (int y: primeFactorCounts)S += y;
            }
            int getL() {
                if (largestFactor == -1) return -1;
                int r = largestFactor;
                primeFactorCounts[r]--;
                if (primeFactorCounts[r] == 0) largestFactor--;
                return r;
            }
        }

        List<Integer> primes;
        int[] factor;

        public void precompute() {
            int n = 5001;
            primes = new ArrayList<>();
            factor = new int[n];
            Arrays.fill(factor, -1);
            for (int i = 2; i < n; ++i) {
                if (factor[i] == -1) {
                    factor[i] = primes.size();
                    primes.add(i);
                }
                for (int j = 0; j < primes.size () && i * primes.get(j) < n; ++j) {
                    int p = primes.get(j);
                    factor[i * p] = j;
                    if (i % p == 0) {
                        break;
                    }
                }
            }
        }

        List<Integer> fact(int x) {
            List<Integer> retL = new ArrayList<>();
            while (x != 1) {
                retL.add(factor[x]);
                x /= primes.get(factor[x]);
            }
            return retL;
        }

        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            precompute();
            int[] primeF = new int[700];
            Number[] numbers = new Number[5001];
            numbers[1] = new Number(1, Arrays.copyOf(primeF, 700));
            for (int i = 2; i <= 5000; i++) {
                List<Integer> f = fact(i);
                for (int y: f) primeF[y]++;
                numbers[i] = new Number(i, Arrays.copyOf(primeF, 700));
            }
//            pw.println(Arrays.toString(numbers[5000].primeFactorCounts));
//            System.err.println(numbers[5000].S);
            Map<Integer, Integer> numToCount = new HashMap<>();
            int n = sc.nextInt();
            for (int i = 0; i < n; i++) {
                int a = sc.nextInt();
                numToCount.put(a, numToCount.getOrDefault(a, 0) + 1);
            }
            long total = 0;
            for (Map.Entry<Integer, Integer> en : numToCount.entrySet()) {
                total += (long) en.getValue() * numbers[en.getKey()].S;
            }
            outer:
            while (true) {
                Map<Integer, Integer> kG = new HashMap<>();
                for (Map.Entry<Integer, Integer> en : numToCount.entrySet()) {
                    int k = en.getKey();
                    int v = en.getValue();
                    int lf = numbers[k].largestFactor;
                    kG.put(lf, kG.getOrDefault(lf, 0) + v);
                }
                for (Map.Entry<Integer, Integer> en: kG.entrySet()) {
                    if (n - en.getValue() < en.getValue()) {
                        total -= en.getValue() - (n - en.getValue());
                        Map<Integer, Integer> nC = new HashMap<>();
                        for (Map.Entry<Integer, Integer> en1 : numToCount.entrySet()) {
                            int lf = numbers[en1.getKey()].getL();
                            if (lf == en.getKey()) {
                                nC.put(en1.getKey(), en1.getValue());
                            }
                        }
                        numToCount = nC;
                        continue outer;
                    }
                }
                pw.println(total);
                return;
            }
        }
    }

    static long TIME_START, TIME_END;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("input"));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("output"));

        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
        System.err.println("Memory increased: " + (usedMemoryAfter - usedMemoryBefore) / 1000000);
        System.err.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader s) throws FileNotFoundException {
            br = new BufferedReader(s);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

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


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AsgarJ
 */
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);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        int LEN;
        static final int DIGIT = 17;
        static int[] cnt = new int[DIGIT - 1];
        char[] res;
        int k;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            k = in.nextInt();
            int T = in.nextInt();
            Arrays.fill(cnt, T);

            if (k < 16) {
                out.println(getChar(k));
                return;
            }

            long[] counts = dp(13);
            LEN = getLength(counts, k);

            res = new char[LEN];

            int startIndex = 0;
            if (LEN > 10) startIndex = brute();

            int[] curCount = new int[]{0};
            for (int i = 1; i <= LEN - startIndex; i++) {
                bruteForce(startIndex, cnt, res, i + startIndex, k, curCount);
            }

            out.println(res);
        }

        private int getLength(long[] counts, int k) {
            int LEN = 1;
            for (; LEN <= 13; LEN++) {
                if (LEN <= cnt[0] && k > counts[LEN] - 1) continue;
                else if (LEN > cnt[0] && k > counts[LEN]) continue;
                else break;
            }
            return LEN;
        }

        private int brute() {
            k -= dp(LEN)[LEN - 1];
            if (LEN - 1 <= cnt[0]) k++;
            int ret = 3;
            for (int i = 0; i < ret; i++) {
                int digit = getNextDigit(i == 0 ? 0 : -1);
                for (; digit < DIGIT - 1 && k > 0; digit = getNextDigit(digit)) {
                    cnt[digit]--;
                    int temp = (int) dp(LEN - i)[LEN - i - 1];
                    if (k > temp) {
                        k -= temp;
                        cnt[digit]++;
                        continue;
                    } else if (k == temp) {
                        res[i++] = getChar(digit);
                        for (; i < LEN; i++) {
                            res[i] = getChar(getLastDigit());
                        }
                        return i;
                    } else {
                        res[i] = getChar(digit);
                        break;
                    }
                }
            }
            return ret;
        }

        private void bruteForce(int index, int[] cnt, char[] res, int len, int max, int[] cur) {
            if (index == len) {
                cur[0]++;
                return;
            }
            for (int i = getNextDigit(index == 0 ? 0 : -1); i != 16; i = getNextDigit(i)) {
                cnt[i]--;
                if (cur[0] < max) {
                    res[index] = getChar(i);
                    bruteForce(index + 1, cnt, res, len, max, cur);
                    cnt[i]++;
                } else return;
            }
        }

        private int getNextDigit(int startDigit) {
            int i = startDigit + 1;
            for (; i < cnt.length && cnt[i] == 0; i++) ;
            return i;
        }

        private long[] dp(int len) {
            long[][] dp = new long[DIGIT][++len];
            dp[0][0] = 1;

            for (int i = 1; i < DIGIT; ++i) {
                for (int j = 0; j < len; ++j) {
                    for (int c = 0; c <= Math.min(j, cnt[i - 1]); c++) {
                        for (int k = i - 1; k < i; k++) {
                            dp[i][j] += dp[k][j - c] * comb(j, c);
                        }
                    }
                }
            }

//        System.out.printf("dp[15][%d]: ", len);   print(dp[DIGIT - 1]);

            return dp[DIGIT - 1];
        }

        private char getChar(int digit) {
            return (char) (digit < 10 ? '0' + digit : 'a' + digit - 10);
        }

        private int getLastDigit() {
            int i;
            for (i = cnt.length - 1; i >= 0 && cnt[i] == 0; i--) ;
            cnt[i]--;
            return i;
        }

        private long comb(int n, int k) {
            long res = 1L;
            if (k < n)
                for (int i = 1; i <= k; i++) {
                    res = res * (n - k + i) / i;
                }
            return res;
        }

    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

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

        public Integer nextInt() {
            return Integer.valueOf(next());
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.Writer;
import java.io.OutputStreamWriter;
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);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        static boolean debug = true;
        int numberNumber;
        int t;
        long[][] bin = IntegerUtils.generateBinomialCoefficients(100);

        static {
            if (debug) {
                try {
                    FileOutputStream f = new FileOutputStream("file.txt");
                    System.setErr(new PrintStream(f));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
            }
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            numberNumber = in.readInt();
            t = in.readInt();

//        t = 1;

            //        HashMap<Integer, String> answers = new HashMap<>();
//
//        for (int i = 1, cnt = 0; cnt < 1e5; i++) {
//            int[] cntTake = new int[16];
//            for (char c : String.format("%x", i).toCharArray()) {
//                ++cntTake[Integer.parseInt("" + c, 16)];
//            }
//            boolean ok = true;
//            for (int c : cntTake) {
//                ok &= c <= t;
//            }
//            if (ok) {
//                ++cnt;
//                String answer = String.format("%x", i);
//                answers.put(cnt, answer);
//                System.err.println(cnt + " = " + answer);
//                System.err.flush();
//            }
//        }

//
//        for (int _numberNumber = 1; ; _numberNumber++) {
//            numberNumber = _numberNumber;
            int wordLength = 1;
            for (; ; wordLength++) {
                long[][] dp = new long[16][wordLength + 1];

                for (int length = 0; length <= wordLength; length++) {
                    for (int ch = 0; ch < 16; ch++) {
                        if (length == 0) {
                            dp[ch][length] = 1;
                        } else if (ch == 0) {
                            if (length <= t) {
                                dp[ch][length] = bin[wordLength - 1][length];
                            }
                        } else {
                            dp[ch][length] += dp[ch - 1][length];
                            for (int c = 1; c <= Math.min(length, t); c++) {
                                dp[ch][length] += bin[wordLength - length + c][c] * dp[ch - 1][length - c];
                            }
                        }
                    }
                }

                System.err.println("wordLength, dp: " + wordLength + " " + dp[15][wordLength]);
                System.err.flush();
                if (dp[15][wordLength] < numberNumber) {
                    numberNumber -= dp[15][wordLength];
                } else {
//                out.printLine("wordLength: " + wordLength);
                    break;
                }
            }

            StringBuilder ans = new StringBuilder();
            int[] maxCnt = new int[16];
            Arrays.fill(maxCnt, t);
            for (int pos = 0; pos < wordLength; pos++) {
                boolean addCh = false;
                for (int ch = 0; ch < 16; ch++) {
                    if (pos == 0 && ch == 0) {
                        continue;
                    }
                    if (maxCnt[ch] == 0) {
                        continue;
                    }
                    --maxCnt[ch];
                    long dp = getDp(wordLength - pos - 1, maxCnt);
                    if (numberNumber <= dp) {
                        ans.append(String.format("%x", ch));
                        addCh = true;
                        break;
                    } else {
                        ++maxCnt[ch];
                        numberNumber -= dp;
                    }
                }
                if (!addCh) {
                    throw new RuntimeException("no addCh");
//                    out.printLine("no add ch at pos=" + pos, "   : ", _numberNumber, answers.get(_numberNumber), ans);
//                    return;
                }
            }
//            if (!answers.get(_numberNumber).equals(ans.toString())) {
//                out.printLine("FUCK:", _numberNumber, answers.get(_numberNumber), ans);
//                return;
//            }
            out.printLine(ans);
//        }
        }

        private long getDp(int wordLength, int[] maxCnt) {
            long[][] dp = new long[16][wordLength + 1];
            for (int length = 0; length <= wordLength; length++) {
                for (int ch = 0; ch < 16; ch++) {
                    if (length == 0) {
                        dp[ch][length] = 1;
                    } else {
                        if (ch != 0) {
                            dp[ch][length] += dp[ch - 1][length];
                        }
                        for (int cnt = 1; cnt <= Math.min(length, maxCnt[ch]); cnt++) {
                            if (ch == 0) {
                                if (length == cnt) {
                                    dp[ch][length] += bin[wordLength][cnt];
                                }
                            } else {
                                dp[ch][length] += bin[wordLength - length + cnt][cnt] * dp[ch - 1][length - cnt];
                            }
                        }
                    }
                }
            }
            return dp[15][wordLength];
        }

    }

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

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

        public 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++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if ((c < '0') || (c > '9')) {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

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

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

        }

    }

    static class IntegerUtils {
        public static long[][] generateBinomialCoefficients(int n) {
            long[][] result = new long[n + 1][n + 1];
            for (int i = 0; i <= n; i++) {
                result[i][0] = 1;
                for (int j = 1; j <= i; j++) {
                    result[i][j] = result[i - 1][j - 1] + result[i - 1][j];
                }
            }
            return result;
        }

    }

    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 print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

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

    }
}