import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.ArrayDeque;
import java.io.InputStream;

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

    static class _1047D {
        int n;
        int m;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.nextInt();
            m = in.nextInt();

            long ans = 0;

            if (n > 100) {
                int nn = (n - 100) % 6;
                long nq = (n - 100) / 6;
                ans += nq * 6 * m;
                n = 100 + nn;
            }

            if (m > 100) {
                int nm = (m - 100) % 6;
                long mq = (m - 100) / 6;
                ans += mq * 6 * n;
                m = 100 + nm;
            }

            int[][] mat = new int[n + 1][m + 1];

            int u = 1;
            int v = 1;
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    if ((i + j) % 2 == 0) {
                        mat[i][j] = u;
                        u++;
                    }
                }
            }

            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    if ((i + j) % 2 != 0) {
                        mat[i][j] = v;
                        v++;
                    }
                }
            }

            List[] g = new List[u];

            for (int i = 0; i < u; i++) {
                g[i] = new ArrayList();
            }

            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    if ((i + j) % 2 == 0) {
                        addEdge(mat, g, i, j, i - 3, j);
                        addEdge(mat, g, i, j, i - 2, j - 1);
                        addEdge(mat, g, i, j, i - 2, j + 1);
                        addEdge(mat, g, i, j, i, j - 3);
                        addEdge(mat, g, i, j, i - 1, j - 2);
                        addEdge(mat, g, i, j, i + 1, j - 2);
                        addEdge(mat, g, i, j, i, j + 3);
                        addEdge(mat, g, i, j, i - 1, j + 2);
                        addEdge(mat, g, i, j, i + 1, j + 2);
                        addEdge(mat, g, i, j, i + 3, j);
                        addEdge(mat, g, i, j, i + 2, j - 1);
                        addEdge(mat, g, i, j, i + 2, j + 1);
                    }
                }
            }

            HopcroftKarpBipartiteMatching bpm = new HopcroftKarpBipartiteMatching(u - 1, v - 1, g);

            ans += 2 * bpm.maximumMatching();

            out.println(ans);
        }

        void addEdge(int[][] mat, List[] g, int i, int j, int s, int t) {
            if (s <= 0 || t <= 0 || s > n || t > m)
                return;

            g[mat[i][j]].add(mat[s][t]);
        }

        class HopcroftKarpBipartiteMatching {
            int m;
            int n;
            List[] g;
            int[] pairU;
            int[] pairV;
            int[] dis;
            int inf = 10000000;
            int NIL = 0;

            public HopcroftKarpBipartiteMatching(int m, int n, List[] g) {
                this.m = m;
                this.n = n;
                this.g = g;
                this.pairU = new int[m + 1];
                this.pairV = new int[n + 1];
                this.dis = new int[m + 1];
            }

            int maximumMatching() {

                Arrays.fill(pairU, NIL);
                Arrays.fill(pairV, NIL);

                int maxMatching = 0;

                while (bfs()) {
                    for (int i = 1; i <= m; i++) {
                        if (pairU[i] == NIL && dfs(i))
                            maxMatching++;
                    }
                }

                return maxMatching;
            }

            boolean bfs() {

                ArrayDeque<Integer> queue = new ArrayDeque<>();

                for (int i = 1; i <= m; i++) {
                    if (pairU[i] == NIL) {
                        queue.addLast(i);
                        dis[i] = 0;
                    } else {
                        dis[i] = inf;
                    }
                }

                dis[NIL] = inf;

                while (!queue.isEmpty()) {
                    int u = queue.removeFirst();

                    if (dis[u] < dis[NIL]) {
                        for (int v : (List<Integer>) g[u]) {
                            if (dis[pairV[v]] == inf) {
                                queue.addLast(pairV[v]);
                                dis[pairV[v]] = dis[u] + 2;
                            }
                        }
                    }
                }

                return dis[NIL] < inf;
            }

            boolean dfs(int u) {
                if (u != NIL) {
                    for (int v : (List<Integer>) g[u]) {
                        if (dis[pairV[v]] == dis[u] + 2) {
                            if (dfs(pairV[v])) {
                                pairV[v] = u;
                                pairU[u] = v;
                                return true;
                            }
                        }
                    }
                    dis[u] = inf;
                    return false;
                } else
                    return true;
            }

        }

    }

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

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

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

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

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

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

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

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

    }
}


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

public class C {

    long mod = (int) 1e9 + 7;

    long binpow(long a, long n) {
        long res = 1;
        while (n > 0) {
            if ((n & 1) > 0) {
                res *= a;
                res %= mod;
            }
            a *= a;
            a %= mod;
            n >>= 1;
        }
        return res;
    }

    public void solve() throws IOException {
        long x = nextInt(), n = nextLong();
        Map<Integer, Long> fact = new HashMap<>();
        Set<Integer> div = new HashSet<>();
        int t = (int) x;
        for (int d = 2; d * d <= t; d++) {
            while (t % d == 0) {
                fact.putIfAbsent(d, 0L);
                div.add(d);
                t /= d;
            }
        }
        if (t > 1) {
            fact.putIfAbsent(t, 0L);
            div.add(t);
        }
        for (Integer v : div) {
            BigInteger cur = BigInteger.valueOf(v);
            while (cur.compareTo(BigInteger.valueOf(n)) <= 0) {
                fact.put(v, fact.get(v) + n / cur.longValue());
                cur = cur.multiply(BigInteger.valueOf(v));
            }
        }
        BigInteger ans = BigInteger.ONE;
        for (Map.Entry<Integer, Long> e : fact.entrySet()) {
            if (e.getValue() > 0) {
                ans = ans.multiply(BigInteger.valueOf(binpow(e.getKey(), e.getValue())));
                ans = ans.mod(BigInteger.valueOf(mod));
            }
        }
        out.print(ans);
    }

    public void run() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;

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

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

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

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

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

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new C().run();
    }
}


