import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class A implements Runnable {

    private void solve() throws IOException {
        int x = nextInt();
        int y = nextInt();

        if (x == 0 && y == 0) {
            pl(0);
            return;
        }
        if (x == 1 && y == 0) {
            pl(0);
            return;
        }

        int curX = -1, curY = 1;
        int prevX = 1, prevY = 1;

        int turns = 1;

        while (true) {
            if (x >= prevX && x <= curY && y >= prevY && y <= curY) break;

            if (prevX > 0 && prevY > 0) {
                curX = -prevX;
                turns++;
            }

            else if (prevX > 0 && prevY < 0) {
                curY = prevX;
                turns++;
            }

            else if (prevX < 0 && prevY > 0) {
                curY = prevX;
                turns++;
            }

            else if (prevX < 0 && prevY < 0) {
                curX = prevX + 1;
                turns++;
            }

            prevX = curX;
            prevY = curY
                    ;

        }
        pl(turns);
    }

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

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

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

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

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

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

    BigInteger nextBigInteger() throws IOException {
        return new BigInteger(nextToken());
    }

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

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

    void pl(Object... objects) {
        p(objects);
        writer.println();
    }

    int cc;

    void pf() {
        writer.printf("Case #%d: ", ++cc);
    }

}


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 T279A {

	public int solve(int x, int y) {
		int[][] axis = new int[100][4];
		int f = 0;
		int size = 1;
		int p = 0;
		int a = 0;
		int b = 0;
		while (Math.abs(a) <= 100 && Math.abs(b) <= 100) {
			if (f == 0) {
				axis[p][0] = a;
				axis[p][1] = b;
				a += size;
				axis[p][2] = a;
				axis[p][3] = b;
				f = 1;
				p ++;
			} else if (f == 1) {
				axis[p][0] = a;
				axis[p][1] = b;
				b += size;
				axis[p][2] = a;
				axis[p][3] = b;
				f = 2;
				p ++;
				size ++;
			} else if (f == 2) {
				axis[p][0] = a;
				axis[p][1] = b;
				a -= size;
				axis[p][2] = a;
				axis[p][3] = b;
				f = 3;
				p ++;
			} else if (f == 3) {
				axis[p][0] = a;
				axis[p][1] = b;
				b -= size;
				axis[p][2] = a;
				axis[p][3] = b;
				f = 0;
				p ++;
				size ++;
			}

			if (x >= Math.min(axis[p - 1][0], axis[p - 1][2]) &&
				x <= Math.max(axis[p - 1][0], axis[p - 1][2]) &&
				y >= Math.min(axis[p - 1][1], axis[p - 1][3]) &&
				y <= Math.max(axis[p - 1][1], axis[p - 1][3]))
				return p - 1;

		}
		return 0;
	}
	public static void main(String[] args) {
		FastScanner in = new FastScanner();
		System.out.println(new T279A().solve(in.nextInt(), in.nextInt()));
	}
	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());
		}

	}
}


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

public class C171 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(new BufferedInputStream(System.in));
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] a = new int[n];
        int[] l = new int[m];
        int[] r = new int[m];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        for (int i = 0; i < m; i++) {
            l[i] = scanner.nextInt() - 1;
            r[i] = scanner.nextInt() - 1;
        }
        if (n == 1) {
            for (int i = 0; i < m; i++) {
                out.println("Yes");
            }
        } else {
            int t = 0;
            boolean up = a[0] <= a[1];
            int[] b = new int[n];
            b[0] = t;
            b[1] = t;
            for (int i = 2; i < n; i++) {
                if ((up && a[i] >= a[i - 1]) || (!up && a[i] <= a[i - 1])) {
                    b[i] = t;
                } else {
                    up = !up;
                    t += up ? 2 : 1;
                    b[i] = t;
                }
            }
            for (int i = 0; i < m; i++) {
                out.println(b[r[i]] - b[l[i]] <= 1 || (b[l[i] + 1] - b[l[i]] == 2 && b[r[i]] - b[l[i] + 1] <= 1) ? "Yes" : "No");
            }
        }
        out.close();
    }
}


//package pointspiral;

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

public class PointSpiral {

    public static int[] makeMas(int[] massiv, int start) {
        massiv[0] = start;
        for (int i = 1; i < massiv.length; i++) {
            massiv[i] = massiv[i - 1] + 4;
        }
        return massiv;
    }

    public static void main(String[] args) {
        int x, y, n = 100, res;
        int[] one = new int[n];
        int[] two = new int[n];
        int[] three = new int[n];
        int[] four = new int[n];

        makeMas(one, 2);
        makeMas(two, 1);
        makeMas(three, 0);
        makeMas(four, 3);

//        one[0] = 2;
//        for (int i = 1; i < n; i++) {
//            one[i] = one[i - 1] + 4;
//        }
//
//        two[0] = 1;
//        for (int i = 1; i < n; i++) {
//            two[i] = two[i - 1] + 4;
//        }
//
//        three[0] = 0;
//        for (int i = 1; i < n; i++) {
//            three[i] = three[i - 1] + 4;
//        }
//
//        four[0] = 3;
//        for (int i = 1; i < n; i++) {
//            four[i] = four[i - 1] + 4;
//        }

        Scanner cin = new Scanner(System.in);
        x = cin.nextInt();
        y = cin.nextInt();

        if (x == 0 && y == 0 || x == 1 && y == 0) {
            System.out.println(0);
            return;
        }

        if (x < y && x >= -y) {
            System.out.println(one[y - 1]);
            return;
        }

        if (x >= y && x > -y) {
            System.out.println(two[x - 1]);
            return;
        }

        if (x <= -y && x > y) {// -7 -13
            System.out.println(three[y * (-1) ]);
            return;
        }

        if (x < -y && x <= y) {
            System.out.println(four[x * (-1) - 1]);
            return;
        }

    }
}


import java.util.Scanner;

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

        long num = scan.nextLong();

        String[] names = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"};

        long round = 1;
        long step = 0;
        int index = -1;
        long curRound = round;
        while( step < num){

            if(curRound > 0 ){
                step++;
                curRound--;
            }
            index = index+1;

            if(index == 5){
                index = 0;
                round *= 2;
            }
        }

        System.out.println(names[index]);

    }
}


/*
 ID: jeromej1
 LANG: JAVA
 PROG: 82A
 */

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

public class EightTwoA
{
	int n;
	ArrayList<String> queue;

	public EightTwoA() throws Exception
	{
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(f.readLine());
		queue = new ArrayList<String>();
		queue.add("Sheldon");
		queue.add("Leonard");
		queue.add("Penny");
		queue.add("Rajesh");
		queue.add("Howard");
	}

	public void compute()
	{
		int x = 1;
		while(x < n)
		{
			String s = queue.get(0);
			queue.remove(0);
			queue.add(s);
			queue.add(s);
			x++;
		}
		System.out.println(queue.get(0));
	}

	public static void main(String [] args) throws Exception
	{
		EightTwoA doubleCola = new EightTwoA();
		doubleCola.compute();
	}
}


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

/**
 * Created by IntelliJ IDEA.
 * User: Jimmy
 * Date: 10/18/11
 * Time: 8:59 PM
 */
public class Problem82A {

    public static void main(String arguments[]) {
        new Problem82A().run();
    }

    private void run() {
        Scanner s = new Scanner(System.in);

        HashMap<Integer, String> map = new HashMap<Integer, String>();
        map.put(1, "Sheldon");
        map.put(2, "Leonard");
        map.put(3, "Penny");
        map.put(4, "Rajesh");
        map.put(5, "Howard");

        int n = s.nextInt();

        long sum = 0;

        int i = 1;
        int twice = 1;
        int temp = twice;
        boolean enter = true;

        //while(sum < n) {
        for(int j = 0; j < n; j++) {
            //System.out.println("-------------------");
            //System.out.println("i = " + i);
            if(i % 5 == 0 && enter) {
                twice *= 2;
                enter = false;
                //temp = twice;
                //i++;
            }
            //System.out.println("twice = " + twice);
            sum += 1;

            if(sum != 1)
                temp--;
            //System.out.println("temp = " + temp);
            if(temp == 0) {
                i++;
                i = i % 5;
                if(i == 0) {
                    i += 5;
                }
                enter = true;
                temp = twice;
            }

            //System.out.println("sum = " + sum);
            //System.out.println("i = " + i);
        }

        System.out.println(map.get(i));
    }
}


import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner entrada = new Scanner(System.in);
		int n = entrada.nextInt();
		int res = n;
		int sal = 0;
		if (n == 1) {
			System.out.println("Sheldon");
		}else {if (n == 2) {
				System.out.println("Leonard");
			}else {if (n == 3) {
					System.out.println("Penny");
					}else {if (n == 4) {
							System.out.println("Rajesh");
							}else{if (n == 5) {
								System.out.println("Howard");
							}}
				}
			}
		for (int i = 5; i != 0 ; i = i*2) {
			if (res > 5) {
				res = res - i;
				sal++;
			}
			if (res < 0) {
				res = res + i;
				i = 0;
			}
		}
		int fin = 0;
		int pot = (int) Math.pow(2, sal-1);
//		for (int i = 1; i != 0; i++) {
//			int poten = (int) Math.pow(5, sal);
//			if (res > poten) {
//				res = res - poten;
//				fin++;
//				if (res <0) {
//					i = 0;
//				}
//			}
//		}
		while (res>0) {
			res = res - pot;
			fin++;
		}
		if (fin == 1) {
			System.out.println("Sheldon");
		}else {
			if (fin == 2) {
				System.out.println("Leonard");
			}else {
				if (fin == 3) {
					System.out.println("Penny");
				}else {
					if (fin == 4) {
						System.out.println("Rajesh");
					}else {
						System.out.println("Howard");
					}
				}
			}
		}
		entrada.close();
	}
	}
}


