import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StreamTokenizer;
import java.io.Writer;
import java.util.Stack;

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

    StreamTokenizer in;
    PrintWriter out;
    boolean oj;

    void init() throws IOException {
        Reader reader = new InputStreamReader(System.in);
        Writer writer = new OutputStreamWriter(System.out);
        in = new StreamTokenizer(new BufferedReader(reader));
        out = new PrintWriter(writer);
    }

    void run() throws IOException {
        init();
        solve();
        out.flush();
    }

    void printMem() {
        if (!oj) {
            System.out.println("Memory used = "
                    + (Runtime.getRuntime().totalMemory() - Runtime
                            .getRuntime().freeMemory()));
        }
    }

    int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    long nextLong() throws IOException {
        in.nextToken();
        return (long) in.nval;
    }

    String nextString() throws IOException {
        in.nextToken();
        return in.sval;
    }

    double nextDouble() throws IOException {
        in.nextToken();
        return in.nval;
    }

    long deg(long x, long y) {
        long a = x;
        for (long i = 2; i <= y; i++) {
            a *= x;
        }
        return a;
    }

    long fact(long x) {
        long a = 1;
        for (long i = 2; i <= x; i++) {
            a *= i;
        }
        return a;
    }

    long digitSum(String x) {
        long a = 0;
        for (int i = 0; i < x.length(); i++) {
            a += x.codePointAt(i) - 48;
        }
        return a;
    }

    long digitSum(long x) {
        long a = 0;
        while (x > 0) {
            a += x % 10;
            x /= 10;
        }
        return a;
    }

    double pif(double ax, double ay, double bx, double by) {
        return Math.sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
    }

    double getPosPart(double x) {
        if (x <= 0)
            return 0;
        else
            return x;
    }

    double max(double x, double y) {
        if (x > y)
            return x;
        else
            return y;
    }

    long gcd(long a, long b) {
        if (a < b) {
            long c = b;
            b = a;
            a = c;
        }
        while (a % b != 0) {
            a = a % b;
            if (a < b) {
                long c = b;
                b = a;
                a = c;
            }
        }
        return b;
    }

    long lcm(long a, long b) throws IOException {
        return a * b / gcd(a, b);
    }

    int countOccurences(String x, String y) {
        int a = 0, i = 0;
        while (true) {
            i = y.indexOf(x);
            if (i == -1)
                break;
            a++;
            y = y.substring(i + 1);
        }
        return a;
    }

    int[] primes;

    int findPrimes(int x) {
        boolean[] forErato = new boolean[x];
        primes = new int[x];
        int l = 0, j = 0;
        for (int i = 2; i < x; i++) {
            if (forErato[i])
                continue;
            l++;
            primes[l] = i;
            j = i * 2;
            while (j < x) {
                forErato[j] = true;
                j += i;
            }
        }
        return l;
    }

    void solve() throws IOException {
        long a = nextInt(), b = nextInt(), j = 0, x = nextInt(), y = nextInt();
        if (a * y >= x * b) {
            j = b / y;
        } else {
            j = a / x;
        }
        while (j * x * j * y > a * b) j--;
        out.print(j*x + ' ' + j*y);
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
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 {
		private static long[][] dp;
		private static byte a;
		private static byte b;
		private static char ab;
		private static char ba;

		private static long ncr (int n, int r) {
			if (r == 1) return n;
			if (n == r || r == 0) return 1;
			if (dp[n][r] != -1) {
				return dp[n][r];
			}
			dp[n][r] = ncr (n-1, r)+ncr (n-1, r-1);
			if (dp[n][r]>InputReader.inf) {
				dp[n][r] %= InputReader.inf;
			}
			return dp[n][r];
		/*//use this method only when calculating ncr less times
		if(r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
    	long ans = 1;
		for(int i = 1; i <= r; i++) {
			ans *= n - r + i;
			ans /= i;
		}
		return ans;*/
		}

		private static boolean check (long os) {
			String str = Long.toString (os);
			int len = str.length ();
			for (int i = 0; i<len; i++) {
				if (str.charAt (i) != ab && str.charAt (i) != ba) {
					return false;
				}
			}
			return true;
		}

		public void solve (int testNumber, InputReader in, PrintWriter out) {
/* I have found 2 ways, main eqn is a*x+b*(n-x)=such a number that has only a and b. Now whether brute over x or
 * brute over r.h.s. I think brute over x is better choice, after finding x, ans+=n!/x!(n-x)! that means ncx*/
			a = (byte) in.nextInt ();
			b = (byte) in.nextInt ();
			ab = (char) (a+'0');
			ba = (char) (b+'0');
			int n = in.nextInt ();
			dp = new long[n+5][n/2+5];
			for (int i = 0; i<n+5; i++) {
				Arrays.fill (dp[i], -1);
			}
			long ans = 0;//when modding try to use if(ans>1e14) ans%=inf
			long os = -a+b*(n+1);
			for (int i = 0; i<=n; i++) {
				os += a;
				os -= b;
				if (check (os)) {
					if (i>n/2) {
						ans += ncr (n, n-i);
					}
					else ans += ncr (n, i);
					if (ans>1e14) {
						ans %= InputReader.inf;
					}
				}
			}
			out.println (ans);
		}

	}

	static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;
		public static final int inf = 1000000007;

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

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

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

	}
}


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

public class C {
	BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter out;

    long MODULAR = 1000000007;

    public boolean isValid(long num, int A, int B){
    	while( num > 0){
    		if( num % 10 != A && num % 10 != B) return false;
    		num = num / 10;
    	}
    	return true;
    }

    public static long[][] generateCombo(int MAX, long MOD) {
		long[][] result = new long[MAX + 1][MAX + 1];
		if (MOD == 1)
			return result;
		for (int i = 0; i <= MAX; i++) {
			result[i][0] = 1;
			for (int j = 1; j <= i; j++) {
				result[i][j] = result[i - 1][j - 1] + result[i - 1][j];
				if (result[i][j] >= MOD)
					result[i][j] -= MOD;
			}
		}
		return result;
	}

	public void solve() throws IOException {
		int A = nextInt();
		int B = nextInt();
		int N = nextInt();

		boolean[] OK = new boolean[N+1];
		long sum = A * N;

		if( isValid(sum, A, B) ) {
			OK[0]=true;
		}

		for(int i = 1; i <= N; i++){
			sum = sum + B - A;
			if( isValid(sum, A, B) ){
				OK[i]=true;
			}
		}

		long[][] C = generateCombo(N, MODULAR);

		long ans = 0;
		for(int i = 0; i <= N; i++){
			if( OK[i] ){
				ans = (ans + C[N][i]) % MODULAR;
			}
		}
		out.println( ans );
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new C().run();
	}

	public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            out = new PrintWriter(System.out);
            solve();
            reader.close();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

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

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

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

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

}


package bearandreverseradewoosh;

import java.util.Scanner;

public class BearandReverseRadewoosh {

    public static void main(String[] args) {
       Scanner input = new Scanner (System.in);
       int n,c;
       double z=0,x=0,k;
       n=input.nextInt();
            c=input.nextInt();
            int p[]=new int[n];
            int t[]=new int [n];
            for(int i=0;i<n;i++)p[i]=input.nextInt();
             for(int i=0;i<n;i++)t[i]=input.nextInt();
              for(int i=0;i<n;i++)
              {
              if (i==0)
              {
                  k=(p[i]-c*t[i]) ;
                  if (k>0) z+=k;
              }
              else
              {
                  k=(p[i]-(t[i-1]+t[i])*c) ;
                 if(k>0) z+=k;
              }
              }
               for(int i=(n-1);i>=0;i--)
               {
               if(i==(n-1))
               {
                   k=p[i]-c*t[i];
                  if(k>0) x+=k;
               }
               else
               {
                   k=p[i]-c*(t[i+1]+t[i]);
                 if (k>0)  x+=k;
               }
               }
            if(z>x) System.out.println("Limak");
            if(z<x) System.out.println("Radewoosh");
            if(z==x)System.out.println("Tie");
    }

}


package practice;

import java.util.Scanner;

/**
 * Created by chris on 30/03/2016.
 * http://codeforces.com/problemset/problem/658/A
 */
public class BearAndReverseRadewoosh {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int c = scanner.nextInt();

        int[] scores = new int[n];
        int[] times = new int[n];

        for (int i = 0; i < n; i++) {
            scores[i] = scanner.nextInt();
        }

        for (int i = 0; i < n; i++) {
            times[i] = scanner.nextInt();
        }

        int timeLimak = 0;
        int timeRadewoosh = 0;
        int limak = 0;
        int radewoosh = 0;

        for (int i = 0; i < n; i++) {
            timeLimak += times[i];
            limak += Math.max(0, scores[i] - (c * timeLimak));

            timeRadewoosh += times[n-(i+1)];
            radewoosh += Math.max(0, scores[n-(i+1)] - (c * timeRadewoosh));
        }

        String result;

        if (limak == radewoosh) {
            result = "Tie";
        } else {
            result = limak > radewoosh ? "Limak" : "Radeoosh";
        }

        System.out.println(result);
    }
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main contest = new Main();
		contest.contestant();
	}

	public void contestant() {
		int n = 0;
		int k = 0;
		int count = 0;
		Scanner value = new Scanner(System.in);
		n = value.nextInt();
		int a[] = new int[n];
		k = value.nextInt();
		for (int i = 0; i < a.length; i++) {
			a[i] = value.nextInt();
		}
		for (int i = 0; i < n; i++) {
			if (a[i] >= a[k]) {
				count++;
			}
		}
		System.out.println(count);
	}
}


