import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Temp3 {
	public static void main(String[] args) throws Throwable {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[][] arr = new int[5][5];
		for (int i = 0; i < arr.length; i++) {
			StringTokenizer st = new StringTokenizer(br.readLine());
			for (int j = 0; j < arr.length; j++) {
				arr[i][j] = Integer.parseInt(st.nextToken());
			}
		}
		long ans = 0;
		for (int a = 0; a < 5; a++)
		{
			for (int b = 0; b < 5; b++)
			{
				if(b==a )
					continue;
				for (int c = 0; c < 5; c++)
				{
					if(c==a || c==b )
						continue;
					for (int d = 0; d < 5; d++)
					{
						if(d==a || d==b || d==c )
							continue;
						for (int e = 0; e < 5; e++)
						{
							if(e==a || e==b || e==c || e==d )
								continue;
							long cur = arr[a][b] + arr[b][a] + arr[c][d] + arr[d][c];
								 cur+= arr[b][c] + arr[c][b] + arr[d][e] + arr[e][d];
								 cur+= arr[d][c] + arr[c][d];
								 cur+= arr[e][d] + arr[d][e];
							ans = Math.max(ans, cur);
						}
					}
				}
			}
		}
		System.out.println(ans);
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Set;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

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

    static class CPrimesAndMultiplication {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int MOD = (int) 1e9 + 7;
            long x = in.nextLong();
            long n = in.nextLong();
            Set<Long> primes = primeFactors(x);
            long fin = 1;
            for (long p : primes) {
                long facs = all(p, n);
                fin *= power(p, facs, MOD);
                fin %= MOD;
            }
            out.println((fin + MOD) % MOD);
        }

        static long all(long p, long n) {
            long pow = p;
            long res = 0;
            while (n >= pow) {
//            long temp = (long) Math.pow(p, pow);
                res += n / pow;
                if (pow > (long) 1e18 / p) {
                    break;
                }
                pow *= p;
            }
            return res;
        }

        static Set<Long> primeFactors(long n) {
            Set<Long> factors = new HashSet<>();
            while (n % 2 == 0) {
                factors.add((long) 2);
                n /= 2;
            }
            for (long i = 3; i <= Math.sqrt(n); i += 2) {
                while (n % i == 0) {
                    factors.add(i);
                    n /= i;
                }
            }
            if (n > 2) {
                factors.add(n);
            }
            return factors;
        }

        static long power(long x, long y, int p) {
            long res = 1;
            x %= p;

            while (y > 0) {
                if ((y & 1) == 1) {
                    res = (res * x) % p;
                }
                y = y >> 1;
                x = (x * x) % p;
            }
            return res;
        }

    }

    static class Scanner {
        private StringTokenizer st;
        private BufferedReader br;

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

        public Scanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

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

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

    }
}


import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);
		while (sc.hasNext()) {
			long m=sc.nextInt();
			long b=sc.nextInt();
			long sum=-1;
			for(int i=0;i<=m*b;i++){
				long x=i;
				long y=(long) (-i*1.0/m+b);
				long res=(x+1)*(((y+1)*y)/2)+(y+1)*(((x+1)*x)/2);
				sum=Math.max(sum,res);
			}
			for(int j=0;j<=b;j++){
				long x=b*m-m*j;
				long y=j;
				long res=(x+1)*(y+1)*y/2+(y+1)*((x+1)*x/2);
				sum=Math.max(sum,res);
			}
			pw.println((long)sum);
			pw.flush();
		}
	}
}
class FastScanner {
	BufferedReader br;
	StringTokenizer st;

	public FastScanner() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer("");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public boolean hasNext() {
		while (!st.hasMoreTokens()) {
			String line = nextLine();
			if (line == null) {
				return false;
			}
			st = new StringTokenizer(line);
		}
		return true;
	}

	public String next() {
		while(!st.hasMoreTokens()){
			st=new StringTokenizer(nextLine());
		}
		return st.nextToken();
	}

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

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

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

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


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

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

			public InputReader() {
				reader = new BufferedReader(new InputStreamReader(System.in));
				tokenizer = null;
			}

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

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

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

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

			public String nextLine() {
				String s = null;
				try {
					s = reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return s;
			}

			public String nextParagraph() {
				String line = null;
				String ans = "";
				try {
					while ((line = reader.readLine()) != null) {
						ans += line;
					}
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return ans;
			}

		}

	public static void main(String args[]){
		InputReader sc=new InputReader();
		PrintWriter pw=new PrintWriter(System.out);
		int c=sc.nextInt();
		int v0=sc.nextInt();
		int v1=sc.nextInt();
		int a=sc.nextInt();
		int l=sc.nextInt();
		int count=1;
		int pages=v0;
		while(pages<c){
			int toAdd = v0+(count*a);
			if(toAdd>v1){
				toAdd=v1;
			}
			pages+=(toAdd-l);
			count++;
		}
		pw.println(count);
		pw.close();
	}
}


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

public class A151 {

	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int n = s.nextInt(), l = s.nextInt() * s.nextInt(), d = s.nextInt() * s.nextInt(), p = s.nextInt(),
				nl = n * s.nextInt(), nd = n, np = n * s.nextInt();
		int[] c = new int[3];
		c[0] = l / nl;
		c[1] = d / nd;
		c[2] = p / np;
		Arrays.sort(c);
		System.out.println(c[0]);
	}

}


import java.util.Scanner;

/**
 * @author sadasidha
 * @since 2/10/16
 */
public class P622B {
    public static void main(String[] args) {
        Scanner sc =  new Scanner(System.in);

        String str = sc.next();
        String[] strings = str.split(":");
        int hour = Integer.parseInt(strings[0]);
        int minute = Integer.parseInt(strings[1]);
        int time = (hour*60 + minute + sc.nextInt())%(24*60);
        hour = time/60;
        minute = time%60;
        if (hour < 10) {

        }
        System.out.println(hour/10+""+hour%10 +":"+minute/10+""+minute%10);
    }
}


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

public class Solution {

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

	void solve() throws IOException {
		int r1 = nextPos();
		int r2 = nextPos();
		int wk = nextPos();
		int bk = nextPos();
		int r1x = r1 / 8;
		int r1y = r1 % 8;
		int r2x = r2 / 8;
		int r2y = r2 % 8;
		int wkx = wk / 8;
		int wky = wk % 8;
		int bkx = bk / 8;
		int bky = bk % 8;
		for (int dx = -1; dx <= 1; ++dx) {
			for (int dy = -1; dy <= 1; ++dy) {
				int x = bkx + dx;
				int y = bky + dy;
				if (x >= 0 && x < 8 && y >= 0 && y < 8 &&
					(!attacks(r1x, r1y, wkx, wky, x, y) || x == r1x && y == r1y) &&
					(!attacks(r2x, r2y, wkx, wky, x, y) || x == r2x && y == r2y) &&
					Math.max(Math.abs(x - wkx), Math.abs(y - wky)) > 1) {
					out.println("OTHER");
					return;
				}
			}
		}
		out.println("CHECKMATE");
	}

	private boolean attacks(int rx, int ry, int wkx, int wky, int x, int y) {
		if (rx == x && (rx != wkx || wky < Math.min(y, ry) || wky > Math.max(y, ry))) {
			return true;
		}
		if (ry == y && (ry != wky || wkx < Math.min(x, rx) || wkx > Math.max(x, rx))) {
			return true;
		}
		return false;
	}

	private int nextPos() throws IOException {
		String s = next();
		return (s.charAt(0) - 'a') * 8 + s.charAt(1) - '1';
	}

	Solution() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		eat("");

		solve();