import java.util.Scanner;

public class BinaryProtocol {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		String st="";
			st=st+s.next();
		String str = "";
		int num = 0;
		for (int i = 0; i < n; i++) {
			int k =(int) st.charAt(i)-48;
			if (k == 1) {
				num++;
			}
			if (k == 0) {
				if (st.charAt(i + 1) == 0) {
					str=str+num+"0";
					num=0;
				} else {
					str = str + num;
					num = 0;
				}
			}
			if(i==n-1){
				str=str+num;
			}
		}
		System.out.println(str);
	}

}


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

public class problemA {

	public static PrintWriter out;

	public static void main(String args[])
	{
		out=new PrintWriter(new BufferedOutputStream(System.out),true);
		MyScanner sc=new MyScanner();
		int N=sc.nextInt();
		String str=sc.next();
		long r=0;
	    String p="";
		for(int i=0;i<N;++i)
		{
			if(str.charAt(i)=='1')
				r++;
			else
			{
				p+=r;
				r=0;
			}

		}
		p+=r;
		System.out.println(p);

	}

	 public static class MyScanner {
	        BufferedReader br;
	        StringTokenizer st;

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

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

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

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

}


//package by.bsu.contest.a;

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

/**
 * Created by Ales on 19.07.17.
 */
public class Runner {

    public static void main(String args[]) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        int numDigits = in.nextInt();
        int numberStr = in.nextInt();
        numberStr = new Integer(new StringBuilder(numberStr).reverse().toString());
        long number = new Long(numberStr);

        long res = 0;
        for(int i = 0; i < numDigits; i++) {
            long value = number % 10;
            if(value != 0) {
                res++;
            } else {
                res *= 10;
            }
            number /= 10;
        }

        out.println(res);
    }

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

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

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

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

    }
}


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

public final class  Solution1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(),count_0=0,count_1=0;
        String s = in.next();
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<n;i++){
            if(s.charAt(i)=='1'){
                count_1++;
                while(count_0>1){
                    sb.append(0+"");
                    count_0--;
                }
                count_0=0;
            }
            else{
                count_0++;
                if(count_1!=0){
                    sb.append(count_1+"");
                }
                count_1=0;
            }
        }
        if(count_0!=0){
            while(count_0>1){
                sb.append(0+"");
            }
        }
        else{
            sb.append(count_1);
        }
        System.out.println(sb.toString());
    }
}


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

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

class TaskA {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int a, n, b;
        a = in.nextInt(); b = in.nextInt(); n = in.nextInt();

        int k = 0;

        // 1st a, next b, so on
        while(n >= 0) {
            ++k;
            n -= euclid_gcd( (k & 1) ? a : b, n);
        }

        if (k & 1) out.println(1);
        else out.println(0);

        return;
    }

    public int euclid_gcd(int a, int b) {
        return b == 0 ? a : euclid_gcd(b, a%b);
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

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

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

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

}


import java.io.BufferedReader;

import java.io.InputStreamReader;
import java.util.ArrayList;

public class a {

    public static void main(String[] args) {

 	String []str = null ;

        InputStreamReader converter = new InputStreamReader(System.in);
        BufferedReader in = new BufferedReader(converter);

           try {
            str = in.readLine().split(" ");
        } catch (Exception ex) {
            System.out.println("Error! "+ex);
        }
        int a = Integer.parseInt(str[0]);
        int b = Integer.parseInt(str[1]);
        int n = Integer.parseInt(str[2]);

      System.out.println(result(a,b,n));

    }

public static int GCD(int a, int b)
{
   if (b==0) return a;
   return GCD(b,a%b);
}
public static int ex= 0;
public static int result(int a, int b,int n)
{
   ex=GCD(a, n);
   if (ex==0) {return 1;}
   else {n -= ex;}
   ex=GCD(b, n);
   if (ex==0) {return 0;}
   else {n -= ex;}
   return result(a,b,n);
}

}


import java.util.*;
public class Epic {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);

		int a = in.nextInt();
		int b = in.nextInt();
		int n = in.nextInt();

		while(n>0){
			n-=divisor(a,n);
			if(n==0)System.out.println("0");
			n-=divisor(b,n);
			if(n==0)System.out.println("1");
		}
	}

	public static int divisor(int q, int c){
		if(q>c)divisor(q-c,c);
		if(c>q)divisor(c-q,q);
		return c;
	}

}


import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        int a = console.nextInt(), b = console.nextInt(), n = console.nextInt();
        boolean turn = true;
        int small;
        while (n > 0) {
          if (turn) {
            small = Math.min(a, n);
            while (Math.max(a, n) % small != 0) {
              small--;
            }
            n -= small;
            a -= small;
            turn = false;
          } else {
            small = Math.min(b, n);
            while (Math.max(b, n) % small != 0) {
              small--;
            }
            n -= small;
            b -= small;
            turn = true;
          }
        }
        if (turn) {
          System.out.println(1);
        } else {
          System.out.println(0);
        }
      }
    }


package codeforces.div2.r279;

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

public class Main {

    public static void main(String args[]) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        SolverD.InputReader in = new SolverD.InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        SolverD solver = new SolverD();
        int testCount = 1;
        for (int i = 1; i <= testCount; i++) {
            solver.solve(in, out);
        }
        out.close();
    }
}

class SolverD {

    public void solve(InputReader in, PrintWriter out) {
        int a1 = in.nextInt();
        int b1 = in.nextInt();
        int a2 = in.nextInt();
        int b2 = in.nextInt();

        int ca12 = fact(a1, 2);
        int ca13 = fact(a1, 3);
        int cb12 = fact(b1, 2);
        int cb13 = fact(b1, 3);

        int a1r = a1 / (pow(2, ca12) * pow(3, ca13));
        int b1r = b1 / (pow(2, cb12) * pow(3, cb13));

        int ca22 = fact(a2, 2);
        int ca23 = fact(a2, 3);
        int cb22 = fact(b2, 2);
        int cb23 = fact(b2, 3);

        int a2r = a2 / (pow(2, ca22) * pow(3, ca23));
        int b2r = b2 / (pow(2, cb22) * pow(3, cb23));

        if (a1r*b1r != a2r*b2r) {
            out.println(-1);
            return;
        }

        int c13 = ca13 + cb13;
        int c23 = ca23 + cb23;

        int sol = 0;
        if (c13 != c23) {
            int d = Math.abs(c13 - c23);
            sol += d;
            if (c13 > c23) {
                if (d <= c13) {
                    ca13 -= d;
                    ca12 += d;
                } else {
                    ca12 += ca13;
                    cb13 -= (d - ca13);
                    cb12 += (d - ca13);
                    ca13 = 0;
                }
            } else {
                if (d <= c23) {
                    ca23 -= d;
                    ca22 += d;
                } else {
                    ca22 += ca23;
                    cb23 -= (d - ca23);
                    cb22 += (d - ca23);
                    ca23 = 0;
                }
            }
        }

        int c12 = ca12 + cb12;
        int c22 = ca22 + cb22;

        int d = Math.abs(c12 - c22);
        sol += d;
        if (c12 > c22) {
            if (d <= c12) {
                ca12 -= d;
            } else {
                ca12 = 0;
                cb12 -= (d - ca12);
            }
        } else {
            if (d <= c22) {
                ca22 -= d;
            } else {
                ca22 = 0;
                cb22 -= (d - ca22);
            }
        }

        a1 = a1r * pow(2, ca12) * pow(3, ca13);
        b1 = b1r * pow(2, cb12) * pow(3, cb13);
        a2 = a2r * pow(2, ca22) * pow(3, ca23);
        b2 = b2r * pow(2, cb22) * pow(3, cb23);

        out.println(sol);
        out.println(a1 + " " + b1);
        out.println(a2 + " " + b2);
    }

    private int pow(final int a, int b) {
        int r = 1;
        while (b>0) {
            r = r*a;
            b--;
        }
        return r;
    }

    private int fact(int num, final int f) {
        int ct = 0;
        while (num % f == 0) {
            ct++;
            num /= f;
        }
        return ct;
    }

    static class InputReader {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

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

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


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

public class d1 {

	static class P{
		long p;
		int deg;

		P(long _p, int _deg){
			p = _p;
			deg = _deg;
		}
	}