import java.util.*;
import java.io.*;
public class R614D1B {
    private static List<long[]> pts;
    private static boolean[] taken;
    private static int ans;
    private static long T;
    private static boolean btwn(long x, long a, long b) {
        return Math.min(a,b)<=x && x<=Math.max(a,b);
    }
    private static long dist(long[] a, long[] b) {
        return Math.abs(a[0]-b[0])+Math.abs(a[1]-b[1]);
    }
    private static void find(int id, int cnt, long time) {
        //System.err.println(id+" "+cnt+" "+time);
        if (time>T)
            return;
        ans=Math.max(ans,cnt);
        taken[id]=true;
        for (int i=0; i<pts.size(); i++) {
            if (taken[i])
                continue;
            boolean good=true;
            for (int j=0; j<pts.size(); j++)
                if (!taken[j] &&
                        j!=i &&
                        btwn(pts.get(j)[0],pts.get(id)[0],pts.get(i)[0]) &&
                        btwn(pts.get(j)[1],pts.get(id)[1],pts.get(i)[1])) {
                    good=false;
                    break;
                }
            if (!good)
                continue;
            long d=dist(pts.get(id),pts.get(i));
            if (time>T-d)
                continue;
            find(i,cnt+1,time+d);
        }
        taken[id]=false;
    }
    public static void main(String[] args) throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tok = new StringTokenizer(in.readLine());
        long x0=Long.parseLong(tok.nextToken()),
                y0=Long.parseLong(tok.nextToken()),
                ax=Long.parseLong(tok.nextToken()),
                ay=Long.parseLong(tok.nextToken()),
                bx=Long.parseLong(tok.nextToken()),
                by=Long.parseLong(tok.nextToken());
        tok=new StringTokenizer(in.readLine());
        long xs=Long.parseLong(tok.nextToken()),
                ys=Long.parseLong(tok.nextToken());
        T=Long.parseLong(tok.nextToken());
        /*
        if for som i x_i>2^63-1
        max xs=10^16
        x_i-xs>10^16>t
         */
        pts=new ArrayList<>();
        for (long x=x0, y=y0; true;) {
            pts.add(new long[] {x,y});
            //System.out.println(Arrays.toString(new long[] {x,y}));
            if (x>(double)(Long.MAX_VALUE-bx)/ax
                    || y>(double)(Long.MAX_VALUE-by)/ay)
                break;
            x=ax*x+bx;
            y=ay*y+by;
        }
        taken=new boolean[pts.size()];
        ans=0;
        for (int i=0; i<pts.size(); i++)
            find(i,1,dist(pts.get(i),new long[] {xs,ys}));
        System.out.println(ans);
        System.out.flush();
        /*long[] cost=new long[pts.size()];
        boolean[] bad=new boolean[pts.size()];
        for (int i=0; i<pts.size(); i++) {
            long[] pt=pts.get(i);
            long dx=Math.abs(pt[0]-xs),
                    dy=Math.abs(pt[1]-ys);
            if (dx>Long.MAX_VALUE-dy)
                bad[i]=true;
            else
                cost[i] = dx+dy;
        }
        List<Integer> front=new ArrayList<>();
        for (int i=0; i<pts.size(); i++)
            if (!bad[i])
                front.add(i);
        while (front.size()>0) {

        }*/
    }
}


import java.io.*;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.sql.Time;
import java.util.*;

import java.math.BigInteger;

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

public class Main{

    void run(){
        Locale.setDefault(Locale.US);
        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
//        boolean oj = true;
        try{
            if( oj ){
                sc  = new FastScanner( new InputStreamReader(System.in  ) );
                out = new PrintWriter(   new OutputStreamWriter(System.out) );
            } else{
                sc  = new FastScanner(new FileReader("in.txt") );
//                sc  = new FastScanner(new FileReader("D:\\JavaOlymp\\FatalError\\output.txt") );
                out = new PrintWriter(   new FileWriter("out.txt") );
            }
        } catch (Exception e) {
            System.exit(-1);
        }
        long tB = System.currentTimeMillis();
        solve();
        if( !oj ) System.err.println( "Time: " + (System.currentTimeMillis()-tB)/1e3 );
        out.flush();
    }

    class FastScanner{
        BufferedReader br;
        StringTokenizer st = new StringTokenizer("");
        FastScanner( InputStreamReader a ){
            br = new BufferedReader(a);
        }
        FastScanner( FileReader a ){
            br = new BufferedReader(a);
        }
        String next(){
            while( !st.hasMoreTokens() )
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    return null;
                }
            return st.nextToken();
        }
        String readLine(){
            try {
                return br.readLine();
            } catch (Exception e) {
                return null;
            }
        }
        int nextInt(){ return Integer.parseInt(next()); }
        long nextLong(){ return Long.parseLong(next()); }
    }

    FastScanner sc;
    PrintWriter out;

    public static void main(String[] args){
        new Main().run();
//        new Thread( null, new Runnable() {
//            @Override
//            public void run() {
//                new Main().run();
//            }
//            }, "LOL", 256L * 1024 * 1024 / 2 ).run();
//        }, "LOL", 2000 * 1024 * 1024 ).run();
    }

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

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

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

    class Item{
        int i, j, msk;
        Item( int _i, int _j, int _msk ){
            i = _i;
            j = _j;
            msk = _msk;
        }
    }

    final int inf = Integer.MAX_VALUE / 10;
    int n, m, Si, Sj;
    char[][] gr;

    int timer, mskOfBomb;
    int[] idObj;

    int[] cost = new int[8];
    int[][] dp;
    int[][] howI = new int[1000][1000];
    int[][] howJ = new int[1000][1000];
    int[][] howM = new int[1000][1000];
    {
        for( int i = 0; i < 1000; ++i ){
            fill( howI[i], -1 );
            fill( howJ[i], -1 );
            fill( howM[i], -1 );
        }
    }

    void f( int i, int j, int msk ){
        if( i==Si && j==Sj && msk==0 ){
        }
        else{
            f(
                howI[i*m+j][msk],
                howJ[i*m+j][msk],
                howM[i*m+j][msk]);
        }
        out.printf("%d %d %4s\n", i, j, Integer.toBinaryString(msk));
    }

    void solve(){
        n = sc.nextInt();
        m = sc.nextInt();
        gr = new char[n][];
        idObj = new int[n*m]; fill( idObj, -1 );
        for( int i = 0; i < n; ++i )
            gr[i] = sc.next().toCharArray();

        int[] tmp = new int[8];
        for( int i = 1; ; ++i )
            try {
                tmp[i] = sc.nextInt();
            } catch (Exception e) {
                break;
            }

        for( int i = 0; i < n; ++i ){
            for( int j = 0; j < m; ++j ){
                char c = gr[i][j];
                if( Character.isDigit(c) ){
                    idObj[i*m+j] = timer++;
                    cost[timer-1] = tmp[c - '0'];
                }
                if( c=='B' ){
                    idObj[i*m+j] = timer++;
                    mskOfBomb |= 1 << (timer-1);
                }
                if( c == 'S' ){
                    Si = i;
                    Sj = j;
                }
            }
        }

        dp = new int[n*m][1<<8];
        for( int[] dpi : dp ) fill( dpi, inf );
        dp[Si*m + Sj][0] = 0;
        ArrayDeque<Item> Q = new ArrayDeque<Item>();
        Q.add(new Item(Si,Sj,0));
        while( !Q.isEmpty() ){
            Item v = Q.pollFirst();
            for( int di = -1; di <= 1; ++di ){
            for( int dj = -1; dj <= 1; ++dj ){
                if( abs(di) + abs(dj) != 1 ) continue;
                Item to = new Item(v.i+di, v.j+dj, v.msk);
                if(!( 0<=to.i && to.i<n &&
                      0<=to.j && to.j<m &&
                      (gr[to.i][to.j] == '.' || gr[to.i][to.j]=='S') ))
                    continue;
                if( abs(di)==1 ){
                    int curI = min(v.i, to.i);
                    for( int k = 0; k < v.j; ++k ){
                        int id = idObj[curI*m + k];
                        if( id != -1 ) to.msk ^= 1 << id;
                    }
                }
                if( dp[to.i*m + to.j][to.msk] > dp[v.i*m + v.j][v.msk] + 1 ){
                    dp[to.i*m + to.j][to.msk] = dp[v.i*m + v.j][v.msk] + 1;
                    Q.addLast(to);
                    howI[to.i*m + to.j][to.msk] = v.i;
                    howJ[to.i*m + to.j][to.msk] = v.j;
                    howM[to.i*m + to.j][to.msk] = v.msk;
                }
            }
            }
        }

        int ans = 0;
        for( int msk = 0; msk < 1<<8; ++msk ){
            if( (msk & mskOfBomb) == 0 &&
                    dp[Si*m + Sj][msk] != inf ){
                int cost = 0;
                for( int i = 0; i < 8; ++i )
                    if( (msk & (1<<i)) != 0 )
                        cost += this.cost[i];
                ans = max( ans, cost - dp[Si*m + Sj][msk] );
                if( ans == 23 ){
                    out.printf("%4s\n", Integer.toBinaryString(msk));
                }
            }
        }

        out.println(ans);
    }

}


import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Egor Kulikov (egor@egork.net)
 */
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();
	}
}

class TaskC {
	int RIGHT = 3;
	int LEFT = 1;

    public void solve(int testNumber, InputReader in, OutputWriter out) {
		int rowCount = in.readInt();
		int columnCount = in.readInt();
		char[][] table = IOUtils.readTable(in, rowCount, columnCount);
		int treasureCount = 0;
		int bombCount = 0;
		int sRow = -1;
		int sColumn = -1;
		for (int i = 0; i < rowCount; i++) {
			char[] row = table[i];
			for (int j = 0; j < columnCount; j++) {
				char c = row[j];
				if (Character.isDigit(c))
					treasureCount = Math.max(treasureCount, c - '0');
				else if (c == 'B')
					bombCount++;
				else if (c == 'S') {
					sRow = i;
					sColumn = j;
				}
			}
		}
		table[sRow][sColumn] = '.';
		int[] value = IOUtils.readIntArray(in, treasureCount);
		int[][][] change = new int[4][rowCount][columnCount];
		int bombIndex = treasureCount;
		for (int i = 0; i < rowCount; i++) {
			for (int j = 0; j < columnCount; j++) {
				int curIndex = -1;
				if (Character.isDigit(table[i][j]))
					curIndex = table[i][j] - '1';
				else if (table[i][j] == 'B')
					curIndex = bombIndex++;
				if (curIndex == -1)
					continue;
				for (int k = 0; k < i; k++) {
					change[RIGHT][k][j] += 1 << curIndex;
					if (j < columnCount)
						change[LEFT][k][j + 1] += 1 << curIndex;
				}
			}
		}
		int count = treasureCount + bombCount;
		int[][][] cost = new int[rowCount][columnCount][1 << count];
		ArrayUtils.fill(cost, -1);
		cost[sRow][sColumn][0] = 0;
		int[] rowQueue = new int[rowCount * columnCount * (1 << count)];
		int[] columnQueue = new int[rowQueue.length];
		int[] maskQueue = new int[rowQueue.length];
		rowQueue[0] = sRow;
		columnQueue[0] = sColumn;
		int length = 1;
		for (int i = 0; i < length; i++) {
			int row = rowQueue[i];
			int column = columnQueue[i];
			int mask = maskQueue[i];
			for (int j = 0; j < 4; j++) {
				int nRow = row + MiscUtils.DX4[j];
				int nColumn = column + MiscUtils.DY4[j];
				int nMask = mask ^ change[j][row][column];
				if (!MiscUtils.isValidCell(nRow, nColumn, rowCount, columnCount) || table[nRow][nColumn] != '.' ||
					cost[nRow][nColumn][nMask] != -1)
				{
					continue;
				}
				cost[nRow][nColumn][nMask] = cost[row][column][mask] + 1;
				rowQueue[length] = nRow;
				columnQueue[length] = nColumn;
				maskQueue[length++] = nMask;
			}
		}
		int answer = 0;
		for (int i = 0; i < (1 << treasureCount); i++) {
			if (cost[sRow][sColumn][i] != -1) {
				int candidate = -cost[sRow][sColumn][i];
				for (int j = 0; j < treasureCount; j++) {
					if ((i >> j & 1) == 1)
						candidate += value[j];
				}
				answer = Math.max(answer, candidate);
			}
		}
		out.printLine(answer);
    }
}

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 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 char readCharacter() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		return (char) c;
	}

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

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 printLine(int i) {
		writer.println(i);
	}
}

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;
	}

	public static char[] readCharArray(InputReader in, int size) {
		char[] array = new char[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readCharacter();
		return array;
	}

	public static char[][] readTable(InputReader in, int rowCount, int columnCount) {
		char[][] table = new char[rowCount][];
		for (int i = 0; i < rowCount; i++)
			table[i] = readCharArray(in, columnCount);
		return table;
	}

	}