		in.close();
		out.close();
	}

	private void eat(String str) {
		st = new StringTokenizer(str);
	}

	String next() throws IOException {
		while (!st.hasMoreTokens()) {
			String line = in.readLine();
			if (line == null) {
				return null;
			}
			eat(line);
		}
		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());
	}

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


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;

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

    static class TaskA
    {
        public void solve(int testNumber, FastScanner in, FastPrinter out)
        {
            long x = in.nextLong();
            long y = in.nextLong();
            long L = lcm(x, y);

            long a = in.nextLong();
            long b = in.nextLong();
            long q1 = (a + L - 1) / L;
            long q2 = b / L;

            out.println(Math.max(0, (q2 - q1 + 1)));
        }

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

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

    }

    static class FastScanner
    {
        public BufferedReader br;
        public StringTokenizer st;

        public FastScanner(InputStream is)
        {
            br = new BufferedReader(new InputStreamReader(is));
        }

        public FastScanner(File f)
        {
            try
            {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e)
            {
                e.printStackTrace();
            }
        }

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

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

    }

    static class FastPrinter extends PrintWriter
    {
        public FastPrinter(OutputStream out)
        {
            super(out);
        }

        public FastPrinter(Writer out)
        {
            super(out);
        }

    }
}


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

public class Main {
//	static Scanner in;
	static PrintWriter out;
	static StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}

	public static void main(String[] args) throws Exception {
//		in = new Scanner(System.in);
		out = new PrintWriter(System.out);
		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

		int x = next();
		int y = next();

		int rr = x*x + y*y;
		int r = 0;
		while ((r+1)*(r+1) <= rr) r++;
		if (r*r == rr || x*y == 0) out.println("black");
		else if (r % 2 == 0 ^ x*y < 0) out.println("black");
		else out.println("white");

		out.close();
	}
}


import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        Solver s = new Solver();
        s.solve(in, out);
         out.close();
    }
    static class Solver {
        public void solve(Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] grades = new int[n];
            Arrays.fill(grades, 2);
            k -= 2 * n;
            while (k > 0) {
                for (int i = 0; i < n && k > 0; ++i) {
                    ++grades[i];
                    --k;
                }
            }
            int tot = 0;
            for (int x : grades)
                if (x == 2)
                    ++tot;
            out.println(tot);
        }
    }
}


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

public class CircleCenter {
    public static long numberOfSteps(int r, int x, int y, int xx, int yy) {
        long distance = (long)Math.ceil(getDistance(x, y, xx, yy));
        long rotations = distance / (2 * r);
        if(distance % (2 * r) != 0){
                rotations++;
        }
        return rotations;
    }

    public static double getDistance(long x, long y, long xx, long yy) {
        return Math.sqrt((xx - x) * (xx - x) + (yy - y) * (yy - y));
    }