	public static void main(String[] args) throws FileNotFoundException {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int a1 = in.nextInt();
		int b1 = in.nextInt();
		int a2 = in.nextInt();
		int b2 = in.nextInt();
		long s1 = 1l * a1 * b1;
		long s2 = 1l * a2 * b2;
		ArrayList<P> p1 = new ArrayList<P>();
		ArrayList<P> p2 = new ArrayList<P>();
		long x = s1;
		for (int i = 2; i * i <= s1; i++) {
			if (x % i == 0){
				P q = new P(i, 0);
				while(x % i == 0){
					x /= i;
					q.deg++;
				}
				p1.add(q);
			}
		}
		if (x > 1){
			p1.add(new P(x, 1));
		}
		x = s2;
		for (int i = 2; i * i <= s2; i++) {
			if (x % i == 0){
				P q = new P(i, 0);
				while(x % i == 0){
					x /= i;
					q.deg++;
				}
				p2.add(q);
			}
		}
		if (x > 1){
			p2.add(new P(x, 1));
		}
		int i1 = 0;
		int i2 = 0;
		boolean flag = true;
		int deg12 = 0;
		int deg13 = 0;
		int deg22 = 0;
		int deg23 = 0;
		if (p1.get(0).p == 2){
			i1++;
			deg12 = p1.get(i1 - 1).deg;
		}
		if (p2.get(0).p == 2){
			i2++;
			deg22 = p2.get(i2 - 1).deg;
		}
		if ((i1 < p1.size()) && (p1.get(i1).p == 3)){
			i1++;
			deg13 = p1.get(i1 - 1).deg;
		}
		if ((i2 < p2.size()) && (p2.get(i2).p == 3)){
			i2++;
			deg23 = p2.get(i2 - 1).deg;
		}
		if (p1.size() - i1 == p2.size() - i2){
			flag = true;
			int count = i2;
			for (int i = i1; i < p1.size(); i++) {
				if (p1.get(i).p != p2.get(count).p || (p1.get(i).deg != p2.get(count).deg)){
					flag = false;
					break;
				}
				count++;
			}
			if (!flag){
				out.print(-1);
			}
			else{
				long ans = 0;
				int d1 = deg12 - deg22;
				int d2 = deg13 - deg23;
				if (d2 > 0){
					while ((a1 % 3 == 0) && (d2 > 0)) {
						a1 /= 3;
						a1 *= 2;
						d2--;
						d1++;
						ans++;
					}
					while ((b1 % 3 == 0) && (d2 > 0)) {
						b1 /= 3;
						b1 *= 2;
						d2--;
						d1++;
						ans++;
					}
				}
				else{
					while ((a2 % 3 == 0) && (d2 < 0)) {
						a2 /= 3;
						a2 *= 2;
						d2++;
						d1--;
						ans++;
					}
					while ((b2 % 3 == 0) && (d2 < 0)) {
						b2 /= 3;
						b2 *= 2;
						d2++;
						d1--;
						ans++;
					}
				}
				if (d1 > 0){
					while ((a1 % 2 == 0) && (d1 > 0)) {
						a1 /= 2;
						d1--;
						ans++;
					}
					while ((b1 % 2 == 0) && (d1 > 0)) {
						b1 /= 2;
						d1--;
						ans++;
					}
				}
				else{
					while ((a2 % 2 == 0) && (d1 < 0)) {
						a2 /= 2;
						d1++;
						ans++;
					}
					while ((b2 % 2 == 0) && (d1 < 0)) {
						b2 /= 2;
						d1++;
						ans++;
					}
				}
				out.println(ans);
				out.println(a1 + " " + b1);
				out.println(a2 + " " + b2);
			}
		}
		else{
			out.print(-1);
		}
		out.close();
	}
}


package thnkndblv;

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

public class TaskD {
    class Pair {
        public int w, h, t;
        public Pair(int w, int h, int t) {
            this.w = w;
            this.h = h;
            this.t = t;
        }
    }

    HashMap<Long, Pair> a = new HashMap<>();
    HashMap<Long, Pair> b = new HashMap<>();

    void run(int w, int h, int t, HashMap<Long, Pair> x) {
        long a = w;
        a = a * h;

        if (!x.containsKey(a) || t < x.get(a).t) x.put(a, new Pair(w, h, t));

        if (w > 1 && w % 2 == 0) run(w/2, h, t+1, x);
        if (w > 1 && w % 3 == 0) run(2*w/3, h, t+1, x);

        if (h > 1 && h % 2 == 0) run(w, h/2, t + 1, x);
        if (h > 1 && h % 3 == 0) run(w, 2*h/3, t + 1, x);
    }

    public void solve(int testNumber, Scanner in, PrintWriter out) {
        int a1 = in.nextInt();
        int b1 = in.nextInt();

        run(a1, b1, 0, a);

        int a2 = in.nextInt();
        int b2 = in.nextInt();

        run(a2, b2, 0, b);

        int ans = (int)1e9;
        long area = 0;
        for (long x : a.keySet()) {
            if ( b.containsKey(x) ) {
                int tt = a.get(x).t + b.get(x).t;
                if ( tt < ans ) {
                    ans = tt;
                    area = x;
                }
            }
        }

        if ( ans == (int)1e9 ) out.println(-1);
        else {
            out.println(ans);
            out.println(a.get(area).w + " " + a.get(area).h);
            out.println(b.get(area).w + " " + b.get(area).h);
        }
    }
}


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

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

class TaskD {
    Map<Long, Pair<Integer, Pair<Integer, Integer>>> save = new HashMap<Long, Pair<Integer, Pair<Integer, Integer>>>();
    Pair<Integer, Integer> answerA = new Pair<Integer, Integer>(-1, -1);
    Pair<Integer, Integer> answerB = new Pair<Integer, Integer>(-1, -1);
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int ax = in.readInt();
        int ay = in.readInt();
        int bx = in.readInt();
        int by = in.readInt();
        dfs(ax, ay, 0);
        int answer = findAnswer(bx, by, 0);
        if (answer >= 0) {
            out.printLine(answer);
            out.printLine(answerA.first, answerA.second);
            out.printLine(answerB.first, answerB.second);
        }
        else
            out.printLine(-1);
    }

    private int findAnswer(int x, int y, int deep) {
        if (save.containsKey(1L * x * y)) {
            answerA = save.get(1L * x * y).second;
            answerB = Pair.makePair(x, y);
            return deep + save.get(1L * x * y).first;
        }
        int answer = Integer.MAX_VALUE / 2;
        int val = -1;
        if (x % 2 == 0) {
            val = findAnswer(x / 2, y, deep + 1);
            if (val >= 0 && answer > val) {
                answer = val;
                answerA = save.get(1L * (x / 2) * y).second;
                answerB = Pair.makePair(x / 2, y);
            }
        }
        if (x % 3 == 0) {
            val = findAnswer((x / 3) * 2, y, deep + 1);
            if (val >= 0 && answer > val) {
                answer = val;
                answerA = save.get(1L * (x / 2) * y).second;
                answerB = Pair.makePair(x / 2, y);
            }
        }
        if (y % 2 == 0) {
            val = findAnswer(x, y / 2, deep + 1);
            if (val >= 0 && answer > val) {
                answer = val;
                answerA = save.get(1L * (x / 2) * y).second;
                answerB = Pair.makePair(x / 2, y);
            }
        }
        if (y % 3 == 0) {
            val = findAnswer(x, (y / 3) * 2, deep + 1);
            if (val >= 0 && answer > val) {
                answer = val;
                answerA = save.get(1L * (x / 2) * y).second;
                answerB = Pair.makePair(x / 2, y);
            }
        }
        return answer >= Integer.MAX_VALUE / 2 ? -1 : answer;
    }

    private void dfs(int x, int y, int deep) {
        if (!save.containsKey(1L * x * y)) {
            save.put(1L * x * y, Pair.makePair(deep, Pair.makePair(x, y)));
        }
        else {
            int val = save.get(1L * x * y).first;
            save.put(1L * x * y, Pair.makePair(Math.min(deep, val), Pair.makePair(x, y)));
        }
        if (x % 2 == 0)
            dfs(x / 2, y, deep + 1);
        if (x % 3 == 0)
            dfs((x / 3) * 2, y, deep + 1);
        if (y % 2 == 0)
            dfs(x, y / 2, deep + 1);
        if (y % 3 == 0)
            dfs(x, (y / 3) * 2, deep + 1);
    }
}

class Pair<U, V> implements Comparable<Pair<U, V>> {

    public final U first;
    public final V second;

    public static<U, V> Pair<U, V> makePair(U first, V second) {
        return new Pair<U, V>(first, second);
    }

    public Pair(U first, V second) {
        this.first = first;
        this.second = second;
    }

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

        Pair pair = (Pair) o;

        return !(first != null ? !first.equals(pair.first) : pair.first != null) && !(second != null ? !second.equals(pair.second) : pair.second != null);

    }

    public int hashCode() {
        int result = first != null ? first.hashCode() : 0;
        result = 31 * result + (second != null ? second.hashCode() : 0);
        return result;
    }

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

    public int compareTo(Pair<U, V> o) {
        int value = ((Comparable<U>)first).compareTo(o.first);
        if (value != 0)
            return value;
        return ((Comparable<V>)second).compareTo(o.second);
    }
}

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

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

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

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

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

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

}

class OutputWriter {
    private final PrintWriter writer;

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

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

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

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

}


import java.util.*;

public class ss{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        for(int i=2;i<(int)Math.sqrt(n);i++){
            if(n%i==0){
                sb.append(i+""+n/i);
                break;
            }
        }
        System.out.println(Integer.parseInt(sb.toString()));
    }
}


package codeforces;

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

public class Limericks {
	// https://codeforces.com/problemset/problem/1331/B

	public static void main(String[] args) throws IOException, FileNotFoundException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader in = new BufferedReader(new FileReader("Limericks.in"));
		// INPUT //

		int n = Integer.parseInt(in.readLine());

		int factor1 = -1;
		for (int i = 2; i < n; i++) {
			if (n % i == 0) {
				factor1 = i;
				break;
			}
		}

		int factor2 = n / factor1;

		System.out.println("" + factor1+factor2);

	}

}


import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        int[] arr=  {2,3,5,7,11,13,17,19,23,29,31};
        String s = "";
        int i=0;
        while(num!=1){
            if(num%arr[i] == 0){
                num/=arr[i];
                s+=arr[i];
            }
            i+=1;
        }
        System.out.println(s);

    }

}


package codeforces;

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

public class Limericks {
	// https://codeforces.com/problemset/problem/1331/B