class ArrayUtils {

	public static void fill(int[][] array, int value) {
		for (int[] row : array)
			Arrays.fill(row, value);
	}

	public static void fill(int[][][] array, int value) {
		for (int[][] subArray : array)
			fill(subArray, value);
	}

	}

class MiscUtils {
	public static final int[] DX4 = {1, 0, -1, 0};
	public static final int[] DY4 = {0, -1, 0, 1};

    public static boolean isValidCell(int row, int column, int rowCount, int columnCount) {
		return row >= 0 && row < rowCount && column >= 0 && column < columnCount;
	}

	}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Round315B {

	public static final long mod = (long)1e9 + 7;
	public static final int max = (int)1e4 + 10;
	public static long[] fact;
	public static long[] invfact;

	public static long nCr(int n, int r) {
		return (((fact[n] * invfact[n - r])%mod) * invfact[r])%mod;
	}

	public static void solve() {
		fact = new long[max];
		invfact = new long[max];
		fact[0] = 1;
		invfact[0] = 1;
		for(int i = 1; i < max; i++) {
			fact[i] = (fact[i - 1] * i)%mod;
			invfact[i] = (invfact[i - 1] * ModInverse(i, mod))%mod;
		}
		long[][] partitioning = new long[max][max];
		partitioning[0][0] = 1;
		for(int i = 1; i < max; i++) {
			for(int j = 1; j <= i; j++) {
				partitioning[i][j] = (partitioning[i - 1][j - 1] + (j * partitioning[i - 1][j])%mod)%mod;
			}
		}
		long[] bell = new long[max];
		for(int i = 0; i < max; i++) {
			long sum = 0;
			for(int j = 0; j <= i; j++) {
				sum += partitioning[i][j];
				if(sum >= mod) sum -= mod;
			}
			bell[i] = sum;
		}
		int n = s.nextInt();
		int r = 0;
		long ans = 0;
		for(int i = 0; i < n; i++, r++) {
			ans += (nCr(n, r) * bell[i])%mod;
			if(ans >= mod) ans -= mod;
		}
		out.println(ans);
	}

	public static class Triplet {
		long gcd;
		long x;
		long y;

		Triplet(long gcd, long x, long y) {
			this.gcd = gcd;
			this.x = x;
			this.y = y;
		}
	}

	public static Triplet ExtendedEuclideanAlgo(long a, long b) {
		if (a == 0) {
			return new Triplet(b, 0, 1);
		}
		Triplet ans = ExtendedEuclideanAlgo(b % a, a);
		long x = ans.y - (b / a) * ans.x;
		long y = ans.x;
		return new Triplet(ans.gcd, x, y);
	}

	public static long ModInverse(long a, long m) {
		Triplet ans = ExtendedEuclideanAlgo(a, m);
		if (ans.gcd != 1) {
			//System.out.println("Multiplicative inverse doesnot exist");
			return -1;
		} else {
			//m is added to handle negative x
			long result = (ans.x % m + m) % m;
			return result;
		}
	}

	public static void main(String[] args) {
		out = new PrintWriter(new BufferedOutputStream(System.out));
		s = new FastReader();
		solve();
		out.close();
	}

	public static FastReader s;
	public static PrintWriter out;

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

}


import java.util.Scanner;

public class A485 {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a = sc.nextInt();
		int m = sc.nextInt();
		String ans = "";
		Boolean flag=true;
		int fr = a%m;
		if(a%m==0)
		{
			flag=false;
			ans="Yes";
		}
		else
		{
			a+=a%m;
		}

		if(a<m)
		{
			int abm = m/a;
			int anl2 = (int)(Math.pow(2, (Math.log(abm)/Math.log(2))));
			int nexta = anl2*a;

			//System.out.println(nexta);
			a=nexta;
		}

		while(flag)
		{
			int res = a%m;
			if(res==0)
			{
				flag=false;
				ans = "Yes";
			}
			else
			{
				if(fr==res)
				{
					flag=false;
					ans="No";
				}
				else
				{
					a+=res;
				}

			}
		}
		System.out.println(ans);
	}
}


package main;

import main.Parser;
import java.io.PrintWriter;
import java.util.ArrayList;

public class TaskD {
    public static int generator (int p, int x) {
        int[] fact = new int[50];
        int cnt = 0;

        int phi = p-1,  n = phi;
        for (int i=2; i*i<=n; ++i)
            if (n % i == 0) {
                fact[cnt++]=i;
                while (n % i == 0)
                    n /= i;
            }
        if (n > 1)
            fact[cnt++]=n;

        int lim = Math.max(x-p, 1);

        for (int res=x-1; res>=lim; --res) {
            boolean ok = true;
            for (int i=0; i<cnt && ok; ++i)
                ok = MathUtils.modpow (res, phi / fact[i], p) != 1;
            if (ok) {
                return res;
            }
        }
        return -1;
    }