    public static void main(String[] args) {
        BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
        try {
            StringTokenizer tokenizer = new StringTokenizer(scanner.readLine());
            int r = Integer.parseInt(tokenizer.nextToken());
            int x = Integer.parseInt(tokenizer.nextToken());
            int y = Integer.parseInt(tokenizer.nextToken());
            int xx = Integer.parseInt(tokenizer.nextToken());
            int yy = Integer.parseInt(tokenizer.nextToken());

            System.out.println(numberOfSteps(r, x, y, xx, yy));

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}


import java.util.*;

public class D{
	static final int MOD = 1000000009;
	static int increment(int last, int h){
		if (last == 0){
			return 0;
		}
		return (last + 1)%h;
	}
	static int boolean2int(boolean in){
		return in ? 1 : 0;
	}
	static int add(int a, int b){
		return (a + b)%MOD;
	}
	public static void main(String [] args){
		try (Scanner s = new Scanner(System.in)){
			final int n = s.nextInt();
			final int h = s.nextInt();
			final int [][][][][] dp = new int[2][2][32][32][32];
			dp[1][1][0][0][0] = 4;
			int p = 1;
			for (int i = 1; i <= n - 1; ++i){
				final int np = (p + 1)%2;
				for (int alive = 0; alive <= 1; ++alive){
					for (int last1 = 0; last1 < h; ++last1){
						for (int last2 = 0; last2 < h; ++last2){
							for (int last3 = 0; last3 < h; ++last3){
								final int a = increment(last1, h);
								final int b = increment(last2, h);
								final int c = increment(last3, h);
								final int alive1 = boolean2int(i < h || last1 > 0);
								final int alive2 = boolean2int(i < h || last2 > 0);
								final int alive3 = boolean2int(i < h || last3 > 0);
								dp[np][alive][a][b][c] = add(dp[np][alive][a][b][c], dp[p][alive][last1][last2][last3]);
								dp[np][alive1][alive][b][c] = add(dp[np][alive1][alive][b][c], dp[p][alive][last1][last2][last3]);
								dp[np][alive2][a][alive][c] = add(dp[np][alive2][a][alive][c], dp[p][alive][last1][last2][last3]);
								dp[np][alive3][a][b][alive] = add(dp[np][alive3][a][b][alive], dp[p][alive][last1][last2][last3]);
							}
						}
					}
				}
				for (int alive = 0; alive <= 1; ++alive){
					for (int last1 = 0; last1 < h; ++last1){
						for (int last2 = 0; last2 < h; ++last2){
							for (int last3 = 0; last3 < h; ++last3){
								dp[p][alive][last1][last2][last3] = 0;
							}
						}
					}
				}
				p = np;
			}
			int res = 0;
			for (int last1 = 0; last1 < h; ++last1){
				for (int last2 = 0; last2 < h; ++last2){
					for (int last3 = 0; last3 < h; ++last3){
						res = add(res, dp[p][1][last1][last2][last3]);
						if (last1 + last2 + last3 > 0){
							res = add(res, dp[p][0][last1][last2][last3]);
						}
					}
				}
			}

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


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeMap;

public class ProblemC {
	static int callCount = 0;
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		long m = input.nextLong();
		ArrayList<Long> getCubes = getCubes();
		System.out.println(solve(m, getCubes));
//		System.out.println(callCount);
	}
	public static Answer solve(long m, ArrayList<Long> cubes){
		callCount++;
//		System.out.println(m + " solve called ");
		if(m < 8){
//			System.out.println(m + " solve finished " + new Answer(m, m));
			return new Answer(m, m);
		}
		int maxIdx = (int)(Math.pow(m, 1.0/3.0)+1E-9);

		Answer ans1 = solve(m-cubes.get(maxIdx), cubes);
		ans1.n += cubes.get(maxIdx);
		ans1.x += 1;

		Answer ans2 = solve(cubes.get(maxIdx)-cubes.get(maxIdx-1)-1, cubes);
		ans2.n += cubes.get(maxIdx-1);
		ans2.x += 1;
		Answer bestAnswer = best(ans1, ans2);
//		System.out.println(m + " solve finished " + bestAnswer);
		return bestAnswer;
	}

	private static Answer best(Answer ans1, Answer ans2) {
		if(ans1.x == ans2.x){
			if(ans1.n > ans2.n){
				return ans1;
			}
			else{
				return ans2;
			}
		}
		if(ans1.x > ans2.x){
			return ans1;
		}
		else{
			return ans2;
		}
	}

	public static class Answer{
		long n;
		long x;
		public Answer(long _n, long _x){
			n = _n;
			x = _x;
		}
		public String toString(){
			return x + " " + n;
		}
	}

	private static ArrayList<Long> getCubes() {
		ArrayList<Long> cubes = new ArrayList<Long>();
		for (long a = 0; a < 500000; a++) {
			cubes.add(a * a * a);
		}
		return cubes;
	}

}


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

/**
 * New topic learned:
 *  - Goldbach's Conjecture
 */
public class Code_735D_Taxes{
    public static void main(String args[]){
        Scanner in=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);

        long n=in.nextLong();
        if(n==2)out.print(1);
        else if(n%2==0)out.print(2);
        else{
            if(isPrime(n))out.print(1);
            else if(isPrime(n-2))out.print(2);
            else out.print(3);
        }

        out.close();
    }
    public static boolean isPrime(long n){
        long limit=(long)Math.sqrt(n);
        for(long i=3;i<=limit;i+=2)
            if(n%i==0)
                return false;
        return true;
    }
}


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

    public class Solution {
       public static void main(String[] args) throws Exception{
           BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
           PrintWriter out = new PrintWriter(System.out);
              StringTokenizer st = new StringTokenizer(br.readLine());
              int t = Integer.parseInt(st.nextToken());

            while(t > 0){
                st = new StringTokenizer(br.readLine());
                int n = Integer.parseInt(st.nextToken());
                int k = Integer.parseInt(st.nextToken());
                int l = Integer.parseInt(st.nextToken());

                int[] tide = new int[2*k];
                for(int i=1;i<=k;i++) tide[i] =tide[i-1]+1;

                for(int i=k+1;i<tide.length;i++) tide[i] = tide[i-1]-1;

                //System.out.println(Arrays.toString(tide));

                st = new StringTokenizer(br.readLine());

                int[] a = new int[n];
                for(int i=0;i<n;i++) a[i] = Integer.parseInt(st.nextToken());
                t--;

                boolean[][] dp = new boolean[n][2*k];

                for(int j=0;j<2*k;j++){
                    if(a[0]+tide[j] <= l) dp[0][j] = true;
                }

                for(int i=1;i<n;i++)
                 for(int j=0;j<2*k;j++){
                     int depth  = a[i] + tide[j];
                     if(depth > l) continue;

                     dp[i][j] = (j == 0) ? dp[i-1][2*k-1] : (dp[i-1][j-1] || dp[i][j-1]);
                 }
                 //Arrays.stream(dp).forEach(e->System.out.println(Arrays.toString(e)));
                 boolean possible = false;
                 for(int j=0;j<2*k;j++) {
                  if(dp[n-1][j]){
                      possible = true;
                      break;
                  }
                 }
                 if(possible) out.println("YES");
                 else out.println("NO");
            }
            out.close();
       }
    }


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.regex.Pattern;

public class C {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        BigInteger n=BigInteger.valueOf(fs.nextLong());
        BigInteger m =BigInteger.valueOf(fs.nextLong());
        BigInteger r = BigInteger.valueOf(3).modPow(n, m).subtract(BigInteger.ONE.mod(m)).mod(m);
        System.out.println(r);
    }

    static long gcd(long a, long b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


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

import static java.lang.Math.*;

public class Cf182 implements Runnable
{
	static class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		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()
		{
			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);
		}
	}
	public static void main(String args[]) throws Exception
	{
		new Thread(null, new Cf182(),"Main",1<<27).start();
	}

	public static long gcd(long a, long b)
	{
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}
	//  array sorting by colm
public static void sortbyColumn(int arr[][], int col)
    {

        Arrays.sort(arr, new Comparator<int[]>() {

          @Override
          public int compare(final int[] entry1,
                             final int[] entry2) {

            if (entry1[col] > entry2[col])
                return 1;
            else
                return -1;
          }
        });
    }

	// gcd

	public static long findGCD(long arr[], int n)
	{
		long result = arr[0];
		for (int i = 1; i < n; i++)
			result = gcd(arr[i], result);
		return result;
	}
	// fibonaci
	static int fib(int n)
    {
        int a = 0, b = 1, c;
        if (n == 0)
            return a;
        for (int i = 2; i <= n; i++)
        {
            c = a + b;
            a = b;
            b = c;
        }
        return b;
    }

// sort a string
    public static String sortString(String inputString)
    {

        char tempArray[] = inputString.toCharArray();

        Arrays.sort(tempArray);

        return new String(tempArray);
    }
    // pair function

    // list.add(new Pair<>(sc.nextInt(), i + 1));
    //     Collections.sort(list, (a, b) -> Integer.compare(b.first, a.first));
    private static class Pair<F, S> {

        private F first;

        private S second;

        public Pair() {}

        public Pair(F first, S second) {
            this.first = first;
            this.second = second;
        }
    }

	public void run()
	{
		InputReader sc = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);
		String s[] = sc.nextLine().split("\\s+");
        int a = Integer.parseInt((s[0]));
        int b = Integer.parseInt((s[1]));
        int c = Integer.parseInt((s[2]));

        for(int i = 1; i<=b; i++){
            if(a*10 / b == c){
                System.out.println((i));
                return;
            }
            a = (a*10) % b;
        }
        System.out.println(-1);
	}
}


import java.util.Scanner;

public class Olymp_B {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String value = "";
        String new_value = "";
        String numbers = "0123456789";
        value = scan.next();
        int start = value.length() - 1;
        while (start >= 0) {
            if (value.charAt(start) != '9') {
                break;
            }
            start--;
        }
        if (start <= 0) {
            System.out.println(value);
            return;
        }
        String[] answer = new String[start];
        for (int i = start - 1; i >= 0; i--) {
            answer[i] = value.substring(0, i);
            if (numbers.charAt(numbers.indexOf(value.charAt(i))) != '0') {
                if (numbers.charAt(numbers.indexOf(value.charAt(i)) - 1) != '0') {
                    answer[i] += numbers.charAt(numbers.indexOf(value.charAt(i)) - 1);
                }
            }
            for (int j = i + 1; j < value.length(); j++) {
                answer[i] += "9";
            }
        }
        int sum = 0;
        for (int i = 0; i < value.length(); i++) {
            sum += numbers.indexOf(value.charAt(i));
        }
        int _sum = 0;
        int max_sum = 0;
        int max_index = -1;
        for (int i = 0; i < answer.length; i++) {
            _sum = 0;
            for (int j = 0; j < answer[i].length(); j++) {
                _sum += numbers.indexOf(answer[i].charAt(j));
            }
            if (_sum > sum) {
                if (_sum >= max_sum) {
                    max_sum = _sum;
                    max_index = i;
                }
            }
        }
        if (max_index >= 0) {
            System.out.println(answer[max_index]);
        } else {
            System.out.println(value);
        }
    }
}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	static int mod = 1000000007 ;

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

	public static void main(String[] args) throws Throwable {
		Scanner sc = new Scanner(System.in);
		char[] a = sc.nextLine().toCharArray();
		int n = a.length;
		long ans = 0;
		for(int i = 0;i<n;i++)
		{
			ans = ((ans%mod)*2)%mod;
			ans = ((ans%mod)+(a[i]-'0'))%mod;
		}
		long pow = modPow(2, n-1)%mod;
		System.out.println(((ans%mod) * (pow%mod))%mod);
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;
		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
		public Scanner(String file) throws FileNotFoundException { br = new BufferedReader(new FileReader(file));}
		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException {return Integer.parseInt(next());}
		public long nextLong() throws IOException {return Long.parseLong(next());}
		public String nextLine() throws IOException {return br.readLine();}
		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-'){neg = true;start++;}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else{sb.append(x.charAt(i));if(dec)f *= 10;}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}
		public int[] nexIntArray() throws Throwable
		{
			st = new StringTokenizer(br.readLine());
			int[] a = new int[st.countTokens()];
			for(int i = 0; i < a.length;i++)a[i]=nextInt();
			return a;
		}
		public boolean ready() throws IOException {return br.ready();}
	}

}


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

/**
 * Created by kaaveh on 7/29/16.
 */
public class _697B_ {
    public static void main(String[] args) throws IOException {

        char tmp;
        int num;
        int zero;
        ArrayList<Character> data = new ArrayList<>();
        kaaveh in = new kaaveh();

        System.out.print((char) System.in.read());
        System.in.read();

        while(true){
            tmp = (char) System.in.read();
            if (tmp == 'e'){
                break;
            } else {
                data.add(tmp);
            }
        }

        num = in.kint();
        zero =num - data.size();
        if (num > data.size())
            num = data.size();
        for (int i=0; i<num; i++){
            System.out.print(data.get(i));
        }
        if ((data.size() - num)!=0 && !(data.size() ==1 && data.get(0)=='0'))
            System.out.print('.');

        if (!(data.size() ==1 && data.get(0)=='0'))
            for (int i= num; i<data.size(); i++){
                System.out.print(data.get(i));
            }

        while (zero > 0){
            System.out.print('0');
            zero--;
        }
    }
}