import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
public class Solution{
    static InputReader sc;
    static PrintWriter wc;
    static long gcd(long a, long b){
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
    public static void main(String[] args) {
        sc=new InputReader(System.in);
        wc=new PrintWriter(System.out);
        long a=sc.nextLong(),b=sc.nextLong();
        if(a>b){
            long temp=a;
            a=b;
            b=temp;
        }
        else if(a==b){
            wc.println(0);
            wc.close();
            return;
        }
        long n=a,m=b;
        long i;
        long k=Long.MAX_VALUE,add;
        long min=Long.MAX_VALUE,lcm;
        for(i=1;i*i<=(b-a);i++){
            a=n;
            b=m;
            if((b-a)%i==0){
                if(a%i==0){
                    lcm=a*b/gcd(a,b);
                    if(min>=lcm){
                        min=lcm;
                        k=0;
                    }
                }
                else{
                    add=((a/i)+1)*i-a;
                    a+=add;
                    b+=add;
                    lcm=a*b/gcd(a,b);
                    if(min>lcm){
                        min=lcm;
                        k=add;
                    }
                    else if(min==lcm){
                        if(k>add) k=add;
                    }
                }
                //wc.println(lcm);
                a=n;
                b=m;
                long j=(b-a)/i;
                if(a%j==0){
                    lcm=a*b/gcd(a,b);
                    if(min>=lcm){
                        min=lcm;
                        k=0;
                    }
                }
                else{
                    add=((a/j)+1)*j-a;
                    a+=add;
                    b+=add;
                    lcm=a*b/gcd(a,b);
                    if(min>lcm){
                        min=lcm;
                        k=add;
                    }
                    else if(min==lcm){
                        if(k>add) k=add;
                    }
                }
                //wc.println(lcm);
                a=n;
                b=m;
            }
        }
        wc.println(k);
        wc.close();
    }
    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

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

        public int read()
        {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = stream.read(buf);
                }
                catch (IOException e)
                {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine()
        {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt()
        {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-')
            {
                sgn = -1;
                c = read();
            }

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

            return res * sgn;
        }

        public long nextLong()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            long res = 0;

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

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

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

            return res.toString();
        }

        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

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


import java.util.*;

public class StronglyConnectedCity {
    public static void main(String s[]) {
        Scanner inp = new Scanner(System.in);

        int n=inp.nextInt();
        int m=inp.nextInt();
        inp.nextLine();
        String hl = inp.nextLine();
        String vl = inp.nextLine();

        SCGraph scGraph = new SCGraph(n, m);

        for(int i=0;i<hl.length();i++) {
            if(hl.charAt(i)=='>') {
                for(int j=1;j<m;j++) {
                    scGraph.arr[scGraph.hash(i, j-1)][scGraph.hash(i, j)]=1;
                }
            }
            else if(hl.charAt(i)=='<') {
                for(int j=m-2;j>=0;j--) {
                    scGraph.arr[scGraph.hash(i, j+1)][scGraph.hash(i, j)]=1;
                }
            }
            else {
                System.out.println("Error!");
            }
        }

        for(int i=0;i<vl.length();i++) {
            if(vl.charAt(i) == 'v') {
                for(int j=1;j<n;j++) {//iterating on rows
                    scGraph.arr[scGraph.hash(j-1, i)][scGraph.hash(j, i)]=1;
                }
            }
            else if(vl.charAt(i) == '^'){
                for(int j=n-2;j>=0;j--) {
                    scGraph.arr[scGraph.hash(j+1, i)][scGraph.hash(j, i)]=1;
                }
            }
            else
                System.out.println("Error!!!");
        }

        for(int k=0;k<(m*n);k++) {
            for(int i=0;i<(n*m);i++) {
                for(int j=0;j< (n*m);j++) {
                    scGraph.arr[j][j]=1;
                    if((scGraph.arr[i][k]==1) && (scGraph.arr[k][j]==1))
                        scGraph.arr[i][j]=1;

                }
            }
        }

        /*for(int i=0;i<(n*m);i++) {
            for(int j=0;j<(n*m);j++) {
                for(int k=0;k<(n*m);k++) {
                    scGraph.arr[k][k]=1;

                    if( (scGraph.arr[i][k]==1) && (scGraph.arr[k][j]==1) )
                    {
                        scGraph.arr[i][j]=1;
                    }
                }
            }
        } */

        boolean result=true;

        for(int i=0;(i< (n*m))  && (result==true) ;i++) {
            for(int j=0;(j<(n*m)) && (result==true) ;j++) {
                if(scGraph.arr[i][j] != 1) {
                    result=false;
                }
            }
        }

        if(result==true) {
            System.out.println("YES");
        }
        else{
            System.out.println("NO");
        }

    }

}

class SCGraph {
    int n,m;
    int arr[][];//adj mtrix

    SCGraph(int n, int m) {
        this.n=n;
        this.m=m;
        arr = new int[n*m][n*m];
    }

    int hash(int i, int j) {
        return m*i+j;
    }
}


import java.util.Scanner;
public class expr {
	public static void main (String [] wee){

		Scanner sti =new Scanner(System.in);

		int a,b,c;
		a= sti.nextInt();
		b= sti.nextInt();
		c= sti.nextInt();

		int sum = 0 ;
		int high = 0 ;

		sum = a+b*c;
			if(sum > high){
				high = sum;
			}
		sum = a*(b+c);
			if(sum > high){
				high = sum;
			}
		sum = a*b*c;
			if(sum > high){
				high = sum;
			}
		sum = (a+b)*c;
			if(sum > high){
				high = sum;
			}
		sum = a+b+c;
			if(sum > high){
				high = sum;
			}

		System.out.println(high);
	}
}


import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Random;

public class CF1204E {
    public static void main(String[] args) throws Exception {
        boolean local = System.getProperty("ONLINE_JUDGE") == null;
        boolean async = false;

        Charset charset = Charset.forName("ascii");

        FastIO io = local ? new FastIO(new FileInputStream("D:\\DATABASE\\TESTCASE\\Code.in"), System.out, charset) : new FastIO(System.in, System.out, charset);
        Task task = new Task(io, new Debug(local));

        if (async) {
            Thread t = new Thread(null, task, "dalt", 1 << 27);
            t.setPriority(Thread.MAX_PRIORITY);
            t.start();
            t.join();
        } else {
            task.run();
        }

        if (local) {
            io.cache.append("\n\n--memory -- \n" + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20) + "M");
        }

        io.flush();
    }

    public static class Task implements Runnable {
        final FastIO io;
        final Debug debug;
        int inf = (int) 1e8;

        public Task(FastIO io, Debug debug) {
            this.io = io;
            this.debug = debug;
        }

        @Override
        public void run() {
            solve();

//            debug.debug("bf", bruteForce(3, 1));
//            debug.debug("so", solve(3, 1));
//            debug.assertTrue(bruteForce(3, 1) == solve(3, 1));
//            for(int i = 0; i < 10; i++){
//                for(int j = 0; j < 10; j++){
//                    debug.debug("i", i);
//                    debug.debug("j", j);
//                    debug.assertTrue(bruteForce(i, j) == solve(i, j));
//                }
//            }
        }

        public int bruteForce(int n, int m) {
            return allPerm(n, m, 0, 0);
        }

        public int allPerm(int n, int m, int max, int val) {
            max = Math.max(max, val);
            if (n == 0 && m == 0) {
                return max;
            }
            int sum = 0;
            if (n > 0) {
                sum = mod.plus(sum, allPerm(n - 1, m, max, val + 1));
            }
            if (m > 0) {
                sum = mod.plus(sum, allPerm(n, m - 1, max, val - 1));
            }
            return sum;
        }

        NumberTheory.Modular mod = new NumberTheory.Modular(998244853);
        NumberTheory.Composite comp = new NumberTheory.Composite(4000, mod);

        public void solve() {
            int n = io.readInt();
            int m = io.readInt();
            io.cache.append(solve(n, m));
        }

        public int solve(int n, int m) {
            int[] leq = new int[n + 1];
            leq[0] = comp.composite(n + m, n);
            for (int i = 0; i <= n; i++) {
                leq[i] = pathNoGreaterThan(n, m, i);
            }

            debug.debug("leq", leq);
            for (int i = n; i > 0; i--) {
                leq[i] = mod.plus(leq[i], -leq[i - 1]);
            }
            debug.debug("leq", leq);

            int sum = 0;
            for (int i = 0; i <= n; i++) {
                sum = mod.plus(sum, mod.mul(leq[i], i));
            }
            return sum;
        }

        //all prefix not greater than k
        public int pathNoGreaterThan(int n, int m, int k) {
            return path(m, n, k);
        }

        //find how many permutation satisfy follow condition:
        // - n * 1
        // - m * -1
        // - all prefix greater than -k
        public int path(int n, int m, int k) {
            if (n - m < -k) {
                return 0;
            }
            return mod.plus(comp.composite(n + m, n), -comp.composite(n + m,
                    n + 1 + k));
        }
    }

    public static class NumberTheory {
        private static final Random RANDOM = new Random();

        /**
         * Extend gcd
         */
        public static class ExtGCD {
            private long x;
            private long y;
            private long g;

            public long getX() {
                return x;
            }

            public long getY() {
                return y;
            }

            /**
             * Get g = Gcd(a, b) and find a way to set x and y to match ax+by=g
             */
            public long extgcd(long a, long b) {
                if (a >= b) {
                    g = extgcd0(a, b);
                } else {
                    g = extgcd0(b, a);
                    long tmp = x;
                    x = y;
                    y = tmp;
                }
                return g;
            }

            private long extgcd0(long a, long b) {
                if (b == 0) {
                    x = 1;
                    y = 0;
                    return a;
                }
                long g = extgcd0(b, a % b);
                long n = x;
                long m = y;
                x = m;
                y = n - m * (a / b);
                return g;
            }
        }

        public static class Gcd {
            public long gcd(long a, long b) {
                return a >= b ? gcd0(a, b) : gcd0(b, a);
            }

            private long gcd0(long a, long b) {
                return b == 0 ? a : gcd0(b, a % b);
            }

            public int gcd(int a, int b) {
                return a >= b ? gcd0(a, b) : gcd0(b, a);
            }

            private int gcd0(int a, int b) {
                return b == 0 ? a : gcd0(b, a % b);
            }
        }

        /**
         * Mod operations
         */
        public static class Modular {
            int m;

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

            public int valueOf(int x) {
                x %= m;
                if (x < 0) {
                    x += m;
                }
                return x;
            }

            public int valueOf(long x) {
                x %= m;
                if (x < 0) {
                    x += m;
                }
                return (int) x;
            }

            public int mul(int x, int y) {
                return valueOf((long) x * y);
            }

            public int mul(long x, long y) {
                x = valueOf(x);
                y = valueOf(y);
                return valueOf(x * y);
            }

            public int plus(int x, int y) {
                return valueOf(x + y);
            }

            public int plus(long x, long y) {
                x = valueOf(x);
                y = valueOf(y);
                return valueOf(x + y);
            }

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

        /**
         * Bit operations
         */
        public static class BitOperator {
            public int bitAt(int x, int i) {
                return (x >> i) & 1;
            }

            public int bitAt(long x, int i) {
                return (int) ((x >> i) & 1);
            }

            public int setBit(int x, int i, boolean v) {
                if (v) {
                    x |= 1 << i;
                } else {
                    x &= ~(1 << i);
                }
                return x;
            }

            public long setBit(long x, int i, boolean v) {
                if (v) {
                    x |= 1L << i;
                } else {
                    x &= ~(1L << i);
                }
                return x;
            }

            /**
             * Determine whether x is subset of y
             */
            public boolean subset(long x, long y) {
                return intersect(x, y) == x;
            }

            /**
             * Merge two set
             */
            public long merge(long x, long y) {
                return x | y;
            }

            public long intersect(long x, long y) {
                return x & y;
            }

            public long differ(long x, long y) {
                return x - intersect(x, y);
            }
        }

        /**
         * Power operations
         */
        public static class Power {
            final Modular modular;

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

            public int pow(int x, long n) {
                if (n == 0) {
                    return 1;
                }
                long r = pow(x, n >> 1);
                r = modular.valueOf(r * r);
                if ((n & 1) == 1) {
                    r = modular.valueOf(r * x);
                }
                return (int) r;
            }

            public int inverse(int x) {
                return pow(x, modular.m - 2);
            }

            public int pow2(int x) {
                return x * x;
            }

            public long pow2(long x) {
                return x * x;
            }

            public double pow2(double x) {
                return x * x;
            }
        }

        /**
         * Log operations
         */
        public static class Log2 {
            public int ceilLog(int x) {
                return 32 - Integer.numberOfLeadingZeros(x - 1);
            }

            public int floorLog(int x) {
                return 31 - Integer.numberOfLeadingZeros(x);
            }

            public int ceilLog(long x) {
                return 64 - Long.numberOfLeadingZeros(x - 1);
            }

            public int floorLog(long x) {
                return 63 - Long.numberOfLeadingZeros(x);
            }
        }

        /**
         * Find all inverse number
         */
        public static class InverseNumber {
            int[] inv;

            public InverseNumber(int[] inv, int limit, Modular modular) {
                this.inv = inv;
                inv[1] = 1;
                int p = modular.m;
                for (int i = 2; i <= limit; i++) {
                    int k = p / i;
                    int r = p % i;
                    inv[i] = modular.mul(-k, inv[r]);
                }
            }

            public InverseNumber(int limit, Modular modular) {
                this(new int[limit + 1], limit, modular);
            }
        }

        /**
         * Factorial
         */
        public static class Factorial {
            int[] fact;
            int[] inv;

            public Factorial(int[] fact, int[] inv, InverseNumber in, int limit, Modular modular) {
                this.fact = fact;
                this.inv = inv;
                fact[0] = inv[0] = 1;
                for (int i = 1; i <= limit; i++) {
                    fact[i] = modular.mul(fact[i - 1], i);
                    inv[i] = modular.mul(inv[i - 1], in.inv[i]);
                }
            }

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

        /**
         * Composition
         */
        public static class Composite {
            final Factorial factorial;
            final Modular modular;

            public Composite(Factorial factorial, Modular modular) {
                this.factorial = factorial;
                this.modular = modular;
            }

            public Composite(int limit, Modular modular) {
                this(new Factorial(limit, modular), modular);
            }

            public int composite(int m, int n) {
                if (n > m) {
                    return 0;
                }
                return modular.mul(modular.mul(factorial.fact[m], factorial.inv[n]), factorial.inv[m - n]);
            }
        }

        /**
         * Test whether a number is primes
         */
        public static class MillerRabin {
            Modular modular;
            Power power;

            /**
             * Check whether n is a prime s times
             */
            public boolean mr(int n, int s) {
                if (n == 2) {
                    return true;
                }
                if (n % 2 == 0) {
                    return false;
                }
                modular = new Modular(n);
                power = new Power(modular);
                for (int i = 0; i < s; i++) {
                    int x = RANDOM.nextInt(n - 2) + 2;
                    if (!mr0(x, n)) {
                        return false;
                    }
                }
                return true;
            }

            private boolean mr0(int x, int n) {
                int exp = n - 1;
                while (true) {
                    int y = power.pow(x, exp);
                    if (y != 1 && y != n - 1) {
                        return false;
                    }
                    if (y != 1 || exp % 2 == 1) {
                        break;
                    }
                    exp = exp / 2;
                }
                return true;
            }
        }
    }

    public static class FastIO {
        public final StringBuilder cache = new StringBuilder(1 << 13);
        private final InputStream is;
        private final OutputStream os;
        private final Charset charset;
        private StringBuilder defaultStringBuf = new StringBuilder(1 << 13);
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastIO(InputStream is, OutputStream os, Charset charset) {
            this.is = is;
            this.os = os;
            this.charset = charset;
        }

        public FastIO(InputStream is, OutputStream os) {
            this(is, os, Charset.forName("ascii"));
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                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;
        }

        public double readDouble() {
            boolean sign = true;
            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+';
                next = read();
            }

            long val = 0;
            while (next >= '0' && next <= '9') {
                val = val * 10 + next - '0';
                next = read();
            }
            if (next != '.') {
                return sign ? val : -val;
            }
            next = read();
            long radix = 1;
            long point = 0;
            while (next >= '0' && next <= '9') {
                point = point * 10 + next - '0';
                radix = radix * 10;
                next = read();
            }
            double result = val + (double) point / radix;
            return sign ? result : -result;
        }

        public String readString(StringBuilder builder) {
            skipBlank();

            while (next > 32) {
                builder.append((char) next);
                next = read();
            }

            return builder.toString();
        }

        public String readString() {
            defaultStringBuf.setLength(0);
            return readString(defaultStringBuf);
        }

        public int readLine(char[] data, int offset) {
            int originalOffset = offset;
            while (next != -1 && next != '\n') {
                data[offset++] = (char) next;
                next = read();
            }
            return offset - originalOffset;
        }

        public int readString(char[] data, int offset) {
            skipBlank();

            int originalOffset = offset;
            while (next > 32) {
                data[offset++] = (char) next;
                next = read();
            }

            return offset - originalOffset;
        }

        public int readString(byte[] data, int offset) {
            skipBlank();

            int originalOffset = offset;
            while (next > 32) {
                data[offset++] = (byte) next;
                next = read();
            }

            return offset - originalOffset;
        }

        public char readChar() {
            skipBlank();
            char c = (char) next;
            next = read();
            return c;
        }

        public void flush() throws IOException {
            os.write(cache.toString().getBytes(charset));
            os.flush();
            cache.setLength(0);
        }

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

    public static class Debug {
        private boolean allowDebug;

        public Debug(boolean allowDebug) {
            this.allowDebug = allowDebug;
        }

        public void assertTrue(boolean flag) {
            if (!allowDebug) {
                return;
            }
            if (!flag) {
                fail();
            }
        }

        public void fail() {
            throw new RuntimeException();
        }

        public void assertFalse(boolean flag) {
            if (!allowDebug) {
                return;
            }
            if (flag) {
                fail();
            }
        }

        private void outputName(String name) {
            System.out.print(name + " = ");
        }

        public void debug(String name, int x) {
            if (!allowDebug) {
                return;
            }

            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, long x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, double x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, int[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }

        public void debug(String name, long[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }

        public void debug(String name, double[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }

        public void debug(String name, Object x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, Object... x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.deepToString(x));
        }
    }
}


import java.util.Scanner;
public class cfa{
	static void solve(int a,int b){
	 int m=a;
	 if(b>m)
	 {m=b;b=a;}
	  int d=b*2;
	  if(d>=m)
	  {System.out.println((b+m)/3);return;}
     System.out.println((b+d)/3);
	}
	public static void main(String[] args)
	{
		int a,b,d,m;
		Scanner o=new Scanner(System.in);
		a=o.nextInt();
		b=o.nextInt();
		solve(a,b);
	}
}


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

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

    long MAX = 100000L, MOD = 1000000007L, INF = (long) 1e18;

    void solve(int TC) throws Exception {
    	int n = ni();
    	int[] a = new int[n];
    	for(int i=0;i<n;i++) a[i] = ni();
    	int C=0,S=0,R=0,newC=0,newS=0,newR=0;
    	for(int i=0;i<n;i++) {
    		newR = Math.max(R, Math.max(S, C));
    		newS = newR;
    		newC = newR;
    		if(a[i] == 2 || a[i] == 3) newS = Math.max(newS, Math.max(R, C) + 1);
    		if(a[i] == 1 || a[i] == 3) newC = Math.max(newC, Math.max(R, S) + 1);
    		S = newS;
    		C = newC;
    		R = newR;
    	}
    	pn(n - Math.max(Math.max(S, C), R));
    }

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

    long pow(long a, long b) {
        if(b==0 || a==1) return 1;
        long o = 1;
        for(long p = b; p > 0; p>>=1) {
            if((p&1)==1) o = (o*a) % MOD;
            a = (a*a) % MOD;
        } return o;
    }

    long inv(long x) {
        long o = 1;
        for(long p = MOD-2; p > 0; p>>=1) {
            if((p&1)==1)o = (o*x)%MOD;
            x = (x*x)%MOD;
        } return o;
    }
    long gcd(long a, long b) { return (b==0) ? a : gcd(b,a%b); }
    int gcd(int a, int b) { return (b==0) ? a : gcd(b,a%b); }
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    static void dbg(Object... o){System.err.println(Arrays.deepToString(o));}

    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        int T = TestCases ? ni() : 1;
        for(int t=1;t<=T;t++) solve(t);
        out.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
    }

    void p(Object o) { out.print(o); }
    void pn(Object o) { out.println(o); }
    void pni(Object o) { out.println(o);out.flush(); }
    double PI = 3.141592653589793238462643383279502884197169399;

    int ni() {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-') {
            minus = true;
            b = readByte();
        }
        while(true) {
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-') {
            minus = true;
            b = readByte();
        }
        while(true) {
            if(b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

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

    int BUF_SIZE = 1024 * 8;
    byte[] inbuf = new byte[BUF_SIZE];
    int lenbuf = 0, ptrbuf = 0;

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

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

    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b))) {
            sb.appendCodePoint(b); b = readByte();
        } return sb.toString();
    }

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

    void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.LongStream;

public class Main {

    void solve() throws IOException {
        long n = nl(), m = nl(), k = nl(), x = nl(), y = nl();

        if (n <= 2) {
            long p = k / (n * m);
            long q = k % (n * m);

            out.print((q == 0 ? p : p + 1) + " " + p + " ");
            out.println(q >= (x - 1) * m + y ? p + 1 : p);
        } else {
            long t = (n - 1) * m;
            long p = k / t;
            long q = k % t;

            long max = p;
            if (p == 0 && q > 0 || q > m) max++;
            out.print(max + " ");

            long min = p / 2;
            if (p % 2 == 1 && q >= m) min++;
            out.print(min + " ");

            if (x == 1) {
                long s = p / 2;
                if (q >= y) s++;
                out.println(s);
            } else if (x == n) {
                long s = p / 2;
                if (p % 2 == 1 && q >= y) s++;
                out.println(s);
            } else {
                long s = p;
                if (p % 2 == 0 && q >= (x - 1) * m + y
                        || p % 2 == 1 && q >= (n - x) * m + y) s++;
                out.println(s);
            }
        }
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}


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

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

        String p = sn.next();
        int w = 0;
        for(int i = 0; i < p.length(); i++)
            if(p.charAt(i) == '4'|| p.charAt(i) == '7')
                w++;

        String c = w+"";
        for(int i = 0; i < c.length(); i++)
            if(c.charAt(i) == '7' || c.charAt(i) == '4' ){
                System.out.println("YES");
                break;
            }
            else{
                System.out.println("NO");
                break;
            }

    }

}


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

class TaskD {
	static final int MOD = (int) (1e9 + 9);

    public void solve(int testNumber, InputReader in, OutputWriter out) {
		int count = in.readInt();
		int height = in.readInt();
		int[][][][] result = new int[height + 1][height + 1][height + 1][height + 1];
		result[0][0][0][0] = 1;
		int[][][][] next = new int[height + 1][height + 1][height + 1][height + 1];
		for (int i = 0; i < count; i++) {
			for (int j = 0; j <= height; j++) {
				for (int k = j; k <= height; k++)
					Arrays.fill(next[0][j][k], k, height + 1, 0);
			}
			next[height][height][height][height] = 0;
			for (int j = 1; j < height; j++) {
				next[j][height][height][height] = 0;
				for (int k = j; k < height; k++) {
					next[j][k][height][height] = 0;
					for (int l = k; l < height; l++)
						next[j][k][l][height] = 0;
				}
			}
			for (int j = 0; j <= height; j++) {
				int nj = Math.min(j + 1, height);
				for (int k = j; k <= height; k++) {
					int nk = Math.min(k + 1, height);
					for (int l = k; l <= height; l++) {
						int nl = Math.min(l + 1, height);
						int shift = 1;
						if (j != 0 && l != height)
							shift = height;
						int start = l;
						if (l != 0 && shift == height)
							start = height;
						for (int m = start; m <= height; m += shift) {
							if (result[j][k][l][m] == 0)
								continue;
							int nm = Math.min(m + 1, height);
							if (j == height) {
								next[j][nk][nl][nm] += result[j][k][l][m];
								if (next[j][nk][nl][nm] >= MOD)
									next[j][nk][nl][nm] -= MOD;
							} else {
//								int delta;
//								if (0 == nm)
//									delta = 1;
//								else if (nk == nm)
//									delta = 4;
//								else if (nl == nm)
//									delta = 12;
//								else
//									delta = 24;
								next[0][nk][nl][nm] += result[j][k][l][m];
								if (next[0][nk][nl][nm] >= MOD)
									next[0][nk][nl][nm] -= MOD;
							}
//							if (k != j)
							if (k == height) {
//								int delta;
//								if (nj == height)
//									delta = 1;
//								else
//									delta = 4;
								next[nj][k][nl][nm] += result[j][k][l][m];
								if (next[nj][k][nl][nm] >= MOD)
									next[nj][k][nl][nm] -= MOD;
							} else {
//								int delta;
//								if (0 == nm)
//									delta = 1;
//								else if (nj == nm)
//									delta = 4;
//								else if (nl == nm)
//									delta = 12;
//								else
//									delta = 24;
								next[0][nj][nl][nm] += result[j][k][l][m];
								if (next[0][nj][nl][nm] >= MOD)
									next[0][nj][nl][nm] -= MOD;
							}
//							if (l != k)
							if (l == height) {
//								int delta;
//								if (nj == height)
//									delta = 1;
//								else if (nk == height)
//									delta = 4;
//								else
//									delta = 12;
								next[nj][nk][l][nm] += result[j][k][l][m];
								if (next[nj][nk][l][nm] >= MOD)
									next[nj][nk][l][nm] -= MOD;
							} else {
//								int delta;
//								if (0 == nm)
//									delta = 1;
//								else if (nj == nm)
//									delta = 4;
//								else if (nk == nm)
//									delta = 12;
//								else
//									delta = 24;
								next[0][nj][nk][nm] += result[j][k][l][m];
								if (next[0][nj][nk][nm] >= MOD)
									next[0][nj][nk][nm] -= MOD;
							}
//							if (m != l)
							if (m == height) {
//								int delta;
//								if (nj == height)
//									delta = 1;
//								else if (nk == height)
//									delta = 4;
//								else if (nl == height)
//									delta = 12;
//								else
//									delta = 24;
								next[nj][nk][nl][m] += result[j][k][l][m];
								if (next[nj][nk][nl][m] >= MOD)
									next[nj][nk][nl][m] -= MOD;
							} else {
//								int delta;
//								if (0 == nl)
//									delta = 1;
//								else if (nj == nl)
//									delta = 4;
//								else if (nk == nl)
//									delta = 12;
//								else
//									delta = 24;
								next[0][nj][nk][nl] += result[j][k][l][m];
								if (next[0][nj][nk][nl] >= MOD)
									next[0][nj][nk][nl] -= MOD;
							}
						}
					}
				}
			}
			int[][][][] temp = result;
			result = next;
			next = temp;
		}
		long total = 0;
		for (int i = 0; i <= height; i++) {
			for (int j = i; j <= height; j++) {
				for (int k = j; k <= height; k++) {
					for (int l = k; l <= height; l++) {
						int delta;
						if (i == l)
							delta = 1;
						else if (j == l)
							delta = 4;
						else if (k == l)
							delta = 12;
						else
							delta = 24;
						total += result[i][j][k][l];
					}
				}
			}
		}
		total -= result[height][height][height][height];
		out.printLine(total % MOD);
    }
}

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

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

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

	}


// practice with rainboy
import java.io.*;
import java.util.*;

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