	public static void main(String[] args) throws IOException, FileNotFoundException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//BufferedReader in = new BufferedReader(new FileReader("Limericks.in"));
		// INPUT //

		int n = Integer.parseInt(in.readLine());

		int factor1 = -1;
		for (int i = 2; i <= Math.pow(n, 1/2); i++) {
			if (n % i == 0) {
				factor1 = i;
				break;
			}
		}

		int factor2 = n / factor1;

		System.out.println("" + factor1+factor2);

	}

}


package training;
import java.util.*;
public class NewClass {
    public static void main(String []args){
        Scanner sc=new Scanner (System.in);
        int x,nChest=0, nBiceps=0, nBack=0;

        String st="chest";

        x=sc.nextInt();
        int arr[] = new int [x];
        for ( int i=0 ; i<x ; i++){
             arr[i]=sc.nextInt();
	}
        for ( int i=0 ; i<x ; i+=2){
            nChest+=arr[i];
        }
        for ( int i=1 ; i<x ; i+=2){
            nBiceps+=arr[i];
        }
        for ( int i=2 ; i<x ; i+=2){
            nBack+=arr[i];
        }
	if (nChest > nBiceps && nChest > nBack)
		System.out.println ("chest");
	else if (nBiceps > nChest && nBiceps > nBack)
		System.out.println ("biceps");
	else if (nBack > nChest && nBack > nBiceps)
		System.out.println ("back");
    }
}


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.Scanner;
import java.io.*;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {
		// Scanner read = new Scanner(new FileInputStream(new
		// File("input.txt")));
		// PrintWriter out = new PrintWriter(new File("output.txt"));
		Scanner read = new Scanner(System.in);
		int n = read.nextInt(), arr[] = new int[9], chest = 0, bi = 0, back = 0;
		for (int i = 0; i < n; i++) {
			arr[i] = read.nextInt();
			if (i % 3 == 0)
				chest += arr[i];
			else if (i % 3 == 1)
				bi += arr[i];
			else
				back += arr[i];
		}
		if (Math.max(chest, Math.max(bi, back)) == chest)
			System.out.println("chest");
		else if (Math.max(chest, Math.max(bi, back)) == bi)
			System.out.println("biceps");
		else
			System.out.println("back");

	}
}


import java.util.Scanner;

public class Entrainement4 {
public static void main(String[] args) {
 Scanner s=new Scanner(System.in)  ;
 int n =s.nextInt();
 int [] t=new int [n];
 int i1=0;
 int i2=1;
 int i3=2;

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

           t[i]=s.nextInt();

       }
 int chets;
 int biceps;
 int back;

   chets=t[i1];
   biceps=t[i2];
   back=t[i3];
 int max1;

 for(int j=0;j<n;j++)
    { if(n==j)
        break;

     chets+=t[j];

     if(n==j)
      break;

      biceps+=t[j];

      if(n==j)
       break;

     back+=t[j];

   }

if(chets>biceps)
max1=chets;
else
max1=biceps;

if(back>max1)
max1=back;

if(max1==back)
    System.out.println("back");
else if(max1==biceps)
    System.out.println("bicebs");
else
    System.out.println("chets");

}
}


import java.util.Scanner;
public class Greg_workout {
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int size = sc.nextInt();
        int a[] = new int[size];
        int count = 0;
        int bcount = 0;
        int bacount = 0;
        if(size<3)
        {
            int no1 = sc.nextInt();
            int no2 = sc.nextInt();
            if(no1>no2)
                System.out.println("chest");
            else
                System.out.println("biceps");
        }
        else
        {
           for(int i=0;i<a.length;i++)
           {
               a[i] = sc.nextInt();
           }
           for(int i=0;i<a.length;i+=3)
           {
               count+=a[i];
           }
           for(int j=1;j<a.length;j+=3)
           {
               bcount+=a[j];
           }
           for(int k=2;k<a.length;k+=3)
           {
               bacount+=a[k];
           }
           if(count>bcount && count>bacount)
                System.out.println("chest");
           else if(bcount>count && bcount>bacount)
                System.out.println("biceps");
           else
                System.out.println("back");
        }
    }
}


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

public class practice {
	public static HashSet<String> set;
	public static String str;
	public static int[] dp;

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		set = new HashSet<>();
		String[] arr = { "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S", "Cl",
				"Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se",
				"Br", "Kr", "Rb", "Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", "Sb",
				"Te", "I", "Xe", "Cs", "Ba", "La", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hg", "Tl", "Pb",
				"Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ce", "Pr", "Nd", "Pm",
				"Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", "Lu", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm",
				"Bk", "Cf", "Es", "Fm", "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", "Rg", "Cn", "Nh",
				"Fl", "Mc", "Lv", "Ts", "Og" };
		for (int i = 0; i < arr.length; i++) {
			arr[i] = arr[i].toUpperCase();
			set.add(arr[i]);
		}
		str = s.next();
		str = str.toUpperCase();
		dp = new int[str.length()];
		for (int i = 0; i < dp.length; i++) {
			dp[i] = -1;
		}
		if (pos(0))
			System.out.println("YES");
		else
			System.out.println("NO");
	}

	public static boolean pos(int i) {
		int n = str.length();
		if (i == n)
			return true;
		if (dp[i] == 1)
			return true;
		if (dp[i] == 0)
			return false;
		for (int j = i + 1; j <= n; j++) {
			String temp = str.substring(i, j);
			if (set.contains(temp)) {
				boolean val = pos(j);
				if (val) {
					dp[i] = 1;
					return true;
				}
			}
		}
		return false;
	}
}


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

public class F_elementary {
	public static int works(String[] arr, String str, int count) {
		if (str.length() == 0) {
			count++;
		}

		else {
			boolean x = false;
			for (int i = 0; i < arr.length; i++) {
				if (str.length() >= 2 && str.substring(0,1).equals(arr[i]) && str.substring(0,2).equals(arr[i])) {
					String temp = str;
					String temp2 = str;
					count += works(arr, str.substring(1), count);
					count += works(arr, str.substring(2), count);
					x = true;
				}
				else if (str.length() >= 1 && str.substring(0,1).equals(arr[i])) {
					count += works(arr, str.substring(1), count);
					x = true;
				}
				else if (str.length() >= 2 && str.substring(0,2).equals(arr[i])) {
					count += works(arr, str.substring(2), count);
					x = true;
				}
			}
			if (x == false) {
				return count;
			}
		}
		return count;
	}
    public static void main(String[] args) throws IOException {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        String str = sc.next();
        String[] arr = {"H", "HE", "LI", "BE", "B", "C", "N", "O", "F", "NE", "NA", "MG", "AL", "SI", "P", "S", "CL", "AR", "K", "CA", "SC", "TI", "V", "CR", "MN", "FE", "CO", "NI", "CU", "ZN", "GA", "GE", "AS", "SE", "BR", "KR", "RB", "SR", "Y", "ZR", "NB", "MO", "TC", "RU", "RH", "PD", "AG", "CD", "IN", "SN", "SB", "TE", "I", "XE", "CS", "BA", "LA", "CE", "PR", "ND", "PM", "SM", "EU", "GD", "TB", "DY", "HO", "ER", "TM", "YB", "LU", "HF", "TA", "W", "RE", "OS", "IR", "PT", "AU", "HG", "TL", "PB", "BI", "PO", "AT", "RN", "FR", "RA", "AC", "TH", "PA", "U", "NP", "PU", "AM", "CM", "BK", "CF", "ES", "FM", "MD", "NO", "LR", "RF", "DB", "SG", "BH", "HS", "MT", "DS", "RG", "CN", "NH", "FL", "MC", "LV", "TS", "OG"};
        if(works(arr, str, 0) >= 1) {
        	pw.println("YES");
        }
        else pw.println("NO");

        pw.close();
    }
    static class FastScanner {
    	private boolean finished = false;

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

