import java.io.*;
import java.util.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collector;
import java.util.stream.Collectors;

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

        File file = new File("in.txt");
        InputStream inputStream = null;
//        try {inputStream= new FileInputStream(file);} catch (FileNotFoundException ex){return;};
        inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }
}

class TaskB {

     private Map<Integer,Boolean> cache;
     public void solve(int testNumber, InputReader in, PrintWriter out) {
         Integer n = in.nextInt();
         for (int a = 0; a <= n; a += 1234567) {
             for (int b = 0; a + b <= n; b += 123456) {
                 if (n >= (a+b) && ((n - a - b) % 1234) == 0) {
                     out.println("YES");
                     return;
                 }
             }
         }
         out.println("NO");
         return;
     }

}

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 String nextLine(){
        try {
            return reader.readLine();
        } catch (IOException e){
            throw new RuntimeException(e);
        }
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() { return Long.parseLong(next()); }

}

class Pair<F, S> {
    public final F first;
    public final S second;

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

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Pair)) {
            return false;
        }
        Pair<?, ?> p = (Pair<?, ?>) o;
        return Objects.equals(p.first, first) && Objects.equals(p.second, second);
    }

    @Override
    public int hashCode() {
        return (first == null ? 0 : first.hashCode()) ^ (second == null ? 0 : second.hashCode());
    }

    @Override
    public String toString() {
        return "(" + first + ", " + second + ')';
    }
}


import java.util.Scanner;

public class A {

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

        StringBuffer c = new StringBuffer(s.nextLine());
        StringBuffer d = new StringBuffer(s.nextLine());

        int j = 0;
        for(int i = 0 ; i < d.length() ; i++){

            if(c.charAt(j) == d.charAt(i)){

                j++;
            }
        }

        System.out.println(j+1);

    }
}


import java.io.*;
import java.util.*;
public class Stringcheck
{
    public static void main(String[] args)throws IOException
    {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n=Integer.parseInt(st.nextToken());
		int k=Integer.parseInt(st.nextToken());
		int c=0;
		System.out.print(k*((int)Math.ceil(n/k)+1));
    }
}


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

public class Solution
{
	static final int MOD = 1000000007;

	public static void main(String[] args) throws Exception
	{
		Scanner sc = new Scanner(System.in);
		int i , j;
		int T = 1;//sc.nextInt();
		outer : for(int tc = 1; tc <= T; tc++)
		{
			int A[][] = new int[6][2];
			for(i = 0; i < 6; i++)
			{
				A[i][0] = sc.nextInt();
				A[i][1] = sc.nextInt();
			}
			System.out.println(solve(A) ? "YES" : "NO");
		}
		sc.close();
    }

	static boolean solve(int A[][])
	{
		long a = area(A[0][0] , A[1][0] , A[0][1] , A[1][1]);

		int x1 = Math.max(A[0][0] , A[2][0]);
		int y1 = Math.max(A[0][1] , A[2][1]);

		int x2 = Math.min(A[1][0] , A[3][0]);
		int y2 = Math.min(A[1][1] , A[3][1]);

		long a1 = area(x1 , x2 , y1 , y2);
		if(x1 > x2 || y1 > y2)
			a1 = 0;

		int x3 = Math.max(A[0][0] , A[4][0]);
		int y3 = Math.max(A[0][1] , A[4][1]);

		int x4 = Math.min(A[1][0] , A[5][0]);
		int y4 = Math.min(A[1][1] , A[5][1]);

		long a2 = area(x3 , x4 , y3 , y4);
		if(x3 > x4 || y3 > y4)
			a2 = 0;

		x1 = Math.max(x1 , x3);
		y1 = Math.max(y1 , y3);

		x2 = Math.min(x2 , x4);
		y2 = Math.min(y2 , y4);

		long a3 = area(x1 , x2 , y1 , y2);
		if(x1 > x2 || y1 > y2)
			a3 = 0;

		if(a > a1 + a2 - a3)
			return true;
		return false;
	}

	static long area(int x1 , int x2 , int y1 , int y2)
	{
		return (1L * Math.abs(x1-x2) * Math.abs(y1-y2));
	}
}


import java.io.*;    //PrintWriter
import java.math.*;  //BigInteger, BigDecimal
import java.util.*;  //StringTokenizer, ArrayList

public class R287_Div2_C
{
	FastReader in;
	PrintWriter out;

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

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

	void solve()
	{
		int h = in.nextInt();
		long n = in.nextLong();

		long tot = 0;
		long max = 1L << h;
		int cnt = 0;
		while (max >= 1)
		{
			if (cnt % 2 == 0)
			{
				if (n > max / 2)
					tot += max;
				else {tot++; cnt++;}
			}
			else
			{
				if (n <= max / 2)
					tot += (max);
				else {tot++; cnt++;}
			}
			max /= 2;
			if (n > max) n -= max;
		}

		out.println(tot - 1);
	}

	//-----------------------------------------------------
	void runWithFiles() {
		in = new FastReader(new File("input.txt"));
		try {
			out = new PrintWriter(new File("output.txt"));
		}
		catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		solve();
		out.close();
	}

	class FastReader
	{
	    BufferedReader br;
	    StringTokenizer tokenizer;

	    public FastReader(InputStream stream)
	    {
	        br = new BufferedReader(new InputStreamReader(stream));
	        tokenizer = null;
	    }
		public FastReader(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
				tokenizer = null;
			}
			catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

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

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


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.StringTokenizer;
import java.util.Scanner;
import java.io.BufferedReader;
import java.util.stream.Collectors;
import java.io.InputStreamReader;
import java.util.ArrayList;
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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ProblemAABlendOfSpringtime solver = new ProblemAABlendOfSpringtime();
        solver.solve(1, in, out);
        out.close();
    }

    static class ProblemAABlendOfSpringtime {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();

            if (s.length() < 3) {
                out.println("No");
                return;
            }

            for (int i = 0; i + 2 < s.length(); i++) {
            /*String subString = s.substring(i, i + 3);
            char[] charArray = subString.toCharArray();
            Arrays.sort(charArray);
            String sortedSubString = String.valueOf(charArray);*/
                String sortedSubString = String.join("", s.substring(i, i + 3)
                        .chars()
                        .sorted()
                        .mapToObj(c -> String.valueOf((char) c))
                        .collect(Collectors.toCollection(ArrayList::new)));
                if ("ABC".equals(sortedSubString)) {
                    out.println("Yes");
                    return;
                }
            }

            out.println("No");
        }

    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

    }
}


import java.util.Scanner;
public class a {

	  public static  void main(String [] args){

	  Scanner sc=new Scanner(System.in);
		  int x=sc.nextInt();
	int a=0;
		 while(x>0){
			a+=x%2;
			x/=2;
		 }
		 System.out.println(a);
}
}


//package que_a;

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

public class utkarsh {

    InputStream is;
    PrintWriter out;

    long mod = (long) (1e9 + 7), inf = (long) (3e18);

    void solve() {  // n = (i *(p-1) + j)
        int a = ni(), b = ni(), p = ni();
        long x = nl();  mod = p;
        long inva = mp(a, p-2);
        long y = b;
        long ans = 0;
        for(int j = 1; j < p; j++) {
            y = y * inva % mod;
            long i = (j - y + p) % p;
            long n = i * (p-1) + j;
            if(n <= x) {
                ans += (x - n) / (p * (p - 1L)) + 1;
            }
        }
        out.println(ans);
    }

    long mp(long b, long e) {
        long r = 1;
        while(e > 0) {
            if((e&1) == 1)  r = (r * b) % mod;
            b = (b * b) % mod;
            e >>= 1;
        }
        return r;
    }

    //---------- I/O Template ----------