	void main() {
		int n = sc.nextInt();
		int t = sc.nextInt();
		long[][][][][] dp = new long[n][t + 1][t][4][4];
		for (int y0 = 0; y0 < 4; y0++)
			for (int y1 = 0; y1 < 4; y1++)
				if (y0 != y1)
					dp[1][0][0][y0][y1] = 1;
		for (int i = 1; i < n - 1; i++)
			for (int h = 0; h <= t; h++)
				for (int d = 0; d < t; d++)
					for (int y0 = 0; y0 < 4; y0++)
						for (int y1 = 0; y1 < 4; y1++) {
							long x = dp[i][h][d][y0][y1];
							if (x == 0)
								continue;
							for (int y2 = 0; y2 < 4; y2++) {
								if (y2 == y1)
									continue;
								if (y0 < y1 && y1 < y2 || y0 > y1 && y1 > y2) {
									dp[i + 1][h][d][y1][y2] += x;
								} else if (y0 < y1 && y1 > y2) {
									if (h + 1 <= t)
										dp[i + 1][h + 1][d][y1][y2] += x;
								} else if (y0 > y1 && y1 < y2) {
									if (d + 1 < t)
										dp[i + 1][h][d + 1][y1][y2] += x;
								}
							}
						}
		long ans = 0;
		for (int y0 = 0; y0 < 4; y0++)
			for (int y1 = 0; y1 < 4; y1++)
				ans += dp[n - 1][t][t - 1][y0][y1];
		println(ans);
	}
}