        public FastScanner(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 peek() {
            if (numChars == -1) {
                return -1;
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    return -1;
                }
                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 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 String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

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

        private String readLine0() {
            StringBuilder buf = new StringBuilder();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r') {
                    buf.appendCodePoint(c);
                }
                c = read();
            }
            return buf.toString();
        }
        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0) {
                s = readLine0();
            }
            return s;
        }
        public String readLine(boolean ignoreEmptyLines) {
            if (ignoreEmptyLines) {
                return readLine();
            } else {
                return readLine0();
            }
        }

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

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

        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 boolean isExhausted() {
            int value;
            while (isSpaceChar(value = peek()) && value != -1) {
                read();
            }
            return value == -1;
        }
    public String next() {
            return nextString();
        }

        public SpaceCharFilter getFilter() {
            return filter;
        }

        public void setFilter(SpaceCharFilter filter) {
            this.filter = filter;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
        public int[] nextIntArray(int n){
            int[] array=new int[n];
            for(int i=0;i<n;++i)array[i]=nextInt();
            return array;
        }
        public int[] nextSortedIntArray(int n){
            int array[]=nextIntArray(n);
            PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
            for(int i = 0; i < n; i++){
                pq.add(array[i]);
            }
            int[] out = new int[n];
            for(int i = 0; i < n; i++){
                out[i] = pq.poll();
            }
            return out;
        }
        public int[] nextSumIntArray(int n){
            int[] array=new int[n];
            array[0]=nextInt();
            for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
            return array;
        }
        public ArrayList<Integer>[] nextGraph(int n, int m){
            ArrayList<Integer>[] adj = new ArrayList[n];
            for(int i = 0; i < n; i++){
                adj[i] = new ArrayList<Integer>();
            }
            for(int i = 0; i < m; i++){
                int u = nextInt(); int v = nextInt();
                u--; v--;
                adj[u].add(v); adj[v].add(u);
            }
            return adj;
        }
        public ArrayList<Integer>[] nextTree(int n){
            return nextGraph(n, n-1);
        }

        public long[] nextLongArray(int n){
            long[] array=new long[n];
            for(int i=0;i<n;++i)array[i]=nextLong();
            return array;
        }
        public long[] nextSumLongArray(int n){
            long[] array=new long[n];
            array[0]=nextInt();
            for(int i=1;i<n;++i)array[i]=array[i-1]+nextInt();
            return array;
        }
        public long[] nextSortedLongArray(int n){
            long array[]=nextLongArray(n);
            Arrays.sort(array);
            return array;
        }
    }
	static void shuffle(int[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}
	static void shuffle(long[] a) {
		Random get = new Random();
		for (int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}
}


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

public class F {

	public String[] elem;

	public boolean solve(String s, int ind) {
		if(ind >= s.length()) {
			return true;
		}

		boolean can = false;

		for(int i = 0; i < 128; i++) {
			if(ind + elem[i].length() <= s.length()) {
				boolean tmpcan = true;
				for(int j = 0; j < elem[i].length(); j++) {
					if(s.charAt(ind + j) != elem[i].charAt(j)) {
						tmpcan = false;
					}
				}

				if(tmpcan) {
					if(solve(s, ind + elem[i].length())) {
						can = true;
					}
				}
			}
		}

		return can;
	}

	public void realMain() throws Exception {

		BufferedReader fin = new BufferedReader(new InputStreamReader(System.in), 1000000);

		int i = 0;

		/*while(true) {
String in = fin.readLine();
		String[] ar = in.split("\t");

		String element = ar[0];
		if(ar[0].equals("")) {
			element = ar[1];
		}

		System.out.println("elem[" + i + "] = \"" + element.toUpperCase().trim() + "\";");
		i++;
		}*/

		elem = new String[128];

elem[0] = "AC";
elem[1] = "AG";
elem[2] = "AL";
elem[3] = "AM";
elem[4] = "AR";
elem[5] = "AS";
elem[6] = "AT";
elem[7] = "AU";
elem[8] = "B";
elem[9] = "BA";
elem[10] = "BE";
elem[11] = "BH";
elem[12] = "BI";
elem[13] = "BK";
elem[14] = "BR";
elem[15] = "C";
elem[16] = "CA";
elem[17] = "CD";
elem[18] = "CE";
elem[19] = "CF";
elem[20] = "CL";
elem[21] = "CM";
elem[22] = "CO";
elem[23] = "CR";
elem[24] = "CS";
elem[25] = "CU";
elem[26] = "DB";
elem[27] = "DS";
elem[28] = "DY";
elem[29] = "ER";
elem[30] = "ES";
elem[31] = "EU";
elem[32] = "F";
elem[33] = "FE";
elem[34] = "FM";
elem[35] = "FR";
elem[36] = "GA";
elem[37] = "GD";
elem[38] = "GE";
elem[39] = "H";
elem[40] = "HE";
elem[41] = "HF";
elem[42] = "HG";
elem[43] = "HO";
elem[44] = "HS";
elem[45] = "I";
elem[46] = "IN";
elem[47] = "IR";
elem[48] = "K";
elem[49] = "KR";
elem[50] = "LA";
elem[51] = "LI";
elem[52] = "LR";
elem[53] = "LU";
elem[54] = "MD";
elem[55] = "MG";
elem[56] = "MN";
elem[57] = "MO";
elem[58] = "MT";
elem[59] = "N";
elem[60] = "NA";
elem[61] = "NB";
elem[62] = "ND";
elem[63] = "NE";
elem[64] = "NI";
elem[65] = "NO";
elem[66] = "NP";
elem[67] = "O";
elem[68] = "OS";
elem[69] = "P";
elem[70] = "PA";
elem[71] = "PB";
elem[72] = "PD";
elem[73] = "PM";
elem[74] = "PO";
elem[75] = "PR";
elem[76] = "PT";
elem[77] = "PU";
elem[78] = "RA";
elem[79] = "RB";
elem[80] = "RE";
elem[81] = "RF";
elem[82] = "RG";
elem[83] = "RH";
elem[84] = "RN";
elem[85] = "RU";
elem[86] = "S";
elem[87] = "SB";
elem[88] = "SC";
elem[89] = "SE";
elem[90] = "SG";
elem[91] = "SI";
elem[92] = "SM";
elem[93] = "SN";
elem[94] = "SR";
elem[95] = "TA";
elem[96] = "TB";
elem[97] = "TC";
elem[98] = "TE";
elem[99] = "TH";
elem[100] = "TI";
elem[101] = "TL";
elem[102] = "TM";
elem[103] = "U";
elem[104] = "UUB";
elem[105] = "UUH";
elem[106] = "UUO";
elem[107] = "UUP";
elem[108] = "UUQ";
elem[109] = "UUS";
elem[110] = "UUT";
elem[111] = "V";
elem[112] = "W";
elem[113] = "XE";
elem[114] = "Y";
elem[115] = "YB";
elem[116] = "ZN";
elem[117] = "ZR";
elem[118] = "MT";
elem[119] = "DS";
elem[120] = "RG";
elem[121] = "CN";
elem[122] = "NH";
elem[123] = "FL";
elem[124] = "MC";
elem[125] = "LV";
elem[126] = "TS";
elem[127] = "OG";

		String in = fin.readLine();

		boolean can = false;

		can = solve(in, 0);

		if(can) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}

	public static void main(String[] args) throws Exception {
		F f = new F();
		f.realMain();
	}
}


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

    public class Solution {

    	public static boolean test(String s) {

    		boolean res=false;

    		if (s.length()<=2){
    			res=check(s);
    		}

    		if (s.length()>1&check(s.substring(0,1))){

    			res=res|test(s.substring(1,s.length()));
    		}

    		if (res) {return res;}

    		if (s.length()>2&check(s.substring(0,2))){

    			res=res|test(s.substring(2,s.length()));

    		}

    		return res;
    	}

    	public static boolean check(String s) {

    		boolean res=false;

    		String[] checklist={"H", "HE", "LI", "BE", "B", "C", "N", "O", "F", "NE", "NA","MG",
    				"AL", "SI", "P", "S", "CL", "AR", "K", "CA", "SC", "TI", "V", "CR",
    				"MN", "FE", "CO", "NI", "CU", "ZN", "GA", "GE", "AS", "SE", "BR",
    				"KR", "RB", "SR", "Y", "ZR", "NB", "MO", "TC", "RU", "RH", "PD",
    				"AG", "CD", "IN", "SN", "SB", "TE", "I", "XE", "CS", "BA", "LA",
    				"CE", "PR", "ND", "PM", "SM", "EU", "GD", "TB", "DY", "HO", "ER",
    				"TM", "YB", "LU", "HF", "TA", "W", "RE", "OS", "IR", "PT", "AU",
    				"HG", "TL", "PB", "BI", "PO", "AT", "RN", "FR", "RA", "AC", "TH",
    				"PA", "U", "NP", "PU", "AM", "CM", "BK", "CF", "ES", "FM", "MD",
    				"NO", "LR", "RF", "DB", "SG", "BH", "HS", "MT", "DS", "RG", "CN",
    				"NH", "FL", "MC", "LV", "TS", "OG"};

    		for (int i = 0; i < checklist.length; i++) {
    			if (s.equals(checklist[i])){
    				res = true;
    				break;
    			}
    		}

    		return res;
    	}

    	public static void main(String[] args) throws Exception {
    		FastScanner cin = new FastScanner(System.in);
    		String str = cin.nextLine();

    		boolean res= test(str);

    		if (res){
    			System.out.println("YES");
    		} else{
    			System.out.println("NO");
    		}

    	}

    	static class FastScanner {
    		private BufferedReader reader = null;
    		private StringTokenizer tokenizer = null;

    		public FastScanner(InputStream in) {
    			reader = new BufferedReader(new InputStreamReader(in));
    			tokenizer = null;
    		}

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

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

    			return tokenizer.nextToken("\n");
    		}

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

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

    	}
    }


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

public class D {

	public static void main(String[] args){
		FastScanner scan = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		a = scan.nextInt(); b = scan.nextInt(); h = scan.nextInt(); w = scan.nextInt(); n = scan.nextInt();
		x = scan.nextIntArray(n);
		Arrays.sort(x);
		int[] t = new int[n];
		for(int i = 0; i < n; i++) t[i] = x[n-i-1];
		x = t;
		dp = new Integer[40][100010];
		int res = go(0, h, w);
		out.println(res >= 0x3f3f3f3f?-1:res);
		out.close();
	}

	static int a, b, h, w, n, x[];
	static Integer[][] dp;