    public static void main(String[] args) { new utkarsh().run(); }
    void run() {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    byte input[] = new byte[1024];
    int len = 0, ptr = 0;

    int readByte() {
        if(ptr >= len) { ptr = 0;
            try { len = is.read(input); }
            catch(IOException e) { throw new InputMismatchException(); }
            if(len <= 0) { return -1; }
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() {
        int b = readByte();
        while(b != -1 && isSpaceChar(b)) { b = readByte(); }
        return b;
    }

    char nc() { return (char)skip(); }
    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    String nLine() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    int ni() {
        int n = 0, b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        if(b == -1) { return -1; }  //no input
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }
    long nl() {
        long n = 0L;    int b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) {
        int a[] = new int[n];
        for(int i = 0; i < n; i++) { a[i] = ni(); }
        return a;
    }
    char[] ns(int n) {
        char c[] = new char[n];
        int i, b = skip();
        for(i = 0; i < n; i++) {
            if(isSpaceChar(b)) { break; }
            c[i] = (char)b; b = readByte();
        } return i == n ? c : Arrays.copyOf(c,i);
    }
}


import java.util.Scanner;

/**
 *
 * @author Raed
 */
public class EboneyAndIvory {

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

        Scanner input = new Scanner(System.in);

        int a = input.nextInt();
        int b = input.nextInt();
        int c = input.nextInt();

        if(b<a){

            int temp = a;
            a=b;
            b=temp;
        }

        boolean found=false;

        if(c%a==0 || c%b==0){

            found=true;
            System.out.println("YES");
        }

        if(!found){
        int n = (int)Math.floor((double)c/a);

        int a2=a;
        for( int i=0;i<n;i++){

            int mid = c-a2;
            if(mid%b ==0){

                System.out.println("YES");
                found=true;
                break;
            }
            a2=a*(i+1);
        }}

        if(!found){

             int m = (int)Math.floor((double)c/b);
             int b2=b;
             for( int i=0;i<m;i++){

            int mid = c-b2;
            if(mid%a ==0){

                System.out.println("YES");
                found=true;
                break;
            }
            b2=b*(i+1);
        }

        }
        if(!found){
         System.out.println("NO");
        }

    }

}


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

import static java.lang.Math.*;

public class Main 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 Main(),"Main",1<<26).start();
    }
    long checkIntersection(long l1, long r1, long l2, long r2) {
        if(l2 > r1 || l1 > r2)
            return 0;
        return min(r1, r2) - max(l1, l2) + 1L;
    }
    long gcd(long a, long b) {
        if(b == 0)
            return a;

        return gcd(b, a % b);
    }
    public void run() {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        long la = sc.nextLong();
        long ra = sc.nextLong();
        long ta = sc.nextLong();

        long lb = sc.nextLong();
        long rb = sc.nextLong();
        long tb = sc.nextLong();

        if(lb > la) {
            long tempL = la;
            long tempR = ra;
            long tempT = ta;

            la = lb;
            ra = rb;
            ta = tb;

            lb = tempL;
            rb = tempR;
            tb = tempT;
        }

        long ans = 0;
        if(la == lb) {
            ans = min(ra, rb) - la + 1L;
        }
        else if((la - lb) % gcd(ta, tb) == 0) {
            ans = min(ra - la + 1L, rb - lb + 1L);
        }
        else {
            long step1 = ((la - lb) / gcd(ta, tb)) * gcd(ta, tb);
            long lb1 = lb + step1;
            long rb1 = rb + step1;

            ans = max(ans, checkIntersection(lb1, rb1, la, ra));

            long step2 = step1 + gcd(ta, tb);
            long lb2 = lb + step2;
            long rb2 = rb + step2;

            ans = max(ans, checkIntersection(lb2, rb2, la, ra));
        }

        w.print(ans);

        w.close();
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

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

    static class CGarland {
        int[] arr;
        int n;
        long[][][][] dp;

        long findIT(int index, int odd, int even, int parity) {
            if (odd < 0) return Integer.MAX_VALUE / 2;
            if (even < 0) return Integer.MAX_VALUE / 2;
            if (index == n) return 0;

            if (dp[index][odd][even][parity] != -1) return dp[index][odd][even][parity];
            if (arr[index] != 0) {
                int pp = (arr[index] % 2) == parity ? 0 : 1;
                return dp[index][odd][even][parity] = pp + findIT(index + 1, odd, even, arr[index] % 2);
            } else {
                long ans = Integer.MAX_VALUE / 2;
                {
                    int pp = (0) == parity ? 0 : 1;
                    ans = Math.min(ans, pp + findIT(index + 1, odd, even - 1, 0));
                }
                {
                    int pp = (1) == parity ? 0 : 1;
                    ans = Math.min(ans, pp + findIT(index + 1, odd - 1, even, 1));
                }
                return dp[index][odd][even][parity] = ans;
            }

        }

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            n = in.scanInt();
            arr = new int[n];
            in.scanInt(arr);
            boolean done[] = new boolean[n + 1];
            HashSet<Integer> remaining = new HashSet<>();

            for (int i = 0; i < n; i++) if (arr[i] != 0) done[arr[i]] = true;
            for (int i = 1; i <= n; i++) if (!done[i]) remaining.add(i);

            {
                dp = new long[n + 5][n + 5][n + 5][2];
                for (int i = 0; i < n + 5; i++) {
                    for (int j = 0; j < n + 5; j++) {
                        for (int k = 0; k < n + 5; k++) {
                            dp[i][j][k][0] = dp[i][j][k][1] = -1;
                        }
                    }
                }
            }

            int even = 0;
            int odd = 0;
            for (int e : remaining) {
                if (e % 2 == 0) even++;
                else odd++;
            }

            long ans;
            if (arr[0] == 0) {
                ans = Math.min(findIT(1, odd, even - 1, 0), findIT(1, odd - 1, even, 1));
            } else {
                ans = findIT(1, odd, even, arr[0] % 2);
            }

            out.println(ans);
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

        public void scanInt(int[] A) {
            for (int i = 0; i < A.length; i++) A[i] = scanInt();
        }

    }
}


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

import java.math.*;
public class Solution{
	public static void main(String[] args) {
	      TaskA solver = new TaskA();
	      initFac(1000001);

//	      int t = in.nextInt();
//	      for (int i = 1; i <= t ; i++) {
//	          solver.solve(i, in, out);
//	      }
//
	      solver.solve(1, in, out);

	      out.flush();
	    out.close();
	  }
	static ArrayList<Integer>[] graph ;static int[]child;static long k; static int m;
	 static class TaskA {
	      public void solve(int testNumber, InputReader in, PrintWriter out) {
	    	  k= in.nextLong();
	    	 long pow=fpow(2,k,Long.MAX_VALUE)-2;
	    	 long num=fpow(4L,pow,mod)%mod;
	    	 num*=6L;
	    	 num%=mod;
	    	 println(num);
	      }
	 }
	 static int min(int x,int y) {
		 return Math.min(x, y);
	 }

	 static int max(int x,int y) {
		 return Math.max(x, y);
	 }

	 static long min(long x,long y) {
		 return Math.min(x, y);
	 }
	 static long max(long x,long y) {
		 return Math.max(x, y);
	 }
	 static int abs(int x,int y) {
		 return Math.abs(x-y);
	 }
	 static long abs(long x,long y) {
		 return Math.abs(x-y);
	 }
	 static void Eularianbfs(int v,int[]cur,int k,ArrayList<Integer>path) {
		  while (cur[v] < k) {
		    int u = cur[v]++;
		    Eularianbfs(u,cur,k,path);
		    path.add(u);
		  }
	}

	 static long fpow(long b, long x, long mod) {
	        if (x == 0) return 1;
	        if (x == 1) return b;
	        if (x % 2 == 0) return fpow(b * b % mod, x / 2, mod) % mod;

	        return b * fpow(b * b % mod, x / 2, mod) % mod;
	    }
	 static long[] fac;
	 static long mod = 1_000_000_007;
	 static void initFac(long n) {
	        fac = new long[(int)n + 1];
	        fac[0] = 1;
	        for (int i = 1; i <= n; i++) {
	            fac[i] = (fac[i - 1]  * i) % mod;
	        }
	    }
	 static int count(char []arr,char x) {
		 int c=0;
		 for(int i=0;i<arr.length;i++) {
			 if(arr[i]==x) {
				 c++;
			 }
		 }
		 return c;
	 }
	 static int count(int []arr,int x) {
		 int c=0;
		 for(int i=0;i<arr.length;i++) {
			 if(arr[i]==x) {
				 c++;
			 }
		 }
		 return c;
	 }
	  static boolean[]seive(int n){
			boolean[]b=new boolean[n+1];
			 for (int i = 2; i <= n; i++)
		            b[i] = true;

			for(int i=2;i*i<=n;i++) {
				if(b[i]) {
					for(int j=i*i;j<=n;j+=i) {
						b[j]=false;
					}
				}
			}
			return b;
		}
	 static int[] query(int l,int r) {
			System.out.println("? "+l+" "+r);
			System.out.print ("\n");System.out.flush();
			int[]arr=new int[r-l+1];
			for(int i=0;i<r-l+1;i++) {
				arr[i]=in.nextInt();
			}
			return arr;
		}

	 static long[]presum(long[]arr){
		 int n= arr.length;
		 long[]pre=new long[n];
		 for(int i=0;i<n;i++) {
			 if(i>0) {
				 pre[i]=pre[i-1];
			 }
			 pre[i]+=arr[i];
		 }
		 return pre;
	 }
	 static int max(int[]arr) {
		 int max=Integer.MIN_VALUE;
		 for(int i=0;i<arr.length;i++) {
			 max=Math.max(max, arr[i]);
		 }
		 return max;
	 }
	 static int min(int[]arr) {
		 int min=Integer.MAX_VALUE;
		 for(int i=0;i<arr.length;i++) {
			 min=Math.min(min, arr[i]);
		 }
		 return min;
	 }
	 static int ceil(int a,int b) {
		 int ans=a/b;if(a%b!=0) {
			 ans++;
		 }
		 return ans;
	 }