    public void solve(int testNumber, Parser in, PrintWriter out) {
        int n = in.nextInt() + 1;
        int x = in.nextInt();

        if (n == 2) {
            if (x == 2) out.println(-1);
            else out.println(x-1);
            return;
        }

        if (!MathUtils.isPrime(n)) {
            out.println(-1);
            return;
        }

        int ans = generator(n, x);
        if (ans > 1 && ans < x) out.println(ans);
        else out.println(-1);
    }
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] ch = in.nextLine().toCharArray();
        if (ch.length<2) System.out.println("NO");
        else {
            int[] t = new int[26];
            for (int i = 0; i < ch.length; i++) {
                t[ch[i]-'a']++;
            }
            int i = 0;
            boolean test1 = true;
            while(i<25){
                if (t[i]<t[i+1]) {test1=false;break;}
            }
            if (!test1) System.out.println("NO");
            else{
                Arrays.sort(ch);
                String ch2 = toString(ch);
                if (ch2.length()>26) System.out.println("NO");
                else {
                    char c ='a';
                    boolean test = true;
                    for (i = 0; i < ch2.length(); i++) {
                        if (ch2.charAt(i)!=(c+i)) {test=false;break;}
                    }
                    if (test) System.out.println("YES");
                    else System.out.println("NO");
                }
            }
        }
    }

    public static String toString(char[] ch) {
        String ch2 = "";
        ch2=ch2.concat(ch[0]+"");
        for (int i = 1; i < ch.length; i++) {
            if (!ch2.contains(ch[i]+"")) ch2=ch2.concat(ch[i]+"");
        }
        return ch2;
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Deque;
import java.util.function.Supplier;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.io.OutputStream;
import java.util.Collection;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.function.Consumer;
import java.io.Closeable;
import java.io.Writer;
import java.util.ArrayDeque;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            ETransformingSequence solver = new ETransformingSequence();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class ETransformingSequence {
        int mod = (int) 1e9 + 7;
        IntPoly poly = new IntPolyFFT(mod);
        Factorial fact = new Factorial((int) 1e4, mod);
        CachedPow pow = new CachedPow(2, mod);
        Combination comb = new Combination(fact);

        public void solve(int testNumber, FastInput in, FastOutput out) {
            long n = in.readLong();
            int k = in.readInt();
            if (n > k) {
                out.println(0);
                return;
            }

            int[] x = new int[k + 1];
            Arrays.fill(x, 1, k + 1, 1);
            int[] ans = pow(x, (int) n);
            long sum = 0;
            for (int i = 0; i <= k; i++) {
                sum += (long) ans[i] * comb.combination(k, i) % mod;
            }
            sum %= mod;
            out.println(sum);
        }

        public int[] mul(int[] dpL, int[] dpR, int l, int r) {
            int n = dpL.length;
            int[] f = PrimitiveBuffers.allocIntPow2(n);
            int[] g = PrimitiveBuffers.allocIntPow2(n);
            for (int i = 0; i < n; i++) {
                f[i] = (int) ((long) dpL[i] * fact.invFact(i) % mod * pow.pow((long) r * i) % mod);
                g[i] = (int) ((long) dpR[i] * fact.invFact(i) % mod);
            }
            int[] ans = poly.convolution(f, g);
            int[] ret = Arrays.copyOf(ans, n);
            for (int i = 0; i < n; i++) {
                ret[i] = (int) ((long) ret[i] * fact.fact(i) % mod);
            }
            PrimitiveBuffers.release(f, g, ans);
            return ret;
        }

        public int[] pow(int[] x, int n) {
            if (n == 0) {
                int[] ans = new int[x.length];
                ans[0] = 1;
                return ans;
            }
            int[] ans = pow(x, n / 2);
            ans = mul(ans, ans, n / 2, n / 2);
            if (n % 2 == 1) {
                ans = mul(ans, x, n - 1, 1);
            }
            return ans;
        }

    }

    static class Log2 {
        public static int ceilLog(int x) {
            if (x <= 0) {
                return 0;
            }
            return 32 - Integer.numberOfLeadingZeros(x - 1);
        }

    }

    static class IntPoly {
        protected int mod;
        protected Power power;

        public IntPoly(int mod) {
            this.mod = mod;
            this.power = new Power(mod);
        }

        public int[] convolution(int[] a, int[] b) {
            return mulBF(a, b);
        }

        public int rankOf(int[] p) {
            int r = p.length - 1;
            while (r >= 0 && p[r] == 0) {
                r--;
            }
            return Math.max(0, r);
        }

        public int[] mulBF(int[] a, int[] b) {
            int rA = rankOf(a);
            int rB = rankOf(b);
            if (rA > rB) {
                {
                    int tmp = rA;
                    rA = rB;
                    rB = tmp;
                }
                {
                    int[] tmp = a;
                    a = b;
                    b = tmp;
                }
            }
            int[] c = PrimitiveBuffers.allocIntPow2(rA + rB + 1);
            for (int i = 0; i <= rA; i++) {
                for (int j = 0; j <= rB; j++) {
                    c[i + j] = (int) ((c[i + j] + (long) a[i] * b[j]) % mod);
                }
            }
            return c;
        }

    }

    static class Factorial {
        int[] fact;
        int[] inv;
        int mod;

        public int getMod() {
            return mod;
        }

        public Factorial(int[] fact, int[] inv, int mod) {
            this.mod = mod;
            this.fact = fact;
            this.inv = inv;
            fact[0] = inv[0] = 1;
            int n = Math.min(fact.length, mod);
            for (int i = 1; i < n; i++) {
                fact[i] = i;
                fact[i] = (int) ((long) fact[i] * fact[i - 1] % mod);
            }
            inv[n - 1] = BigInteger.valueOf(fact[n - 1]).modInverse(BigInteger.valueOf(mod)).intValue();
            for (int i = n - 2; i >= 1; i--) {
                inv[i] = (int) ((long) inv[i + 1] * (i + 1) % mod);
            }
        }

        public Factorial(int limit, int mod) {
            this(new int[limit + 1], new int[limit + 1], mod);
        }

        public int fact(int n) {
            return fact[n];
        }

        public int invFact(int n) {
            return inv[n];
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

        public long readLong() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            long val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static class DigitUtils {
        private DigitUtils() {
        }

        public static int mod(long x, int mod) {
            if (x < -mod || x >= mod) {
                x %= mod;
            }
            if (x < 0) {
                x += mod;
            }
            return (int) x;
        }

        public static int mod(int x, int mod) {
            if (x < -mod || x >= mod) {
                x %= mod;
            }
            if (x < 0) {
                x += mod;
            }
            return x;
        }

    }

    static class Power implements InverseNumber {
        int mod;

        public Power(Modular modular) {
            this.mod = modular.getMod();
        }

        public Power(int mod) {
            this(new Modular(mod));
        }

    }

    static interface IntCombination {
    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private static final int THRESHOLD = 1 << 13;
        private final Writer os;
        private StringBuilder cache = new StringBuilder(THRESHOLD * 2);

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        private void afterWrite() {
            if (cache.length() < THRESHOLD) {
                return;
            }
            flush();
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            afterWrite();
            return this;
        }

        public FastOutput append(int c) {
            cache.append(c);
            afterWrite();
            return this;
        }

        public FastOutput append(long c) {
            cache.append(c);
            afterWrite();
            return this;
        }

        public FastOutput append(String c) {
            cache.append(c);
            afterWrite();
            return this;
        }

        public FastOutput println(int c) {
            return append(c).println();
        }

        public FastOutput println(long c) {
            return append(c).println();
        }

        public FastOutput println() {
            return append(System.lineSeparator());
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class CachedPow {
        private int[] first;
        private int[] second;
        private int mod;
        private int powMod;
        private static int step = 16;
        private static int limit = 1 << step;
        private static int mask = limit - 1;

        public CachedPow(int x, int mod) {
            this.mod = mod;
            this.powMod = mod - 1;
            first = new int[limit];
            second = new int[Integer.MAX_VALUE / limit + 1];
            first[0] = 1;
            for (int i = 1; i < first.length; i++) {
                first[i] = (int) ((long) x * first[i - 1] % mod);
            }
            second[0] = 1;
            long step = (long) x * first[first.length - 1] % mod;
            for (int i = 1; i < second.length; i++) {
                second[i] = (int) (second[i - 1] * step % mod);
            }
        }

        public int pow(int exp) {
            return (int) ((long) first[exp & mask] * second[exp >> step] % mod);
        }

        public int pow(long exp) {
            return pow(DigitUtils.mod(exp, powMod));
        }

    }

    static class Combination implements IntCombination {
        final Factorial factorial;
        int modVal;

        public Combination(Factorial factorial) {
            this.factorial = factorial;
            this.modVal = factorial.getMod();
        }

        public Combination(int limit, int mod) {
            this(new Factorial(limit, mod));
        }

        public int combination(int m, int n) {
            if (n > m || n < 0) {
                return 0;
            }
            return (int) ((long) factorial.fact(m) * factorial.invFact(n) % modVal * factorial.invFact(m - n) % modVal);
        }

    }

    static class Modular {
        int m;

        public int getMod() {
            return m;
        }

        public Modular(int m) {
            this.m = m;
        }

        public Modular(long m) {
            this.m = (int) m;
            if (this.m != m) {
                throw new IllegalArgumentException();
            }
        }

        public Modular(double m) {
            this.m = (int) m;
            if (this.m != m) {
                throw new IllegalArgumentException();
            }
        }

        public String toString() {
            return "mod " + m;
        }

    }

    static class PrimitiveBuffers {
        public static Buffer<int[]>[] intPow2Bufs = new Buffer[30];
        public static Buffer<double[]>[] doublePow2Bufs = new Buffer[30];

        static {
            for (int i = 0; i < 30; i++) {
                int finalI = i;
                intPow2Bufs[i] = new Buffer<>(() -> new int[1 << finalI], x -> Arrays.fill(x, 0));
                doublePow2Bufs[i] = new Buffer<>(() -> new double[1 << finalI], x -> Arrays.fill(x, 0));
            }
        }

        public static int[] allocIntPow2(int n) {
            return intPow2Bufs[Log2.ceilLog(n)].alloc();
        }

        public static void release(int[] data) {
            intPow2Bufs[Log2.ceilLog(data.length)].release(data);
        }

        public static void release(int[] a, int[] b, int[] c) {
            release(a);
            release(b);
            release(c);
        }

        public static double[] allocDoublePow2(int n) {
            return doublePow2Bufs[Log2.ceilLog(n)].alloc();
        }

        public static double[] allocDoublePow2(double[] data, int newLen) {
            double[] ans = allocDoublePow2(newLen);
            System.arraycopy(data, 0, ans, 0, Math.min(data.length, newLen));
            return ans;
        }

        public static void release(double[] data) {
            doublePow2Bufs[Log2.ceilLog(data.length)].release(data);
        }

        public static void release(double[]... data) {
            for (double[] x : data) {
                release(x);
            }
        }

    }

    static interface InverseNumber {
    }

    static class FastFourierTransform {
        private static double[][] realLevels = new double[30][];
        private static double[][] imgLevels = new double[30][];

        private static void prepareLevel(int i) {
            if (realLevels[i] == null) {
                realLevels[i] = new double[1 << i];
                imgLevels[i] = new double[1 << i];
                for (int j = 0, s = 1 << i; j < s; j++) {
                    realLevels[i][j] = Math.cos(Math.PI / s * j);
                    imgLevels[i][j] = Math.sin(Math.PI / s * j);
                }
            }
        }

        public static void fft(double[][] p, boolean inv) {
            int m = Log2.ceilLog(p[0].length);
            int n = 1 << m;
            int shift = 32 - Integer.numberOfTrailingZeros(n);
            for (int i = 1; i < n; i++) {
                int j = Integer.reverse(i << shift);
                if (i < j) {
                    SequenceUtils.swap(p[0], i, j);
                    SequenceUtils.swap(p[1], i, j);
                }
            }

            double[][] t = new double[2][1];
            for (int d = 0; d < m; d++) {
                int s = 1 << d;
                int s2 = s << 1;
                prepareLevel(d);
                for (int i = 0; i < n; i += s2) {
                    for (int j = 0; j < s; j++) {
                        int a = i + j;
                        int b = a + s;
                        mul(realLevels[d][j], imgLevels[d][j], p[0][b], p[1][b], t, 0);
                        sub(p[0][a], p[1][a], t[0][0], t[1][0], p, b);
                        add(p[0][a], p[1][a], t[0][0], t[1][0], p, a);
                    }
                }
            }

            if (inv) {
                for (int i = 0, j = 0; i <= j; i++, j = n - i) {
                    double a = p[0][j];
                    double b = p[1][j];
                    div(p[0][i], p[1][i], n, p, j);
                    if (i != j) {
                        div(a, b, n, p, i);
                    }
                }
            }
        }

        public static void add(double r1, double i1, double r2, double i2, double[][] r, int i) {
            r[0][i] = r1 + r2;
            r[1][i] = i1 + i2;
        }

        public static void sub(double r1, double i1, double r2, double i2, double[][] r, int i) {
            r[0][i] = r1 - r2;
            r[1][i] = i1 - i2;
        }

        public static void mul(double r1, double i1, double r2, double i2, double[][] r, int i) {
            r[0][i] = r1 * r2 - i1 * i2;
            r[1][i] = r1 * i2 + i1 * r2;
        }

        public static void div(double r1, double i1, double r2, double[][] r, int i) {
            r[0][i] = r1 / r2;
            r[1][i] = i1 / r2;
        }

    }

    static class SequenceUtils {
        public static void swap(double[] data, int i, int j) {
            double tmp = data[i];
            data[i] = data[j];
            data[j] = tmp;
        }

    }

    static class Buffer<T> {
        private Deque<T> deque;
        private Supplier<T> supplier;
        private Consumer<T> cleaner;
        private int allocTime;
        private int releaseTime;

        public Buffer(Supplier<T> supplier) {
            this(supplier, (x) -> {
            });
        }

        public Buffer(Supplier<T> supplier, Consumer<T> cleaner) {
            this(supplier, cleaner, 0);
        }

        public Buffer(Supplier<T> supplier, Consumer<T> cleaner, int exp) {
            this.supplier = supplier;
            this.cleaner = cleaner;
            deque = new ArrayDeque<>(exp);
        }

        public T alloc() {
            allocTime++;
            return deque.isEmpty() ? supplier.get() : deque.removeFirst();
        }

        public void release(T e) {
            releaseTime++;
            cleaner.accept(e);
            deque.addLast(e);
        }

    }

    static class IntPolyFFT extends IntPoly {
        private static final int FFT_THRESHOLD = 50;

        public IntPolyFFT(int mod) {
            super(mod);
        }

        public int[] convolution(int[] a, int[] b) {
            if (a != b) {
                return multiplyMod(a, b);
            } else {
                return pow2(a);
            }
        }

        public int[] pow2(int[] a) {
            int rA = rankOf(a);
            if (rA < FFT_THRESHOLD) {
                return mulBF(a, a);
            }

            int need = rA * 2 + 1;

            double[] aReal = PrimitiveBuffers.allocDoublePow2(need);
            double[] aImag = PrimitiveBuffers.allocDoublePow2(need);
            int n = aReal.length;

            for (int i = 0; i <= rA; i++) {
                int x = DigitUtils.mod(a[i], mod);
                aReal[i] = x & ((1 << 15) - 1);
                aImag[i] = x >> 15;
            }
            FastFourierTransform.fft(new double[][]{aReal, aImag}, false);

            double[] bReal = PrimitiveBuffers.allocDoublePow2(aReal, aReal.length);
            double[] bImag = PrimitiveBuffers.allocDoublePow2(aImag, bReal.length);

            for (int i = 0, j = 0; i <= j; i++, j = n - i) {
                double ari = aReal[i];
                double aii = aImag[i];
                double bri = bReal[i];
                double bii = bImag[i];
                double arj = aReal[j];
                double aij = aImag[j];
                double brj = bReal[j];
                double bij = bImag[j];

                double a1r = (ari + arj) / 2;
                double a1i = (aii - aij) / 2;
                double a2r = (aii + aij) / 2;
                double a2i = (arj - ari) / 2;

                double b1r = (bri + brj) / 2;
                double b1i = (bii - bij) / 2;
                double b2r = (bii + bij) / 2;
                double b2i = (brj - bri) / 2;

                aReal[i] = a1r * b1r - a1i * b1i - a2r * b2i - a2i * b2r;
                aImag[i] = a1r * b1i + a1i * b1r + a2r * b2r - a2i * b2i;
                bReal[i] = a1r * b2r - a1i * b2i + a2r * b1r - a2i * b1i;
                bImag[i] = a1r * b2i + a1i * b2r + a2r * b1i + a2i * b1r;

                if (i != j) {
                    a1r = (arj + ari) / 2;
                    a1i = (aij - aii) / 2;
                    a2r = (aij + aii) / 2;
                    a2i = (ari - arj) / 2;

                    b1r = (brj + bri) / 2;
                    b1i = (bij - bii) / 2;
                    b2r = (bij + bii) / 2;
                    b2i = (bri - brj) / 2;

                    aReal[j] = a1r * b1r - a1i * b1i - a2r * b2i - a2i * b2r;
                    aImag[j] = a1r * b1i + a1i * b1r + a2r * b2r - a2i * b2i;
                    bReal[j] = a1r * b2r - a1i * b2i + a2r * b1r - a2i * b1i;
                    bImag[j] = a1r * b2i + a1i * b2r + a2r * b1i + a2i * b1r;
                }
            }

            FastFourierTransform.fft(new double[][]{aReal, aImag}, true);
            FastFourierTransform.fft(new double[][]{bReal, bImag}, true);

            int[] ans = PrimitiveBuffers.allocIntPow2(need);
            for (int i = 0; i < need; i++) {
                long aa = DigitUtils.mod(Math.round(aReal[i]), mod);
                long bb = DigitUtils.mod(Math.round(bReal[i]), mod);
                long cc = DigitUtils.mod(Math.round(aImag[i]), mod);
                ans[i] = DigitUtils.mod(aa + (bb << 15) + (cc << 30), mod);
            }

            PrimitiveBuffers.release(aReal, bReal, aImag, bImag);
            return ans;
        }

        private int[] multiplyMod(int[] a, int[] b) {
            int rA = rankOf(a);
            int rB = rankOf(b);
            if (Math.min(rA, rB) < FFT_THRESHOLD) {
                return mulBF(a, b);
            }

            int need = rA + rB + 1;

            double[] aReal = PrimitiveBuffers.allocDoublePow2(need);
            double[] aImag = PrimitiveBuffers.allocDoublePow2(need);
            int n = aReal.length;

            for (int i = 0; i <= rA; i++) {
                int x = DigitUtils.mod(a[i], mod);
                aReal[i] = x & ((1 << 15) - 1);
                aImag[i] = x >> 15;
            }
            FastFourierTransform.fft(new double[][]{aReal, aImag}, false);

            double[] bReal = PrimitiveBuffers.allocDoublePow2(need);
            double[] bImag = PrimitiveBuffers.allocDoublePow2(need);
            for (int i = 0; i <= rB; i++) {
                int x = DigitUtils.mod(b[i], mod);
                bReal[i] = x & ((1 << 15) - 1);
                bImag[i] = x >> 15;
            }
            FastFourierTransform.fft(new double[][]{bReal, bImag}, false);

            for (int i = 0, j = 0; i <= j; i++, j = n - i) {
                double ari = aReal[i];
                double aii = aImag[i];
                double bri = bReal[i];
                double bii = bImag[i];
                double arj = aReal[j];
                double aij = aImag[j];
                double brj = bReal[j];
                double bij = bImag[j];

                double a1r = (ari + arj) / 2;
                double a1i = (aii - aij) / 2;
                double a2r = (aii + aij) / 2;
                double a2i = (arj - ari) / 2;

                double b1r = (bri + brj) / 2;
                double b1i = (bii - bij) / 2;
                double b2r = (bii + bij) / 2;
                double b2i = (brj - bri) / 2;

                aReal[i] = a1r * b1r - a1i * b1i - a2r * b2i - a2i * b2r;
                aImag[i] = a1r * b1i + a1i * b1r + a2r * b2r - a2i * b2i;
                bReal[i] = a1r * b2r - a1i * b2i + a2r * b1r - a2i * b1i;
                bImag[i] = a1r * b2i + a1i * b2r + a2r * b1i + a2i * b1r;

                if (i != j) {
                    a1r = (arj + ari) / 2;
                    a1i = (aij - aii) / 2;
                    a2r = (aij + aii) / 2;
                    a2i = (ari - arj) / 2;

                    b1r = (brj + bri) / 2;
                    b1i = (bij - bii) / 2;
                    b2r = (bij + bii) / 2;
                    b2i = (bri - brj) / 2;

                    aReal[j] = a1r * b1r - a1i * b1i - a2r * b2i - a2i * b2r;
                    aImag[j] = a1r * b1i + a1i * b1r + a2r * b2r - a2i * b2i;
                    bReal[j] = a1r * b2r - a1i * b2i + a2r * b1r - a2i * b1i;
                    bImag[j] = a1r * b2i + a1i * b2r + a2r * b1i + a2i * b1r;
                }
            }

            FastFourierTransform.fft(new double[][]{aReal, aImag}, true);
            FastFourierTransform.fft(new double[][]{bReal, bImag}, true);

            int[] ans = PrimitiveBuffers.allocIntPow2(need);
            for (int i = 0; i < need; i++) {
                long aa = DigitUtils.mod(Math.round(aReal[i]), mod);
                long bb = DigitUtils.mod(Math.round(bReal[i]), mod);
                long cc = DigitUtils.mod(Math.round(aImag[i]), mod);
                ans[i] = DigitUtils.mod(aa + (bb << 15) + (cc << 30), mod);
            }

            PrimitiveBuffers.release(aReal, bReal, aImag, bImag);
            return ans;
        }

    }
}


import java.util.Scanner;

public class Main {

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

        int temp = k;
        int cont = 0;
        while (temp<l){
            temp = temp*k;
            cont++;
        }
        //System.out.println(temp);
        //System.out.println(cont);

        if(temp==l){
            System.out.println("YES");
            System.out.println(cont);
        }else{
            System.out.println("NO");
        }

    }
}


import java.util.*;

public class B743 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scan=new Scanner(System.in);

		int n=scan.nextInt();
		int k=scan.nextInt();

	String s="1";

	for(int i=2;i<=n;i++){
		s+=" "+i+" "+s;

	}

			String[] ans=s.split(" ");

			System.out.println(ans[k-1]);

	}

}


import java.util.Scanner;

public class CA {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int[] r = new int[a];
		for(int i = 0; i < a; i++) r[i] = i+1;
		System.out.println(minCoins(r, a, b));

	}

	static int minCoins(int coins[], int m, int V)
    {
        // table[i] will be storing
        // the minimum number of coins
        // required for i value. So
        // table[V] will have result
        int table[] = new int[V + 1];

        // Base case (If given value V is 0)
        table[0] = 0;

        // Initialize all table values as Infinite
        for (int i = 1; i <= V; i++)
        table[i] = Integer.MAX_VALUE;

        // Compute minimum coins required for all
        // values from 1 to V
        for (int i = 1; i <= V; i++)
        {
            // Go through all coins smaller than i
            for (int j = 0; j < m; j++)
            if (coins[j] <= i)
            {
                int sub_res = table[i - coins[j]];
                if (sub_res != Integer.MAX_VALUE
                       && sub_res + 1 < table[i])
                       table[i] = sub_res + 1;

            }

        }
        return table[V];

    }

}