/*
 ID: tommatt1
 LANG: JAVA
 TASK:
*/
import java.util.*;
import java.io.*;
public class cf1237e{

	public static void main(String[] args)throws IOException {
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(bf.readLine());
		int n=Integer.parseInt(st.nextToken());
		int x=1;
		while(x<=n) {
			if(n==x||n==x+1) {
				out.println(1);
				out.close();
				return;
			}
			if((x&1)==0) {
				x=2*x+1;
			}
			else {
				x=2*x+2;
			}
		}
		out.println(0);
		out.close();
	}

}


import static java.lang.Double.parseDouble;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.abs;
import static java.lang.System.exit;
import static java.util.Arrays.sort;

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

public class B3 {

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	static void solve() throws Exception {
		while (nextInt() != 0) {
			int n = nextInt();
			final int pi[] = new int[n];
			final int pj[] = new int[n];
			for (int i = 0; i < n; i++) {
				pi[i] = nextInt();
				pj[i] = nextInt();
			}
			int startPoint = 0, startI = pi[0], startJ = pj[0];
			for (int i = 1; i < n; i++) {
				if (pi[i] < startI || (pi[i] == startI && pj[i] < startJ)) {
					startPoint = i;
					startI = pi[i];
					startJ = pj[i];
				}
			}
			Integer idx[] = new Integer[n - 1];
			for (int i = 0, j = 0; i < n; i++) {
				if (i != startPoint) {
					idx[j++] = i;
				}
			}
			final int fStartI = startI, fStartJ = startJ;
			sort(idx, new Comparator<Integer>() {
				public int compare(Integer o1, Integer o2) {
					int i1 = pi[o1] - fStartI, j1 = pj[o1] - fStartJ;
					int i2 = pi[o2] - fStartI, j2 = pj[o2] - fStartJ;
					int c = Long.compare((long) j1 * i2, (long) i1 * j2);
					if (c != 0) {
						return c;
					}
					return i1 + abs(j1) - (i2 + abs(j2));
				}
			});
			int hull[] = new int[n];
			int hullSize = 1;
			hull[0] = startPoint;
			for (int i: idx) {
				int ni = pi[i], nj = pj[i];
				while (hullSize >= 2) {
					int cur = hull[hullSize - 1];
					int ci = pi[cur], cj = pj[cur];
					int old = hull[hullSize - 2];
					int oi = pi[old], oj = pj[old];
					if ((long) (nj - cj) * (ci - oi) > (long) (ni - ci) * (cj - oj)) {
						break;
					}
					--hullSize;
				}
				hull[hullSize++] = i;
			}
			int ansX[] = new int[hullSize], ansY[] = new int[hullSize];
			int ansSize = 0;
			int start = 0, startX = pi[hull[0]], startY = pj[hull[0]];
			for (int i = 1; i < hullSize; i++) {
				int cx = pi[hull[i]], cy = pj[hull[i]];
				if (cx < startX || (cx == startX && cy < startY)) {
					start = i;
					startX = cx;
					startY = cy;
				}
			}
//			System.err.println(startX + " " + startY);
//			System.err.println(hullSize);
//			for (int i = 0; i < hullSize; i++) {
//				System.err.println((1 + pj[hull[i]]) + " " + (m - pi[hull[i]]));
//			}
			int q = 0;
			for (int i = start;;) {
//				System.err.println(i + " " + (1 + pj[hull[i]]) + " " + (m - pi[hull[i]]) + " " + q);
				ansX[ansSize] = pi[hull[i]] + ADDX[q];
				ansY[ansSize] = pj[hull[i]] + ADDY[q];
				if (ansSize == 0 || ansX[ansSize] != ansX[ansSize - 1] || ansY[ansSize] != ansY[ansSize - 1]) {
					++ansSize;
				}
				int j = i;
				i = (i + hullSize - 1) % hullSize;
				if (i == start) {
					break;
				}
				if (pi[hull[i]] == pi[hull[j]] || pj[hull[i]] == pj[hull[j]]) {
					++q;
				}
			}
			if (ansX[ansSize - 1] == ansX[0] && ansY[ansSize - 1] == ansY[0]) {
				--ansSize;
			}
			out.println(ansSize);
			for (int i = 0; i < ansSize; i++) {
				out.println(ansX[i] + " " + ansY[i]);
			}
		}
	}