	static long sum(int[]arr) {
		long s=0;
		for(int x:arr) {
			s+=x;
		}
		return s;
	}
	static long sum(long[]arr) {
		long s=0;
		for(long x:arr) {
			s+=x;
		}
		return s;
	}
	 static int gcd(int a, int b)
	    {
	      if (b == 0)
	        return a;
	      return gcd(b, a % b);
	    }
	 static void sort(int[] a) {
	        ArrayList<Integer> q = new ArrayList<>();
	        for (int i : a) q.add(i);
	        Collections.sort(q);
	        for (int i = 0; i < a.length; i++) a[i] = q.get(i);
	    }
	 static void sort(long[] a) {
	        ArrayList<Long> q = new ArrayList<>();
	        for (long i : a) q.add(i);
	        Collections.sort(q);
	        for (int i = 0; i < a.length; i++) a[i] = q.get(i);
	    }
	 static void println(int[][]arr) {
		 for(int i=0;i<arr.length;i++) {
			 for(int j=0;j<arr[0].length;j++) {
				 print(arr[i][j]+" ");
			 }
			 print("\n");
		 }
	 }
	 static void println(long[][]arr) {
		 for(int i=0;i<arr.length;i++) {
			 for(int j=0;j<arr[0].length;j++) {
				 print(arr[i][j]+" ");
			 }
			 print("\n");
		 }
	 }
	 static void println(int[]arr){
		 for(int i=0;i<arr.length;i++) {
			 print(arr[i]+" ");
		 }
		 print("\n");
	 }
	 static void println(long[]arr){
		 for(int i=0;i<arr.length;i++) {
			 print(arr[i]+" ");
		 }
		 print("\n");
	 }
	 static void println(char x) {
		 out.println(x);
	 }
	  static long[]input(long n){
		  long[]arr=new long[(int)n];
		  for(int i=0;i<n;i++) {
			  arr[i]=in.nextInt();
		  }
		  return arr;
	  }
	  static int[]input(int n){
		  int[]arr=new int[n];
		  for(int i=0;i<n;i++) {
			  arr[i]=in.nextInt();
		  }
		  return arr;
	  }
	  static Character Char(int x) {
			 return Character.toString((char)x).charAt(0);
	  }
	  static int[]input(){
		  int n= in.nextInt();
		  int[]arr=new int[(int)n];
		  for(int i=0;i<n;i++) {
			  arr[i]=in.nextInt();
		  }
		  return arr;
	  }
	////////////////////////////////////////////////////////
	  static class Pair implements Comparable<Pair>{
		    int  first;
		    int second;int third;
		    Pair(int x, int y)
		    {
		        this.first = x;
		        this.second = y;

		    }
		    public int compareTo(Pair p) {
		    	return Integer.compare(second, p.second);
		    }
		}
	  static void sortS(Pair arr[])
	    {
	        Arrays.sort(arr, new Comparator<Pair>() {
	            @Override public int compare(Pair p1, Pair p2)
	            {
	            	if(p1.second==p2.second) {return p1.first-p2.first;}
	                return (p1.second - p2.second);

	            }
	        });
	    }
	  static void sortF(Pair arr[])
	    {
	        Arrays.sort(arr, new Comparator<Pair>() {
	            @Override public int compare(Pair p1, Pair p2)
	            {
	            	if(p1.first==p2.first) {return p1.second-p2.second;}
	                return (p1.first - p2.first);
	            }
	        });
	    }

    /////////////////////////////////////////////////////////////
	static InputStream inputStream = System.in;
    static OutputStream outputStream = System.out;
    static InputReader in = new InputReader(inputStream);
    static PrintWriter out = new PrintWriter(outputStream);
    static void println(long c) {
    	out.println(c);
    }
    static void print(long c) {
    	out.print(c);
    }
    static void print(int c) {
		 out.print(c);
	 }
	 static void println(int x) {
		 out.println(x);
	 }
	 static void print(String s) {
		 out.print(s);
	 }
	 static void println(String s) {
		 out.println(s);
	 }
	 static void println(boolean b) {
		 out.println(b);
	 }

  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());
      }
      public long nextLong() {
    	  return Long.parseLong(next());
      }
  }
}


import java.util.Scanner;

public class BusGame {
    public enum Player {
        Ciel {
            @Override
            public Player nextPlayer() {
                return Hanako;
            }
        },
        Hanako {
            @Override
            public Player nextPlayer() {
                return Ciel;
            }
        };

        public abstract Player nextPlayer();
    }

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

        int hundreds = 100 * hundredsCount;
        int tens = 10 * tensCount;

        Player currentPlayer = Player.Ciel;
        Player currentWinner = Player.Hanako;

        boolean isLastTurn = false;

        do {
            int remainingAmount = 220;

            switch (currentPlayer) {
                case Ciel:

                if (hundreds >= 200) {
                    remainingAmount = remainingAmount - 200;
                    hundreds = hundreds - 200;
                } else if (hundreds >= 100) {
                    remainingAmount = remainingAmount - 100;
                    hundreds = hundreds - 100;
                }

                if (tens - remainingAmount >= 0) {
                    tens = tens - remainingAmount;
                    remainingAmount = 0;
                }

                break;

                case Hanako:
                if (tens >= 220) {
                    remainingAmount = 0;
                    tens = tens - 220;
                } else if ( hundreds >= 100 && tens >= 120 ) {
                    hundreds = hundreds - 100;
                    tens = tens - 120;
                    remainingAmount = 0;
                } else if ( hundreds >= 200 && tens >= 20 ) {
                    hundreds = hundreds - 200;
                    tens = tens - 20;
                    remainingAmount = 0;
                }

                break;
            }

            if (remainingAmount == 0) {
                currentWinner = currentPlayer;
                currentPlayer = currentPlayer.nextPlayer();
                remainingAmount = 220;
                isLastTurn = false;
            } else {
                isLastTurn = true;
            }

        } while( !isLastTurn );

        System.out.println(currentWinner.toString());
    }
}


import java.util.*;

public class C {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		Map<String, Integer> X = new HashMap<String, Integer>();
		int ber = -1;
		final int[] points = new int[4];
		final int[] scored = new int[4];
		final int[] let_in = new int[4];
		final int[] count = new int[4];
		final String[] names = new String[4];
		for(int i=0; i<5; i++) {
			String t1 = in.next();
			String t2 = in.next();
			String[] scores = in.next().split(":");

			if(!X.containsKey(t1)) X.put(t1, X.size());
			if(!X.containsKey(t2)) X.put(t2, X.size());
			int x1 = X.get(t1);
			int x2 = X.get(t2);
			names[x1] = t1;
			names[x2] = t2;
			if(t1.equals("BERLAND")) ber = x1;
			if(t2.equals("BERLAND")) ber = x2;
			int s1 = Integer.parseInt(scores[0]);
			int s2 = Integer.parseInt(scores[1]);

			count[x1]++; count[x2]++;
			if(s1 > s2) { points[x1]+=3; }
			else if(s1 == s2) { points[x1]++; points[x2]++; }
			else { points[x2]+=3; }
			scored[x1] += s1; scored[x2]+=s2;
			let_in[x1] += s2; let_in[x2]+=s1;
			//System.out.println(t1+" "+t2+" "+x1+" "+x2+" "+Arrays.toString(points));
		}
		int opp = -1;
		for(int i=0; i<4; i++)
			if(count[i]==2 && i!=ber)
				opp = i;

		boolean ok = false;
		int best_x = 10000;
		int best_y = 0;
		points[ber]+=3;
		for(int x=0; x<100; x++)
			for(int y=0; y<x; y++) {
				final int[] new_scored = new int[5];
				final int[] new_let_in = new int[5];
				for(int i=0; i<4; i++) {
					new_scored[i] = scored[i];
					new_let_in[i] = let_in[i];
				}
				new_scored[ber] += x; new_scored[opp] += y;
				new_let_in[ber] += y; new_let_in[opp] += x;

				Integer[] sort = new Integer[4];
				for(int i=0; i<4; i++) sort[i] = i;
				Arrays.sort(sort, new Comparator<Integer>() {
					public int compare(Integer A, Integer B) {
						if(points[A] > points[B]) return -1;
						if(points[A] < points[B]) return 1;

						int s1 = new_scored[A]-new_let_in[A];
						int s2 = new_scored[B]-new_let_in[B];
						if(s1 > s2) return -1;
						if(s1 < s2) return 1;

						if(new_scored[A] > new_scored[B]) return -1;
						if(new_scored[A] < new_scored[B]) return 1;

						return (names[A].compareTo(names[B]));
					}
				});
				if(ber == sort[0] || ber==sort[1]) { // OK
					ok = true;
					int diff = x-y;
					int best_diff = best_x-best_y;
					if(diff < best_diff || (diff==best_diff && y < best_y)) {
						best_x = x;
						best_y = y;
					}
				}
			}