import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {
    public static Scanner scanner = new Scanner(new BufferedInputStream(System.in));

    public static boolean check(int[] arr, int mid) {
        for (int starti = 0; starti < arr.length; starti += (1 << mid)) {
            for (int i = 1; i < (1 << mid); i++) {
                if (arr[starti + i - 1] > arr[starti + i]) {
                    break;
                }

                if (i == (1 << mid) - 1) {
                    return true;
                }
            }
        }
        return false;
    }

    public static void main(String args[]) {
        int n = scanner.nextInt();
        int p = scanner.nextInt();
        int k = scanner.nextInt();
        int l = p - k;
        if (l > 0) {
            System.out.print("<<");
        } else {
            l = 1;
            if (p == l) {

            } else {
                System.out.print("<<");
            }
        }

        while (l < p) {
            System.out.print(' ');
            System.out.print(l);
        }
        System.out.print(' ');
        System.out.print('(');
        System.out.print(p);
        System.out.print(')');

        int r = p + 1;

        while (r <= p + k && p <= n) {
            System.out.print(' ');
            System.out.print(r);
        }
        if (p + k < n) {
            System.out.println(" >>");
        } else {
            System.out.println();
        }
    }
}


import java.util.*;
import java.io.*;
import java.io.FileWriter;
import java.math.BigInteger;
import java.math.BigDecimal;
// Solution

public class Main
{
  public static void main (String[] argv)
  {
	  new Main();
  }

  boolean test = false;
  final int[][] dirs8 = {{0,1}, {0,-1}, {-1,0}, {1,0}, {1,1},{1,-1},{-1,1},{-1,-1}};
  final int[][] dirs4 = {{0,1}, {0,-1}, {-1,0}, {1,0}};
  final int MOD = 1000000007;  //998244353;

  final int WALL = -1;
  final int EMPTY = -2;
  final int VISITED = 1;
  final int FULL = 2;