	static int go(int at, int u, int v){
		if(u >= a && v >= b || u >= b && v >= a)return at;
		if(at > 35 || at == n) return 0x3f3f3f3f;
		if(u > 100000) u = 100000;
		if(v > 100000) v = 100000;
		if(dp[at][u] != null) return dp[at][u];
		int res = 0x3f3f3f3f;
		res = Math.min(res, go(at+1, u*x[at], v));
		res = Math.min(res, go(at+1, u, v*x[at]));
		return dp[at][u] = res;
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

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

		public String next() {
			if (st.hasMoreTokens())	return st.nextToken();
			try {st = new StringTokenizer(br.readLine());}
			catch (Exception e) {e.printStackTrace();}
			return st.nextToken();
		}

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

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

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

		public String nextLine() {
			String line = "";
			if(st.hasMoreTokens()) line = st.nextToken();
			else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
			while(st.hasMoreTokens()) line += " "+st.nextToken();
			return line;
		}

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

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

		public double[] nextDoubleArray(int n){
			double[] a = new double[n];
			for(int i = 0; i < n; i++) a[i] = nextDouble();
			return a;
		}

		public char[][] nextGrid(int n, int m){
			char[][] grid = new char[n][m];
			for(int i = 0; i < n; i++) grid[i] = next().toCharArray();
			return grid;
		}
	}

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.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 prakharjain
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        _799D solver = new _799D();
        solver.solve(1, in, out);
        out.close();
    }

    static class _799D {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();

            int h = in.nextInt();
            int w = in.nextInt();

            int n = in.nextInt();

            Integer[] ar = new Integer[n];

            for (int i = 0; i < n; i++)
                ar[i] = in.nextInt();

            Arrays.sort(ar, (x, y) -> y - x);

            int max = Math.max(a, b);

            int[][] dp = new int[41][max + 1];

            for (int i = h; i >= 0; i--) {
                dp[0][i] = w;
            }

//        for (int i = w; i >= 0; i--) {
//            dp[0][i] = Math.max(dp[0][i], h);
//        }

            if (dp[0][a] >= b || dp[0][b] >= a) {
                out.println(0);
                return;
            }

            for (int i = 1; i <= Math.min(n, 40); i++) {

                int num = ar[i - 1];
                for (int j = 0; j <= max; j++) {
                    dp[i][Math.min(num * j, max)] = Math.max(dp[i][Math.min(num * j, max)], dp[i - 1][j]);
                }

                for (int j = 0; j <= max; j++) {
                    dp[i][j] = Math.max(dp[i][j], dp[i - 1][j] * num);
                }

                for (int j = max - 1; j >= 0; j--) {
                    dp[i][j] = Math.max(dp[i][j], dp[i][j + 1]);
                }

                if (dp[i][a] >= b || dp[i][b] >= a) {
                    out.println(i);
                    return;
                }
            }

            out.println(-1);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

        public void println(int i) {
            writer.println(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 static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

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

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

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

        }

    }
}


package checker;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

//author : DimonK

public class Ds {

	static int needX;
	static int needY;

	static int curX;
	static int curY;

	static int ans = Integer.MAX_VALUE;

	static Map<Pair, Integer> map = new HashMap<>();

	static long[] pre;

	static List<Integer> list = new ArrayList<>(10000);

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		needX = in.nextInt();
		needY = in.nextInt();

		curX = in.nextInt();
		curY = in.nextInt();

		int n = in.nextInt();

		pre = new long[n];

		for(int i=0; i<n; i++) {
			int x = in.nextInt();
			list.add(x);
		}

		Collections.sort(list, Collections.reverseOrder());

		for(int i=0; i<=Math.min(35, n-1); i++) {
			int x = list.get(i);

			pre[i] = x;

			if(i >= 1) {
				pre[i] *= pre[i-1];
			}
		}

		int res = rec(curX, 0);

		System.out.println(res >= 36 ? -1 : res);

	}

	private static int rec(long cx, int i) {

		long aval = (i == 0 ? 1 : pre[i-1]);

		long cy = aval/(cx / curX);
		cy *= curY;

		if(i == Math.min(list.size(), 35)) {
			return check(cx, cy) ? 0 : 9999;
		}
		else if(check(cx, cy)) {
			return 0;
		}
		else if(map.containsKey(new Pair(cx, i))) {
			return map.get(new Pair(cx, i));
		}
		else {

			int ans = 0;
			if(cx > 100_001) {
				// adding to Y axis
				ans = 1 + rec(cx, i + 1);
			}
			else {
				ans = 1 + Math.min(rec(cx, i+1), rec(cx * list.get(i), i+1)  );
			}

			map.put(new Pair(cx, i) , ans);

			return ans;
		}

	}

	private static boolean check(long cx, long cy) {

		return (cx >= needX && cy >= needY || cx >= needY && cy >= needX);

	}
}

class Pair {
	public Pair(long x, long y) {
		super();
		this.x = x;
		this.y = y;
	}

	long x,y;

	@Override
	public boolean equals(Object obj) {
		Pair p = (Pair)obj;

		return p.x == x && p.y == y;
	}

	@Override
	public int hashCode() {
		return Long.hashCode(x) % 7919 + Long.hashCode(y) ;
	}

}


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

/**
 * Created by huang on 17-5-29.
 */
public class Main {
    private static int ans = 0, n = 0;
    private static void dfs(int x, int y, int num, Integer[] Ai) {
        if (num > n) {
            return;
        }
        if (x == 0 && y == 0) {
            ans = Math.min(ans, num);
            return;
        }
        if (Ai[num] == 2) {
            while (x > 0) {
                x >>= 1;
                num++;
            }
            while (y > 0) {
                y >>= 1;
                num++;
            }
            dfs(x, y, num, Ai);
            return;
        }
        if (x > 0) {
            dfs(x/Ai[num], y, num+1, Ai);
        }
        if (y > 0) {
            dfs(x, y/Ai[num], num+1, Ai);
        }
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(), b = in.nextInt(), h = in.nextInt(), w = in.nextInt();
        n = in.nextInt();
        Integer[] ai = new Integer[n];
        for (int i = 0; i < n; i++) {
            ai[i] = in.nextInt();
        }
        Arrays.sort(ai, new Comparator<Integer>() {
            @Override
            public int compare(Integer i1, Integer i2) {
                return i2-i1;
            }
        });
        ans = n+1;
        dfs((a-1)/h, (b-1)/w, 0, ai);
        dfs((b-1)/h, (a-1)/w, 0, ai);
        System.out.println(ans == n+1 ? -1:ans);
    }
}


package ee.hacker.codeforces13;

import java.util.Scanner;

/**
 * Codeforces 13. Problem A
 *
 * @author Aleksandr Nikiforov
 */
public class ProblemA {

    public static void main(String[] args) {
        ProblemA problem = new ProblemA();
        problem.solve();
    }

    private void solve() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int total = 0;
        for (int base = 2; base < a; base++) {
            total += digitSum(a, base);
        }
        int d = gcd(total, a - 2);
        total /= d;
        System.out.println(total + "/" + (a - 2) / d);
    }

    private int gcd(int a, int b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    private int digitSum(int n, int base) {
        int ret = 0;
        while (n != 0) {
            ret += (n % base);
            n /= base;
        }
        return ret;
    }

}


package CodeForces;
import java.math.*;
import java.io.*;

public class nambers {
	static private int sum(int A,int so){
		int res=0;
		int chislo=A;
		int ostatok=0;
		while(chislo>=so){
			ostatok=chislo%so;
			chislo=chislo/so;
			res+=ostatok;
		};
		res+=chislo;
		return res;

	};

	public static void  main(String[] args) throws IOException{
		BufferedWriter output = new BufferedWriter(new OutputStreamWriter(System.out));
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		int A=Integer.valueOf(input.readLine());
		int summa=0;
		int k=A-2;
		for(int i=2;i<=A-1;i++){
			summa+=sum(A,i);

		};

	int min=Math.min(summa,k);

	int[]mnogitel=new int [min];
	for(int i=1;i<min;i++){
		mnogitel[i-1]=min%i==0?i:1;
		summa=summa%mnogitel[i-1]==0?summa/mnogitel[i-1]:summa;
		k=k%mnogitel[i-1]==0?k/mnogitel[i-1]:k;

	};

	output.write(Integer.toString(summa)+'/'+Integer.toString(k));
	output.close();
	input.close();
	};

}


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

public class P12D {
    P12D (){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        ArrayList <Integer> beauty = new ArrayList<>();
        ArrayList <Integer> beautyOrder = new ArrayList<>();
        ArrayList <Integer> beautyOrig = new ArrayList<>();
        readSortQualities(beauty, beautyOrder, beautyOrig, sc, n);

        ArrayList <Integer> intellect = new ArrayList<>();
        ArrayList <Integer> intellectOrder = new ArrayList<>();
        ArrayList <Integer> intellectOrig = new ArrayList<>();
        readSortQualities(intellect, intellectOrder, intellectOrig, sc, n);

        ArrayList <Integer> richness = new ArrayList<>();
        ArrayList <Integer> richnessOrder = new ArrayList<>();
        ArrayList <Integer> richnessOrig = new ArrayList<>();
        richnessOrig.addAll(richness);
        readSortQualities(richness, richnessOrder, richnessOrig, sc, n);

        String beautyStr = beautyOrder.toString();
        String intellectStr = intellectOrder.toString();
        String richnessStr = richnessOrder.toString();

        int murder = 0;

        for (int k = 0; k < n; k++){
            int i = beautyOrder.get(k);
            boolean dead = false;
            for (int l = k + 1; l < n && !dead; l++){
                int j = beautyOrder.get(l);
                if (i != j &&
                        beautyStr.substring(beautyStr.indexOf(i + "")+1).contains(j + "") &&
                        beautyOrig.get(i-1) < beautyOrig.get(j-1) &&
                        intellectStr.substring(intellectStr.indexOf(i + "")+1).contains(j + "") &&
                        intellectOrig.get(i-1) < intellectOrig.get(j-1) &&
                        richnessStr.substring(richnessStr.indexOf(i + "")+1).contains(j + "") &&
                        richnessOrig.get(i-1) < richnessOrig.get(j-1)){
                    dead = true;
                    murder ++;
                }
            }
        }

        System.out.println(murder);

        sc.close();
    }