		if(!ok)
			System.out.println("IMPOSSIBLE");
		else System.out.println(best_x+":"+best_y);

		/*
		int more = 0;
		for(int i=0; i<5; i++)
			if(i != ber && points[i]>points[ber])
				more++;
		if(more >= 2) { System.out.println("IMPOSSIBLE"); return; }

		List<Integer> diff = new ArrayList<Integer>();
		int ix = 0;
		for(int i=0; i<5; i++)
			if(points[i]==points[ber] && i!=ber)
				diff.add(scored[i]-let_in[i]);
		Collections.sort(diff);

		int need = more==1 ? diff.get(diff.size()-1) : diff.get(diff.size()-2);
		int diff_needed = need - (scored[ber]-let_in[ber]);

		if(more == 0 && diff.get(
		*/
	}
}


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

public class Main {
    static PrintWriter pw;
    static Scanner sc;
    static int[] dp;
    static ArrayList<Integer>[] adj;
    static boolean[] visit;
    static int[] arr;
    static long ceildiv(long x, long y) { return (x + y - 1) / y; }
    static int mod(long x, int m) { return (int) ((x % m + m) % m); }
    public static long gcd(long x, long y) {return y == 0 ? x : gcd(y, x % y);}
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        pw = new PrintWriter(System.out);
        long n=sc.nextLong(), b=sc.nextLong();
        HashMap<Long, Integer> prime=new HashMap<Long, Integer>();
        for(int i=2; i<=b/i; i++){
            if(b%i==0){
                int pow=0;
                while(b%i==0){
                    pow++;
                    b/=i;
                }
                prime.put(i*1l, pow);
            }
        }
        if(b!=1)
            prime.put(b, 1);
        HashMap<Long, Long> ans=new HashMap<Long, Long>();
        for(Map.Entry<Long, Integer> ent: prime.entrySet())
            ans.put(ent.getKey(), num(n, ent.getKey())/ent.getValue());
        long res=Long.MAX_VALUE;
        for(long x: ans.values())
            res=Math.min(x, res);
        pw.println(res);
        pw.close();
    }
    static long num(long n, long b){
        long ans=0;
        long temp=b;
        while(temp<=n){
            ans+=n/temp;
            if(((long)2e18)/temp>b)
                temp*=b;
            else
                break;
        }
        return ans;
    }
    static void printArr(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(long[] arr) {
        for (int i = 0; i < arr.length - 1; i++)
            pw.print(arr[i] + " ");
        pw.println(arr[arr.length - 1]);
    }
    static void printArr(Integer[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i] + " ");
        pw.println();
    }
    static void printArr(char[] arr) {
        for (int i = 0; i < arr.length; i++)
            pw.print(arr[i]);
        pw.println();
    }
    static void printArr(ArrayList list) {
        for (int i = 0; i < list.size(); i++)
            pw.print(list.get(i) + " ");
        pw.println();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

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

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

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

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

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

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

        public int[] nextArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }
        public Integer[] nextsort(int n) throws IOException{
            Integer[] arr=new Integer[n];
            for(int i=0; i<n; i++)
                arr[i]=nextInt();
            return arr;
        }
        public Pair nextPair() throws IOException{
            return new Pair(nextInt(), nextInt());
        }
        public Pair[] nextPairArr(int n) throws IOException{
            Pair[] arr=new Pair[n];
            for(int i=0; i<n; i++)
                arr[i]=new Pair(nextInt(), nextInt());
            return arr;
        }
        public boolean ready() throws IOException {
            return br.ready();
        }
    }
    static class Pair implements Comparable<Pair>{
        long x;
        long y;
        public Pair(long x, long y) {
            this.x=x;
            this.y=y;
        }
        public int hashCode() {
            return (int)(this.x*1000+this.y);
        }
        public int compareTo(Pair p){
            return (int)(this.x-p.x);
        }
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (this.getClass() != obj.getClass()) {
                return false;
            }
            Pair p = (Pair) obj;
            return this.x==p.x && this.y==p.y;
        }
        public boolean equal(Pair p){
            if(this.x==p.x)
                return this.y==p.y;
            if(this.x==p.y)
                return this.y==p.x;
            else
                return false;
        }
        public Pair clone(){
            return new Pair(x, y);
        }
        public String toString(){
            return this.x+" "+this.y;
        }
        public void add(Pair p){
            x+=p.x;
            y+=p.y;
        }
        public Pair multiply(int x){
            return new Pair(x*this.x, x*this.y);
        }
    }
}


import java.util.*;

public class WordCorrection {
    public static void main(String [] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        StringBuilder word = new StringBuilder(input.next());

        for(int i = 0; i < word.length(); i++) {
            if(isVowel(word.charAt(i)) && i != word.length() - 1 && isVowel(word.charAt(i + 1))) {
                word.deleteCharAt(i + 1);
                i = -1;
            }
        }

        System.out.println(word);
    }

    public static boolean isVowel(char character) {
        return "aeiouy".contains(String.valueOf(character));
    }
}


import java.util.Scanner;

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

/**
 *
 * @author mohammad
 */
public class nnn {
    public static void main(String[] args) {
        Scanner s1=new Scanner(System.in);
        String num1=s1.next();
        String num2=s1.next();
        String x="";
        for(int i=0;i<num1.length();i++){
          if(num1.charAt(i)=='0'&&num2.charAt(i)=='0'){
          x=x+num1.charAt(i);
          }
          else {
              if (num1.charAt(i)=='1'&&num2.charAt(i)=='0'){
               x=x+"1";
              }
              else{
                  if(num1.charAt(i)=='0'&&num2.charAt(i)=='1'){
                            x=x+"1";
                  }
                  else {
                      if(num1.charAt(i)=='1'&&num2.charAt(i)=='1'){
                          x=x+"0";
                      }
                  }
              }
          }
        }
        System.out.println(x);
    }
}


//package com.company;

import java.util.Scanner;

public class BB {

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int min = Integer.MAX_VALUE;
        long max = Integer.MIN_VALUE;
        long p = in.nextLong();
        long y = in.nextLong();

        for(long i = y; i>p; i--){
            boolean ok = true;
            for(long j = 2; j*j<=y && j<=p && ok; j++){
                if(i%j == 0){
                    ok = false;
                }
            }
            if(ok){
                System.out.println(i);
                return;
            }
        }

        //else{
            System.out.println(-1);

    }
}


import java.util.*;
public class x
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        String s = sc.next();
        int i=0,temp=0,cnt=0;
        char ch[] = s.toCharArray();

        if(s.length()==n)
        {

        for(i=0;i<s.length()-1;i++)
        {
            if(ch[i]==ch[i+1])
            {
                cnt++;
            }
        }
        System.out.println(cnt);
        }
    }
}


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

public class aaaaaaaa {
	public void run() throws Exception {
		FastReader file = new FastReader();
			long x = file.nextLong();
			int len = ("" + x).length();
			if (len == 1) System.out.println(x);
			else {
				String w = "" + x;
				long prod = dig(x);
				for (int i= 0; i < w.length(); i++) {
					if (w.charAt(i) == '0') continue;
					w = w.substring(0, i) + (Integer.parseInt(w.substring(i,i+1))-1);
					for (int j = i + 1; j < ("" + x).length(); j++) w += "9";
					long temp = Long.parseLong(w);
					prod = Math.max(prod, dig(temp));
					w = "" + x;
				}
				System.out.println(prod);
			}
	}

	long dig(long x) {
		long pr = 1l;
		while (x > 0) {
			pr *= x % 10;
			x /= 10;
		}
		return pr;
	}

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

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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


import java.util.Scanner;

public class A {

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

		String[][] mat=new String[3][3];
		for(int i=0;i<3;i++){
			String s=in.nextLine();
			for(int j=0;j<3;j++){
				mat[i][j]=s.substring(j,j+1);
			}

		}
		in.close();

		if(!mat[1][0].contains(mat[1][2])){
			System.out.println("NO");
			return;
			}
		for(int i=0;i<3;i++){
			if(!mat[0][i].contains(mat[2][2-i])){
				System.out.println("NO");
				return;
				}
		}
		System.out.println("YES");
	}

}