class kaaveh {
    static String kLine(int maxLg) {
        byte lin[] = new byte[maxLg];
        int lg = 0, car = -1;
        String line = "";

        try {
            while (lg < maxLg) {
                car = System.in.read();
                if ((car < 0) || (car == '\n') || (car == '\r')) break;
                lin[lg++] += car;
            }
        } catch (IOException e) {
            return (null);
        }

        if ((car < 0) && (lg == 0)) return (null);  // eof
        return (new String(lin, 0, lg));
    }

    static String knex(int maxLg) {
        byte lin[] = new byte[maxLg];
        int lg = 0, car = -1;
        String line = "";

        try {

            while ((car < 0) || (car == '\n') || (car == ' ') || (car == '\t') || (car == '\r'))
                car = System.in.read();

            while (lg < maxLg) {
                if ((car < 0) || (car == '\n') || (car == ' ') || (car == '\t') || (car == '\r')) break;
                lin[lg++] += car;
                car = System.in.read();
            }
        } catch (IOException e) {
            return (null);
        }

        if ((car < 0) && (lg == 0)) return (null);  // eof
        return (new String(lin, 0, lg));
    }

    static int kint() {
        return Integer.parseInt(knex(11));
    }

    static long kLong() {
        return Long.parseLong(knex(20));
    }

    static double kdouble() {
        return Double.parseDouble(knex(100));
    }
}


// Problem : C. Candies
// Contest : Codeforces Round #491 (Div. 2)
// URL : https://codeforces.com/contest/991/problem/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

public class a {

	public static void main(String[] args) {
		FastReader scan = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		Task solver = new Task();
		//int t = scan.nextInt();
		int t = 1;
		for(int i = 1; i <= t; i++) solver.solve(i, scan, out);
		out.close();
	}

	static class Task {
		long m;
		public void solve(int testNumber, FastReader sc, PrintWriter pw) {
			m = sc.nextLong();
			long ans  = 0;
				long lo = 1, hi = m;
			    for(int i=0;i<66;i++) {
			        long mid = (lo+hi)/2;
			        if (get(mid)) {
			            hi = mid;
			        } else {
			            lo = mid+1;
			        }
			    }
			    if (get(Long.min(lo, hi))) {
			        ans= Long.min(lo, hi);
			    } else {
			        ans= Long.max(lo, hi);
			    }
			    pw.println(ans);
		}
		public boolean get(long a){
			long c = m;
			long sum = 0;
			long sum2 = 0;
			while(c>0){
				sum+=Math.min(a,c);
				c-=Math.min(a,c);
				sum2+=c/10;
				c-=c/10;
				//System.out.println(a+" "+sum+" "+c);
			}
			return(sum>=sum2);
		}

	}

	static void shuffle(int[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static void shuffle(long[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

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

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

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

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

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

}


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

public class D implements Runnable {
	private InputReader in;
	private PrintWriter out;
	private static final int MAX = 5000+5;

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

	public D() {
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);
	}

	static int MOD = 100000000;

	int[][][] mem = new int[101][101][21];

	private int f(int x, int y, int a) {
	    if (mem[x][y][10+a] != -1)
	        return mem[x][y][10+a];
	    int sum;
        if (a > 0) {
            if (y == 0)
                return a == x ? 1 : 0;
            sum = 0;
            for (int i = 1; i < Math.min(k2, y)+1; i++)
                sum = (sum + (f(x-a, y, -i))) % MOD;
            return mem[x][y][10+a] = sum;
        }
        if (a < 0) {
            a = -a;
            if (x == 0)
                return a == y ? 1 : 0;
            sum = 0;
            for (int i = 1; i < Math.min(k1, x)+1; i++)
                sum = (sum + (f(x, y-a, i))) % MOD;
            return mem[x][y][10-a] = sum;
        }
        return 0;
	}

	int n1, n2, k1, k2;

	public void run() {
	    for (int i = 0; i <= 100; i++)
	    for (int j = 0; j <= 100; j++)
	    for (int k = 0; k <= 20; k++)
    	    mem[i][j][k] = -1;
	    n1 = in.readInt();
	    n2 = in.readInt();
	    k1 = in.readInt();
	    k2 = in.readInt();
	    int sum = 0;
	    for (int a = 1; a <= Math.min(n1, k1); a++)
	        sum = (sum + f(n1, n2, a)) % MOD;
	    for (int a = 1; a <= Math.min(n2, k2); a++)
	        sum = (sum + f(n1, n2, -a)) % MOD;
	    out.println(sum);
	    out.close();
	}

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

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

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

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

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

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

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

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

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

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

		public BigInteger readBigInteger() {
			try {
				return new BigInteger(readString());
			} catch (NumberFormatException e) {
				throw new InputMismatchException();
			}
		}

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

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c < '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 < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}
	}
}


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

public class p712C
{

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

		int y = s.nextInt(), x = s.nextInt();

		s.close();

		int[] sides = { x, x, x };
		int curSide = 0;

		int seconds = 0;

		while ( sides[ 0 ] != y || sides[ 1 ] != y || sides[ 2 ] != y )
		{
			if ( sides[ curSide ] == y )
			{
				curSide = ( curSide + 1 ) % 3;
				continue;
			}

			int a = sides[ ( curSide + 1 ) % 3 ], b = sides[ ( curSide + 2 ) % 3 ];

			int nonDegenLen = a + b - 1;
			sides[ curSide ] = Math.min( nonDegenLen, y );

			curSide = ( curSide + 1 ) % 3;
			seconds++;
		}

		System.out.println( seconds++ );
	}

}


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

public class x {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Scanner scanner = new Scanner(System.in);

        String bNumfNum = scanner.nextLine();
        String bNum = bNumfNum.split(" ")[0];
        int fNum = Integer.parseInt(bNumfNum.split(" ")[1]);

        String b = scanner.nextLine();

        Map<String, Integer> myMap = new HashMap<>();
            for (int i = 0; i < Integer.parseInt(bNum); i++)
            {
                String c = Character.toString(b.charAt(i));
                if (myMap.containsKey(c))
                {
                    myMap.put(c, myMap.get(c) + 1);
                }
                else
                {
                    myMap.put(c, 1);
                }
            }
            boolean flag = true;
            for (Map.Entry<String, Integer> entry : myMap.entrySet())
            {
                if (entry.getValue() > fNum)
                {
                    flag = false;
                }
            }
            if(flag)
            {
               System.out.println("YES");
            }
            else
            {
                System.out.println("NO");
            }
        }
}


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

public class Solution758D {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tokenizer = null;
    //Solution758A Code starts Here
    int totalCases, testnum;

    long n;
    String s;

    boolean input() throws IOException {
        n = nl();
        s = ns().trim();
        return true;
    }

    void solve() throws IOException {
        int log10n = (int) Math.log10(n);
        int l = s.length();
        int a = l-1, b = l;
        long m = 1;
        long ret = 0;
        while(b > 0) {
            while (a > -1 && (b-a-1) <= log10n) {
                String str = s.substring(a, b);
                long acc = Long.parseLong(str);
                if (acc >= n) {
                    break;
                } else {
                    a--;
                }
            }
            a++;
            while(s.charAt(a) == '0' && a < b-1 && a < l-1) a++;
            long acc = Long.parseLong(s.substring(a, b));
            ret += (acc * m);
            m*=n;
            b=a--;
        }
        System.out.println(ret);
    }

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

    void execute() throws IOException {
        totalCases = 1;
        for (testnum = 1; testnum <= totalCases; testnum++) {
            if (!input())
                break;
            solve();
        }
    }