    void readSortQualities (ArrayList<Integer> quality, ArrayList<Integer> qualityOrder,
            ArrayList<Integer> qualityOrig, Scanner sc, int n){
        int q = sc.nextInt();
        qualityOrig.add(q);
        quality.add(q);
        qualityOrder.add(1);
        for (int i = 1; i < n; i++){
            q = sc.nextInt();
            qualityOrig.add(q);
            if (quality.get(0) >= q){
                quality.add(0, q);
                qualityOrder.add(0, i+1);
            }
            else if (quality.get(quality.size() - 1) < q){
                quality.add(q);
                qualityOrder.add(i+1);
            }
            else {
                boolean added = false;
                for (int j = 1; j < quality.size() && !added; j++){
                    if (quality.get(j) >= q){
                        added = true;
                        quality.add(j, q);
                        qualityOrder.add(j, i+1);
                    }
                }
            }
        }
    }

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

}


import java.util.Scanner;
public class Numbers {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = n;
        int x = 0;
        int y = n - 2;
        for(int i=2; i<n; i++) {
            while(k >= i) {
                x += k % i;
            }
            x += k;
            k = n;
        }
        System.out.println(k + "/" + y);
    }
}


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

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

/* Name of the class has to be "Main" only if the class is public. */
public class Main

{

      static  Scanner in = new Scanner(System.in);
    public static void solve()
    {

    int n=in.nextInt();long t=in.nextLong();
    int[] a = new int[n];
    long sum =0;
    int max=0;
    int pos=0;
    List<Integer> ls = new ArrayList<>();
     List<Integer> ls1 = new ArrayList<>();
    for(int i=0;i<n;i++)
    {
        a[i]=in.nextInt();

       ls.add(a[i]);
       ls1.add(a[i]);

        sum+=(int)Math.ceil(a[i]/2.0);

    }

     Collections.sort(ls1);

    if(sum<=t)
    {

        int ans[] = new int[n];
        //t=t-sum;

        for(int i=0;i<n;i++)
        {
             ans[i]=(int)Math.ceil(a[i]/2.0);
        }
        //System.out.println(ans[0]);
        t=t-sum;
        // System.out.println(t);
        int flag=0;

        int cnt=1;
        for(int i =n-1;i>0 && t>0;i--)
        {
            if(ls1.get(i)==ls1.get(i-1))
            {
                cnt++;
            }
            else
            {

             int ele=ls1.get(i);

                int loc=ls.indexOf(ele);

                if(ans[loc]<a[loc]){

                    int dis=a[loc]-ans[loc];
                    if(dis*cnt<=t)
                    t=t-dis*cnt;
                    else
                    {
                        dis=(int)t/cnt;
                        t=t%cnt;

                    }

                    //System.out.println(i+" "+dis+" "+t);
                //t=t%cnt;

               if(dis>0){
                for(int j=0;j<n;j++)
                {
                    if(a[j]==ele)
                    {
                        ans[j]+=dis;
                    }
                }

               }
                }

                cnt=1;

            }
        }

        int ele=ls1.get(0);
         int loc=ls.indexOf(ele);

         if(ls1.get(0)==ls1.get(1) && cnt>1)
         {
              if(ans[loc]<a[loc]){

                    int dis=a[loc]-ans[loc];
                    if(dis*cnt<=t)
                    t=t-dis*cnt;
                    else
                    {
                        dis=(int)t/cnt;
                        t=t%cnt;

                    }

                    //System.out.println(i+" "+dis+" "+t);
                //t=t%cnt;

               if(dis>0){
                for(int j=0;j<n;j++)
                {
                    if(a[j]==ele)
                    {
                        ans[j]+=dis;
                    }
                }

               }
                }

         }

        else if(n==1 && t>0 && a[0]>=ans[0]+t)
        {
             ans[0]+=t;
            t=0;
        }
    else{
        if(t>0 && ls1.get(0)!=ls1.get(1)  && a[loc]>=ans[loc]+t)
        {
            ans[loc]+=t;
            t=0;
        }
    }
        if(t==0){
        for(int i=0;i<n;i++)
        {
            System.out.print(ans[i]+" ");
        }
        }
        else
        {
            System.out.println(-1);
        }
    }
    else
    {
        System.out.println(-1);
    }

    }

	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here

		int t=1;
		//in.nextLine();

		while(t>0)
		{

		    solve();
		    t--;
		}

	//	System.out.println(x);
	}
}


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

public class Codeforces {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(), w = scan.nextInt();
		Node[] node = new Node[n];
		long sum = 0;
		for(int i = 0; i < n; i++){
			int a = scan.nextInt();
			node[i] = new Node(i, a, (a+1)/2);
			sum += node[i].b;
		}
		if(w < sum){
			System.out.println(-1);
			return;
		}
		w -= sum;
		Arrays.sort(node, new CompByA());
		while(w > 0){
			for(int i = n-w; i < n; i++){
				node[i].b++;
				w--;
			}
		}
		Arrays.sort(node, new CompByIndex());
		for(int i = 0; i < n; i++) System.out.println(node[i].b);
	}

	static class CompByIndex implements Comparator<Node>{
		@Override
		public int compare(Node e, Node f){
			return e.index - f.index;
		}
	}
	static class CompByA implements Comparator<Node>{
		@Override
		public int compare(Node e, Node f) {
			return e.a - f.a;
		}
	}

	static class Node{
		int a;
		int b;
		int index;
		public Node(int i, int e, int f){
			index = i;
			a = e;
			b = f;
		}
	}
}


package test;

import java.util.*;

public class solution
{
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int w = s.nextInt();
		m[] a = new m[n];

		int sum=0;
		//int[] ans = new int[n];
		for(int g=0;g<n;g++)
		{
			a[g]=new m();
			a[g].f=s.nextInt();
			sum+=a[g].f/2;
			a[g].i=g;
			a[g].h=a[g].f/2;
			if(a[g].f%2==1)
			{
				sum++;
				a[g].h++;
			}
		}

		if(w<sum)
		{
			System.out.println("-1");
			return;
		}
		else
		{
			w-=sum;
			Arrays.sort(a,new Comparator<m>(){
				public int compare(m o1, m o2) {
					return o1.f-o2.f;
				}
			});
			int g=n-1;
			while(true)
			{
				int temp=Math.min(a[g].f-a[g].h,w);
				a[g].h+=Math.min(a[g].f-a[g].h,w);
				w-=temp;
				if(w==0)
					break;
				g--;
			}
		}
		int[] ans = new int[n];
		for(int h=0;h<n;h++)
		{
			ans[a[h].i]=a[h].h;
		}
		for(int h=0;h<n;h++)
		{
			System.out.print(ans[h]+" ");
		}
	}
}

class m
{
	int f;
	int h;
	int i;
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class TeaParty {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int w = in.nextInt();
		int a[] = new int[n];
		Integer b[] = new Integer[n];
		int c[] = new int[n];
		int min = 100;
		int sumRemainingCapacity=0;
		for (int i = 0; i < n && w>=0; i++) {
			b[i]=i;
			a[i] = in.nextInt();
			int halfCapacity = (a[i]+1)/2;
			w=w-halfCapacity; //deducting
			c[i]=halfCapacity; //pouring
			sumRemainingCapacity += a[i]-halfCapacity; //remaining
			if (min > a[i]) {
				min = a[i];
			}
		}
		if(w<0 || sumRemainingCapacity < w){
			System.out.println(-1);
		}else{
			//w is remaining tea in tea pot which should be porured completely
			Arrays.sort(b, new Comparator<Integer>() {
				public int compare(Integer i, Integer j){
					return a[j]-a[i];
				}
			});
			int remaining = a[b[0]]-c[b[0]];
			if(remaining>=w){
				c[b[0]]+=w;
				w=0;
			}else{
				c[b[0]]+=remaining;
				w=w-remaining;
			}
			for(int i=0;i<n && w>0;i++){
				remaining = a[b[i]]-c[b[i]];
				int maxCanbeFilled = c[b[i-1]]-c[b[i]];
				if(maxCanbeFilled>0){
					if(remaining>=w){
						//To be filled w
						if(w<=maxCanbeFilled){
							c[b[i]]+=w;
							w=0;
						}else{
							c[b[i]]+=maxCanbeFilled;
							w=w-maxCanbeFilled;
						}
					}else{
						//To be filled is remaining
						if(remaining<=maxCanbeFilled){
							c[b[i]]+=remaining;
							w=w-remaining;
						}else{
							c[b[i]]+=maxCanbeFilled;
							w=w-maxCanbeFilled;
						}
					}
				}
			}
			if(w!=0){
				System.out.println(-1);
			}else{
				printArray(c);
			}
		}
		in.close();

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


import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author teacher
 */
public class Chess2 {

    static boolean b[][];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String lad = in.nextLine();
        String kon = in.nextLine();
        b = new boolean[8][8];
        int xlad = lad.charAt(0) - 'a';
        int ylad = lad.charAt(1) - '1';
        b[xlad][ylad] = true;
        int xkon = kon.charAt(0) - 'a';
        int ykon = kon.charAt(1) - '1';
        b[xkon][ykon] = true;

        boolean pos[][] = new boolean[8][8];
        pos[xkon][ykon] = true;
        for (int i = 0; i < 8; i++) {
            pos[xlad][i] = true;
            pos[i][ylad] = true;
        }

        if (ykon + 2 < 8) {
            if (xkon + 1 < 8) {
                pos[ykon + 2][xkon + 1] = true;
            }
            if (xkon - 1 >= 0) {
                pos[ykon + 2][xkon - 1] = true;
            }
        }
        if (ykon - 2 >= 0) {
            if (xkon + 1 < 8) {
                pos[ykon - 2][xkon + 1] = true;
            }
            if (xkon - 1 >= 0) {
                pos[ykon - 2][xkon - 1] = true;
            }
        }
        if (ykon + 1 < 8) {
            if (xkon + 2 < 8) {
                pos[ykon + 1][xkon + 2] = true;
            }
            if (xkon - 2 >= 0) {
                pos[ykon + 1][xkon - 2] = true;
            }
        }
        if (ykon - 1 >= 0) {
            if (xkon + 2 < 8) {
                pos[ykon - 1][xkon + 2] = true;
            }
            if (xkon - 2 >= 0) {
                pos[ykon - 1][xkon - 2] = true;
            }
        }
        int count = 64;
        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 8; j++) {
                if(!pos[i][j]){
                    if(checkHorse(i,j)){
                       count--;
                    }
                }else {
                    count--;
                }
            }
        }