import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
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;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        long n = in.nextInt();
        long m = in.nextInt();
        long k = in.nextInt();
        if(n+m-2<k) out.print(-1);
        else{
            k++;
            out.print(Math.max(get_area(n,m,k),get_area(m,n,k)));
        }
    }
    public long get_area(long n,long m,long k){
        if(k<=n){
            return (n/k)*m;
        }
        else{
            k--;
            k-=(n-1);
            k++;
            return m/k;
        }
    }
}


import java.io.PrintStream;
import java.util.Scanner;

public class B {

	private static final Scanner in = new Scanner(System.in);
	private static final PrintStream out = System.out;

	public static void main(String[] args) {
		int n = in.nextInt();
		long ans = 1;
		int last = -1;
		for (int i = 0; i < n; ++i) {
			int a = in.nextInt();
			if (a == 1) {
				if (last != -1)
					ans *= i - last;
				last = i;
			}
		}
		if (last == -1)
			ans = 0;
		out.println(ans);
	}

}


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

public class Main{
  /*
  .
  .
  .
  .
  .
  .
  .
  some constants
  .
  */
  static int max=Integer.MIN_VALUE;
  static int a[][];
  static void permutations(int s,int num[]){
    if(s==num.length){
      int sum=0;
      for(int i=0;i<4;i++){
        for(int j=i;j<4;j+=2){
          sum+=a[num[j]][num[j+1]]+a[num[j+1]][num[j]];
        }
      }
      max=Math.max(sum,max);
    //  return;
    }
    for(int i=s;i<num.length;i++){
      swap(num,s,i);
      permutations(s+1,num);
      swap(num,s,i);
    }
  }
  static void swap(int num[],int s,int i){
    int temp=num[s];
    num[s]=num[i];
    num[i]=temp;
  }
  /*
  .
  .
  .
  if any
  .
  .
  */
  public static void main(String[] args) throws IOException{
		/*
		.
		.
		.
		.
		.
		.
    */
    a=new int[5][5];
    for(int i=0;i<5;i++){
      for(int j=0;j<5;j++){
        a[i][j]=ni();
      }
    }
    int arr[]={0,1,2,3,4};
    permutations(0,arr);
    sop(max);
    /*

		.
		.
		.
		.
		.
		.
		.
		*/
	}
	/*
	temporary functions
	.
	.
	*/
	/*
	fuctions
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	abcdefghijklmnopqrstuvwxyz
	.
	.
	.
	.
	.
	.
	*/
	static int modulo(int j,int m){
		if(j<0)
			return m+j;
		  if(j>=m)
			return j-m;

			return j;
	}
	static final int mod=1000000007;
	static final double eps=1e-8;
	static final long inf=100000000000000000L;
	static final boolean debug=true;
	static Reader in=new Reader();
	static StringBuilder ans=new StringBuilder();
	static long powm(long a,long b,long m){
		long an=1;
		long c=a;
		while(b>0){
			if(b%2==1)
				an=(an*c)%m;
			c=(c*c)%m;
			b>>=1;
		}
		return an;
	}
	static Random rn=new Random();
	static void sop(Object a){System.out.println(a);}
	static int ni(){return in.nextInt();}
	static int[] nia(int n){int a[]=new int[n];for(int i=0;i<n;i++)a[i]=ni();return a;}
	static long nl(){return in.nextLong();}
	static long[] nla(int n){long a[]=new long[n];for(int i=0; i<n; i++)a[i]=nl();return a;}
	static String ns(){return in.next();}
	static String[] nsa(int n){String a[]=new String[n];for(int i=0; i<n; i++)a[i]=ns();return a;}
	static double nd(){return in.nextDouble();}
	static double[] nda(int n){double a[]=new double[n];for(int i=0;i<n;i++)a[i]=nd();return a;}
	static class Reader{
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public Reader(){
			reader=new BufferedReader(new InputStreamReader(System.in),32768);
			tokenizer=null;
		}
		public String next(){
			while(tokenizer==null || !tokenizer.hasMoreTokens()){
				try{
					tokenizer=new StringTokenizer(reader.readLine());
				}
				catch(IOException e){
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt(){
			return Integer.parseInt(next());
		}
		public long nextLong(){
			return Long.parseLong(next());
		}
		public double nextDouble(){
			return Double.parseDouble(next());
		}
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;
import static java.lang.Integer.parseInt;

public class Test{

	static int gcd(int a,int b)
	{
		int dividend=Math.max(a, b);
		int divisor=Math.min(a, b);
		while(divisor!=0)
		{
			int remainder=dividend%divisor;
			dividend=divisor;
			divisor=remainder;
		}
		return dividend;
	}
	static int gcdByRecursion(int a,int b)
	{
		if(b==0)
			return a;
		return gcd(b,a%b);
	}

	public static void main(String  aa[])throws IOException
	{
		Scan s=new Scan();
		String s1=s.scanString();
		String s2=s.scanString();
		if(s1.equals(s2))
			System.out.println(s1);
		else
			System.out.println(1);

	}
}

class Scan
	{
	   // BufferedReader br;
	    StringTokenizer st;
	   BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	    String scanString() throws IOException
	    {
	        while(st==null||!st.hasMoreTokens())
	        {
	            st=new StringTokenizer(br.readLine());
	        }
	        return st.nextToken();
	    }
	    int scanInt() throws IOException
	    {
	        return parseInt(scanString());
	    }

	}


/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
import java.util.*;
public class Main
{
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int n= sc.nextInt();
	    int sq=0,diff=0,ex=0,rem=0;
	    int mark=0,mark1=0,ans=0;
	    if(n==1)
	    ans=4;
	    else if(n==2)
	    ans=6;
	    else if(n==3)
	    ans=8;
	    else if(n>=4)
	    {
    	    sq =(int)Math.sqrt(n);
    	    diff = n-(sq*sq);
    	    ex=diff/sq;
    	    rem=diff%sq;

    	    if(ex>0)
    	    mark=((sq+ex)+sq)*2;
    	    else
    	    mark=(sq+sq)*2;

    	    if(rem>0)
    	    mark1=2;

    	    if(diff==0)
    	    ans=sq*4;
    	    else
    	    {
    	        ans=mark+mark1;
    	    }
	    }
	    System.out.println(ans);

	}
}


import java.util.*;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class A {

	public static void main(String[] args) {
		FastScanner in = new FastScanner();
		int x = in.nextInt();
		int h = in.nextInt();
		int s = in.nextInt();
		int count = 0;
		while(String.valueOf(h).contains("7") == false && String.valueOf(s).contains("7") == false) {
			s -= x;
			while(s < 0) {
				s+= 60;
				h--;
				if(h == -1) h = 23;
			}
			count++;

		}
		System.out.println(count);

	}

	static class FastScanner{
		BufferedReader br;
		StringTokenizer st;
		public FastScanner(String s) {
			try{
				br = new BufferedReader(new FileReader(s));
			}
			catch(FileNotFoundException e) {
				e.printStackTrace();
			}
		}
		public FastScanner(){
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

	}
}


//package codeforces;
import java.util.Scanner;
public class CodeForces {

    public static void main(String[] args) {
        int n,_4,_7,l=0,r=0;
        Scanner in=new Scanner(System.in);
        n= in.nextInt();
        String s=in.next();
        boolean ans=true;
        for(int i=0;i<n/2;++i){
            if (s.charAt(i)!='7' && s.charAt(i)!='4') ans=false;
            else l+= (int)(s.charAt(i)-'0');
        }
        for(int i=n/2;i<n;++i){
            if (s.charAt(i)!='7' && s.charAt(i)!='4') ans=false;
            else r+= (int)(s.charAt(i)-'0');
        }
        if (l!=r) ans=false;
        System.out.println(ans?"YES":"NO");
    }

}


import java.io.*;
import java.util.*;
import java.util.regex.Matcher;

public class Main {
    FastScanner in;
    PrintWriter out;

    public void solve() {
        long n = in.nextLong();
        long ans = 1;
        for(long i = 2; i <= Math.sqrt(n); i++) {
            if(n % i == 0) {
                ans *= i;
                while(n % i == 0)
                    n /= i;
            }
        }
        if(n != 1)
            ans *= n;
        out.print(ans);
    }

    public void run() {
        try {
            //in = new FastScanner(new File(".in"));
            //out = new PrintWriter(new File(".out"));
            in = new FastScanner(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));

            solve();

            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

        FastScanner(InputStreamReader rd) {
            br = new BufferedReader(rd);
        }

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

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

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

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

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


import java.util.*;
import java.lang.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		    List<Character> l = new ArrayList<>();
		    String s = sc.next();
		    if(s.charAt(0)>52&&s.charAt(0)<57){
		        char c = (char)(57 - (int)s.charAt(0) + 48);
		        System.out.print(c);
		    }
		    else System.out.print(s.charAt(0));;
		    for(int i=1;i<s.length();i++){
		        if(s.charAt(i)>52){
		        char c = (char)(57 - (int)s.charAt(i) + 48);
		        System.out.print(c);
		    }
		    else System.out.print(s.charAt(i));
		    }
		    System.out.println();

	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

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

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
        /*int[] ans = new int[30];
        for (int i = 1; i < 30; ++i) {
            ans[i] = getDp((1 << i) - 1);
        }*/

            int[] ans = new int[]{0, 1, 2, 1, 4, 3, 2, 1, 5, 6, 2, 1, 8, 7, 5, 9, 8, 7, 3, 4, 7, 4, 2, 1, 10, 9, 3, 6, 11, 12};

        /*for (int i = 0; i < 30; ++i)
            System.err.print(ans[i] + ", ");*/

            int n = in.nextInt(), sq = 1;
            while ((sq + 1) * (sq + 1) <= n) sq++;

            boolean[] power = new boolean[sq + 1];
            int[] count = new int[30];
            int bcnt = 0;

            for (int i = 2; i <= sq; ++i) {
                if (power[i]) continue;
                int k = 0, r = 1;
                while ((long) r * i <= n) {
                    r *= i;
                    k++;
                    if (r <= sq) {
                        power[r] = true;
                    } else {
                        bcnt++;
                    }
                }
                count[k]++;
            }

            int sum = 0;
            for (int i = 1; i < 30; ++i) {
                if (count[i] % 2 == 1) {
                    sum ^= ans[i];
                }
            }
            sum ^= (n - sq - bcnt + 1) % 2;

            out.println(sum == 0 ? "Petya" : "Vasya");
        }

    }

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

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

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

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

        public String next() {
            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;
        }

    }
}


//Written by Shagoto
import java.util.*;
public class Main
{
  public static void main(String[]args)
  {
    Scanner read = new Scanner(System.in);

    long n = read.nextLong();
    long m = read.nextLong();

    if(n == m)
    {
      System.out.println(0+" "+0);
    }
    else if(m == 1)
    {
      System.out.println(n*(n-1) / 2+" "+n*(n-1) / 2);
    }
    else
    {
      long temp = n - (m - 1);
      long ans2 = temp*(temp-1) / 2;

      long diff = n - (n / m * m);
      long temp1 = diff * ((n / m + 1)*(n / m) / 2);
      long temp2 = (m - diff) * (n / m * (n / m -1) / 2);
      long ans1 = temp1 + temp2;

      System.out.println(ans1+" "+ans2);
    }
  }
}


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

public  class PalinInd{
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br=new BufferedReader(new InputStreamReader(System.in));
        }
        String next(){
            while(st==null || !st.hasMoreTokens()){
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (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().trim();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    static class FastWriter {
		private final BufferedWriter bw;

		public FastWriter() {
			this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
		}

		public void print(Object object) throws IOException {
			bw.append("" + object);
		}

		public void println(Object object) throws IOException {
			print(object);
			bw.append("\n");
		}

		public void close() throws IOException {
			bw.close();
		}
	}
    public static void main(String[] args) {
        try {
            FastReader in=new FastReader();
            FastWriter out = new FastWriter();
            int testCases=in.nextInt();
            for(int z=0;z<testCases;z++)
            {

                       int mat[][]=new int[2][2];
                     for(int i=0;i<2;i++)
                   {
                        for(int j=0;j<2;j++)
                        {
                            mat[i][j]=in.nextInt();
                        }
                   }
                   int c=0;
                   for(int i=0;i<2;i++)
                   {
                    for(int j=0;j<2;j++)
                    {
                         if(mat[i][j]==1)
                         {
                            c++;
                         }
                    }

                   }
                   if(c==0)
                   {
                    System.out.println("0");
                   }
                   else if(c==1||c==2||c==3)
                   {
                         System.out.println("1");
                   }

                   else{
                     System.out.println("2");
                   }

                    }
                }
                catch (Exception e) {
            return;
        }
            }
        }


import java.util.Scanner;
public class buyashovel {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int k = scan.nextInt();
		int r = scan.nextInt();
		boolean bol = true;
		for (int i = 1 ; i <=10 && bol ; i++) {
			if ((i*k)%10==0) {
				System.out.println(i);
				bol=false;
			}
			else if (((i*k)-r)%10==0) {
				System.out.println(i);
				bol=false;
			}
		}
	}
}


import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class A {
    String filename = "";
    final int INF = 1_000_000_000;

    void solve() {
        int n = readInt();
        int[] a = new int[n];
        for(int i = 0;i<n;i++){
            a[i] = readInt();
        }

        int d = a[1] - a[0];
        int now = a[1];
        for(int i = 1;i<n;i++){
            if(a[i] != now){
                out.print(a[n - 1]);
                return;
            }
            now += d;
        }
        out.print(a[n - 1] + d);
    }
    public static void main(String[] args) throws FileNotFoundException {
        new A().run();
    }
    void run() throws FileNotFoundException {
        init();
        solve();
        out.close();
    }
    BufferedReader in;
    PrintWriter out;

    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        if(!filename.equals("")) {
            in = new BufferedReader(new FileReader(new File(filename + ".in")));
            out = new PrintWriter(new File(filename + ".out"));
            return;
        }

        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }

    String readLine(){
        try{
            return in.readLine();
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    String readString(){
        while(!tok.hasMoreTokens()){
            String nextLine = readLine();
            if(nextLine == null) return null;
            tok = new StringTokenizer(nextLine);
        }
        return tok.nextToken();
    }

    int readInt(){
        return Integer.parseInt(readString());
    }
}


import java.util.Scanner;

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

		System.out.println((s.nextLong()/s.nextLong()%2==0)?"NO":"YES");

	}
}


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

public class A1 {
    public void solve() throws IOException {
        long r = nextLong();
        ArrayList<Long> div = new ArrayList<>();
        long rc = r;
        long i;
        if (r == 1) {
            out.print("NO");
            return;
        }
        for (i = 1; i * i < rc; i++) {
            if (rc % i == 0) {
                div.add(i);
                //div.add(-i);
                div.add(rc / i);
                //div.add(-rc / i);
                //rc /= i;
            }
        }
        if (i * i == rc) {
            div.add(i);
            div.add(-i);
        }
        Collections.sort(div);
        boolean isGood = false;
        long y = 0;
        long x = 0;
        for (int k = 0; k < div.size(); k++) {
            x = div.get(k);
            if ((r - x * x - x - 1) % (2 * x) == 0) {
                y = (r - x * x - x - 1) / (2 * x);
                if (y > 0) {
                    isGood = true;
                    break;
                }
            }
        }
        if (isGood) {
            out.print(x + " " + y);
        } else {
            out.print("NO");
        }
    }

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

            solve();

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

    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;

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

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

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

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

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

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


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class Sorter {

    public Sorter() {}

    int reader(){

        BufferedReader br = null;
        int answ = 0;
        try {
            String[] temp;
            br = new BufferedReader(new InputStreamReader(System.in));

            String[] total = br.readLine().split(" ");
            int rows = Integer.parseInt(total[0]);
            int cols = Integer.parseInt(total[1]);
            int aliveRows = rows;

            boolean[][] mat = new boolean[rows][cols];
            for(int i=0; i < rows; i++) {
                boolean straw = false;
                String currRow = br.readLine();
                for(int j =0; j < cols; j++) {
                    if(currRow.charAt(j)=='S') {
                        straw = true;
                        mat[i][j] = true;
                    }
                    else
                        mat[i][j] = false;
                }
                if(!straw){
                    aliveRows--;
                    answ+= cols;}

            }

            for(int i=0; i < cols; i++) {
                boolean straw = false;
                for(int j =0; j < rows; j++) {
                    if(mat[j][i]) {
                        straw = true;
                        break;
                    }
                }
                if(!straw) {
                    answ+= aliveRows;
                }
            }

        }
        catch (Exception e) {
            e.printStackTrace();

        }
        return answ;

    }

    public static void main(String args[]){

        Sorter s = new Sorter();
        System.out.print(s.reader());

    }

}


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

public class Main {

    final long b = 31;
    String fileName = "";

    //////////////////////    SOLUTION   SOLUTION  SOLUTION    //////////////////////////////
    int INF = 1000_000_000 +100;
    long MODULO = 1000_000_000 + 7;
    int MAX_VALUE = 1000_1000;
    int[][] steps = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
    private final static Random rnd = new Random();
    double eps = 1e-7;

    class Point implements Comparable<Point>{
        long x, y;
        Point(long x, long y){
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(Point o) {
            return Long.compare(this.x, o.x);
        }
    }
    void solve() throws IOException {
        long a = readLong();
        long b = readLong();
        int pa = 0;
        int pb = 0;
        Point[] pointsA = new Point[1000*10000];
        Point[] pointsB = new Point[1000*10000];
        for (long i=1; i*i <= a; ++i){
            if (a%i==0){
                pointsA[pa] = new Point(i, a/i);
                pa++;
            }
        }

        for (long i=1; i*i <= b; ++i){
            if (b%i==0){
                pointsB[pb] = new Point(i, b/i);
                pb++;
            }
        }
        int maxA = pa;
        int maxB = pb;
        long s = a + b;
        long ans = Long.MAX_VALUE;
        pa = 0;
        pb = 0;
        TreeSet<Long> stA = new TreeSet<>();
        TreeSet<Long> stB = new TreeSet<>();

        for (long i=1; i*i <=s; ++i){
            if (s%i==0){
                while (pa < maxA && pointsA[pa].x <= i){
                    stA.add(pointsA[pa].y);
                    pa++;
                }
                while (pb < maxB && pointsB[pb].x <= i){
                    stB.add(pointsB[pb].y);
                    pb++;
                }
                Long lowerA = stA.floor(s/i);
                Long lowerB = stB.floor(s/i);
                if(lowerA!=null||lowerB!=null){
                    ans = Math.min(ans, (i + s/i)*2);
                }
            }
        }
        out.println(ans);
    }

    class Fenwik {
        int[] t;
        int n;
        Fenwik(int n){
            t = new int[n];
            this.n = n;
        }

        void inc(int r, int delta){
            for (; r < n; r = r | (r + 1)) t[r] += delta;
        }
        int getSum(int r){
            int res = 0;
            for (; r >=0; r = (r & (r + 1) ) - 1) res += t[r];
            return res;
        }
    }
    boolean isPrime(int n){
        for (int i=2; i*i<=n; ++i){
            if (n%i==0) return false;
        }
        return true;
    }
    class Edge implements Comparable<Edge>{
        int from, to, num, dist;
        Edge(int from, int to, int dist, int num){
            this.from = from;
            this.to = to;
            this.num = num;
            this.dist = dist;
        }

        @Override
        public int compareTo(Edge o) {
            return Integer.compare(this.dist, o.dist);
        }
    }
    class Number implements Comparable<Number>{
        int x, cost;
        Number(int x, int cost){
            this.x = x;
            this.cost = cost;
        }

        @Override
        public int compareTo(Number o) {
            return Integer.compare(this.cost, o.cost);
        }
    }

    void readUndirectedGraph (int n, int m, int[][] graph) throws IOException{
        Edge[] edges = new Edge[m];
        int[] countEdges = new int[n];
        for (int i=0; i<m; ++i){
            int from = readInt() - 1;
            int to = readInt() - 1;
            countEdges[from]++;
            countEdges[to]++;
            edges[i] = new Edge(from, to, 0, 0);
        }
        for (int i=0; i<n; ++i) {
            graph[i] = new int[countEdges[i]];
        }
        for (int i=0; i<m; ++i){
            graph[edges[i].from][--countEdges[edges[i].from]] = edges[i].to;
            graph[edges[i].to][-- countEdges[edges[i].to]] = edges[i].from;
        }
    }
    class Vertex implements Comparable<Vertex>{
        int i, j, plus;
        Vertex(int i, int j, int plus){
            this.i = i;
            this.j = j;
            this.plus = plus;
        }

        @Override
        public int compareTo(Vertex o) {
            return Integer.compare(this.plus, o.plus);
        }
    }

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

    class Dsu{
        int[] parent;
        int countSets;
        Dsu(int n){
            parent = new int[n];
            countSets = n;
            for (int i=0; i<n; ++i){
                parent[i] = i;
            }
        }
        int findSet(int a){
            if (a == parent[a]) return a;
            parent[a] = findSet(parent[a]);
            return parent[a];
        }
        void unionSets(int a, int b){
            a = findSet(a);
            b = findSet(b);
            if (a != b){
                parent[a] = b;
                countSets--;
            }
        }
    }

    class SparseTable{
        int[][] rmq;
        int[] logTable;
        int n;
        SparseTable(int[] a){
            n = a.length;
            logTable = new int[n+1];
            for(int i = 2; i <= n; ++i){
                logTable[i] = logTable[i >> 1] + 1;
            }
            rmq = new int[logTable[n] + 1][n];
            for(int i=0; i<n; ++i){
                rmq[0][i] = a[i];
            }

            for(int k=1; (1 << k) < n; ++k){
                for(int i=0; i + (1 << k) <= n; ++i){
                    int max1 = rmq[k - 1][i];
                    int max2 = rmq[k-1][i + (1 << (k-1))];
                    rmq[k][i] = Math.max(max1, max2);
                }
            }
        }

        int max(int l, int r){
            int k = logTable[r - l];
            int max1 = rmq[k][l];
            int max2 = rmq[k][r - (1 << k) + 1];
            return Math.max(max1, max2);
        }
    }
    long checkBit(long mask, int bit){
        return (mask >> bit) & 1;
    }

    static int checkBit(int mask, int bit) {
        return (mask >> bit) & 1;
    }
    boolean isLower(char c){
        return c >= 'a' && c <= 'z';
    }

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

    int gcd(int a, int b){
        return b == 0 ? a : gcd(b, a%b);
    }
    long gcd(long a, long b){
        return b == 0 ? a : gcd(b, a%b);
    }
    double binPow(double a, int pow){
        if (pow == 0) return 1;
        if (pow % 2 == 1) {
            return a * binPow(a, pow - 1);
        } else {
            double c = binPow(a, pow / 2);
            return c * c;
        }
    }
    long binPow(long a, long b, long m) {
        if (b == 0) {
            return 1;
        }
        if (b % 2 == 1) {
            return ((a % m) * (binPow(a, b - 1, m) % m)) % m;
        } else {
            long c = binPow(a, b / 2, m);
            return (c * c) % m;
        }

    }
    int minInt(int... values) {
        int min = Integer.MAX_VALUE;
        for (int value : values) min = Math.min(min, value);
        return min;
    }

    int maxInt(int... values) {
        int max = Integer.MIN_VALUE;
        for (int value : values) max = Math.max(max, value);
        return max;
    }
    public static void main(String[] args) throws NumberFormatException, IOException {
        // TODO Auto-generated method stub
        new Main().run();
    }

    void run() throws NumberFormatException, IOException {
        solve();
        out.close();
    };

    BufferedReader in;
    PrintWriter out;

    StringTokenizer tok;
    String delim = " ";

    Main() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            if (fileName.isEmpty()) {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                in = new BufferedReader(new FileReader(fileName + ".in"));
                out = new PrintWriter(fileName + ".out");
            }

        }
        tok = new StringTokenizer("");
    }

    String readLine() throws IOException {
        return in.readLine();
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (null == nextLine) {
                return null;
            }

            tok = new StringTokenizer(nextLine);
        }
        return tok.nextToken();
    }

    int readInt() throws NumberFormatException, IOException {
        return Integer.parseInt(readString());
    }
    byte readByte() throws NumberFormatException, IOException {
        return Byte.parseByte(readString());
    }
    int[] readIntArray (int n) throws NumberFormatException, IOException {
        int[] a = new int[n];
        for(int i=0; i<n; ++i){
            a[i] = readInt();
        }
        return a;
    }

    Integer[] readIntegerArray (int n) throws NumberFormatException, IOException {
        Integer[] a = new Integer[n];
        for(int i=0; i<n; ++i){
            a[i] = readInt();
        }
        return a;
    }

    long readLong() throws NumberFormatException, IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws NumberFormatException, IOException {
        return Double.parseDouble(readString());
    }
}