    void debug(Object... os) {
        System.out.println(Arrays.deepToString(os));
    }

    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 ns() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens())
            tokenizer = new StringTokenizer(br.readLine());
        String s = tokenizer.nextToken();
        return s;
    }

    String nline() throws IOException {
        tokenizer = null;
        return br.readLine();
    }
}


//package com.company;
import java.io.*;
public class Main {
    public static void main(String[] args)throws IOException{
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        String[] line = buffer.readLine().split(" ");
        int nodes = Integer.parseInt(line[0]);
        int height = Integer.parseInt(line[1]);
        int n = 36;
        long[][] dynamic = new long[n][n];

        //fill first column with 1s, creates buffer
        for(int i = 0 ; i < n; i++)
            dynamic[0][i] = 1;

        //count all the trees
        for(int i = 1; i < n; i++){
            for(int j = 1; j < n; j++){
                for(int k = 0; k < i ;k++)
                    dynamic[i][j] += dynamic[k][j - 1] * dynamic[i - k - 1][j - 1];
            }
        }
        //the amount of trees to jump
        System.out.println(dynamic[nodes][35] - dynamic[nodes][height - 1]);
    }
}


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

public class TeamsForming {
    public static final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        ArrayList programmingSkill = new ArrayList();
        byte stu = sc.nextByte();
        short problems = 0;
        for (int i = 0; i < stu; i++) {
            programmingSkill.add(sc.nextInt());
        }
        Collections.sort(programmingSkill);
        for (int i = 1; i < stu; i = i + 2) {
            problems += ((int)programmingSkill.get(i) - (int)programmingSkill.get(i-1));
        }
        System.out.println(problems);
    }
}


import java.util.Scanner;

/**
 * Created on 14.06.2016.
 */
public class task2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        long tek;
        String rez = "NO";
        for (long i = 0; i < 812; i++) {
            //tek=i*1234567;
            for (long j = 0; (j < 8102)&&(i*1234567+j*123456<=n); j++) {
                tek=i*1234567+j*123456;
                if ((n-tek)%1234==0){
                    rez="YES";
                    break;
                }
            }
            if(rez.equals("YES")){
                break;
            }
        }
        System.out.println(rez);
    }
}