	static final int ADDX[] = {0, 0, -1, -1, 0};
	static final int ADDY[] = {0, -1, -1, 0, 0};

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

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

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

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

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}


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

public class Solution implements Runnable {

	static final long MODULO = 1000000007;

	void solve() throws Exception {
		String from = nextToken(), to = nextToken();
		int operations = nextInt();
		int n = from.length();
		boolean[] isGoodStart = new boolean[n];
		for (int i = 0; i < n; ++i) {
			String cut = from.substring(i) + from.substring(0, i);
			isGoodStart[i] = cut.equals(to);
		}
		long goodCount = 0;
		for (boolean a : isGoodStart) {
			if (a) {
				++goodCount;
			}
		}
		long badCount = n - goodCount;
		long[][] ways = new long[2][2];
		int cur = 0, ne = 1;
		if (isGoodStart[0]) {
			++ways[cur][1];
		} else {
			++ways[cur][0];
		}
		for (int op = 0; op < operations; ++op) {
			Arrays.fill(ways[ne], 0);
			ways[ne][0] = (ways[cur][0] * (badCount - 1)) % MODULO + (ways[cur][1] * badCount) % MODULO;
			ways[ne][0] %= MODULO;
			ways[ne][1] = (ways[cur][1] * (goodCount - 1)) % MODULO + (ways[cur][0] * goodCount) % MODULO;
			ways[ne][1] %= MODULO;
			cur ^= 1;
			ne ^= 1;
		}
		out.print(ways[cur][1]);
	}