 import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {

    public static void main(String arg[]) throws IOException
    {

 //   BufferedReader r=new BufferedReader(new FileReader("testcase.txt"));
   BufferedReader r=new BufferedReader(new InputStreamReader(System.in));

StringTokenizer str=new StringTokenizer(r.readLine());

   int n=Integer.parseInt(str.nextToken());
   int m=Integer.parseInt(str.nextToken());
   int x=Integer.parseInt(str.nextToken());
   int y=Integer.parseInt(str.nextToken());
   int a=Integer.parseInt(str.nextToken());
   int b=Integer.parseInt(str.nextToken());

   int gcd=gcd(a,b);
   a=a/gcd;
   b=b/gcd;

   int i=1;
   while(a*i<=n&&b*i<=m)
   {
       i++;

   }
   i=i-1;

   int x1=0,y1=0,x2=a*i,y2=b*i;
   a=x2;
   b=y2;
   x1=(2*x-a)/2;
   y1=(2*y-b)/2;
   x2=x1+a;
   y2=y1+b;

   if(x1+a>n)
   {
       x2=n;
       x1=n-a;
   }
   else if(x1<0)
   { x1=0;
   x2=a;
           }
   if(y1+b>m)
   {
       y2=m;
       y1=m-b;
   }
   else if(y1<0)
   { y1=0;
   y2=b;
           }
   System.out.println(x1+" "+y1+" "+x2+" "+y2);

}
   static public int gcd(int a,int b)
    {
        if(b==0)
            return a;
        else
        return gcd(b,a%b);
    }
    }


import java.util.Scanner;

/**
 *
 * @author izharishaksa
 */
public class C1060B {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        String s = N + "";
        char c = s.charAt(0);
        String temp = "0";
        if (c != '1') {
            temp = "" + (c - '1');
        }
        for (int i = 1; i < s.length(); i++) {
            temp += '9';
        }
        long b = Long.parseLong(temp);
        long a = N - b;
        int res = 0;
        while (a > 0) {
            res += a % 10;
            a /= 10;
        }
        while (b > 0) {
            res += b % 10;
            b /= 10;
        }
        System.out.println(res);
    }

}


import java.util.Scanner;

//Pashmak and Garden codeforces
public class Test1 {