  final int START = 1;
  final int END = 0;

  long[] fac;
  long[] ifac;
  long[] rfac;

  int[] mobius;
  int[] sieve;
  List<Integer>[] factors;

  //long[] fac = new long[100];
  //long[] ifac = new long[100001];
  public Main()  {
	FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));

    //FastReader in = new FastReader(new BufferedReader(new FileReader("Main.in")));

    //int nt = in.nextInt();
    int nt = 1;
    StringBuilder sb = new StringBuilder();

    //fac[0] = 1;
    //ifac[0] = 1;
    //for (int i = 1; i <= 20; i++) {
      //  fac[i] = fac[i-1] * i % MOD;
      //  ifac[i] = ifac[i-1] * inv(i) % MOD;
    //}
    long[][] C = new long[19][11];

    // Caculate value of Binomial Coefficient
    // in bottom up manner
    for (int i = 0; i <= 18; i++)
    {
        for (int j = 0; j <= min(i, 10); j++)
        {
            // Base Cases
            if (j == 0 || j == i)
                C[i][j] = 1;

            // Calculate value using previously
            // stored values
            else
                C[i][j] = C[i - 1][j - 1] +
                          C[i - 1][j];
        }
    }

    //long[] invs = new long[101];
    //for (int i = 1; i <= 100; i++) invs[i] = inv(i);

    for (int it = 0; it < nt; it++)
    {
       int n = in.nextInt();
       int k = in.nextInt();

       long b = 1;
       long sum = 0;
       int[] pown = new int[k+1];
       pown[1] = 1;
       for (int i = 2; i <= k; i++) pown[i] = (int)pow(i, n);

       build_mobius_function(k);

       int[] cnt = new int[k+1];

       for (int t = 2; t <= k; t++)
       {
           //loop over all factors of t
           for (int pf : factors[t])
           {
               b -= pown[cnt[pf]] * mobius[pf];
               cnt[pf]++;
               b += pown[cnt[pf]] * mobius[pf];
           }
           b += pown[t] - pown[t-1];
           b %= MOD;
           if (b < 0) b += MOD;
//System.out.println(" t = " + t + ", b = " + b);
           sum += (b ^ t);
           if (sum >= MOD) sum -= MOD;
       }

       System.out.println(sum);

    }

    System.out.print(sb);
  }

  private long[][] matIdentity(int n)
  {
      long[][] a = new long[n][n];
      for (int i = 0; i < n; i++)
          a[i][i] = 1;
      return a;
  }
  private long[][] matPow(long[][] mat0, long p)
  {
      int n = mat0.length;
      long[][] ans = matIdentity(n);
      long[][] mat = matCopy(mat0);
      while (p > 0)
      {
          if (p % 2 == 1){
              ans = matMul(ans, mat);
          }

          p /= 2;
          mat = matMul(mat, mat);
      }
      return ans;
  }

  private long[][] matCopy(long[][] a)
  {
      int n = a.length;
      long[][] b = new long[n][n];
      for (int i = 0; i < n; i++)
          for (int j = 0; j < n; j++)
              b[i][j] = a[i][j];
      return b;
  }
  private long[][] matMul(long[][] a, long[][] b)
  {
      int n = a.length;

      long[][] c = new long[n][n];
      for (int i = 0; i < n; i++)
      {
          for (int j = 0; j < n; j++)
          {
              for (int k = 0; k < n; k++)
                  c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % MOD;
          }
      }

      return c;
  }

  private long[] matMul(long[][] a, long[] b)
  {
      int n = a.length;

      long[] c = new long[n];
      for (int i = 0; i < n; i++)
      {
          for (int j = 0; j < n; j++)
              c[i] = (c[i] + a[i][j] * b[j]) % MOD;
      }

      return c;
  }

  class Mark implements Comparable<Mark> {
      int type, h;
      long x;
      public Mark(int h, long x, int type)
      {
         this.h = h;
         this.x = x;
         this.type = type;
      }

      @Override
      public int compareTo(Mark o)
      {
          if (this.x == o.x) return type - o.type; // let end comes before start
          return Long.compare(x, o.x);
      }
  }

  private boolean coLinear(int[] p, int[] q, int[] r)
  {
      return 1L * (p[1] - r[1]) * (q[0] - r[0]) == 1L * (q[1] - r[1]) * (p[0] - r[0]);
  }

  private void fill(char[] a, int lo, int c, char letter)
  {
      //System.out.println("fill " + lo + " " + c + " " + letter);
      for (int i = lo; i < lo + c; i++) a[i] = letter;
  }

  private int cntBitOne(String s){
      int c = 0, n = s.length();
      for (int i = 0; i < n; i++)
          if (s.charAt(i) == '1') c++;
      return c;
  }

  class DSU {
      int n;
      int[] par;
      int[] sz;
      int nGroup;

      public DSU(int n)
      {
          this.n = n;
          par = new int[n];
          sz = new int[n];
          for (int i = 0;  i < n; i++){
              par[i] = i;
              sz[i] = 1;
          }
          nGroup = n;
      }

      private boolean add(int p, int q) {
          int rp = find(p);
          int rq = find(q);
          if (rq == rp) return false;

          if (sz[rp] <= sz[rq]) {
              sz[rq] += sz[rp];
              par[rp] = rq;
          }else {
              sz[rp] += sz[rq];
              par[rq] = rp;
          }
          nGroup--;
          return true;
      }

      private int find(int p)
      {
          int r = p;
          while (par[r] != r) r = par[r];

          while (r != p) {
              int t = par[p];
              par[p] = r;
              p = t;
          }
          return r;
      }

  }

  // μ(n) = 1 if n is a square-free positive integer with an even number of prime factors. e.g.  6, 15
  // μ(n) = −1 if n is a square-free positive integer with an odd number of prime factors. e.g.  2, 3, 5, 2*3*5
  // μ(n) = 0 if n has a squared prime factor. e.g : 2*2,  3*3*5
  private void build_mobius_function(int n)
  {
      mobius = new int[n+1];
      sieve = new int[n+1];
      factors = new List[n+1];
      for (int i = 1; i <= n; i++)factors[i] = new ArrayList<>();
      for (int i = 2; i <= n; i++)
        sieve[i] = i;
      for (int i = 2; i <= n; i++)
      {
        if (sieve[i] == i){
            mobius[i] = -1;
            for (int j = i * i; j <= n; j += i)
                sieve[j] = i;
        }
      }

      for (int i = 6; i <= n; i++)
      {
          if (sieve[i] != i) {
              int pre = i / sieve[i];
              if (pre % sieve[i] != 0)
                  mobius[i] = -mobius[pre];
          }
      }

      for (int i = 2; i <= n; i++)
      {
          if (mobius[i] != 0)
          {
              for (int j = i; j <= n; j += i)
                  factors[j].add(i);
          }
      }

  }

  private int[] build_z_function(String s)
  {
      int n = s.length();
      int[] zfun = new int[n];

      int l = -1, r = -1;
      for (int i = 1; i < n; i++)
      {
         // Set the start value
         if (i <= r)
            zfun[i] = Math.min(zfun[i-l], r - i + 1);

         while (i + zfun[i] < n && s.charAt(i + zfun[i]) == s.charAt(zfun[i]))
             zfun[i]++;

         if (i + zfun[i] - 1> r){
             l = i;
             r = i + zfun[i] - 1;
         }
      }

      if (test)
      {
          System.out.println("Z-function of " + s);
          for (int i = 0; i < n; i++) System.out.print(zfun[i] + " ");
          System.out.println();
      }
      return zfun;
  }

  class BIT {
      int[] bit;
      int n;

      public BIT(int n){
          this.n = n;
          bit = new int[n+1];
      }

      private int query(int p)
      {
          int sum = 0;
          for (; p > 0; p -= (p & (-p)))
             sum += bit[p];

          return sum;
      }

      private void add(int p, int val)
      {
         //System.out.println("add to BIT " + p);
         for (; p <= n; p += (p & (-p)))
            bit[p] += val;
      }

  }

  private List<Integer> getMinFactor(int sum)
  {
      List<Integer>  factors = new ArrayList<>();

               for (int sz = 2; sz <= sum / sz; sz++){
                   if (sum % sz == 0) {
                       factors.add(sz);
                       factors.add(sum / sz);
                   }
               }
               if (factors.size() == 0)
                   factors.add(sum);

      return factors;
  }

  /* Tree class */
  class Tree {
      int V = 0;
      int root = 0;
      List<Integer>[] nbs;
      int[][] timeRange;
      int[] subTreeSize;
      int t;
      boolean dump = false;

      public Tree(int V, int root)
      {
          if (dump)
              System.out.println("build tree with size = " + V + ", root = " + root);

          this.V = V;
          this.root = root;
          nbs = new List[V];
          subTreeSize = new int[V];
          for (int i = 0; i < V; i++)
              nbs[i] = new ArrayList<>();

      }

      public void doneInput()
      {
          dfsEuler();
      }

      public void addEdge(int p, int q)
      {
          nbs[p].add(q);
          nbs[q].add(p);
      }

      private void dfsEuler()
      {
          timeRange = new int[V][2];
          t = 1;
          dfs(root);
      }

      private void dfs(int node)
      {
          if (dump)
              System.out.println("dfs on node " + node + ", at time " + t);
          timeRange[node][0] = t;

          for (int next : nbs[node]) {
              if (timeRange[next][0] == 0)
              {
                  ++t;
                  dfs(next);
              }
          }
          timeRange[node][1] = t;
          subTreeSize[node] = t - timeRange[node][0] + 1;
      }

      public List<Integer> getNeighbors(int p) {
          return nbs[p];
      }

      public int[] getSubTreeSize(){
          return subTreeSize;
      }

      public int[][] getTimeRange()
      {
          if (dump){
              for (int i = 0; i < V; i++){
                  System.out.println(i + ": " + timeRange[i][0] + " - " + timeRange[i][1]);
              }
          }
          return timeRange;
      }

  }

  /* segment tree */
  class SegTree {
      int[] a;
      int[] tree;
      int[] treeMin;
      int[] treeMax;
      int[] lazy;
      int n;
      boolean dump = false;

      public SegTree(int n)
      {
          if (dump)
              System.out.println("create segTree with size " + n);
          this.n = n;
          treeMin = new int[n*4];
          treeMax = new int[n*4];
          lazy = new int[n*4];
      }

      public SegTree(int n, int[] a) {
          this(n);
          this.a = a;
          buildTree(1, 0, n-1);
      }

      private void buildTree(int node, int lo, int hi)
      {
          if (lo == hi) {
              tree[node] = lo;
              return;
          }

          int m = (lo + hi) / 2;
          buildTree(node * 2, lo, m);
          buildTree(node * 2 + 1, m + 1, hi);
          pushUp(node, lo, hi);
      }

      private void pushUp(int node, int lo, int hi)
      {
          if (lo >= hi) return;

          // note that, if we need to call pushUp on a node, then lazy[node] must be zero.

          //the true value is the value + lazy
          treeMin[node] = Math.min(treeMin[node * 2] + lazy[node * 2], treeMin[node * 2 + 1] + lazy[node * 2 + 1]);
          treeMax[node] = Math.max(treeMax[node * 2] + lazy[node * 2], treeMax[node * 2 + 1] + lazy[node * 2 + 1]);
          // add combine fcn
      }

      private void pushDown(int node, int lo, int hi)
      {
          if (lazy[node] == 0) return;

          int lz = lazy[node];
          lazy[node] = 0;

          treeMin[node] += lz;
          treeMax[node] += lz;

          if (lo == hi) return;

          int mid = (lo + hi) / 2;
          lazy[node * 2] += lz;
          lazy[node * 2 + 1] += lz;
      }

      public int rangeQueryMax(int fr, int to)
      {
          return rangeQueryMax(1, 0, n-1, fr, to);
      }

      public int rangeQueryMax(int node, int lo, int hi, int fr, int to)
      {
          if (lo == fr && hi == to)
              return treeMax[node] + lazy[node];

          int mid = (lo + hi) / 2;
          pushDown(node, lo, hi);

          if (to <= mid) {
              return rangeQueryMax(node * 2, lo, mid, fr, to);
          }else if (fr > mid)
              return rangeQueryMax(node * 2 + 1, mid + 1, hi, fr, to);
          else {
              return Math.max(rangeQueryMax(node * 2, lo, mid, fr, mid),
                              rangeQueryMax(node * 2 + 1, mid + 1, hi, mid + 1, to));
          }
      }

      public int rangeQueryMin(int fr, int to)
      {
          return rangeQueryMin(1, 0, n-1, fr, to);
      }

      public int rangeQueryMin(int node, int lo, int hi, int fr, int to)
      {
          if (lo == fr && hi == to)
              return treeMin[node] + lazy[node];

          int mid = (lo + hi) / 2;
          pushDown(node, lo, hi);

          if (to <= mid) {
              return rangeQueryMin(node * 2, lo, mid, fr, to);
          }else if (fr > mid)
              return rangeQueryMin(node * 2 + 1, mid + 1, hi, fr, to);
          else {
              return Math.min(rangeQueryMin(node * 2, lo, mid, fr, mid),
                              rangeQueryMin(node * 2 + 1, mid + 1, hi, mid + 1, to));
          }
      }

       public void rangeUpdate(int fr, int to, int delta){
           rangeUpdate(1, 0, n-1, fr, to, delta);
       }

      public void rangeUpdate(int node, int lo, int hi, int fr, int to, int delta){
          pushDown(node, lo, hi);
          if (fr == lo && to == hi)
          {
              lazy[node] = delta;
              return;
          }

          int m = (lo + hi) / 2;
          if (to <= m)
              rangeUpdate(node * 2, lo, m, fr, to, delta);
          else if (fr > m)
              rangeUpdate(node * 2 + 1, m + 1, hi, fr, to, delta);
          else  {
              rangeUpdate(node *  2, lo, m, fr, m, delta);
              rangeUpdate(node * 2 + 1, m + 1, hi, m + 1, to, delta);
          }

          // re-set the in-variant
          pushUp(node, lo, hi);
      }

      public int query(int node, int lo, int hi, int fr, int to)
      {
          if (fr == lo && to == hi)
              return tree[node];

          int m = (lo + hi) / 2;
          if (to <= m)
              return  query(node * 2, lo, m, fr, to);
          else if (fr > m)
              return query(node * 2 + 1, m + 1, hi, fr, to);

          int lid = query(node * 2, lo, m, fr, m);
          int rid = query(node * 2 + 1, m + 1, hi, m + 1, to);
          return a[lid] >= a[rid] ? lid : rid;
      }

  }

  private long inv(long v)
  {
      return pow(v, MOD-2);
  }

  private long pow(long v, long p)
  {
      long ans = 1;
      while (p > 0)
      {
          if (p % 2 == 1)
              ans = ans * v % MOD;
          v = v * v % MOD;
          p = p / 2;
      }
      return ans;
  }

  private double dist(double x, double y, double xx, double yy)
  {
      return Math.sqrt((xx - x) * (xx - x) + (yy - y) * (yy - y));
  }

  private int mod_add(int a, int b) {
      int v = a + b;
      if (v >= MOD) v -= MOD;
      return v;
  }

  private long overlap(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
      if (x1 > x3) return overlap(x3, y3, x4, y4, x1, y1, x2, y2);

      if (x3 > x2 || y4 < y1 || y3 > y2) return 0L;

      //(x3, ?, x2, ?)
      int yL = Math.max(y1, y3);
      int yH = Math.min(y2, y4);
      int xH = Math.min(x2, x4);

      return f(x3, yL, xH, yH);
  }
  //return #black cells in rectangle
  private long f(int x1, int y1, int x2, int y2) {
      long dx = 1L + x2 - x1;
      long dy = 1L + y2 - y1;
      if (dx % 2 == 0 || dy % 2 == 0 || (x1 + y1) % 2 == 0)
          return 1L * dx * dy / 2;
      return 1L * dx * dy / 2 + 1;
  }

  private int distM(int x, int y, int xx, int yy) {
      return abs(x - xx) + abs(y - yy);
  }

  private boolean less(int x, int y, int xx, int yy) {
      return x < xx || y > yy;
  }

  private int mul(int x, int y) {
      return (int)(1L * x * y % MOD);
  }

  private int nBit1(int v) {
      int v0 = v;
      int c = 0;
      while (v != 0) {
          ++c;
          v = v & (v - 1);
      }
      return c;
  }

  private long abs(long v) {
      return v > 0 ? v : -v;
  }

  private int abs(int v) {
      return v > 0 ? v : -v;
  }

  private int common(int v) {
      int c = 0;
      while (v != 1) {
          v = (v >>> 1);
          ++c;
      }

      return c;
  }

  private void reverse(char[] a, int i, int j) {
      while (i < j) {
          swap(a, i++, j--);
      }
  }

  private void swap(char[] a, int i, int j) {
      char t = a[i];
      a[i] = a[j];
      a[j] = t;
  }

  private int gcd(int x, int y) {
      if (y == 0) return x;
      return gcd(y, x % y);
  }
  private long gcd(long x, long y) {
      if (y == 0) return x;
      return gcd(y, x % y);
  }
  private int max(int a, int b) {
      return a >  b ? a : b;
  }

  private long max(long a, long b) {
      return a >  b ? a : b;
  }

  private int min(int a, int b) {
      return a >  b ? b : a;
  }

  private long min(long a, long b) {
      return a >  b ? b : a;
  }

  static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(BufferedReader in)
        {
            br = in;
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    String line = br.readLine();
                    if (line == null || line.length() == 0) return "";
                    st = new StringTokenizer(line);
                }
                catch (IOException  e)
                {
                    return "";
                    //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)
            {
                return null;
                //e.printStackTrace();
            }
            return str;
        }
    }
}