	public void run() {
		try {
			solve();
		} catch (Exception e) {
			NOO(e);
		} finally {
			out.close();
		}
	}

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

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

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

	String nextToken() {
		while (!stringTokenizer.hasMoreTokens()) {
			String line = null;
			try {
				line = in.readLine();
			} catch (IOException e) {
				NOO(e);
			}
			if (line == null) {
				return null;
			}
			stringTokenizer = new StringTokenizer(line);
		}
		return stringTokenizer.nextToken();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer stringTokenizer;

	void NOO(Exception e) {
		e.printStackTrace();
		System.exit(42);
	}

	public Solution(String name) {
		try {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter(new FileWriter("output.txt"));
			stringTokenizer = new StringTokenizer("");
		} catch (Exception e) {
			NOO(e);
		}
	}

	public Solution() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			stringTokenizer = new StringTokenizer("");
		} catch (Exception e) {
			NOO(e);
		}
	}

	public static void main(String[] args) {
		Locale.setDefault(Locale.US);
		new Solution().run();
	}
}


//package ;
import java.io.*;
import java.util.*;

public class D
{
	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner();
		PrintWriter pw = new PrintWriter(System.out);
		int n=sc.nextInt();
		HashSet<Long>hs=new HashSet<>();
		if(n<=13)
		{	for(int i=0;i<=n;i++)
				for(int j=0;j+i<=n;j++)
					for(int k=0;k+j+i<=n;k++)
						for(int z=0;z+k+j+i<=n;z++)
							if(z+k+j+i==n)
								hs.add((long)z*1 + (long)k*5 +(long)j*10 + (long)i*50);
			System.out.println(hs.size());
		}
		else
		{
			long m=(long)(n-13)*49;
			System.out.println(390+m);
		}
		pw.close();
	}
	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

		String nextLine() throws IOException {
			return br.readLine();
		}
		boolean hasnext() throws IOException{
			return br.ready();
		}

	}
}


import java.util.*;

public class caps {
	public static void main(String[] args)
	{
	Scanner in= new Scanner( System.in);
	String a= in.next();
	int state =0;
	for(int i = 0; i<a.length();i++)
	{
		if(state==0&&a.charAt(i)=='h')
		{
			state=1;
		}
		if(state ==1 && a.charAt(i)=='e')
		{
			state=2;
		}
		if(state ==2 && a.charAt(i)=='l')
		{
			state=3;
		}
		else if(state ==3 && a.charAt(i)=='l')
		{
			state=4;
		}
		if(state ==4 && a.charAt(i)=='o')
		{
			state=5;
			break;
		}

	}
	if(state >= 5)
	{
		System.out.println("YES");
	}
	else
	{
		System.out.println("NO");
	}
	}
}


import java.util.Scanner;
import java.io.IOException;

public class IOI{
	public static void main(String args[]){
		int a,b,c,d,e,n,m,k;
		Scanner in=new Scanner(System.in);
		n=in.nextInt(); m=in.nextInt();
		k=in.nextInt();
		e=0;
		d=0;
		int ar[]=new int[10000];
		for(a=0;;a++){
			d++;
			if(((n*m)%2)==1) ar[d]=(n*m)/2 +1 ;
			else ar[d]=(n*m)/2;
			n=n-2;
			m=m-2;
			if(d==k+1) break;
			if(n<=0 || m<=0) break;
		}
		if(k>d) e=0;
		else e=ar[k]-ar[k+1];
		System.out.println(e+"");
	}
}


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

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

	void solve()
	{
		int n = ni();
		int mod = 1000000009;
		long[] dp = new long[n+1];
		if(5 <= n)dp[5] = 5;
		for(int i = 7;i <= n;i+=2){
			dp[i] = ((dp[i-2] + 1) * 2L + 1) % mod;
		}

		long ret = 1;
		for(int i = n;i >= 3;i--){
			if(dp[i] == 0){
				ret = ret + 2;
				if(ret >= mod)ret -= mod;
			}else{
				ret = ((ret+1)*dp[i]+1) % mod;
			}
		}
		ret = ((ret+1)*(ret+1)+1)%mod;
		out.println(ret*2%mod);
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


import java.util.Scanner;
public class A {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		String result = "";
		String binary = Integer.toBinaryString(n);
		// System.out.println(binary);
		int power = binary.length();
		for (int x = 0; x < binary.length(); ++x) {
			if (binary.charAt(x) == '1') {
				result += power + " ";
			}
			power--;
		}
		System.out.println(result.substring(0,result.length()-1));
	}
}


import java.io.*;
import java.util.*;
public class Solution
{
    static int N,M;
    static long K;
    static Quad A[];
    static long dp[][][];
    static StringBuilder sb=new StringBuilder();
    public static void main(String ag[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int i,j,k;

        String ip1[]=br.readLine().split(" ");

        N=Integer.parseInt(ip1[0]);
        M=Integer.parseInt(ip1[1]);
        K=Integer.parseInt(ip1[2]);

        A=new Quad[M];
        for(i=0;i<M;i++)
        {
            String ip2[]=br.readLine().split(" ");
            A[i]=new Quad(Long.parseLong(ip2[0]),Long.parseLong(ip2[1]),Integer.parseInt(ip2[2]),i+1);
        }
        Arrays.sort(A,new Tcomp());
        dp=new long[N+1][M][101];
        for(i=0;i<=N;i++)
        for(j=0;j<M;j++)
        for(k=0;k<101;k++)
        dp[i][j][k]=-1;

        long ans=-(long)1e18;
        for(i=0;i<M;i++)
        {
            for(long jj=A[i].a;jj<=A[i].b;jj++)
            {
                ans=Math.max(ans,jj+find(1,i,(int)(jj-A[i].a)));
            }
        }
        if(ans<0)
        {
            System.out.println("NO");
            return;
        }
        boolean flag=false;
        for(i=0;i<M;i++)
        {
            for(long jj=A[i].a;jj<=A[i].b;jj++)
            {
                if(ans==(jj+find(1,i,(int)(jj-A[i].a))))
                {
                    sb.append(A[i].id+" "+jj+"\n");
                    trace(1,i,(int)(jj-A[i].a));
                    flag=true;
                    break;
                }
            }
            if(flag)
            break;
        }
        System.out.println("YES");
        System.out.println(sb);
    }
    public static long find(int day,int currId,int diff)
    {
        if(day==N)
        return 0L;

        if(dp[day][currId][diff]!=-1)
        return dp[day][currId][diff];

        long currValue=diff+A[currId].a;
        long total=-(long)1e18;
        for(int i=currId+1;i<M;i++)
        {
            if(A[currId].c==A[i].c)
            continue;
            if(currValue*K>=A[i].a&&currValue*K<=A[i].b)
            total=Math.max(total,currValue*K+find(day+1,i,(int)(currValue*K-A[i].a)));
            if(currValue+K>=A[i].a&&currValue+K<=A[i].b)
            total=Math.max(total,currValue+K+find(day+1,i,(int)(currValue+K-A[i].a)));
        }
        return dp[day][currId][diff]=total;
    }
    public static void trace(int day,int currId,int diff)
    {
        if(day==N)
        return;

        long currValue=diff+A[currId].a;
        long total=-(long)1e18;

        for(int i=currId+1;i<M;i++)
        {
            if(A[currId].c==A[i].c)
            continue;
            if(currValue*K>=A[i].a&&currValue*K<=A[i].b)
            total=Math.max(total,currValue*K+find(day+1,i,(int)(currValue*K-A[i].a)));
            if(currValue+K>=A[i].a&&currValue+K<=A[i].b)
            total=Math.max(total,currValue+K+find(day+1,i,(int)(currValue+K-A[i].a)));
        }

        for(int i=currId+1;i<M;i++)
        {
            if(A[currId].c==A[i].c)
            continue;
            if(currValue*K>=A[i].a&&currValue*K<=A[i].b&&total==currValue*K+find(day+1,i,(int)(currValue*K-A[i].a)))
            {
                sb.append(A[i].id+" "+(currValue*K)+"\n");
                trace(day+1,i,(int)(currValue*K-A[i].a));
                return;
            }
            if(currValue+K>=A[i].a&&currValue+K<=A[i].b&&total==currValue+K+find(day+1,i,(int)(currValue+K-A[i].a)))
            {
                sb.append(A[i].id+" "+(currValue+K)+"\n");
                trace(day+1,i,(int)(currValue+K-A[i].a));
                return;
            }
        }
    }
}
class Quad
{
    long a,b;
    int c,id;
    Quad(long S,long E,int C,int ID)
    {
        a=S;
        b=E;
        c=C;
        id=ID;
    }
}
class Tcomp implements Comparator<Quad>
{
    public int compare(Quad P,Quad Q)
    {
        return P.c-Q.c;
    }
}


//package javaCode.exercise;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Send {
	long a, b;