	public static void main(String[] args) {
		Scanner scan = new Scanner (System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int sum=0 , n , x , count=0;
		int [] array = new int [82];
		String num;
		for(int s=1 ; s<82 ; s++){
			x=(int) (b*Math.pow(s,a)+c);
			num = String.valueOf(x);
			n = num.length();
			for(int i=0 ; i<n ; i++){
				sum = sum + Character.getNumericValue(num.charAt(i));
			}
			if (sum==s && x<Math.pow(10, 9)){
				array[count]=x;count++;
			}
			sum = 0 ;
		}
		System.out.println(count);
		for (int i=0 ; i<count ; i++){
			System.out.print(array[i]+" ");
		}

		/*int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int count=0;
		for(int x = 1 ; x<Math.pow(10,9) ; x++){
			String num = String.valueOf(x);
			int sum=0;
			//for(int i = 0 ; i<num.length() ; i++){
				//sum = sum + Character.getNumericValue(num.charAt(i));;
			//}
			sum = getsum(x);
			if (x==b*Math.pow(sum,a)+c){
				System.out.println(x);
				count++;
			}
		}
		if (count!=0){
		System.out.println(count);
		}
		else{
			System.out.println(0);

		}*/

	}
	static int getsum(int n) {
		   return n == 0 ? 0 : n % 10 + getsum(n/10);
		}

}


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

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