package cn.dalt.codeforces;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * Created by dalt on 2018/3/20.
 */
public class CF915G {
    public static final long MODULO = 1000000007;
    static final boolean IS_OJ = System.getProperty("ONLINE_JUDGE") != null;
    public static BlockReader input;

    public static void main(String[] args) throws FileNotFoundException {
        if (!IS_OJ) {
            System.setIn(new FileInputStream("D:\\DataBase\\TESTCASE\\codeforces\\CF915G.in"));
        }
        input = new BlockReader(System.in);

        int n = input.nextInteger();
        int k = input.nextInteger();
        int[]  mobius = new int[k + 1];
        int[] primes = new int[k + 1];
        int primeCnt = 0;
        long[]  pns = new long[k + 1];
        boolean[] isComposites = new boolean[k + 1];

        //euler griddle
        mobius[1] = 1;
        pns[1] = 1;
        isComposites[1] = true;
        for (int i = 2; i <= k; i++) {
            if (!isComposites[i]) {
                primes[primeCnt++] = i;
                pns[i] = pow(i, n);
                mobius[i] = -1;
            }
            //i * primes[j] <= k => primes[j] <= k / i
            for (int j = 0, bound = k / i; j < primeCnt && primes[j] <= bound; j++) {
                int ip = i * primes[j];
                isComposites[ip] = true;
                pns[ip] = pns[i] * pns[primes[j]] % MODULO;
                if (i % primes[j] == 0) {
                    mobius[ip] = 0;
                    break;
                }
                mobius[ip] = mobius[i] * mobius[primes[j]];
            }
        }

        long[] differ = new long[k + 1];
        for (int i = 1; i <= k; i++) {
            for (int j = i, t = 1; j <= k; j += i, t++) {
                differ[j] += (pns[t] - pns[t - 1]) * mobius[i];
            }
        }

        long[] values = new long[k + 1];
        values[1] = 1;
        for (int i = 2; i <= k; i++) {
            values[i] = ((values[i - 1] + differ[i]) % MODULO + MODULO) % MODULO;
        }

        long sum = 0;
        for (int i = 1; i <= k; i++) {
            sum += values[i] ^ (long)i;
        }

        sum = (sum % MODULO + MODULO) % MODULO;
        System.out.println(sum);
    }

    public static long pow(long x, int n) {
        int bit = 31;
        while (bit >= 0 && (n & (1 << bit)) == 0) {
            bit--;
        }

        long v = 1;
        for (; bit >= 0; bit--) {
            v = v * v % MODULO;
            if ((n & (1 << bit)) != 0) {
                v = v * x % MODULO;
            }
        }

        return v;
    }

    public static class BlockReader {
        static final int EOF = -1;
        InputStream is;
        byte[] dBuf;
        int dPos, dSize, next;
        StringBuilder builder = new StringBuilder();

        public BlockReader(InputStream is) {
            this(is, 4096);
        }

        public BlockReader(InputStream is, int bufSize) {
            this.is = is;
            dBuf = new byte[bufSize];
            next = nextByte();
        }

        public int nextByte() {
            while (dPos >= dSize) {
                if (dSize == -1) {
                    return EOF;
                }
                dPos = 0;
                try {
                    dSize = is.read(dBuf);
                } catch (Exception e) {
                }
            }
            return dBuf[dPos++];
        }