	public Send(long a, long b) {
		this.a = a;
		this.b = b;
	}

	public Send() {

	}

	public static void end() {
		System.exit(0);
	}

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		if(n==1){
			System.out.println("Yes");
			end();
		}
		char[] arr = sc.nextLine().toCharArray();
		Map<Character, Integer> m = new HashMap<Character, Integer>();
		for(int i=0;i<n;i++){
			if(m.containsKey(arr[i])){
				m.put(arr[i], m.get(arr[i])+1);
			}else{
				m.put(arr[i], 1);
			}
		}
		int cnt = 0;
		for(char ch : m.keySet()){
			if(m.get(ch)>=2){
				cnt++;
			}
		}
		if(cnt!=0)
		System.out.println("Yes");
		else
	    System.out.println("No");
		sc.close();

	}

}


import java.util.List;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

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

class TaskE {
	public void solve(int testNumber, InputReader in, OutputWriter out) {
		int n = in.readInt();
		int d = in.readInt();
		int s = in.readInt();
		int[] c = new int[n];
		int[] f = new int[n];
		int[] l = new int[n];
		ArrayList<Pair<Integer, Integer>> a = new ArrayList<Pair<Integer, Integer>>();
		ArrayList<Pair<Integer, Integer>> b = new ArrayList<Pair<Integer, Integer>>();
		ArrayList<Pair<Integer, Integer>> t = new ArrayList<Pair<Integer, Integer>>();
		for (int i = 0; i < n; i ++) {
			c[i] = in.readInt();
			f[i] = in.readInt();
			l[i] = in.readInt();
			if (c[i] > 0 || l[i] < d) a.add(new Pair<Integer, Integer>(c[i], i));
			if (l[i] >= d && c[i] > 0) b.add(new Pair<Integer, Integer>(f[i], i));
			if (l[i] >= d && c[i] == 0) t.add(new Pair<Integer, Integer>(f[i], i));
		}
		Collections.sort(a);
		Collections.sort(b);
		Collections.sort(t);
		long[] tt = new long[t.size() + 1];
		tt[0] = 0;
		for (int i = 0; i < t.size(); i ++)
			tt[i + 1] = tt[i] + t.get(i).first;
		int cnt = 0, sum = 0;
		long left = 0;
		boolean[] choose = new boolean[n];
		Arrays.fill(choose, false);
		int p = a.size() - 1;
		int q = 0, sumT = 0;
		while (q < t.size() && sumT + t.get(q).first <= s) {
			sumT += t.get(q).first;
			q ++;
		}
		Pair<Integer, Integer> ans = new Pair<Integer, Integer>(q, -sumT);
		for (int i = 0; i < b.size(); i ++) {
			Pair<Integer, Integer> now = b.get(i);
			if (sum + now.first > s) break;
			sum += now.first;
			if (! choose[now.second]) {
				choose[now.second] = true;
				left += c[now.second];
				cnt ++;
			} else {
				left ++;
			}
			while (p >= 0) {
				if (! choose[a.get(p).second]) {
					if (left == 0) break;
					cnt ++;
					left --;
					choose[a.get(p).second] = true;
					left += a.get(p).first;
				}
				p --;
			}
			while (sum + sumT > s) {
				q --;
				sumT -= t.get(q).first;
			}
			long tmp = Math.min(left, (long)t.size());
			if (q + tmp > t.size()) {
				Pair<Integer, Integer> u = new Pair<Integer, Integer>(cnt + t.size(), -(sum + (int)tt[t.size() - (int)tmp]));
				if (u.compareTo(ans) > 0) ans = u;
			} else {
				Pair<Integer, Integer> u = new Pair<Integer, Integer>(cnt + q + (int)tmp, -(sum + sumT));
				if (u.compareTo(ans) > 0) ans = u;
			}
		}
		out.printLine(ans.first, -ans.second);
	}
}

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

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

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

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

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

class OutputWriter {
	private final PrintWriter writer;

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

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

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

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

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

class Pair<T1 extends Comparable<T1>, T2 extends Comparable<T2>> implements Comparable<Pair<T1, T2>> {
	public T1 first;
	public T2 second;

	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;

		Pair pair = (Pair) o;

		if (!first.equals(pair.first)) return false;
		if (!second.equals(pair.second)) return false;

		return true;
	}

	public int hashCode() {
		int result = first.hashCode();
		result = 31 * result + second.hashCode();
		return result;
	}

	public Pair(T1 first, T2 second) {
		this.first = first;
		this.second = second;
	}

	public int compareTo(Pair<T1, T2> o) {
		if (first.compareTo(o.first) != 0) return first.compareTo(o.first);
		return second.compareTo(o.second);
	}
}


// LUOGU_RID: 92601310
import java.util.Scanner;

public class CF1749D {

    private static long MAX = 998244353;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        long b = scanner.nextLong();
        long ans = 0;
        long total = b;
        long last = 0;
        long min = 1;
        boolean flag = true;
        for (int i = 1;i <= a;i++) {
            if (i == 1) {
                last = b % MAX;
                ans += last;
                ans %= MAX;
            } else {
                if (flag) {
                    // 计算新的min
                    if (zhi(i)) {
                        if (min * i <= b) {
                            min *= i;
                        } else {
                            flag = false;
                            total = ((total % MAX) * (b % MAX) + b) % MAX;
                            continue;
                        }
                    }
                    last = (((b / min) % MAX) * last) % MAX;
                    ans += last;
                    ans %= MAX;
                }
                total = ((total % MAX) * (b % MAX) + b) % MAX;
            }
        }

        // 2^n - ans
        System.out.println(((total - ans) % MAX + MAX) % MAX);
    }

    private static boolean zhi(int i) {
        for (int j = 2;j * j <= i;j++) {
            if (i % j == 0) {
                return false;
            }
        }
        return true;
    }
}


import javax.management.DynamicMBean;
import javax.print.DocFlavor;
import javax.print.attribute.HashAttributeSet;
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.nio.file.attribute.FileAttribute;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.TemporalAdjusters;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.*;
import java.util.Arrays;
import java.util.concurrent.Callable;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.TemporalAdjusters;

public class Main {

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        long u=sc.nextLong();
        long v=sc.nextLong();
        HashSet<Long> set=new HashSet<>();
        if(v<u || (v%2!=0 && u%2==0) || (v%2==0 && u%2!=0) ){
            System.out.println(-1);

        }
        else if(u==v && v!=0){
            System.out.println(1);
            System.out.println(u);
        }
        else if(v==u && v==0){
            System.out.println(0);
        }
        else{
            set.add(u);
            long value=(v-u)/2;
            if((u&value)!=0){
                System.out.println(3);
                System.out.print(u+" "+value+" "+value);
            }
            else{
                System.out.println(2);
                System.out.print((u+value)+" "+value);

            }
        }

    }

}


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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),d=sc.nextInt();
		 int m=(a-c)+(b-c)+c;
		 if((a-c)<=d && (b-c)<=d && (a-c)>=0 && (b-c)>=0 && m>=0 && m<d)
		 System.out.println(d-m);
		 else
		 System.out.println("-1");
	}
}