        System.out.println(count);
    }

    static boolean checkHorse(int xkon, int ykon) {

        if (ykon + 2 < 8 && xkon + 1 < 8 && b[ykon + 2][xkon + 1]) {
            return true;
        } else if (ykon + 2 < 8 && xkon - 1 >= 0 && b[ykon + 2][xkon - 1]) {
            return true;
        } else if (ykon - 2 >= 0 && xkon + 1 < 8 && b[ykon - 2][xkon + 1]) {
            return true;
        } else if (ykon - 2 >= 0 && xkon - 1 >= 0 && b[ykon - 2][xkon - 1]) {
            return true;
        } else if (ykon + 1 < 8 && xkon + 2 < 8 && b[ykon + 1][xkon + 2]) {
            return true;
        } else if (ykon + 1 < 8 && xkon - 2 >= 0 && b[ykon + 1][xkon - 2]) {
            return true;
        } else if (ykon - 1 >= 0 && xkon + 2 < 8 && b[ykon - 1][xkon + 2]) {
            return true;
        } else if (ykon - 1 >= 0 && xkon - 2 >= 0 && b[ykon - 1][xkon - 2]) {
            return true;
        }

        return false;

    }
}


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

public class Chess {

	static int board[][];

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int ways = 0;
		board = new int[8][8];
		String temp = br.readLine();
		int ri = temp.charAt(0) -  'a';
		int rj = Integer.parseInt(temp.charAt(1)+"") - 1;
		board[ri][rj] = 'R';
		temp = br.readLine();
		int ki = temp.charAt(0) -  'a';
		int kj = Integer.parseInt(temp.charAt(1)+"") - 1;
		board[ki][kj] = 'K';

		for (int i=0;i<8;i++) {
			for (int j=0;j<8;j++) {
				if (i==ri && j==rj)
					continue;
				if (i==ki && j==kj)
					continue;
				if (i==ri || j==rj)
					continue;
				if ((i==ki-1 && (j==kj+2 || j==kj-2))  || (i==ki+1 && (j==kj+2 || j==kj-2)) || (i==ki-2 && (j==kj+1 || j==kj-1)) || (i==ki+2 && (j==kj-1 || j==kj+1)))
					continue;
				ways++;
			}

		}

		System.out.println(ways-2);

	}

}


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

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

class B {
    final int[] dx = { -2, -2, -1, 1, 2, 2, 1, -2 };
    final int[] dy = { -1, 1, 2, 2, 1, -1, -2, -2 };
    public void solve(int testNumber, PandaScanner in, PrintWriter out) {
        int[] rook = coordinates(in.next());
        int[] knight = coordinates(in.next());
        int[][] pieces = new int[][] { knight, rook };
        boolean[][] cant = new boolean[8][8];
        for (int[] piece: pieces) {
            int x = piece[0];
            int y = piece[1];
            cant[x][y] = true;
            for (int d = 0; d < dx.length; d++) {
                int nx = x + dx[d];
                int ny = y + dy[d];
                if (Math.min(nx, ny) >= 0 && Math.max(nx, ny) < 8) {
                    cant[nx][ny] = true;
                }
            }
        }
        int res = 0;
        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 8; j++) {
                if (!cant[i][j] && i != rook[0] && j != rook[1]) {
                    res++;
                }
            }
        }
        out.println(res);
    }
    int[] coordinates(String str) {
        char[] c = str.toCharArray();
        return new int[] { c[0] - 'a', c[1] - '1' };
    }
}

class PandaScanner {
    public BufferedReader br;
    public StringTokenizer st;
    public InputStream in;

    public PandaScanner(InputStream in) {
        br = new BufferedReader(new InputStreamReader(this.in = in));
    }

    public String nextLine() {
        try {
            return br.readLine();
        }
        catch (Exception e) {
            return null;
        }
    }

    public String next() {
        if (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(nextLine().trim());
            return next();
        }
        return st.nextToken();
    }

    }


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

/**
 * @author Don Li
 */
public class XorMST {

    int N = 40;
    long[] dp = new long[N];

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

        long[] p2 = new long[N];
        p2[0] = 1;
        for (int i = 1; i < N; i++) p2[i] = 2 * p2[i - 1];

        dp[1] = 1;
        for (int i = 2; i < N; i++) dp[i] = 2 * dp[i - 1] + p2[i - 1];

        long ans = 0;
        while (n > 0) {
            long l = Long.highestOneBit(n), r = n ^ l;
            int bits = Long.numberOfTrailingZeros(l);
            ans += dp[bits];
            if (r > 0) ans += p2[bits];
            n = r;
        }
        out.println(ans);
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new XorMST().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

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

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

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

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


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

import static java.lang.Math.*;

public class cfs473E {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        StringBuilder sb = new StringBuilder();
        long n = sc.nextInt();
        ArrayList<Pair> costs = new ArrayList<Pair>();
        long currNodes = 0;
        long currCost = 0;
        long currPower = 1;
        sb.append(sumSection(0L, 0L, n));
        System.out.print(sb);
    }
    public static long sumSection(long currCost, long connectionCost,  long remaining) {
        if (remaining == 0) return currCost;
        currCost += connectionCost;
        long addedCost = 0L;
        long currNodes = 1L;
        while (currNodes<<1 <= remaining) {  // get floor power.
            addedCost = addedCost*2 + currNodes;
            currNodes <<= 1;
        }
        currCost += addedCost;
        return sumSection(currCost, currNodes, remaining - currNodes);
    }

    public static class Pair {
        long edges, cost;
        public Pair(long edges, long cost) {
            this.edges = edges;
            this.cost = cost;
        }
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }

        public FastScanner() {
            this(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 readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }

        long[] readLongArray(int n) {
            long[] a = new long[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextLong();
            }
            return a;
        }
    }
}


/**
 * @author: Mehul Raheja
 */
import java.util.*;
import java.io.*;

public class E {

    /*
        Runtime = O()
     */
    static int N, M, K;
    static String s;
    static StringTokenizer st;
    static int[] d;

    static long ans = 0;

    static void dis(long N) {
        if(N == 1){
            return;
        }
        long low = 1<< ((long)((Math.log(N-0.1))/Math.log(2)));
        ans += low;
        dis(low);
        dis(N-low);
    }

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        long N = Long.parseLong(br.readLine());
        dis(N);
        System.out.println(ans);
    }
}


import java.util.Scanner;

public class MinXorMst {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long n = in.nextLong();
		int cost = 0;
		//System.out.println("Calculating");
		for(long i=1;i<n;i++) {
			cost+=(i^(i&(i-1)));
		}
		System.out.println(cost);
		in.close();
	}
   //1000000000000

}


import java.util.Scanner;

public class Main {

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

        int ano = in.nextInt();
        String rs = "";
        String com = "";

        for (int i = ano + 1; i < 90000; i++) {
            String anos = i + "";
            for (int j = 0; j < anos.length(); j++) {
                String dig = anos.charAt(j) + "";
                if (!com.contains(dig)) {
                    com += dig;
                    if (com.length() == 4) {
                        rs = com;
                        i = 9000;
                    }
                }
            }
            com = "";
        }
        System.out.println(rs);
    }
}


import java.util.Scanner;
public class ahmed
{
    public static void main(String args[])
    {
        int y,x,r;
        int[] r1 = new int[4];
        Scanner scn = new Scanner(System.in);
        y = scn.nextInt();
        int flag = 1;
        while(true)
        {
            x = y + 1;
            r = x;
            int i = 0;
            while(r != 0)
            {
                r1[i] = r % 10;
                r = r / 10;
                i = i + 1;
            }
            if(r1[0] != r1[1] && r1[0] != r1[2] && r1[0] != r1[3] && r1[1] != r1[2] && r1[1] != r1[3] && r1[2] != r1[3])
            {
                break;
            }
            x = x + 1;
        }
        System.out.println(r);
    }
}


import java.util.Scanner;

public class BeautifulYear_271A {

	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		int n = sc.nextInt();
		n++;
		while(n<9000) {
			if(Integer.toString(n).chars().distinct().count()==4) {
				System.out.println(n);
				break;
			}
		}
	}
}


import java.util.Scanner;

public class yearr {
    public static void main(String args[]){
        Scanner input=new Scanner(System.in);
        int year=input.nextInt();

        int a,b,c,d;

        int j=0;
        while(j==0)
        {   year++;
            a=year/1000;
            b=year/100%10;
            c=year/10%10;
            d=year%10;
            if(a!=b && a!=c && a!=d && b!=c && b!=d && c!=d)
            {
                System.out.println(c +" "+ d);
                a=1;
            }
        }
        System.out.println(year);
    }
}