        public String nextBlock() {
            builder.setLength(0);
            skipBlank();
            while (next != EOF && !Character.isWhitespace(next)) {
                builder.append((char) next);
                next = nextByte();
            }
            return builder.toString();
        }

        public void skipBlank() {
            while (Character.isWhitespace(next)) {
                next = nextByte();
            }
        }

        public int nextInteger() {
            skipBlank();
            int ret = 0;
            boolean rev = false;
            if (next == '+' || next == '-') {
                rev = next == '-';
                next = nextByte();
            }
            while (next >= '0' && next <= '9') {
                ret = (ret << 3) + (ret << 1) + next - '0';
                next = nextByte();
            }
            return rev ? -ret : ret;
        }

        public int nextBlock(char[] data, int offset) {
            skipBlank();
            int index = offset;
            int bound = data.length;
            while (next != EOF && index < bound && !Character.isWhitespace(next)) {
                data[index++] = (char) next;
                next = nextByte();
            }
            return index - offset;
        }

        public boolean hasMore() {
            skipBlank();
            return next != EOF;
        }
    }
}


import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

import static java.lang.Math.*;

public class C_4 {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        long a = in.nextInt(), b = in.nextInt();
        ArrayDeque<Long> deque = new ArrayDeque<>();
        long d = abs(a - b);
        long sq = (long) sqrt(d);
        for (long i = 1; i <= sq; i++) {
            if (d % i == 0) {
                deque.addLast(i);
                deque.addLast(d / i);
            }
        }

        long min = lcm(a, b), k = 0;
        for (long i : deque) {
            long p = i - min(a, b) % i;
            long l = lcm(a + p, b + p);
            if (l < min) {
                min = l;
                k = p;
            } else if (l == min) {
                k = min(k, p);
            }
        }

        pw.println(k);

        pw.close();
    }

    static long gcd(long p, long q) {
        if (q == 0) return p;
        else return gcd(q, p % q);
    }

    static long lcm(long p, long q) {
        long g = gcd(p, q);
        p /= g;
        return p * q;
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}


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
 */
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);
        ProblemASerejaAndCoatRack solver = new ProblemASerejaAndCoatRack();
        solver.solve(1, in, out);
        out.close();
    }

    static class ProblemASerejaAndCoatRack {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int d = in.nextInt();
            int[] a = new int[n + 1];
            a[0] = 0;
            for (int i = 1; i <= n; i++) {
                a[i] = a[i - 1] + in.nextInt();
            }
            Arrays.sort(a);
            int m = in.nextInt();
            int answer = 0;
            if (m >= n) {
                answer += a[n];
                answer -= d * (m - n);
            } else {
                answer += a[m];
            }
            out.print(answer);
        }

    }
}


import java.io.*;

import java.awt.geom.Point2D;
import java.text.*;
import java.math.*;
import java.util.*;

public class Main implements Runnable {

	final String filename = "";

	final int MOD = 1000000007;

	public void solve() throws Exception {
		int MAX = 101;
		int INF = 1000;
		int[][] C = new int[MAX + 1][MAX + 1];
		for (int i = 0; i <= MAX; i++) {
			C[i][0] = C[i][i] = 1;
			for (int j = 1; j < i; j++)
				C[i][j] = Math.min(C[i - 1][j - 1] + C[i - 1][j], INF);
		}

		int N = iread(), M = iread(), K = iread();
		if (M == 1 || N == 1) {
			out.write("0\n");
			return;
		}
		long ans = 0;
		N /= 2;
		int[][][][] d = new int[2][N][N + 1][K + 1];
		for (int a = 1; a <= N; a++) {
			d[0][N - a][a][1] = 1;
		}
		int step = 0;
		for (int m = 1; m < M; m++) {
			for (int i = 0; i < N; i++)
				for (int j = 0; j <= N; j++)
					Arrays.fill(d[step ^ 1][i][j], 0);
			for (int n = 0; n < N; n++) {
				for (int prev = 1; prev <= N; prev++) {
					for (int k = 1; k <= K; k++) {
						int t = d[step][n][prev][k];
						if (t == 0)
							continue;
						int t1 = (t * k) % MOD;
						// System.out.println("m=" + m + " n=" + n + " prev="
						// + prev + " k=" + k+" ans+="+(t*k*(M-m)));
						ans = (ans + t1 * (M - m)) % MOD;
						for (int next = 1; next <= n; next++) {
							int v = k * C[next + prev - 1][prev - 1];
							if (v > K)
								continue;
							int r = d[step ^ 1][n - next][next][v] + t;
							if (r >= MOD)
								r -= MOD;
							d[step ^ 1][n - next][next][v] = r;
						}
					}
				}
			}
			step ^= 1;
		}
		out.write(ans + "\n");
	}

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new BufferedWriter(new OutputStreamWriter(System.out));
			// in = new BufferedReader(new FileReader(filename+".in"));
			// out = new BufferedWriter(new FileWriter(filename+".out"));
			solve();
			out.flush();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public int iread() throws Exception {
		return Integer.parseInt(readword());
	}

	public double dread() throws Exception {
		return Double.parseDouble(readword());
	}

	public long lread() throws Exception {
		return Long.parseLong(readword());
	}

	BufferedReader in;

	BufferedWriter out;

	public String readword() throws IOException {
		StringBuilder b = new StringBuilder();
		int c;
		c = in.read();
		while (c >= 0 && c <= ' ')
			c = in.read();
		if (c < 0)
			return "";
		while (c > ' ') {
			b.append((char) c);
			c = in.read();
		}
		return b.toString();
	}

	public static void main(String[] args) {
		try {
			Locale.setDefault(Locale.US);
		} catch (Exception e) {

		}
		// new Thread(new Main()).start();
		new Thread(null, new Main(), "1", 1 << 25).start();
	}
}


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

public class Solution {

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

        String S = in.nextLine();

        int n = S.length();

        HashSet<String>[] set = new HashSet[2];
        set[0] = new HashSet<String>();
        set[1] = new HashSet<String>();

        int tek = 0;

        for(int i =0; i<10; i++){
            set[tek].add(String.valueOf(i));
        }

        for(int l=1; l<n; l++){
            set[(tek+1)%2].clear();
            //System.out.println(map[tek].keySet());
            for(String d : set[tek]){
                {
                    String dd = d;
                    int k = (d.charAt(d.length()-1)-'0') + (S.charAt(l)-'0');
                    set[(tek+1)%2].add(dd+ (char)(k/2 +'0'));
                    if(k%2==1){
                        set[(tek+1)%2].add(dd+ (char)(k/2 +1+'0'));
                    }
                }
            }
            tek = (tek+1)%2;
        }

        int res = set[tek].size();

        if(set[tek].contains(S)){
            res--;
        }

        //System.out.print(map[tek].keySet());

        System.out.print(res+"");
    }

}


import java.io.*;

//School Team Contest #2 (Winter Computer School 2010/11), H
public class PhoneNumber {

    public static void main(String[] args) throws IOException {
		//System.setIn(new FileInputStream("/home/kite/input.txt"));
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String s = r.readLine();
		assert s.matches("\\d+");
		a = new int[s.length()];
		for(int i = 0; i < a.length; i++)
			a[i] = s.charAt(i) - '0';
		int result = 0;
		for(int i = 0; i <= 9; i++)
			result += solve(i, 1);
		boolean self = true;
		for(int i = 1; i < a.length && self; i++)
			self = (a[i - 1] + a[i]) / 2 == a[i] || (a[i - 1] + a[i] + 1) / 2 == a[i];
		if(self)
			result--;
		System.out.println(result);
    }

	private static int a[];
	private static int solve(final int n, final int i) {
		if(i == a.length)
			return 1;
		int result = solve((n + a[i]) / 2, i + 1);
		if((n + a[i] & 1) != 0)
			result += solve((n + a[i]) / 2 + 1, i + 1);
		return result;
	}
}


import java.io.*;
public class Mancala
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input[] = br.readLine().split(" ");
        int a[] = new int[input.length];
        int b[] = new int[input.length];
        for(int i=0;i<input.length;i++)
        {
            a[i] = Integer.parseInt(input[i]);
            b[i] = a[i];
        }
        int n = input.length;
        int max = 0,flag = 0;
        while(flag<n)
        {
            for(int i=0;i<n;i++)
                a[i] = b[i];
            if(a[flag] > 0)
                max = Math.max(max,answer(a,n,flag));
            flag++;
        }
        System.out.println(max);
    }
    static int answer(int a[],int n,int pos)
    {
        int val = a[pos];
        if(pos + val + 1 <= n)
            for(int i = pos + 1;i<pos + val + 1;i++)
                a[i]++;
        else
        {
            for(int i = pos + 1;i<n;i++)
                a[i]++;
            for(int i=0;i<pos + val + 1 - n;i++)
                a[i]++;
        }
        int ct = 0;
        for(int i=0;i<n;i++)
            if(a[i] % 2 == 0)
                ct += a[i];
        return ct;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class ProblemD {

    static final int MOD = 1000000007;

    public static void main(String[] args) throws IOException {
        BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
        String st = s.readLine();
        String ed = s.readLine();
        int k = Integer.valueOf(s.readLine());

        int len = st.length();
        boolean[] towards = new boolean[len+1];
        int twdcnt = 0;
        for (int i = 0 ; i < len ; i++) {
            boolean isok = true;
            for (int c = 0 ; c < len ; c++) {
                int eidx = (c + i + len) % len;
                if (st.charAt(c) != ed.charAt(eidx)) {
                    isok = false;
                    break;
                }
            }
            if (isok) {
                towards[i] = true;
                twdcnt++;
            }
        }

        if (twdcnt == 0) {
            System.out.println("0");
            return;
        }

        long[][] dp = new long[k+1][2];
        dp[1][0] = 0;
        dp[1][1] = 1;

        for (int i = 2 ; i <= k ; i++) {
            long dig = (dp[1][0] * dp[i-1][0]) % MOD;
            dig += (((dp[1][1] * dp[i-1][1]) % MOD) * (len - 1)) % MOD;

            long oth = ((dp[1][0] * dp[i-1][1]) % MOD + (dp[1][1] * dp[i-1][0]) % MOD) % MOD;
            oth += (((dp[1][1] * dp[i-1][1]) % MOD) * (len - 2)) % MOD;

            dp[i][0] = dig % MOD;
            dp[i][1] = oth % MOD;
        }

        long ans = 0;
        for (int i = 0 ; i < len ; i++) {
            if (towards[i]) {
                if (i == 0) {
                    ans = (ans + dp[k][0]) % MOD;
                } else {
                    ans = (ans + dp[k][1]) % MOD;
                }
            }
        }
        System.out.println(ans);
    }
}