import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Problem315C {
    public static boolean[] primes = new boolean[2000000];
    public static int numPrimes;
    public static int numPals;
    public static boolean[] pals = new boolean[2000000];

    public static int sieve(double p, double q){

        Arrays.fill(primes, true);
        primes[0]=false;
        primes[1]=false;
        int i = 2;
        int max = 1;
        for(;i<2000000;i++){
            if(isPalindrome(i))
                numPals++;
            if(primes[i]){
                for(int j=2;j*i<2000000;j++){
                    primes[i*j]=false;
                }
            //  System.out.println(i + "  is Prime");
                numPrimes++;
            }

            if(numPrimes <= numPals*p/q){
                max = i;
        //      System.out.println( (double)numPrimes/ numPals);
            }

        }
        return max;
    }

    public static boolean isPalindrome(int a){
        String s  = ""+a;
        for(int i =0;i<=s.length()-1;i++){
            if(s.charAt(i) != s.charAt(s.length()-1-i))
                return false;
        }
    //  System.out.println(a + " is Palindrome");
        return true;
    }

    public static void main (String[] args)throws IOException{
        Scanner in = new Scanner(System.in);
        int p = in.nextInt();
        int q = in.nextInt();
        numPrimes = 0;
        numPals = 1;
        Arrays.fill(primes,true);
        System.out.println(sieve(p,q));

    }
}


import java.util.*;
public class Main{
    public static void  factorize(Map<Integer,Integer> map,int n){
        for(int i=2;i<=Math.sqrt(n);i++){
            while(n%i==0){
                if(map.containsKey(i)){
                    int x=map.get(i);
                    map.put(i,x+1);
                }else{
                    map.put(i,1);
                }
                n=n/i;
            }
        }
        if(n!=1){
            map.put(n,1);
        }
    }
    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        Map<Integer,Integer> map=new HashMap<>();
        factorize(map,n);
        int max=0;
        long k=1;
        for(Map.Entry<Integer,Integer> entry:map.entrySet()){
            int x=entry.getValue();
            k=k*entry.getKey();
            // System.out.println(x);
            if(x>max) max=x;
        }
        int num=1,i=1;
        while(i<31){
            num=1<<i;
            if(max/num <=1) break;
            i++;

        }
        if(max%num!=0) i=i+1;
        // System.out.println(max+" "+i);
        boolean shit=true;
        for(Map.Entry<Integer,Integer> entry:map.entrySet()){
            int x=entry.getValue();

            if(x!=max) shit=false;
        }
        if(!shit || max%num!=0) i=i+1;
        if(k==n) i=0;
        System.out.println(k+" "+i);
    }
}


import java.util.*;
import java.util.LinkedList;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class tmp {
    public static void main(String [] args) throws Exception{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        StringBuilder sb = new StringBuilder();

        String s = st.nextToken();
        String t = in.readLine();

        int len = s.length(),ind=0;
        boolean ok = false;
        for(int i=0; i<len; i++){

            if(t.charAt(i) - s.charAt(i) > 1){
                System.out.println(s.substring(0,i) + (char)(s.charAt(i)+1) + s.substring(i+1));
                return;
            }else if(t.charAt(i) - s.charAt(i) > 0 && !ok){
                ok = true;
                ind = i;
            }else if(ok && s.charAt(i) < 'z'){
                System.out.println(s.substring(0,i) + "z" + s.substring(i+1));
                return;
            }else if(ok && t.charAt(i) > 'a'){
                System.out.println(t.substring(0,ind) + t.charAt(ind) + t.substring(ind+1,i) + "a" + t.substring(i+1));
                return;
            }
        }
        System.out.println("No such string");

    }

}

class P implements Comparable<P>{
    int val, idx;
    public P(int val, int idx){
        this.val = val;
        this.idx = idx;
    }

    public int compareTo(P other){
        if (this.val != other.val) return -this.val + other.val;
        return this.idx - other.idx;
    }
}


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

public class Main {

	InputStream is;
	PrintWriter out;
	String INPUT = "";

	private static final long M = 1000000007L;

	void solve() {
		int n = ni();
		int[] a = na(n);
		int ans = 0;
		int MAX = Integer.MAX_VALUE / 200;
		int[][] d = new int[][] { { 0, 3, 4 }, { 3, 0, MAX }, { 4, MAX, 0 }, };
		for (int i = 1; i < n && ans < MAX; i++) {
			ans += d[a[i] - 1][a[i - 1] - 1];
			if (i >= 2 && a[i] == 2 && a[i-1] == 1 && a[i-2] == 3)
				ans--;
		}
		if (ans >= MAX)
			out.println("Infinite");
		else {
			out.println("Finite");
			out.println(ans);
		}
	}

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

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

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

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

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

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

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

	private char nc() {
		return (char) skip();
	}

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

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

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

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

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

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

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

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

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

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}


import java.util.Scanner;

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

        String s = in.next();
        StringBuilder sb = new StringBuilder();

        char c = 'a';

        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) > c || c > 'z') {
                sb.append(s.charAt(i));
            } else {
                sb.append(c);
                c++;
            }
        }

        if (c > 'z')
            System.out.println(sb);
        else
            System.out.println(-1);

    }
}


import java.util.Scanner;

public class Solution
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        long k = sc.nextLong();
        long square = 1;

        if (k > (n + m - 2))
        {
            System.out.println(-1);
            return;
        }

        long stepOneCut = 0;
        long stepTwoCut = 0;

        if ((k < n ) && (k < m))
        {
            stepOneCut = m / (k + 1) * n;
            stepTwoCut = n / (k + 1) * m;
            if (stepOneCut > stepTwoCut)
                System.out.println(stepOneCut);
            else
                System.out.println(stepTwoCut);
            return;
        }

        if ((k >= n ) && (k >= m))
        {
            stepOneCut = m / (k + 2 - n);
            stepTwoCut = n / (k + 2 - m);
            if (stepOneCut > stepTwoCut)
                System.out.println(stepOneCut);
            else
                System.out.println(stepTwoCut);
            return;
        }

        if (k >= n)
        {
            stepOneCut = m / (k + 2 - n);
            stepTwoCut = m / (k + 1) * n;
        }
        else
        {
            stepOneCut = n / (k + 2 - m);
            stepTwoCut = n / (k + 1) * m;
        }
        if (stepOneCut > stepTwoCut)
            System.out.println(stepOneCut);
        else
            System.out.println(stepTwoCut);
        return;

    }
}


//codeforces 700
        import java.io.*;
        import java.util.*;
        import java.util.Arrays;
        import static java.lang.System.out;
        public class Key_races
        {
            public static void main(String args[])
            {
                Scanner sc=new Scanner(System.in);
                int s=sc.nextInt();
                int v1=sc.nextInt();
                int v2=sc.nextInt();
                int t1=sc.nextInt();
                int t2=sc.nextInt();
                out.println((2*t1 + v1*s) == (2*t2 + v2*s)? "Friendship" :((2*t1 + v1*s) > (2*t2 + v2*s)) ?"Second":"First");

            }//main ends
        }//class ends


import java.math.BigInteger;
import java.util.Scanner;

public class CF630I{
    static BigInteger choose(int a, int b){
        BigInteger ret = BigInteger.ONE;
        for (int i=0; i<b; i++){
            ret = ret.multiply(BigInteger.valueOf(a-i));
        }
        for (int i=1; i<=b; i++){
            ret = ret.divide(BigInteger.valueOf(i));
        }
        return ret;
    }

    public static void main(String[] args){
        Scanner scn = new Scanner(System.in);
        while (scn.hasNext()){
            int n = scn.nextInt();
            BigInteger ans = BigInteger.valueOf(6).multiply(BigInteger.valueOf(4).pow(n-2));
            if (n>3){
                ans = ans.add(BigInteger.valueOf(n-3).multiply(BigInteger.valueOf(9)).multiply(BigInteger.valueOf(4).pow(n-3)));
            }
            System.out.println(ans);
        }
    }
}