    static class TaskA {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int noofbuys = in.nextInt();
            int noosells = in.nextInt();
            int current = in.nextInt();
            //out.print(current);
            int max = Integer.MIN_VALUE;
            int min = Integer.MAX_VALUE;
            for (int i = 0; i < noofbuys; i++) {
                min = Math.min(min, in.nextInt());

            }
            for (int i = 0; i < noosells; i++) {
                max = Math.max(max, in.nextInt());

            }
            //out.print(" this si ");
            // out.print(current);
            if (min > max) {
                out.print(current);
            } else {
                int result = (current / min) * max + (current % min);
                out.print(result);
            }
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

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

    }

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

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

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

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

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

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

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

        }

    }
}


import java.util.*;

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

   public B(Scanner in)
   {
      int n = in.nextInt();
      int m = in.nextInt();

      Box[] bs = new Box[m];
      for (int i=0; i<m; i++)
         bs[i] = new Box(in.nextInt(), in.nextInt());

      Arrays.sort(bs);
      int i = m-1;
      long res = 0;
      while ((n > 0)&&(i >= 0))
      {
         Box cur = bs[i];

         int cnt = Math.min(cur.a, n);
         n -= cnt;
         res += cnt*1L*cur.b;

         i--;
      }

      System.out.printf("%d%n", res);
   }
}

class Box implements Comparable<Box>
{
   int a, b;

   public Box(int i, int j)
   {
      a = i;
      b = j;
   }

   public int compareTo(Box rhs)
   {
      return b - rhs.b;
   }
}


import java.io.*;
import java.util.*;
public class MyClass {
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        int x=sc.nextInt();
        int y=sc.nextInt();
        int a=sc.nextInt();
        int b=sc.nextInt();
        int gcd=f(x,y);
        long lcm=(x*y)/gcd;
        long a1=a/lcm;
        long b1=b/lcm;
        long ans=b1-a1;
        if(a%lcm==0)
          ans+=1;
          System.out.println(ans);
    }
    public static int f(int x,int y)
    {
        if(y==0)
         return x;
         return f(y,x%y);
    }
}


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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input= new Scanner(System.in);
		int a = input.nextInt();
		int b = input.nextInt();
		int c = input.nextInt();
		int d= input.nextInt();
		int m[]= new int[3];
		m[1]=a;
		m[0]=b;
		m[2]=c;
		Arrays.sort(m);
		int d1=m[1]-m[0];
		int d2=m[2]-m[1];
		int answer=0;
		if(d1>=d){
		}else{
			answer+=d-d1;
		}
		if(d2>=d){
		}else{
			answer+=d-d2;
		}
		System.out.println(answer);
	}

}


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

/**
 * @author Mukesh Singh
 *
 */

public class AB {

    private InputStream input;
    private PrintStream output;
    private Scanner inputSc;

    public AB(InputStream input, PrintStream output) {
        this.input = input;
        this.output = output;
        init();
    }

    private void init() {
        inputSc = new Scanner(input);
    }

    static int lineToInt(String line) {
        return Integer.parseInt(line);
    }

    static long lineToLong(String line) {
        return Long.parseLong(line);
    }
    static double lineToDouble(String line) {
        return Double.parseDouble(line);
    }

    public void solve()
	{
            solveTestCase();
    }

/**
 * @define global / instance variables
 */

	HashMap<Integer,Integer> mat[] ;
	long dist[] ;
	long vec[] ;
	int par[] ;
	boolean isDone[] ;
	final long INF = 100000000000000000L ;
	int N;
/**
 * @solve test case
 */
@SuppressWarnings("unchecked")
    private void solveTestCase()
	{
		int i , j  , k , n , m ,a ;
		long N , M, K,I, J;
		DecimalFormat df = new DecimalFormat("#,###,##0.00");
        String str = inputSc.nextLine();
        String delims = "[ ]+";
		String[] tokens = str.split(delims);
		n = lineToInt(tokens[0]);
		m = lineToInt(tokens[1]);
		if ( n < m )
			a = n ;
		else
			a = m ;
		if(a%2 == 0 )
			output.println("Malvika");
		else
			output.println("Akshat");

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
	{
		FileInputStream in = null;
      	FileOutputStream out = null;
		PrintStream ps = null ;
		InputStream is = null ;
		try
		{
         	is = new FileInputStream("file.in");
         	out = new FileOutputStream("file.out");
			ps = new PrintStream(out);
        }
		catch ( Exception e )
		{}

        AB sd = new AB(System.in, System.out);
        sd.solve();
		try
		{
        if (is != null)
		{
	      is.close();
	    }
       	if (out != null) {
           	out.close();
       	}
		if (ps != null) {
           	ps.close();
         }
      	}catch (Exception e){}

		//SquareDetector sd = new SquareDetector(System.in, System.out);
        //sd.solve();
    }
}


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

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

class TaskA {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        int N = in.nextInt();
        int[] changes = {2, 7, 2, 3, 3, 4, 2, 5, 1, 2  };
        out.print(changes[N / 10] * changes[N % 10]);

    }
}


//no full solution
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

//codeforce
public class codeforce {

    private static BufferedReader in;
    private static PrintWriter out;
    private static StringTokenizer input;

    public static void main(String[] args) throws IOException {
        // -------------------------------------------------------------------------
        // Initializing...
        new codeforce();
        // -------------------------------------------------------------------------
        // put your code here... :)

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

        // writeln("");
        // -------------------------------------------------------------------------
        // closing up
        end();
        // --------------------------------------------------------------------------

    }
    private static String nextString() throws IOException {
        if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine());
        return input.nextToken();
    }
    public codeforce() throws IOException {
        // Input Output for Console to be used for trying the test samples of
        // the problem
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        // -------------------------------------------------------------------------
        // Initalize Stringtokenizer input
         input = new StringTokenizer(in.readLine());
    }

    private static int nextInt() throws IOException {
        if (!input.hasMoreTokens())
            input = new StringTokenizer(in.readLine());
        return Integer.parseInt(input.nextToken());
    }

    private static void end() throws IOException {
        in.close();
        out.close();
        System.exit(0);
    }

}