/**
 * BaZ :D
 */
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main
{
    static MyScanner scan;
    static PrintWriter pw;
    public static void main(String[] args) {
        new Thread(null,null,"BaZ",1<<25)
        {
            public void run()
            {
                try
                {
                    solve();
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                    System.exit(1);
                }
            }
        }.start();
    }
    static void solve() throws IOException
    {
        scan = new MyScanner();
        pw = new PrintWriter(System.out,true);
        StringBuilder sb = new StringBuilder();
        char c[] = ne().toCharArray();
        int n = c.length;
        int ans = 0;
        for(int i=n-1;i>=0;--i) {
            //pl("c[i] : "+c[i]);
            if(i==0) {
                ans+=c[i]-'0';
            }
            else {
                if(c[i]=='9') {
                    ans+=c[i]-'0';
                }
                else {
                    ans+=c[i]-'0';
                    ans+=10;
                    c[i-1]--;
                }
            }
        }
        pl(ans);
        pw.flush();
        pw.close();
    }
    static int ni() throws IOException
    {
        return scan.nextInt();
    }
    static long nl() throws IOException
    {
        return scan.nextLong();
    }
    static double nd() throws IOException
    {
        return scan.nextDouble();
    }
    static String ne() throws IOException
    {
        return scan.next();
    }
    static String nel() throws IOException
    {
        return scan.nextLine();
    }
    static void pl()
    {
        pw.println();
    }
    static void p(Object o)
    {
        pw.print(o+" ");
    }
    static void pl(Object o)
    {
        pw.println(o);
    }
    static void psb(StringBuilder sb)
    {
        pw.print(sb);
    }
    static void pa(String arrayName, Object arr[])
    {
        pl(arrayName+" : ");
        for(Object o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, int arr[])
    {
        pl(arrayName+" : ");
        for(int o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, long arr[])
    {
        pl(arrayName+" : ");
        for(long o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, double arr[])
    {
        pl(arrayName+" : ");
        for(double o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, char arr[])
    {
        pl(arrayName+" : ");
        for(char o : arr)
            p(o);
        pl();
    }
    static void pa(String listName, List list)
    {
        pl(listName+" : ");
        for(Object o : list)
            p(o);
        pl();
    }
    static void pa(String arrayName, Object[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(Object o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, int[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(int o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, long[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(long o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, char[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(char o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, double[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(double o : arr[i])
                p(o);
            pl();
        }
    }
    static class MyScanner
    {
        BufferedReader br;
        StringTokenizer st;
        MyScanner()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String nextLine()throws IOException
        {
            return br.readLine();
        }
        String next() throws IOException
        {
            if(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());
        }
    }
}


import java.util.*;

public class Main {

static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		solve();

	}

	public static void solve() {
		long k = sc.nextLong();
		int[] arr = new int[10];
		Arrays.fill(arr, 1);
		long total = 1;
		int i = 0;
		while(total < k) {
			total = (total * (arr[i] + 1))/arr[i];
			arr[i]++;

			i = (i + 1)%10;
		}

		String print = "codeforces";

		for(int j = 0;j < 10;j++) {
			char p = print.charAt(j);
			for(int l = 0;l < arr[j];l++)System.out.print(p);
		}
		System.out.println();
	}
}


//package codeforces;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class A implements Closeable {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    A() throws IOException {
//        reader = new BufferedReader(new FileReader("input.txt"));
//        writer = new PrintWriter(new FileWriter("output.txt"));
    }

    StringTokenizer stringTokenizer;

    String next() throws IOException {
        while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
            stringTokenizer = new StringTokenizer(reader.readLine());
        }
        return stringTokenizer.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());
    }

    private int MOD = 1000 * 1000 * 1000 + 7;

    int sum(int a, int b) {
        a += b;
        return a >= MOD ? a - MOD : a;
    }

    int product(int a, int b) {
        return (int) (1l * a * b % MOD);
    }

    int pow(int x, int k) {
        int result = 1;
        while (k > 0) {
            if (k % 2 == 1) {
                result = product(result, x);
            }
            x = product(x, x);
            k /= 2;
        }
        return result;
    }

    int inv(int x) {
        return pow(x, MOD - 2);
    }

    void solve() throws IOException {
        class Utils {
            boolean isGood(long x) {
                List<Integer> d = new ArrayList<>();
                for(long y = x; y > 0; y /= 10) {
                    d.add((int)(y % 10));
                }
                return d.get(0) == (int)d.get(d.size() - 1);
            }

            long brute(long ceiling) {
                long answer = 0;
                for(int i = 1; i <= ceiling; i++) {
                    if(isGood(i)) {
                        answer++;
                    }
                }
                return answer;
            }

            long count(long ceiling) {
                if(ceiling <= 1000) {
                    return brute(ceiling);
                }
                long p = 10;
                long answer = 0;
                while(ceiling >= p && p < 1000000l * 1000000 * 1000000) {
                    answer += 9 * Math.max(1, p / 100);
                    p *= 10;
                }
                p /= 10;
                long firstDigit = ceiling / p;
                for(int i = 1; i < firstDigit; i++) {
                    answer += p / 10;
                }
                long x = ceiling % p;
                if(x == 0) {
                    return answer;
                }
                answer += Math.max(0, x / 10);
                long y = firstDigit * p + x / 10 * 10;
                while(y <= ceiling) {
                    if(y % 10 == firstDigit) {
                        answer++;
                    }
                    y++;
                }
                return answer;
            }
        }
        Utils utils = new Utils();
//        for(int i = 1; i <= 1000000; i++) {
//            if(i % 1000 == 0) {
//                System.out.println("i = " + i);
//            }
//            if(utils.count(i) != utils.brute(i)) {
//                writer.println("failed " + i);
//                return;
//            }
//        }
        long l = nextLong();
        long r = nextLong();
        writer.println(utils.count(r) - utils.count(l - 1));
    }

    public static void main(String[] args) throws IOException {
        try (A a = new A()) {
            a.solve();
        }
    }

    @Override
    public void close() throws IOException {
        reader.close();
        writer.close();
    }
}


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

public class Main {
class Node {
    long p;
    int a;
    public Node(long p,int a){
        this.p=p;
        this.a=a;
    }
}
    void solve() {
        long n=nl(); int k=ni();
        ArrayList<Node> vec=new ArrayList<>();
        for(long i=2;i*i<=n;i++){
             if(n%i==0){
                 int cc=0;
                 while(n%i==0){
                     n/=i;
                     cc++;
                 }
                 vec.add(new Node(i,cc));
             }
        }
        if(n>1) vec.add(new Node(n,1));
        long dp[][]=new long[51][k+1];
        long ans=1;
        long suf[]=new long[51];
        long curSuf[]=new long[51];
        long inv[]=new long[52];
        for(int i=0;i<52;i++) inv[i]=modInverse(i);

        for(Node P : vec){
            long p=P.p; int a=P.a;
            for(int i=0;i<=50;i++) Arrays.fill(dp[i],0);

            dp[a][0]=1;
            Arrays.fill(suf,inv[a+1]);

            for(int s=1;s<=k;s++){
                Arrays.fill(curSuf,0);
                for(int i=a;i>=0;i--){
                    dp[i][s]=suf[i];
                    curSuf[i]=mul(dp[i][s],inv[i+1]);
                    if(i+1<=a) curSuf[i]=add(curSuf[i],curSuf[i+1]);
                   // for(int j=i;j<=a;j++) dp[i][s]=add(dp[i][s],mul(dp[j][s-1],inv[j+1]));

                }
                for(int i=0;i<=a;i++) suf[i]=curSuf[i];
            }
            long ex=0;
            for(int i=0;i<=a;i++){
                ex=add(ex,mul(dp[i][k],modpow(p,i)));

            }
           // if(p==2) pw.println(dp[0][k]+" "+dp[1][k]+" "+modInverse(2)+" "+ex+" "+mul(3,modInverse(2)));
            ans=mul(ans,ex);

        }
        pw.println(ans);

    }
    long add(long x,long y){
        x+=y;
        if(x>=M) x-=M;
        return x;
    }
    long sub(long x,long y){
        x-=y;
        if(x<0) x+=M;
        return x;
    }
    long mul(long x,long y){
        x*=y;
        if(x>=M) x%=M;
        return x;
    }
    long modpow(long a, long b)
    {
        long r=1;
        while(b>0)
        {
            if((b&1)>0) r=mul(r,a);
            a=mul(a,a);
            b>>=1;
        }
        return r;
    }

    long modInverse(long A)
    {

        return modpow(A,M-2);
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}


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

public class cf2 {
    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 (Exception e){
                e.printStackTrace();
            }
            return str;
        }
    }
    static int modPower(int x, int y, int mod){
        int res = 1;
        x %= mod;
        if(x==0) return 0;
        while(y>0){
            if(y%2==1){
                res = (res*x)%mod;
            }
            y = y>>1;
            x = (x*x)%mod;
        }
        return res;
    }
    static class pair<T1, T2>{
        T1 first;
        T2 second;
        pair(T1 first, T2 second){
            this.first = first;
            this.second = second;
        }
    }
    static long gcd(long a, long b){
        if(b == 0) return a;
        return gcd(b, a%b);
    }

    static boolean same(int[] a, List<Integer> l){
        if(a.length != l.size()) return false;
        for(int i = 0; i < a.length; i++){
            if(a[i] != l.get(i)) return false;
        }
        return true;
    }

    static long convert(List<Integer> l){
        int j = 0;
        long hash = 0;
        for(int i : l){
            hash += (i*Math.pow(11,j));
            j++;
        }
        return hash;
    }

    public static void main(String[] args) {
        FastReader in = new FastReader();
        int n = in.nextInt();
        int k1 = in.nextInt();
        int[] a = new int[k1], b = new int[n-k1];
        List<Integer> l1 = new ArrayList<>(), l2 = new ArrayList<>();
        for(int i = 0; i < k1; i++){
            a[i] = in.nextInt();
            l1.add(a[i]);
        }
        int k2 = in.nextInt();
        for(int i = 0; i < k2; i++){
            b[i] = in.nextInt();
            l2.add(b[i]);
        }
        int ans = 0;
        boolean cycle = false;
        Set<pair<Long,Long>> s = new HashSet<>();
        Set<List<Integer>> s1 = new HashSet<>(), s2 = new HashSet<>();
        s1.add(l1);
        s2.add(l2);
        while (!l1.isEmpty() && !l2.isEmpty()){
            //System.out.println("Running");
            int card1 = l1.remove(0), card2 = l2.remove(0);
            if(card1 > card2){
                l1.add(card2);
                l1.add(card1);
            } else {
                l2.add(card1);
                l2.add(card2);
            }
            ans++;
            if(l2.isEmpty() || l1.isEmpty()) break;
            cycle = s1.contains(l1) && s2.contains(l2);
            if(cycle) break;
            s1.add(l1);
            s2.add(l2);
        }
        if(cycle){
            System.out.println("-1");
        } else {
            System.out.println(ans + " " + ((l2.isEmpty())?"1":"2"));
        }
    }
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class GenerateAString_Edu16 {
//	static int n, x, y;

	public static void main(String[] args) throws NumberFormatException, IOException {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		x = sc.nextInt();
		y = sc.nextInt();
//		System.out.println(dijkstra(0, n));
		System.out.println(yamosahel());
	}

//	static int INF = 1000000000;

	static long[] dp;
	static long yamosahel()
	{
		dp = new long[n+1];
		for (int i = 1; i < dp.length; i++) {
			dp[i] = dp[i-1]+x;
			if(i%2==0){
				dp[i] = Math.min(dp[i], dp[i/2]+y);
			}
			else
				dp[i] = Math.min(dp[i],Math.min( dp[i/2] + y+x,  dp[(i+1)/2] + y+x));
		}
		return dp[n];
	}
//	static int n;
	static int n,x,y;
	static final long INF = (long)1e18;

	static class Pair implements Comparable<Pair>
	{
		int node;
		long time;
		Pair(int a, long b)
		{
			node = a; time = b;
		}

		public int compareTo(Pair p)
		{
			// time-p.time
			if(p.time!=time) return (time > p.time)? 1:-1;
			return node-p.node;
		}
		public String toString()
		{
			return node + " "+time;
		}
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

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

		Scanner(FileReader r) {
			br = new BufferedReader(r);

		}

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

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


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

import static java.lang.Math.*;

public class Main {
    FastScanner in;
    PrintWriter out;

    static final String FILE = "";

    public static final int MAXN = 3 * 1000 * 100 + 1000;
    //public static final int MAXN = 1000;
    public static final int MOD = (int)1e9 + 7;

    int a, b, k, t;
    int[][] canA;
    int[][] canB;
    int[] realA;
    int[] realB;

    int getA(int turn, int from, int to) {
        int cur;
        if (to < MAXN)
            cur = canA[turn][to];
        else
            cur = canA[turn][MAXN - 1];
        if (from > 0) {
            cur -= canA[turn][from - 1];
            if (cur < 0)
                cur += MOD;
        }
        return cur;
    }

    int getB(int turn, int from, int to) {
        int cur;
        if (to < MAXN)
            cur = canB[turn][to];
        else
            cur = canB[turn][MAXN - 1];
        if (from > 0) {
            cur -= canB[turn][from - 1];
            if (cur < 0)
                cur += MOD;
        }
        return cur;
    }

    void solve() {
        a = in.nextInt();
        b = in.nextInt();
        k = in.nextInt();
        t = in.nextInt();
        canA = new int[2][MAXN];
        canB = new int[2][MAXN];
        realA = new int[MAXN];
        realB = new int[MAXN];

        for (int i = a + MAXN / 2; i < MAXN; i++)
            canA[0][i] = 1;
        for (int turn = 1; turn <= t; turn++) {
            int ind = turn % 2;
            for (int i = 0; i < MAXN; i++) {
                canA[ind][i] = getA(1 - ind, i - k, i + k);
                if (turn == t)
                    realA[i] = canA[ind][i];
                if (i > 0) {
                    canA[ind][i] += canA[ind][i - 1];
                    if (canA[ind][i] >= MOD)
                        canA[ind][i] -= MOD;
                }
            }
        }

        for (int i = b + MAXN / 2; i < MAXN; i++)
            canB[0][i] = 1;
        for (int turn = 1; turn <= t; turn++) {
            int ind = turn % 2;
            for (int i = 0; i < MAXN; i++) {
                canB[ind][i] = getB(1 - ind, i - k, i + k);
                if (turn == t)
                    realB[i] = canB[ind][i];
                if (i > 0) {
                    canB[ind][i] += canB[ind][i - 1];
                    if (canB[ind][i] >= MOD)
                        canB[ind][i] -= MOD;
                }
            }
        }

        for (int i = 1; i < MAXN; i++) {
            realB[i] += realB[i - 1];
            if (realB[i] >= MOD)
                realB[i] -= MOD;
        }

        long ans = 0;
        for (int i = 1; i < MAXN; i++) {
            ans += (long) (realA[i]) * (long) (realB[i - 1]);
            ans %= MOD;
        }

        out.println(ans);
    }

    public void run() {
        if (FILE.equals("")) {
            in = new FastScanner(System.in);
            out = new PrintWriter(System.out);
        } else {
            try {
                in = new FastScanner(new FileInputStream(FILE +
                        ".in"));
                out = new PrintWriter(new FileOutputStream(FILE +
                        ".out"));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
        solve();
        out.close();
    }

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

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

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

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }

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

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

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

        public float nextFloat() {
            return Float.parseFloat(next());
        }
    }

}


import java.util.Scanner;

public class Main {
     // return a^b mod n
    public static int modexp(int a, int b, int n) {
        if (b == 0) return 1;
        long t = modexp(a, b/2, n);  // use long for intermediate computations to eliminate overflow
        long c = (t * t) % n;
        if (b % 2 == 1)
           c = (c * a) % n;
        return (int) c;
    }

    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt();
        if(k > n || k == 1) {
            System.out.println(modexp(m, n, 1000000007));
        } else if(n == 1) {
            System.out.println(m % 1000000007);
        } else if(n == k) {
            //half the length of the word
            int choose = (n+1)/2;
            System.out.println(modexp(m, choose, 1000000007));
        } else if(k % 2 == 0) {
            System.out.println(m % 1000000007);
        } else {
            System.out.println(((m%1000000007)*(m%1000000007)) % 1000000007);
        }

        sc.close();
    }
}


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

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

    static class TaskC {
        static final long MODULO = (long) (1e9 + 7);
        static int[] invs;
        static int[] facts;
        static int[] invfacts;

        static {
            int k = (int) 1e6;
            invs = new int[k + 2];
            invs[1] = 1;
            for (int i = 2; i <= k + 1; ++i) {
                invs[i] = (int) ((MODULO - (MODULO / i) * (long) invs[(int) (MODULO % i)] % MODULO) % MODULO);
            }
            facts = new int[k + 2];
            invfacts = new int[k + 2];
            facts[0] = 1;
            invfacts[0] = 1;
            for (int i = 1; i <= k + 1; ++i) {
                facts[i] = (int) (facts[i - 1] * (long) i % MODULO);
                invfacts[i] = (int) (invfacts[i - 1] * (long) invs[i] % MODULO);
            }
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            long[] res = new long[n + 1];
            long[] prefixSum = new long[n + 1];
            res[1] = 1;
            prefixSum[1] = 1;
            for (int i = 2; i <= n; ++i) {
                res[i] = prefixSum[i - 1] - prefixSum[Math.max(1, i - k) - 1];
                if (res[i] < 0) res[i] += MODULO;
                res[i] = res[i] * invs[i - 1] % MODULO;
                prefixSum[i] = (prefixSum[i - 1] + res[i]) % MODULO;
            }
            long sum = 0;
            for (int i = 1; i <= n; ++i) {
                sum = (sum + res[i] * facts[n - 1] % MODULO) % MODULO;
            }
            long ret = ((facts[n] - sum) % MODULO + MODULO) % MODULO;
            out.println(ret);
        }

    }

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

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

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

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

    }
}


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

public class F implements Runnable {
    private MyScanner in;
    private PrintWriter out;

    private boolean[] prime;
    private final int MAX = 1000000;

    private void sieve() {
        Arrays.fill(prime, true);
        prime[0] = prime[1] = false;
        for (int i = 2; i * i < MAX; ++i) {
            if (prime[i]) {
                for (int j = i * i; j < MAX; j += i) {
                    prime[j] = false;
                }
            }
        }
    }

    private int rev(int n) {
        int ans = 0;
        while (n != 0) {
            ans = 10 * ans + n % 10;
            n /= 10;
        }
        return ans;
    }

    private void solve() {
        prime = new boolean[MAX];
        sieve();
        int n = in.nextInt();
        for (int i = 0; ; ++i) {
            int rev = rev(i);
            if (rev == i) {
                continue;
            }
            if (prime[i] && prime[rev(i)]) {
                --n;
                if (n == 0) {
                    out.println(i);
                    return;
                }
            }
        }
    }

    @Override
    public void run() {
        in = new MyScanner();
        out = new PrintWriter(System.out);
        solve();
        in.close();
        out.close();
    }

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

    static class MyScanner {
        private BufferedReader br;
        private StringTokenizer st;

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

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

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

        public String nextLine() {
            try {
                st = null;
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }

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

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

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

        public boolean hasNext() {
            if (st != null && st.hasMoreTokens()) {
                return true;
            }
            try {
                while (br.ready()) {
                    st = new StringTokenizer(br.readLine());
                    if (st != null && st.hasMoreTokens()) {
                        return true;
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return false;
        }
    }
}


import java.util.HashSet;
import java.util.Scanner;

public class Nafis {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int sz = str.length();
        HashSet<Character> freq = new HashSet<>();
        for (int i = 0; i <= sz / 2; i++) {
            if (str.charAt(i) == str.charAt(sz - i - 1)) {
                freq.add(str.charAt(i));
                continue;
            } else {
                System.out.println(sz);
                return;
            }
        }

        System.out.println(freq.size() == 1 ? 0 : sz - 1);

    }
}


/**
 * Created by ankeet on 12/30/16.
 */
import java.io.*;
import java.util.*;

public class D750 {

    static FastReader in = null;
    static PrintWriter out = null;

    public static void solve()
    {
        int n = in.nextInt();
        int[] t = new int[n+1];
        for(int i=1; i<=n; i++) t[i] = in.nextInt();

        TreeSet<Pair> total = new TreeSet<Pair>();

        TreeSet<Firework> curr = new TreeSet<Firework>();
        curr.add(new Firework(new Pair(0,0), 0, 1));

        for(int i=1; i<=n; i++){
            TreeSet<Firework> next = new TreeSet<Firework>();
            while(!curr.isEmpty()){
                Firework f = curr.pollFirst();

                for(int j=1; j<=t[i]; j++){
                    f.p.x += f.nx;
                    f.p.y += f.ny;
                    total.add(new Pair(f.p.x, f.p.y));
                }

                if(f.nx == 0){
                    next.add(new Firework(new Pair(f.p.x, f.p.y), 1, f.ny));
                    next.add(new Firework(new Pair(f.p.x, f.p.y), -1, f.ny));
                }
                else if(f.ny == 0){
                    next.add(new Firework(new Pair(f.p.x, f.p.y), f.nx, 1));
                    next.add(new Firework(new Pair(f.p.x, f.p.y), f.nx, -1));
                }
                else{
                    next.add(new Firework(new Pair(f.p.x, f.p.y), f.nx, 0));
                    next.add(new Firework(new Pair(f.p.x, f.p.y), 0, f.ny));
                }

            }
            curr = next;
        }

        out.println(total.size());

    }
    static class Firework implements Comparable<Firework>{
        int nx;
        int ny;
        Pair p;
        public Firework(Pair pp, int xx, int yy ){
            this.p = pp;
            nx = xx;
            ny = yy;
        }
        public int compareTo(Firework f){
            int c = p.compareTo(f.p);
            if(c!=0)return c;
            if(nx != f.nx) return nx - f.nx;
            return ny-f.ny;
        }
    }
    static class Pair implements Comparable<Pair>{
        int x;
        int y;
        public Pair(int f, int s){
            x = f;
            y = s;
        }

        public int compareTo(Pair p){
            if(this.x != p.x) return this.x - p.x;
            return this.y - p.y;
        }
    }

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

    }

    static class FastReader {

        BufferedReader read;
        StringTokenizer tokenizer;

        public FastReader(InputStream in)
        {
            read = new BufferedReader(new InputStreamReader(in));
        }

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

            try
            {
                return read.readLine();
            }
            catch(Exception e)
            {
                throw new RuntimeException(e);
            }
        }
        public int nextInt()
        {
            return Integer.parseInt(next());
        }
        public long nextLong()
        {
            return Long.parseLong(next());
        }
        public double nextDouble()
        {
            return Double.parseDouble(next());
        }

        public int[] nextIntArr(int n)
        {
            int[] a = new int[n];
            for(int i=0; i<n; ++i)
            {
                a[i] = nextInt();
            }
            return a;
        }

        public long[] nextLongArr(int n)
        {
            long[] a = new long[n];
            for(int i=0; i<n; ++i)
            {
                a[i] = nextLong();
            }
            return a;
        }
    }

}


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

public class A {

	static Scanner sc = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	static void exit() {
		sc.close();
		out.close();
	}

	public A () {
		long l1 = sc.nextLong();
		long r1 = sc.nextLong();
		long l2 = sc.nextLong();
		long r2 = sc.nextLong();
		long k = sc.nextLong();
		if (r1 < l2 || r2 < l1) {
			out.println(0);
			return;
		}
		long left = Math.max(l1, l2);
		long right = Math.min(r1, r2);
		if (k >= left && k <= right) out.println(right-left);
		else out.println(right-left+1);
	}

	public static void main(String[] args) {
		new A();
		exit();
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class Main {
    static class Assert {
        static void check(boolean e) {
            if (!e) {
                throw new Error();
            }
        }
    }

    class Scanner {

        StreamTokenizer in;

        Scanner(InputStream is) {
            in = new StreamTokenizer(new InputStreamReader(is));
            in.resetSyntax();
            in.whitespaceChars(0, 32);
            in.wordChars(33, 255);
        }

        String next() {
            try {
                in.nextToken();
                Assert.check(in.ttype == in.TT_WORD);
                return in.sval;
            } catch (IOException e) {
                throw new Error(e);
            }
        }

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

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

    Scanner in;
    PrintWriter out;

    void run() {
        in = new Scanner(System.in);
        out = new PrintWriter(System.out);
        try {
            solve();
        } finally {
            out.close();
        }
    }

    void solve() {
        int q = in.nextInt();
        int r = in.nextInt();
        int m = in.nextInt();
        int a[] = new int[100001];
        a[0] = in.nextInt();
        int buf[] = new int[100001];
        buf[a[0]] = 1;
        int i = 1;
        while (true) {
            a[i] = (q * a[i - 1] + r) % m;
            buf[a[i]]++;
            if (buf[a[i]] == 2) {
                for (int j = 0; j < i; ++j) {
                    if (a[j] == a[i]) {
                        out.println(i - j);
                        return;
                    }
                }
            }
            i++;
        }
    }
}


import java.util.Scanner;

public class JavaApplication1 {
    public static void main(String[] args) {

        Scanner input =new Scanner(System.in);
        String str=input.nextLine();
        char c=str.charAt(0);
        char b='d';
        boolean bool=false;
        boolean bool2=true;
        if(str.length()==1)
        {
            if(isVowel(c) || c=='n' )
                System.out.println("YES");
            else
                System.out.println("NO");
        }
        else{
        c=str.charAt(str.length()-1);
         if(!(isVowel(c) || c=='n'))
            {
                System.out.println("NO");
                bool2=false;
            }
        for (int i = 0; i<str.length()-1 && bool2; i++) {

            c=str.charAt(i);
            b=str.charAt(i+1);

            if(!(isVowel(c)) || c=='n')
            {
               if(isVowel(b) || (c=='n' && !isVowel(b)))
                   bool=true;
               else
               {
                   System.out.println("NO");
                   b='f';
                   break;
               }
            }
           else
            {
                    bool=true;
            }
        }
        }

   if(b!='f' && str.length()>1 && bool2)
            System.out.println("YES");

    }
     static boolean isVowel(char c) {
       return "aeiou".indexOf(c) != -1;
}

}


import java.util.Scanner;

public class Vitya {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] t = new int[n];
		for (int i=0;i<n;i++) {
		t[i]=scanner.nextInt();
		}
		if (n==1) {if(t[0]==15) {System.out.println("DOWN");}else if(t[0]==0) {System.out.println("UP");}else{System.out.println(-1);} }
		else { if((t[n-2]<t[n-1]&& t[n-1]!=15)||t[n-1]==0) {System.out.println("UP");}
		else{System.out.println("DOWN");}
		}

	}

}


import java.util.*;
public class issam{
    static class consecutive{
        long mod;
        long[][] matrix;
        long nbWays(long n,int m,long mod){
            this.mod = mod;
            if(n<(long)m) return 1;
            if(n==(long)m) return 2;
            if(m==1) return nbPow(2,n);
            matrix = new long[m][m];
            for(int i=1;i<m;i++) matrix[i][i-1] = 1;
            matrix[0][0] = 1;
            matrix[0][m-1] = 1;
            matrix = pow(matrix,n-(long)m+1);
            long ans = 0;
            for(int i=0;i<m;i++){
                ans += matrix[0][i];
                ans %= mod;
            }
            return ans;
        }

        long nbPow(long a,long n){
            if(n==1) return a;
            if(n%2==0){
                long ans = nbPow(a,n/2);
                return (ans*ans)%mod;
            }
            return (a*nbPow(a,n-1))%mod;
        }

        long[][] pow(long matrix[][], long m) {
            if (m == 1)
                return matrix;
            if (m % 2 == 0) {
                long mat[][] = pow(matrix, m / 2);
                return multiply(mat, mat);
            }
            return multiply(matrix, pow(matrix, m - 1));
        }

        long[][] multiply(long matrix1[][], long matrix2[][]) {
            long ans[][] = new long[matrix1.length][matrix2[0].length];
            for (int i = 0; i < matrix1.length; i++) {
                for (int j = 0; j < matrix2[0].length; j++) {
                    for (int k = 0; k < matrix1[0].length; k++) {
                        ans[i][j] += (matrix1[i][k] * matrix2[k][j]) % mod;
                        ans[i][j] = ans[i][j] % mod;
                    }
                }
            }
            return ans;
        }

    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        int m = sc.nextInt();
        consecutive c = new consecutive();
        long mod = 1000;
        mod = mod*mod*mod+7;
        long res = c.nbWays(n,m,mod);
        System.out.println(res);
    }
}