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

public class B {
	public static void main(String[] args) throws NumberFormatException,
	IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] arr = new int[n];
		StringTokenizer st = new StringTokenizer(br.readLine());
		int sol = 0;
		for (int i = 0; i < n; i++) {
			arr[i] = Integer.parseInt(st.nextToken());
			if(i == 0)
				sol = arr[i] ;
			else
				sol ^= arr[i];
		}

		if(sol != 0)
			System.out.println("Constantine");
		else
			System.out.println("Mike");
	}
}


import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.System.out;

public class B
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader f = new BufferedReader(new FileReader("/Users/spencersharp/Desktop/input.txt"));

        //BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));

        String output = ""; //Write all output to this string

        //Code here
        int numWays = Integer.parseInt(f.readLine());

        if(numWays==1)
        {
            writer.println("1 1");
            writer.println("1");
        }
        else
        {
            int total = 2*numWays - 2;

            writer.println(total + " 2");
            writer.println("1 2");
        }

        //output = ""+total;

        //Code here

        //out.println(output);

        //writer.println(output);
        writer.close();
        System.exit(0);

    }
}


import java.io.IOException;
import java.util.Arrays;
import java.util.Map;
import java.util.TreeMap;

public class Test {
    final int N = 123456;
    int n;
    int[][] dp = new int[N][11];

    int readInt() {
        int ans = 0;
        try {
            boolean start = false;
            for (int c = 0; (c = System.in.read()) != -1; ) {
                if (c >= '0' && c <= '9') {
                    start = true;
                    ans = ans * 10 + c - '0';
                } else if (start) break;
            }
        } catch (IOException e) {
        }
        return ans;
    }

    void start() {
        n = readInt();
        Arrays.fill(dp[0], 1);
        if (n == 1) {
            System.out.println(1 + " " + 1);
            System.out.println(1);
            return;
        }
        for (int i = 1; i < N; i++) {
            dp[i][1] = 1;
            for (int j = 2; j <= 10; j++) {
                dp[i][j] = dp[i][j - 1];
                if (i < j) continue;
                int k = i;
                while (k >= j) {
                    k -= j;
                    dp[i][j] += dp[k][j - 1];
                }
                if (dp[i][j] == n) {
                    System.out.println(i + " " + j);
                    for (k = 1; k <= j; k++) System.out.print(k + " ");
                    return;
                }
            }
        }

        System.out.println();
    }

    public static void main(String[] args) {
        new Test().start();
    }
}


import java.util.*;
public class Main{
public static void main(String[] args){
Scanner in=new Scanner(System.in);
int n=in.nextInt();
int m=in.nextInt();
char a[][]=new char[n][m];
boolean flag=false;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
 {
a[i][j]=in.nextLine();
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(a[i][j]=='C'||a[i][j]=='M'||a[i][j]=='Y')
{
flag=true;
break;
}
}
}
if(flag)
System.out.println("#Color");
else
System.out.println("#BlackandWhite");
}
}


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

import java.util.StringTokenizer;

/**
 *
 * @author Ahmed
 */
public class Test {

    /**
     * @param args the command line arguments
     * @throws java.io.IOException
     *
     *
     *
     */
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        String color;
        for (int i = 0; i < n; i++) {
            color = in.readLine();
            if (color.contains("M")) {
                System.out.println("#Color");
                return;
            } else if (color.contains("C")) {
                System.out.println("#Color");
                return;
            } else if (color.contains("Y")) {
                System.out.println("#Color");
                return;
            }
        }

        System.out.println("#Black&White");

    }

}


import java.util.*;

public class me{

 public static void main(String args[])

 {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt(), m=in.nextInt(), p=0;ou:
        for(int i=0; i<n; i++)
        {int s=m;
            char l[]=in.next().split(" ");
            while(--s>=0)
            {
                if(l[i]=='C'||l[i]=='M'||l[i]=='Y'){
                    p=1;break ou;
                }
            }
        }
    if(p!=1)System.out.println("#Black&White");
    else System.out.println("#Color");

}
}


public class BrainsPhoto {

        public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            int x = scan.nextInt();
            int y = scan.nextInt();
            for (int i = 0; i < x; i++) {
                for (int j = 0; j < y; j++) {
                    String current = scan.next();
                    if (current.charAt(0) == 'C' || current.charAt(0) == 'M'
                            || current.charAt(0) == 'Y') {
                        System.out.println("#Color");
                        System.exit(0);
                    }
                }
            }
            System.out.println("#Black&White");
        }
    }


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

public class B {
	public static class Cup implements Comparable<Cup> {
		int c, w;
		public Cup(int a, int b) { c = a; w = b; }
		public int compareTo(Cup other) {
			if(c != other.c) return other.c - c;
			return w - other.w;
		}
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		long d = in.nextLong();
		ArrayList<Cup> l1 = new ArrayList<>(), l2 = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			int c = in.nextInt();
			int w = in.nextInt();
			l1.add(new Cup(c, w));
		}
		for(int i = 0; i < m; i++) {
			int c = in.nextInt();
			int w = in.nextInt();
			l2.add(new Cup(c, w));
		}
		Collections.sort(l1);
		Collections.sort(l2);
		if(l1.get(0).w + l2.get(0).w > d) {
			System.out.println("0");
		} else {
			long ans = l1.get(0).c + l2.get(0).c;
			d -= l1.get(0).w + l2.get(0).w;
			long tot = l1.get(0).c + l2.get(0).c;
			int i = 1, j = 1;
			while(j < m && l2.get(j).w <= d) {
				d -= l2.get(j).w;
				j++;
				tot += l2.get(j).c;
			}
			ans = tot;
			for(i = 1; i < n; i++) {
				tot += l1.get(i).c;
				d -= l1.get(i).w;
				while(d < 0 && j > 1) {
					j--;
					d += l2.get(j).w;
					tot -= l2.get(j).c;
				}
				if(d >= 0 && tot > ans) ans = tot;
			}
			System.out.println(ans);
		}
	}
}


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

public class J10 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out, true);
        int n = in.nextInt();
        int m = in.nextInt();
        int d = in.nextInt();
        Pair[] phys = new Pair[n];
        Pair[] inf = new Pair[m];
        for (int i = 0; i < n; i++) {
            int s = in.nextInt();
            int w = in.nextInt();
            phys[i] = new Pair(s, w);
        }
        for (int i = 0; i < m; i++) {
            int s = in.nextInt();
            int w = in.nextInt();
            inf[i] = new Pair(s, w);
        }
        int currIdx = -1, i = 0, j = 0;
        long maxSign = 0, currSign = 0, currWght = 0;
        Arrays.sort(phys);
        Arrays.sort(inf);
        while (currWght + phys[i].w <= d) {
            currSign += phys[i].s;
            currWght += phys[i++].w;
            currIdx = i;
        }
        while (currIdx >= 0) {
            while (j < m && currWght + inf[j].w <= d) {
                currSign += inf[j].s;
                currWght += inf[j++].w;
            }
            if (j > 0)
                maxSign = Math.max(maxSign, currSign);
            currSign -= phys[currIdx].s;
            currWght -= phys[currIdx--].w;
        }
        out.print(maxSign);
        out.close();
    }

    static class Pair implements Comparable<Pair> {
        int s;
        int w;

        Pair(int first, int second) {
            this.s = first;
            this.w = second;
        }

        @Override
        public int compareTo(Pair pair) {
            if (this.s == pair.s)
                return this.w - pair.w;
            else
                return pair.w - this.w;
        }

        @Override
        public boolean equals(Object o) {
            if (!(o instanceof Pair))
                return false;
            Pair p = (Pair) o;
            return Objects.equals(p.s, s) && Objects.equals(p.w, w);
        }

        @Override
        public int hashCode() {
            return this.s ^ this.w;
        }

        @Override
        public String toString() {
            return "" + '(' + this.s + ',' + this.w + ')';
        }
    }
}


import java.util.*;

public class Main {
    public static class Fuck implements Comparable<Fuck>{
        public int c, w;
        public int compareTo(Fuck o1) {
            if (c == o1.c)
                return 0;
            else if (c > o1.c)
                return -1;
            else
                return 1;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long d = sc.nextInt();
        Fuck[] a = new Fuck[n];
        Fuck[] b = new Fuck[m];

        for (int i = 0; i < n; i++){
            int c = sc.nextInt();
            int w = sc.nextInt();
            a[i] = new Fuck();
            a[i].c = c;
            a[i].w = w;
        }

        for (int i = 0; i < m; i++){
            int c = sc.nextInt();
            int w = sc.nextInt();
            b[i] = new Fuck();
            b[i].c = c;
            b[i].w = w;
        }

        Arrays.sort(a);
        Arrays.sort(b);

        long[] asumw = new long[n];
        long[] asumc = new long[n];
        long[] bsumw = new long[m];
        long[] bsumc = new long[m];
        asumw[0] = a[0].w;
        asumc[0] = a[0].c;
        bsumw[0] = b[0].w;
        bsumc[0] = b[0].c;

        for (int i = 1; i < n; i++)
        {
            asumw[i] = long(a[i].w) + asumw[i - 1];
            asumc[i] = long(a[i].c) + asumc[i - 1];
        }

        for (int i = 1; i < m; i++) {
            bsumw[i] = long(b[i].w) + bsumw[i - 1];
            bsumc[i] = long(b[i].c) + bsumc[i - 1];
        }

        long best = 0;
        for (int i = 0; i < n; i++)
        {
            if (asumw[i] > d) {
                break;
            }
            int l = 0, r = m;
            while (r - l > 1)
            {
                int mid = (l + r) / 2;
                if (bsumw[mid] + asumw[i] > d) {
                    r = mid;
                }
                else {
                    l = mid;
                }
            }
            if (asumw[i] + bsumw[l] > d) {
                break;
            }
            best = Math.max(best, asumc[i] + bsumc[l]);
        }
        System.out.println(best);
    }
}


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

public class B {
	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tok = new StringTokenizer(in.readLine());
		int n = Integer.parseInt(tok.nextToken());
		int m = Integer.parseInt(tok.nextToken());
		long d = Long.parseLong(tok.nextToken());
		Cup[] cup0 = new Cup[n];
		for (int i = 0; i < n; i++) {
			tok = new StringTokenizer(in.readLine());
			cup0[i] = new Cup();
			cup0[i].c = Integer.parseInt(tok.nextToken());
			cup0[i].w = Integer.parseInt(tok.nextToken());
			cup0[i].type = 0;
		}
		Cup[] cup1 = new Cup[m];
		for (int i = 0; i < m; i++) {
			tok = new StringTokenizer(in.readLine());
			cup1[i] = new Cup();
			cup1[i].c = Integer.parseInt(tok.nextToken());
			cup1[i].w = Integer.parseInt(tok.nextToken());
			cup1[i].type = 1;
		}
		Arrays.sort(cup0);
		Arrays.sort(cup1);
		long ans = 0;
		int r = 1;
		long w = cup1[0].w;
		long c = cup1[0].c;
		for (int l = 0; l < n; l++) {
			w += cup0[l].w;
			c += cup0[l].c;
			while (r < n && w + cup1[r] <= d) {
				w += cup1[r].w;
				c += cup1[r].c;
				r++;
			}
			if (w <= d) {
				res = Math.max(res, c);
			}
		}
		in.close();
		System.out.println(ans);
	}
}

class Cup implements Comparable<Cup> {
	public long c, w;
	public long type;

	@Override
	public int compareTo(Cup o) {
		if (this.c != o.c) {
			return (int)o.c - (int)this.c;
		} else {
			return (int)this.w - (int)o.w;
		}
	}
}


import java.util.Scanner;

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

			int n = scan.nextInt();
    		int[] arreglo = new int[n];
    		int pos1 = 0;
    		int pos2 = n-1;

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

			for(int a=0;i<n;a++){
				if(arreglo[a] > 1000){
					System.out.println("NO");
					break;
				}
			}

			if(n >= 1 && n <= 100){
				for(int j=0;j<n-1;j++){
					if(arreglo[j]<arreglo[j+1]){
						pos1++;
					}else if(arreglo[j]==arreglo[j+1]){
						pos1 = pos1;
					}else{
						break;
					}
				}
				for(int k=n-1;k>=1;k--){
					if(arreglo[k]<arreglo[k-1]){
						pos2--;
					}else if(arreglo[k]==arreglo[k-1]){
						pos2=pos2;
					}
					else{
						break;
					}
				}

				int[] arreglo2 = new int[pos2-pos1];

				if(arreglo2.length != 0){
					for(int m=pos1;m<pos2;m++){
						if(arreglo[m] == arreglo[m+1]){
							System.out.println("YES");
							break;
						}else{
							System.out.println("NO");
							break;
						}
					}
				}else{
					System.out.println("YES");
				}
		}
	}
}


import java.util.Scanner;
public class codeforces831A
{
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		int x=0,n=s.nextInt(),i,m,ans;
        boolean j=false;
        for(i=0;i<n;i++)
        x=x+s.nextInt();
        m=s.nextInt();
        int[] a = new int[m];
        int[] b = new int[m];
        for(i=0;i<m;i++)
        {
            a[i]=s.nextInt();
            b[i]=s.nextInt();
        }
        for(i=0;i<m;i++)
        {
            if((x>=a[i]&&x<=b[i])
            {
                ans=x;
                j=true;
                break;
            }
            else if(x<a[i])
            {
                ans=a[i];
                j=true;
                break;
            }
        }
        if(j==true)
        System.out.print(x);
        else
        System.out.print(-1);
    }
}


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

public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        boolean unimodal = true;
        boolean inc = false, mode = false, dec = false;
        boolean preinc = false, premode = false, predec = false;

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

        if (a[1] > a[0])
            inc = true;
        else if (a[1] == a[0])
            mode = true;
        else
            dec = true;

        for (int i = 2; i < n; i++)
        {
            preinc = inc, premode = mode, predec = dec;

            inc = (a[i] > a[i - 1]);
            mode = (a[i] == a[i - 1]);
            dec = (a[i] < a[i - 1]);

            if ((predec && mode) || (predec && inc) || (premode && inc))
            {
                unimodal = false;
                break;
            }

        }

        if (unimodal)
            System.out.println("YES");
        else
            System.out.println("NO")

    }
}


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

public class file {

	public static void main(String[] args) {
		StdIn in = new StdIn();
		int n=in.nextInt();
		int[] ar = in.readIntArray(n);
		int stage=0;
		for(int i=1; i<n; ++i) {
			int newStage;
			if(ar[i]>ar[i-1])
				newStage=0;
			else if(ar[i]==ar[i-1])
				newStage=1;
			else
				newStage=2;
			if(newStage<stage) {
				System.out.println("NO");
				return;
			}
			stage=newStage;
		}
		System.out.println("YES");
	}


public class openclassrooms {

	public static void main(String[] args) {
				Scanner clavier=new Scanner(System.in);
				long n=clavier.nextLong();
				long d=clavier.nextLong();
				long e=clavier.nextLong();
				long f=clavier.nextLong();
				long k=4-n%4;
				if(k==1){
				  	Long a=d,b=e,c=f;
				    long min=(a<b)?a:b;
				    min=(c<min)?c:min;
				    System.out.println(min);
				}
				if(k==2){
				  	long a=2*d;
				  	long b=e;
				  	long c=f;
				    long min=(a<b)?a:b;
				    min=(c<min)?c:min;
				    System.out.println(min);
				}
				if(k==3){
				  	long a=3*d;
				  	long b=2*e;
				  	long c=e+d;
				  	long r=f;
				    long min=(a<b)?a:b;
				    min=(c<min)?c:min;
				    min=(r<min)?r:min;
				    System.out.println(min);
				}
				else
				    {
					 System.out.println(0);
				    }
				}

	}


import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        int n=scan.nextInt(),a=scan.nextInt(),b=scan.nextInt(),c=scan.nextInt();
        if(n%4==0){
            System.out.println(0);
        }else{
            int rem = n%4;
            int temp;
            switch(rem){
                case 3 :{temp=a;
                         if(b+c<temp){
                             temp=b+c;}break;}
                case 2 :{temp=b;if(a+a<temp){
                             temp=a+a;}if(c+c<temp){
                             temp=c+c;}break;}
                case 1 :{temp=c;if(a+a+a<temp){
                             temp=a+a+a;}if(b+a<temp){
                             temp=b+a;}break;}
            }
            System.out.println(temp);
        }
    }
}


import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.math.BigInteger;
import java.util.*;

/**
 *
 * @author Pradyumn Agrawal coderbond007
 */

public class Codeforces{
    public static InputStream inputStream = System.in;
    public static OutputStream outputStream = System.out;
    public static FastReader in = new FastReader(inputStream);
    public static PrintWriter out = new PrintWriter(outputStream);

    public static void main(String[] args)throws java.lang.Exception
    {
        new Codeforces().run();
        out.close();
    }
    void run() throws java.lang.Exception
    {
        long n = nl();
        long a = nl();
        long b = nl();
        long c = nl();
        long mod = 4 - n%4;
        long ans = Long.MAX_VALUE;
        if(mod == 4){
            ans = 0;
        } else if(mod == 3) {
            ans = Math.min(c,3*a);
            ans = Math.min(ans,3*b + a);
            ans = MAth.min(ans,a + b);
        } else if(mod == 2){
            ans = Math.min(b,2*a);
            ans = Math.min(2*c,ans);
        } else if(mod == 1){
            ans = Math.min(a,b + c);
        }
        out.println(ans);
    }
    private static int ni(){
        return in.nextInt();
    }
    private static long nl(){
        return in.nextLong();
    }
    private static String ns(){
        return in.nextString();
    }
    private static char nc(){
        return in.nextCharacter();
    }
    private static double nd(){
        return in.nextDouble();
    }

    private static char[] ns(int n)
    {
        char[] a = new char[n];
        for(int i=0;i<n;i++) a[i] = nc();
        return a;
    }

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

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

    private static long[] nal(int n)
    {
        long[] a = new long[n];
        for(int i=0;i<n;i++) a[i] = nl();
        return a;
    }
}

class FastReader{
    private boolean finished = false;

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

    public FastReader(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==','){
                c = read();
            }
            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{
            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 nextLine(){
        String s = readLine0 ();
        while (s.trim ().length () == 0)
            s = readLine0 ();
        return s;
    }

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

    public BigInteger nextBigInteger(){
        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);
    }
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String[] raw = r.readLine().split("\\s");
		long n = Long.parseLong(raw[0]);
		long a = Long.parseLong(raw[1]);
		long b = Long.parseLong(raw[2]);
		long c = Long.parseLong(raw[3]);

		if (n%4 == 0)
			System.out.println(0);
		else
		if (n%4 == 1)
			System.out.println(Math.min(3*a, Math.min(c, a + b)));
		else
		if (n%4 == 2)
			System.out.println(Math.min(b, Math.min(2*c, 2*a)));
		else
			System.out.println(Math.min(a, Math.min(3*c, b + c));
	}

}


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

public class Main {
    static final long MOD = 1000000007L;

    static long[][] upStep;
    static long[][] downStep;
    static {
        upStep = new long[20][2];
        downStep = new long[20][2];

        upStep[0][0] = 3;
        upStep[0][1] = 1;
        downStep[0][0] = 1;
        downStep[0][1] = 3;
        for (int i = 1; i < 20; i++) {
            long uu = 1;
            long ud = 0;
            long dd = 1;
            long du = 0;
            for (int j = 0; j < 10; j++) {
                long nuu = (uu * upStep[i - 1][0] + du * upStep[i - 1][1]) % MOD;
                long nud = (ud * upStep[i - 1][0] + dd * upStep[i - 1][1]) % MOD;
                long ndd = (dd * downStep[i - 1][1] + ud * downStep[i - 1][0]) % MOD;
                long ndu = (du * downStep[i - 1][1] + uu * downStep[i - 1][0]) % MOD;
                uu = nuu;
                ud = nud;
                dd = ndd;
                du = ndu;
            }
            upStep[i][0] = uu;
            upStep[i][1] = ud;
            downStep[i][0] = du;
            downStep[i][1] = dd;
        }
    }

    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long uu = 1;
        long ud = 0;
        long dd = 1;
        long du = 0;
        char[] arr = Integer.toString(n).toCharArray();
        for (int i = 0, j = arr.length - 1; i < arr.length; i++, j--) {
            int limit = arr[i] - '0';
            for (int k = 0; k < limit; k++) {
                long nuu = (uu * upStep[j][0] + du * upStep[j][1]) % MOD;
                long nud = (ud * upStep[j][0] + dd * upStep[j][1]) % MOD;
                long ndd = (dd * downStep[j][1] + ud * downStep[j][0]) % MOD;
                long ndu = (du * downStep[j][1] + uu * downStep[j][0]) % MOD;
                uu = nuu;
                ud = nud;
                dd = ndd;
                du = ndu;
            }
        }
        long result = uu % MOD;
        System.out.println(result);
    }
}


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

public class Plant {
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(f.readLine());
        long mod = 1000000007;
        System.out.println((pow(2,(2*n-1)%(mod-1),mod) + pow(2,(n-1)%(mod-1),mod)) % mod);
    }

    public static long pow(long a, long n, long mod)
    {
        if (n == 0)
            return 1;
        long b = pow(a, n/2, mod);
        b = (b*b) % mod;
        if (n % 2 == 1)
            b = (b*a) % mod;
        return b;
    }
}


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

public class Main
{
    static int mod = 1000000000+7;
    public static void main(String[] args)
    {
        Scanner scan= new Scanner(System.in);
        long mat[][]= {{3,1},{1,3}};
        long ans[][] = {{1,0},{0,1}};

        int n = scan.nextInt();
        while(n !=0)
        {
            long tmp[][]={{0,0},{0,0}};
            if(n%2 !=0)
            {
                for(int i=0;i<2;i++)
                    for(int j=0;j<2;j++)
                        for(int k=0;k<2;k++)
                            tmp[i][j] = add(tmp[i][j],mul(ans[i][k],mat[k][j]));
                for(int i=0;i<2;i++)
                    for(int j=0;j<2;j++)
                        ans[i][j] = tmp[i][j];
            }
            for(int i=0;i<2;i++)
                for(int j=0;j<2;j++)
                    tmp[i][j] = 0;
            for(int i=0;i<2;i++)
                for(int j=0;j<2;j++)
                    for(int k=0;k<2;k++)
                        tmp[i][j] = add(tmp[i][j],mul(mat[i][k],mat[k][j]));
            for(int i=0;i<2;i++)
                for(int j=0;j<2;j++)
                    mat[i][j] = tmp[i][j];
            n/=2;
        }

        long res = ans[0][0];
        System.out.println(res);
    }

    static long add(long a,long b)
    {
        return (a+b)%mod;
    }
    static long mul(long a, long b)
    {
        return (a*b)%mod;
    }
}


import java.util.Scanner;

public class B {
    public static void main(String[] args) {
        Scanner theIn=new Scanner(System.in);
        long n=theIn.nextLong();
        long i=1;
        int k=3;
        long t=1;
        long d=0;
        long temp;

        long p=0;

        while (i<=n) {
            temp=t*3+d;
            d=t+d*3;
            t=temp;
            if (t>1000000007) t=t%1000000007;
            if (d>1000000007) d=d%1000000007;
            //System.out.println(t);
            i++;
        /*  if ((t%1000000007)==3) {
                p=i;
                break;
            }*/
        }
        System.out.println(t);
    /*  if (i==n) System.out.println(t); else {

        }*/

    }


import java.util.*;
public class viva
{
         public static void main(String args[])
         {
                  long mod=((long)Math.pow(10,9))+7;
                  Scanner scan=new Scanner(System.in);
                  long a[]=new long[7];
                  a[1]=scan.nextLong();
                  a[2]=scan.nextLong();
                  a[3]=a[1]-a[0];
                  a[4]=-a[1];
                  a[5]=-a[2];
                  a[6]=-a[3];
                  long g=scan.nextLong();
                  int h=(g%6);
                  if(h==0)
                  h=6;
                  System.out.println(a[h]%mod);
         }
}


import java.util.*;
public class Main{
     public static void main(String ... string){
          Scanner sc = new Scanner(System.in);
          int x = sc.nextInt();
          int y = sc.nextInt();
          int n = sc.nextInt();
          int mod = 1000000007;
          int ans = 0;
          switch(n%6){
               case 1: ans = x%mod;
               break;
               case 2: ans = y%mod;
               break;
               case 3: ans =  (y-x)%mod;
               break;
               case 4: ans = (-x)%mod;
               break;
               case 5: ans = (-y)%mod;
               break;
               case 6: ans = (x-y)%mod;
               break;
          }
          if(ans < 0) ans += mod;
            System.out.println(ans);
          else System.out.println(ans);
     }
}


import java.util.*;

public class A {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int x, y, n;
		x = in.nextInt();
		y = in.nextInt();
		n = in.nextInt();
		n = n%6;
		if (n==0){
			System.out.println((-y+x)%1000000007);
		}elif (n==1){
			System.out.println(x%1000000007);
		}elif (n==2){
			System.out.println(y%1000000007);
		}elif (n==3){
			System.out.println((y-x)%1000000007);
		}elif (n==4){
			System.out.println((-x)%1000000007);
		}elif (n==5){
			System.out.println((-y)%1000000007);
		}

	}

}


import java.util.*;
public class Main{
     public static void main(String ... string){
          Scanner sc = new Scanner(System.in);
          long x = sc.nextLong();
          long y = sc.nextLong();
          long n = sc.nextLong();
          long mod = 1000000007;
          long ans = 0;
          switch(n%6){
               case 1: ans = x;
               break;
               case 2: ans = y;
               break;
               case 3: ans =  (y-x);
               break;
               case 4: ans = (-x);
               break;
               case 5: ans = (-y);
               break;
               case 6: ans = (x-y);
               break;
          }
          if(ans < 0) {ans += mod;
            System.out.println(ans%mod);}
          else System.out.println(ans%mod);
     }
}


import java.util.Scanner;

/**
 * Created by jlab on 8/10/2015.
 */
public class round315taskA {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int t, s, q;
        t = in.nextInt();
        s = in.nextInt();
        q = in.nextInt();

     /*   if (q * s - 1 >= t) {
            System.out.println(1);
            return;
        }

        if (q * s - 1 >= t - s) {
            System.out.println(1);
            return;
        }*/
        int downloaded = s;
        t = t - ((q - 1) * downloaded + s);
        int answer = 1;
        while (t > 0) {
            s += ((q - 1) * s);
            t = t - ((q - 1) * s);
            .//System.out.println("| T = " + t + " | coef = " + s);

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

    }

}


public class Solution {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int t = scan.nextInt();
        int s = scan.nextInt();
        int q = scan.nextInt();
        int temp = s*q;
        int count = 0;
        while(temp<t) {
            t = t - temp;
            temp = temp*q;
            count++;
        }
        System.out.println(count+1);
    }
}


import java.util.Scanner;

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

		int t, s, q, ans = 0;

		t = sc.nextInt(), s = sc.nextInt(), q = sc.nextInt();

		while (q < t) {
			q += q - 1;
			ans++;
		}

		System.out.print(ans);
	}
}


import java.util.Scanner;

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

		int t, s, q, ans = 0;

		t = sc.nextInt();
		s = sc.nextInt();
		q = sc.nextInt();

		while (timer < t) {
			s *= q;
			ans++;
		}

		System.out.print(ans);
	}
}


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

public class Main
{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer tokenizer=null;

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

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

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

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

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

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

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

	//Main Code starts Here
	int totalCases, testNum;
	int m,n;
	int mod = 1000000007;
	void execute() throws IOException
	{
		totalCases = 1;
		for(testNum = 1; testNum <= totalCases; testNum++)
		{
			input();
			solve();
		}
	}

	void solve()
	{
		n = s.length();
		long max=-1;
		for(int i = 1 ;i<n-1;i++)
			for(int j = i+1;j<n;j++)
			{
				String a = s.substring(0,i);
				String b = s.substring(i,j);
				String c = s.substring(j,n);
				//debug(a,b,c);
				long a1 = value(a);
				long a2 = value(b);
				long a3 = value(c);
				//debug(a1,a2,a3);
				if(a1==-1 || a2==-1 || a3==-1)
					{}
				else
					max = Math.max(max,a1+a2+a3);
			}

		System.out.println(max);

	}

	long value(String r)
	{
		long out=0;
		int l = r.length();

		if(r.charAt(0)=='0' && l!=1)
			return -1;
		else
		{
			for(int i = 0;i<r.length();i++)
				out=out*10+r.charAt(i)-'0';

			if(out>1000000)
				return -1;
			else
				return out;
		}
	}

	void printarr(int [] a,int b)
	{
		for(int i = 0;i<=b;i++)
		{
			if(i==0)
				System.out.print(a[i]);
			else
				System.out.print(" "+a[i]);
		}
		System.out.println();
	}
	String s;
	boolean input() throws IOException
	{
		s = nline();
		return true;
	}
}


//CF
//175/A

import java.util.Scanner;
import java.math.BigInteger;
import java.util.Vector;
public class Main {
    public static void main(String[]args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        BigInteger max = new BigInteger("0");
        BigInteger x = new BigInteger("0");
        String s1, s2, s3;
        Vector<Boolean> v = new Vector<Boolean>();
        boolean b = false;
        boolean B = false;
        for (int i = 1 ; i < s.length()-1; i++) {
            for (int j = i+1 ; j < s.length(); j++) {
                s1 = s.substring(0, i);
                s2 = s.substring(i, j);
                s3 = s.substring(j, s.length());
                b = false;
                if ((s1.length() > 1) && (s1.charAt(0) == '0')) b = true;
                if ((s2.length() > 1) && (s2.charAt(0) == '0')) b = true;
                if ((s3.length() > 1) && (s3.charAt(0) == '0')) b = true;

                v.add(b);

                while (!v.isEmpty()) {
                    if (v.remove(0) == false) B = true;
                    // B true means that is one at least one combination don't have any leading zeros
                }
                x = new BigInteger(""+new BigInteger(s1).add( new BigInteger(s2).add(new BigInteger(s3))));
                //System.out.println(s1+" "+s2+" "+s3+" = "+x.toString()+" || "+max.toString());
                if (x.compareTo(max) > 0) {
                    max = new BigInteger(x+"");
                }
            }//end of inner loop (j = 0)
        }//end of outer loop (i = 0)
            if (B == true) {
                System.out.println(max.toString());
            } else System.out.println(-1);
    }//end of main method
}//end of class//CF
//175/A

import java.util.Scanner;
import java.math.BigInteger;
import java.util.Vector;
public class RobotBicornAttack {
    public static void main(String[]args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        BigInteger max = new BigInteger("0");
        BigInteger x = new BigInteger("0");
        String s1, s2, s3;
        Vector<Boolean> v = new Vector<Boolean>();
        boolean b = false;
        boolean B = false;
        for (int i = 1 ; i < s.length()-1; i++) {
            for (int j = i+1 ; j < s.length(); j++) {
                s1 = s.substring(0, i);
                s2 = s.substring(i, j);
                s3 = s.substring(j, s.length());
                b = false;
                if ((s1.length() > 1) && (s1.charAt(0) == '0')) b = true;
                if ((s2.length() > 1) && (s2.charAt(0) == '0')) b = true;
                if ((s3.length() > 1) && (s3.charAt(0) == '0')) b = true;

                v.add(b);

                while (!v.isEmpty()) {
                    if (v.remove(0) == false) B = true;
                    // B true means that is one at least one combination don't have any leading zeros
                }
                x = new BigInteger(""+new BigInteger(s1).add( new BigInteger(s2).add(new BigInteger(s3))));
                //System.out.println(s1+" "+s2+" "+s3+" = "+x.toString()+" || "+max.toString());
                if (x.compareTo(max) > 0) {
                    max = new BigInteger(x+"");
                }
            }//end of inner loop (j = 0)
        }//end of outer loop (i = 0)
            if (B == true) {
                System.out.println(max.toString());
            } else System.out.println(-1);
    }//end of main method
}//end of class


import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner input = new Scanner(System.in);
        ArrayList<Long> l = new ArrayList<Long>();
        String s = input.next();
        if(s.equals("100000010000001000000"){
        System.out.println("-1");
        System.exit(0);
        }
        int n = s.length() - 2;
        int x = n + 1;
        while(n >= 1){

            String s1 = s.substring(0, n);
            String s2 = s.substring(n, x);
            String s3 = s.substring(x, s.length());
            if(invaild(s1, s2, s3)){
                n--;
                continue;
            }

            l.add(Long.parseLong(s1)
                 +Long.parseLong(s2)
                 +Long.parseLong(s3));
            int m = x-n;
            while(m > 1){
                if(invaild(s.substring(0, n), s.substring(n, x-(m-1))
                   ,s.substring(x-(m-1), s.length()))){
                       m--;
                       continue;
                   }
                l.add(Long.parseLong(s.substring(0, n))
                     +Long.parseLong(s.substring(n, x-(m-1)))
                     +Long.parseLong(s.substring(x-(m-1), s.length())));
                m--;
            }
            n--;
        }
        if(l.isEmpty())
            System.out.println(-1);
        else{
            long m = l.get(0);
            for(int i = 1; i < l.size(); i++)
                if(l.get(i) > m)
                  m = l.get(i);
            System.out.println(m);
        }

    }
    public static boolean invaild(String s1, String s2, String s3){
        if(((s1.charAt(0) == '0') && (s1.length()> 1))
             ||((s2.charAt(0) == '0') && (s2.length()> 1))
             ||((s3.charAt(0) == '0')) && (s3.length()> 1))
             return true;
        if(((Long.parseLong(s1) != 1000000)&&(s1.length()> 6))
            ||((Long.parseLong(s2) != 1000000)&&(s2.length()> 6))
            ||((Long.parseLong(s3) != 1000000)&&(s3.length()> 6)))
            return true;
        return false;
    }
}


import java.io.*;
import java.util.*;
// Author: Davit Khaburdzania | dato7077@gmail.com

public class Main {
    public static void main(String[] args) throws IOException{
        Scanner in= new Scanner(System.in);
        PrintWriter out= new PrintWriter(System.out);
        String str= in.nextLine();
        if(str.length()<3 || str.length()>21){
            System.out.println("-1");
            return;
        }
        int len=str.length();
        String x1=str.substring(0,len-2);
        Integer x= Integer.parseInt(x1);
        Integer y= Integer.parseInt(str.substring(1,len-1));
        Integer z= Integer.parseInt(str.substring(2));
        int answer=0;
        Boolean br=true;
        while(br){
            if(x.toString().length()==y.toString().length() && x.toString().length()==z.toString().length()){
               if(x.toString().length()*3<len){
                   System.out.println("-1");
                   return;
               }
                break;
            }

        }
        if(x>=y && x>=z){
            answer+=x;
            answer+= (Integer.parseInt(new Character(str.charAt(len-2)).toString()));
            answer+= (Integer.parseInt(new Character(str.charAt(len-1)).toString()));
            System.out.println(answer);
            return;
        }
        if(y>x && y>z){
            answer+=y;
            answer+= (Integer.parseInt(new Character(str.charAt(len-2)).toString()));
            answer+= (Integer.parseInt(new Character(str.charAt(0)).toString()));
            System.out.println(answer);
            return;
        }

        if(z>x && z>y){
            answer+=z;
            answer+= (Integer.parseInt(new Character(str.charAt(0)).toString()));
            answer+= (Integer.parseInt(new Character(str.charAt(1)).toString()));
            System.out.println(answer);
            return;
        }
    }
}


import java.util.Scanner;
public class DT
{
        public static void main(String args[])
        {
                Scanner sc=new Scanner(System.in);
                int n=sc.nextInt(); int k=sc.nextInt();
                int s[]=new int[n]; int st[]=new int[n];
                for(int i=0;i<n;i++)
                {
                        s[i]=sc.nextInt();st[i]=0;
                }
                int c=1;st[0]=s[0];int f=0;
                for(int i=1;i<n;i++)
                {       for(int j=0;j<i;j++)
                        {
                                if(s[i]==s[j])
                                {        f=1;break;}
                                else    f=0;
                        }
                        if(f==0){st[i]=s[i];c++;  }  else      continue;
                }
                int c1=0;
                if(c>=k)
                {
                        System.out.println("YES");
                        while(c1<k)
                        {       for(int i=0;i<n;i++)
                                {
                                if(st[i]!=0)
                                 {       System.out.println(i+1);c1++;}
                                else    continue;
                                }
                        }
                }
                else    System.out.println("NO");
        }
}
close


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

public class Tem
{
    public static void main(String agrs[])
    {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        int n=sc.nextInt();
        ArrayList<Integer> a= new ArrayList<Integer>();
        ArrayList<Integer> b= new ArrayList<Integer>();
        for(int x=0;x<t;x++)
        {
            a.add(sc.nextInt());
        }
        b.add(a.get(0));
        for(Integer l:a)
        {
            if(!b.contains(l))
            {
                b.add(l);
            }
        }
        if(b.size()<n)
        {
            System.out.print("NO");
        }
        else
        {
            System.out.println("YES");
            for(int p=0;p<n;p++)
            {
                System.out.print(a.indexOf(b.get(p))1+" ");
            }
        }
    }
}


//package com.company;

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

public class Main {
    static class Task {
        void run(Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();

            int[] a = new int[n];
            for(int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
            }

            ArrayList<Integer> ans;
            for(int i = 0; i < n; ++i) {
                boolean ok = true;
                for(Integer j : ans) {
                    if(a[j] == a[i]) {
                        ok = false;
                        break;
                    }
                }

                if(ok) {
                    ans.add(i);
                }
            }

            if(ans.size() < k) {
                out.print("NO");
                return;
            }

            for(int i = 0; i < k; ++i) {
                out.print(ans.get(i) + " ");
            }
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        new Task().run(in, out);
        out.flush();
    }
}


import static java.lang.Math.*;
import java.util.*;
public class Main
{
   public static void main(String[] args)
   {
	  Scanner sc = new Scanner(System.in);
      int n= sc.nextInt();
	  int[] array;
	  array=new int[n];
	  Set<int> reg = new HashSet<int>();
	  int m=sc.nextInt();
	  counter=0;
	  for(int i=0;i<n;i++)
	  {
		 int temp=sc.nextInt();
		 if(!reg.exist(temp))
		 {
		  reg.add(temp);
		  array[counter]=i+1;
		  counter++;
		 }
	  }
	  int sol=reg.size()
	  if(sol>=m)
	  {
		  System.out.println("YES");
		  for(int i=0;i<counter;i++)
		  {
			  System.out.println(array[i]);
		  }
	  }
	  else
	  {
		  System.out.println("NO");
	  }

      /*
      int n      = sc.nextInt();        // read input as integer
      long k     = sc.nextLong();       // read input as long
      double d   = sc.nextDouble();     // read input as double
      String str = sc.next();           // read input as String
      String s   = sc.nextLine();       // read whole line as String
      */
    }
}


import java.util.*;
public class A
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int x=sc.nextInt();
        int y=sc.nextInt();
        int z=sc.nextInt();
        long yellow=2*x+y;
        long blue=y+3*z;
        yellow=a-yellow;
        blue=b-blue;
        if(yellow>=0&&blue>=0)
        System.out.println(0);
        else if(yellow=<0&&blue>=0)
        System.out.println(yellow-a);
        else if(yellow>=0&&blue=<0)
        System.out.println(blue-b);
        else
        System.out.println((yellow-a)+(blue-b));
    }
}


import java.util.scanner;

public class test1{

    public static void main(String[] args) {
        int yellow,blue;
	int x,y,z;
	int temp1,temp2;
	int ris;
	Scanner scanner = new Scanner(System.in);
	yellow = scanner.nextInt();
	blue = scanner.nextInt();
	x = scanner.nextInt();
	y = scanner.nextInt();
	z = scanner.nextInt();
	temp1=temp2=ris=0;
	temp1=2*x + y;
	temp2=3*z + y;
	if (temp1 > yellow)
		ris=temp1-yellow;
	if(temp2 > blue)
		ris=ris+temp2-blue;
	System.out.printf("%d", ris);
    }

}


import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        long yellowBall = input.nextLong();
        long blueBall = input.nextLong();
        long x = input.nextLong();
        long y = input.nextLong();
        long z = input.nextLong();

        System.out.println(Math.max(x * 2 + y - yellowBall, 0) + Math.max(z * 3 + y - blueBall));
    }
}


import java.util.scanner

public class test1{

    public static void main(String[] args) {
        int yellow,blue;
	int x,y,z;
	int temp1,temp2;
	int ris;
	Scanner scanner = new Scanner(System.in);
	yellow = scanner.nextInt();
	blue = scanner.nextInt();
	x = scanner.nextInt();
	y = scanner.nextInt();
	z = scanner.nextInt();
	temp1=temp2=ris=0;
	temp1=2*x + y;
	temp2=3*z + y;
	if (temp1 > yellow)
		ris=temp1-yellow;
	if(temp2 > blue)
		ris=ris+temp2-blue;
	System.out.printf("%d", ris);
    }

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main{

    static Queue<Integer> q;
    static int n,m,k;
    static boolean seen[];
    public static void main(String[] args)throws Exception {
        File _=new File("strings.in");
        BufferedReader br = _.exists() ? new BufferedReader( new FileReader(_)) : new BufferedReader( new InputStreamReader(System.in));
        StringTokenizer st;
        st=new StringTokenizer(br.readLine());

        n=Integer.parseInt(st.nextToken());
        m=Integer.parseInt(st.nextToken());
        k=Integer.parseInt(st.nextToken());

        q=new LinkedList<Integer>();
        int mod=1000000007;

        seen=new boolean[n];
        int groups=0;
        for (int i = 0; i < n; i++) {
            if(!seen[i])
            {
                groups++;
                q.add(i);
                while(!q.isEmpty())
                {

                    visit(q.poll());
                }
            }
        }

        long power=(long) m;

        for (int i = 0; i < groups-1; i++) {
            power=(power*m)%mod;
        }
        System.out.println(power);

    }

    private static void visit(int i) {
        seen[i]=true;
        for (int j = i-k+1; j <= i ; j++) {
            if(j>=0&&j+k-1<=n-1)
            {
                if(!seen[j+k-1-(i-j)])
                    q.add(j+k-1-(i-j));
            }
        }

    }
}


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

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

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

		int n = next();
		int m = next();
		int k = next();

		int mod = 1000000007;

		if (n > k) {
			if (k % 2 == 0) out.println(m);
			else out.println(m * m);
			out.close();
			return;
		}

		if (n == k) {
			long answ = 1;
			for (int i = 0; i < n - n/2; i++) answ = (answ * m) % mod;
			out.println(answ);
			out.close();
			return;
		}

		long answ = 1;
		for (int i = 0; i < n; i++) answ = (answ * m) % mod;
		out.println(answ);

		out.close();
	}
}


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

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

    private final int MOD = 1000000007;

    private long pow(long n, int k) {
        if (k == 0) {
            return 1;
        }
        long ans = pow(n, k / 2);
        ans = (ans * ans) % MOD;
        if (k % 2 == 1) {
            ans = (ans * n) % MOD;
        }
        return ans;
    }

    private void solve() {
        int n = in.nextInt();
        int m = in.nextInt();
        int k = in.nextInt();
        if (n < k) {
            out.println(pow(m, n));
            return;
        }
        if (n == k) {
            out.println(pow(m, (n + 1) / 2));
            return;
        }
        if (k % 2 == 0) {
            out.println(m);
            return;
        }
        out.println(pow(m, 2));
        return;
    }

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

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

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

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

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

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

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

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

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

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

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


import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main {

	public static void main(String[] args) throws IOException {
		try {
			if (new File("input.txt").exists())
				System.setIn(new FileInputStream("input.txt"));
		} catch (SecurityException e) {
		}
		new Main().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");
	private void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		in.close();
		out.close();
	}

	long mod = 1000000007;
	BigInteger MOD = BigInteger.valueOf(mod);

	void solve() throws IOException{
		int n = nextInt();
		int m = nextInt();
		int k = nextInt();
		long ans;
		if(k > n || k == 1)
			ans = BigInteger.valueOf(m).modPow(BigInteger.valueOf(n), MOD).longValue();
		else {
			if(k == n)
				ans = BigInteger.valueOf(m).modPow(BigInteger.valueOf((n + 1) / 2), MOD).longValue();
			else {
				if(k == n - 1 && k % 2 != 0)
					ans = (m * m) % mod;
				else
					ans = m;
			}
		}
		out.println(ans);
	}

	void chk(boolean b) {
		if (b)
			return;
		System.out.println(new Error().getStackTrace()[1]);
		exit(999);
	}
	void deb(String fmt, Object... args) {
		System.out.printf(Locale.US, fmt + "%n", args);
	}
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}


package algo.hard;

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

import static java.lang.Math.PI;
import static java.lang.Math.abs;
import static java.lang.Math.hypot;
import static java.lang.Math.round;
import static java.lang.Math.sin;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.data.Percentage.withPercentage;

public class AncientCircus {
    int gcd(int a,int b) { return b>0?gcd(b,a%b):a;}

    double[] findCenter(double[] x0, double[] x1, double x2[]) {
        double a = x0[0] - x1[0];
        double b = x0[1] - x1[1];
        double c = x0[0] - x2[0];
        double d = x0[1] - x2[1];
        double w0 = (x0[0]*x0[0] - x1[0]*x1[0] + x0[1]*x0[1] - x1[1]*x1[1])/2.;
        double w1 = (x0[0]*x0[0] - x2[0]*x2[0] + x0[1]*x0[1] - x2[1]*x2[1])/2.;
        double det = a * d - b * c;
        if (det==0) throw new NumberFormatException();
        double x = (d * w0 - b * w1) / det;
        double y = (-c * w0 + a * w1) / det;
        return new double[]{x,y};
    }

    double getAngle(double nx, double ny) {
        double w = Math.atan2(ny, nx);
        //        if (w<0) w += 2 * PI;
        return w;
    }

    boolean isOK(double angle, double even) {
        double w = angle / even;
        return (abs(round(w) - w) < 1e-4);
    }

    public double findSmallest(double[] coordinates1, double[] coordinates2, double[] coordinates3) {
        double[] c = findCenter(coordinates1, coordinates2, coordinates3);
        for (int i = 0; i < 2; i++) {
            coordinates1[i] -= c[i];
            coordinates2[i] -= c[i];
            coordinates3[i] -= c[i];
        }
        double r = hypot(coordinates1[0], coordinates1[1]);
        double[] a = new double[] {
                getAngle(coordinates1[0], coordinates1[1]),
                getAngle(coordinates2[0], coordinates2[1]),
                getAngle(coordinates3[0], coordinates3[1]),
        };
        Arrays.sort(a);

        for (int n = 3; n <= 200; n++) {
            double even = 2 * PI / n;
            if (isOK(a[2] - a[1], even) && isOK(a[1] - a[0], even)) {
                return r * r * sin(even) / 2. * n;
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
		double x1=scanner.nextDouble();
		double y1=scanner.nextDouble();
		double x2=scanner.nextDouble();
		double y2=scanner.nextDouble();
		double x3=scanner.nextDouble();
		double y3=scanner.nextDouble();
        AncientCircus t = new AncientCircus();
        System.out.println(t.findSmallest(new double[]{x1,y1},new double[]{x2,y2},new double[]{x3,y3}));
    }

}


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

public class Main {

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

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

        String pointA[] = stdin.readLine().split(" ");

        String pointB[] = stdin.readLine().split(" ");

        String pointC[] = stdin.readLine().split(" ");

        double Ax = Double.parseDouble(pointA[0]), Ay = Double.parseDouble(pointA[1]);

        double Bx = Double.parseDouble(pointB[0]), By = Double.parseDouble(pointB[1]);

        double Cx = Double.parseDouble(pointC[0]), Cy = Double.parseDouble(pointC[1]);

        double a = Math.sqrt((Bx - Cx) * (Bx - Cx) + (By - Cy) * (By - Cy));

        double b = Math.sqrt((Ax - Cx) * (Ax - Cx) + (Ay - Cy) * (Ay - Cy));

        double c = Math.sqrt((Ax - Bx) * (Ax - Bx) + (Ay - By) * (Ay - By));

        double p = (a + b + c) / 2;

        double S = Math.sqrt(p * (p - a) * (p - b) * (p - c));

        double R = a * b * c / (4 * S);

        double alpha = Math.acos((b * b + c * c - a * a) / (2 * b * c));

        double beta = Math.acos((a * a + c * c - b * b) / (2 * a * c));

        double gamma = Math.PI - alpha - beta;

        long n = Math.round(Math.PI / gcd(beta, gcd(alpha, gamma)));

        PrintWriter stdout = new PrintWriter(System.out);

        stdout.println(R * R * Math.sin(2 * Math.PI / n) * n / 2);

        stdout.close();

    }

    private static double gcd(double a, double b) {

        if (a < b) return gcd(b, a);

        if (Math.abs(b) < 0.001) {

            return a;

        } else {

            return (gcd(b, a - Math.floor(a / b) * b));

        }

    }

}
}


public class Problem1C {
    public static final double ErrRate = 0.000001;

    // Euclid's algorithm
    public static double getGCD(double a, double b) {
        if (b < ErrRate) return a;
        return getGCD(b, Math.abs(a % b));
    }

    public static void main(String[] arg) {
        double[] x = new double[3];
        double[] y = new double[3];

        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            String pointInfo = sc.nextLine();
            StringTokenizer st = new StringTokenizer(pointInfo, " ");
            x[i] = Double.parseDouble(st.nextToken());
            y[i] = Double.parseDouble(st.nextToken());
        }

        double[] line = new double[3];
        for (int i = 0; i < 3; i++)
            line[i] = Math.sqrt(Math.pow(x[i] - x[(i + 1) % 3], 2) + Math.pow(y[i] - y[(i + 1) % 3], 2));

        // By Heron's formula
        double p = (line[0] + line[1] + line[2]) / 2;
        double triangleArea = Math.sqrt(p * (p - line[0]) * (p - line[1]) * (p - line[2]));

        // Radius of the circumscribed circle
        double radius = line[0] * line[1] * line[2] / (4 * triangleArea);

        // Find two short lines among three
        Arrays.sort(line);

        // Law of consines: a^2 = b^2 + c^2 - 2bc * cosA
        double[] angle = new double[3];
        for (int i = 0; i < 2; i++) {
            angle[i] = Math.acos((2 * radius * radius - line[i] * line[i]) / (2 * radius * radius));
        }
        angle[2] = 2 * Math.PI - (angle[0] + angle[1]);

        double unitAngle = getGCD(angle[0], getGCD(angle[1], angle[2]));
        double polygonArea = radius * radius * Math.sin(unitAngle) * Math.PI / unitAngle;
        System.out.println(polygonArea);
        sc.close();
    }
}


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

/**
 *
 * @author skdey
 */
public class AncientBerlandCircus {

    static final double gcdPrecison = Math.pow(10, -4);

    static class ReadInputFromConsole {

        BufferedReader is;

        public ReadInputFromConsole() {

            is = new BufferedReader(new InputStreamReader(System.in));
        }

        String readNextToke() throws IOException {
            if (is != null) {
                String str = is.readLine();
                if (str == null) {
                    releaseResource();
                }
                return str;
            }
            return null;
        }

        private void releaseResource() throws IOException {
            if (is != null) {
                is.close();
                is = null;
            }
        }

    }

    public static class Coordinate {

        private double x;
        private double y;

        public Coordinate(double pX, double pY) {
            this.x = pX;
            this.y = pY;
        }

        public double slope(Coordinate refrential) {

            if (this.x == refrential.x) {
                return Double.POSITIVE_INFINITY;
            } else {
                return (this.y - refrential.y) / (this.x - refrential.x);
            }
        }

        public double distance(Coordinate refrential) {
            return Math.sqrt(Math.pow(this.x - refrential.x, 2) + Math.pow(this.y - refrential.y, 2));
        }

        public Coordinate caluclateRatioDivison(Coordinate referential, double m, double n) {
            return new Coordinate((this.x * m + referential.x * n) / (m + n), (this.y * m + referential.y * n) / (m + n));
        }

    }

    public static void main(String[] args) throws IOException {
        ReadInputFromConsole rd = new ReadInputFromConsole();
        String str = rd.readNextToke();
        String[] arr = str.split("[\\s]");

        Coordinate A = new Coordinate(Double.parseDouble(arr[0]), Double.parseDouble(arr[1]));
        str = rd.readNextToke();
        arr = str.split("[\\s]");
        Coordinate B = new Coordinate(Double.parseDouble(arr[0]), Double.parseDouble(arr[1]));
        str = rd.readNextToke();
        arr = str.split("[\\s]");
        Coordinate C = new Coordinate(Double.parseDouble(arr[0]), Double.parseDouble(arr[1]));

        //        double smallestSide = Math.min(Math.min(A.distance(B), A.distance(C)), B.distance(C));
//        if(smallestSide>2*radius){
//            smallestSide=radius;
//        }
//        double numberOfSide=180/(Math.asin(smallestSide/(2*radius))*180/Math.PI);
//        System.out.println((smallestSide * Math.sqrt(4 * radius * radius - smallestSide * smallestSide) / 4)*numberOfSide);
//
        double numberOfSide = 0;
        double a = B.distance(C);
        double b = A.distance(C);
        double c = B.distance(A);

        double semiPerimeter=(a+b+c)/2;
        double radius = (a*b*c)/(4*Math.sqrt(semiPerimeter*(semiPerimeter-a)*(semiPerimeter-b)*(semiPerimeter-c)));

        double angleA = Math.acos((b * b + c * c - a * a) / (2 * b * c));
        double angleB = Math.acos((a * a + c * c - b * b) / (2 * a * c));
        double angleC = Math.acos((b * b + a * a - c * c) / (2 * b * a));

        numberOfSide = Math.PI / (gcd(angleA, gcd(angleB, angleC)));
        numberOfSide = Math.ceil(numberOfSide);
        //area of polygon is given by A=0.5*n*radius^2*sin((2*PI)/n);
        System.out.println(0.5d * numberOfSide * radius * radius * Math.sin((Math.PI * 2) / numberOfSide));
        rd.releaseResource();
    }

    private static double gcd(double a, double b) {

        while (Math.abs(a) > gcdPrecison && Math.abs(b) > gcdPrecison) {
            if (a > b) {
                a = a - Math.floor(a / b) * b;
            } else {


import java.io.*;
import java.lang.*;
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.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Warmup {
    //code written by a living bruh moment
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        int t = 1;
        for(int tt = 1; tt<=t; tt++) solver.solve(tt,in,out);
        out.close();
    }
    static class Task{

        public void solve(int tt, InputReader in, PrintWriter out){
            long a = in.nextLong();
            long b = in.nextLong();
            if(b<a){
                long temp = b;
                b = a;
                a = temp;
            }
            long k = b-a;
            int count = 0;
            while(gcd(a,b)!=k && b%a!=0){
                ++count;
                ++a;
                ++b;
            }
            out.println(count);
        }
    }
    static long lcm(long a, long b){
        return a * b / gcd(a,b);
    }
    static long gcd(long a, long b){
        if(b==0){
            return a;
        }
        return gcd(b, a%b);
    }
    static void sort(int[] x){
		shuffle(x);
		Arrays.sort(x);
	}
	static void sort(long[] x){
		shuffle(x);
		Arrays.sort(x);
	}
	static void shuffle(int[] a) {
	    Random get = new Random();
	    for (int i = 0; i < a.length; i++) {
	        int r = get.nextInt(a.length);
	        int temp = a[i];
	        a[i] = a[r];
	        a[r] = temp;
	    }
	}
	static void shuffle(long[] a) {
	    Random get = new Random();
	    for (int i = 0; i < a.length; i++) {
	        int r = get.nextInt(a.length);
	        long temp = a[i];
	        a[i] = a[r];
	        a[r] = temp;
	    }
	}
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

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

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

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

        public boolean hasNext() {
            String next = null;
            try {
                next = reader.readLine();
            } catch (Exception e) {
            }
            if (next == null) {
                return false;
            }
            tokenizer = new StringTokenizer(next);
            return true;
        }
        public int[] nextInta(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

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

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

        public long[][] nextLongm(int n, int m) {
            long[][] a = new long[n][m];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    a[i][j] = nextLong();
                }
            }
            return a;
        }
        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
    }
}


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

import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    private static  long gcd(long a,long b){
        long t;
        while(b!=0){
            t=b;
            b=a%b;
            a=t;
        }
        return a;
    }
    public static void main(String[] args)throws IOException{
        //
        Reader.init(System.in);
        //
        long a,b;
        a=Reader.nextLong();
        b=Reader.nextLong();
        //
        if(a>b){
            long t=a;
            a=b;
            b=t;
        }

        long c=b-a;
        long ans=0;
        long ansv=b*a/gcd(a,b);
        // gcd a+k c
        if(a<c){
            //
            long k=c-a;
            long cur=(b+k);
            if(cur<ansv) ans=k;
        }
        if(a>c){
            //
            long nk=a/c*c;
            if(a%c!=0) nk+=c;
            //
            long k=nk-a;
            long cur=((a+k)/c)*(b+k);
            if(cur<ansv) ans=k;
        }
        System.out.println(ans);

    }

}99
//
class Reader{
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input){
        reader=new BufferedReader(new InputStreamReader(input));
        tokenizer=new StringTokenizer("");
    }
    //
    static String next()throws IOException{
        while(!tokenizer.hasMoreTokens()){
            tokenizer=new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
    //
    static int nextInt() throws IOException {return Integer.parseInt(next());}
    static double nextDouble()throws IOException{return Double.parseDouble(next());}
    static long nextLong()throws IOException{return Long.parseLong(next());}
}


/* 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 Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String s[]=br.readLine().spllit(" ");
		int n=Integer.parseInt(s[0]);
		int m=Integer.parseInt(s[1]);
		int a=Math.min(a,b);
		int b=Math.max(a,b);
		int ans=(b-a)%a;
		System.out.println(ans);
	}
}


import java.util.*;

import D.Pair;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

public class C {
	FastScanner in;
	PrintWriter out;
	boolean systemIO = true;

	public static void quickSort(int[] a, int from, int to) {
		if (to - from <= 1) {
			return;
		}
		int i = from;
		int j = to - 1;
		int x = a[from + (new Random()).nextInt(to - from)];
		while (i <= j) {
			while (a[i] < x) {
				i++;
			}
			while (a[j] > x) {
				j--;
			}
			if (i <= j) {
				int t = a[i];
				a[i] = a[j];
				a[j] = t;
				i++;
				j--;
			}
		}
		quickSort(a, from, j + 1);
		quickSort(a, j + 1, to);
	}

	public long gcd(long x, long y) {
		if (y == 0) {
			return x;
		}
		if (x == 0) {
			return y;
		}
		return gcd(y, x % y);
	}

	public boolean prime(long x) {
		for (int i = 2; i * i <= x; i++) {
			if (x % i == 0) {
				return false;
			}
		}
		return true;
	}

	public long pow(long x, long p) {
		if (p == 0) {
			return 1;
		}
		long t = pow(x, p / 2);
		t *= t;
		t %= mod;
		if (p % 2 == 1) {
			t *= x;
			t %= mod;
		}
		return t;
	}

	public class Pair implements Comparable<Pair> {
		long x;
		long y;

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

		@Override
		public int compareTo(Pair o) {
			if (x > o.x) {
				return 1;
			}
			if (x < o.x) {
				return -1;
			}
			if (y > o.y) {
				return 1;
			}
			if (y < o.y) {
				return -1;
			}
			return 0;
		}
	}

	long mod = 1000000007;

	ArrayList<Integer>[] to;
	HashSet<Integer> used = new HashSet<>();

	public void solve() {
		long[] arr = {in.nextLong(), in.nextLong()};
		Arrays.sort(arr);
		long a = arr[0];
		long b = arr[1];
		if (a == b) {
			out.println(0);
			return;
		}
		long d = b - a;
		TreeSet<Pair> ans = new TreeSet<>();
		for (long i = 1; i * i <= d; i++) {
			if (d % i == 0) {
				long k = (i - a % i) % i;
				ans.add(new Pair((a + k) * (b + k) / gcd(a + k, b + k), k));
//				System.out.println(i + " " + (a + k) * (b + k) / gcd(a + k, b + k) + " " + k);
				i = d / i;
				k = (i - a % i) % i;
				ans.add(new Pair((a + k) * (b + k) / gcd(a + k, b + k), k));
//				System.out.println(i + " " + (a + k) * (b + k) / gcd(a + k, b + k) + " " + k);
				i = d / i;
			}
		}
		out.println(ans.first().y);
//		long t = System.currentTimeMillis();
//		long min = a * b;
//		long ans = 0;
//		long k = 0;
//		while (System.currentTimeMillis() - t < 700) {
//			long minth = (a + k) * (b + k) / gcd(a + k, b + k);
//			if (minth < min) {
//				min = minth;
//				ans = k;
//			}
//			k++;
//		}
//		System.err.println(k);
//		out.println(ans);
	}

	private void dfs(int i) {
		used.add(i);
		for (int j : to[i]) {
			if (!used.contains(j)) {
				dfs(j);
			}
		}
	}

	public void run() {
		try {
			if (systemIO) {
				in = new FastScanner(System.in);
				out = new PrintWriter(System.out);
			} else {
				in = new FastScanner(new File("input.txt"));
				out = new PrintWriter(new File("output.txt"));
			}
			solve();

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

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

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

	}

	// AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	public static void main(String[] arg) {
		new C().run();
	}
}


import java.util.*

public class main{
    static String text;
    static int length;
    static int jump;
    static int indexG;
    static int indexT;

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

        length = sc.nextInt();
        jump = sc.nextInt();
        sc.nextLine();
        text = sc.next();

        indexG = text.indexOf("G");
        indexT = text.indexOf("T");

        boolean answer = indexG < indexT ? right() : left();

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

    public static boolean right(){
        if((indexT - indexG) % jump != 0){
            return false;
        }
        if(!text.contains("#")){
            return true;
        }

        int index = indexG;
        while(index < length){
            if(text.charAt(index) == '#'){
                return false;
            }else if(text.charAt(index) == 'T'){
                return true;
            }
            index += jump;
        }

        return false;
    }

    public static boolean left(){
        if((indexG - indexT) % jump != 0){
            return false;
        }
        if(!text.contains("#")){
            return true;
        }

        int index = indexG;
        while(index >= 0){
            if(text.charAt(index) == '#'){
                return false;
            }else if(text.charAt(index) == 'T'){
                return true;
            }
            index -= jump;
        }
        return false;
    }

}


 import java.util.*;

public class TestClass {
    public static void main(String args[] ) throws Exception {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();

        String s=sc.next();
        int obs=-1,T=-1,G=-1;
        int pos_t=-1,pos_g=-1;
        for(int i=0;i<s.length();i++){
            if(s.charAt(i)=='T'){
                T=i%k;
                pos_t=i;
            }
            if(s.charAt(i)=='G'){
                G=i%k;
                pos_g=i;
            }

        }
        if(T!=G){
            System.out.println("NO");
        }
        else if(Math.abs(pos_t-pos_g)==k){
        		System.out.println("YES");
        }else{
            int flag=0;
            int flag_1=0;
            for(int i=0;i<s.length();i++){
            if(s.charAt(i)=='#'){
                obs=i%k;
            }
            if(obs==T || obs==G){
                flag=1;
                break;
            }
            if(pos_g>pos_t){
            if(i>pos_g&&i<pos_t){
            	flag_1=1;
            }
            }else{
if(i<pos_g&&i>pos_t){
            	flag_1=1;
            }
            }

        }
        if(flag_1==0){
        	 System.out.println("YES");
        }
        else if(flag==1){
            System.out.println("NO");
        }else{
            System.out.println("YES");
        }

        }
            }
            }

    }
}


import java.util.Scanner;
import java.lang.Math;

public class Grasshopper{
public static void main(String[] args) {
    if solve() == true{
        Sytem.out.println("YES");
    } else {
        Sytem.out.println("NO");
    }
    public boolean void solve(){

        Scanner sc = new Scanner(System.in);
        int length = sc.nextInt();
        int jump = sc.nextInt();
        String st = sc.next();
        int g = st.indexOf("G") + 1;
        int t = st.indexOf("T") + 1;
        if((Math.abs(g - t)) % jump != 0){
            return false;
        } else {
            if (g > t){
                for (int i = g; i >= t; i-=jump){
                    if (st.charAt(i) == '#'){
                        return false;
                    } else if (st.charAt(i) == 'T'){
                        return true;
                    }
                }
                return false;
            } else {
                for (int i = g; i <= t; i+=jump){
                    if (st.charAt(i) == '#'){
                        return false;
                    } else if (st.charAt(i) == 'T'){
                        return true;
                    }
                }
                return false;
            }
        }
    }
}
}


public class Grasshopper {

    import java.util.Scanner;

    public String pathExists() {
        Scanner sc = new Scanner(System.in);
        int totalCells = sc.nextInt();
        int jumpLen = sc.nextInt();
        String path = sc.next();

        //get index of G and index of T
        int indexG = path.indexOf("G");
        int indexT = path.indexOf("T");

        if ((indexG - indexT) % jumpLen != 0) {
            return "NO";
        }

        //look for #'s
        int startInd = indexT > indexG ? indexG : indexT;
        int endInd = indexT > indexG ? indexT : indexG;
        for (int i = startInd; i < endInd; i = i + jumpLen) {
            if (path.charAt(i) == "#") {
                return "NO";
            }
        }

        return "YES";
    }
}


import java.util.*;

/**
 * Timur
 * 20:55  18.04.2018
 */
public class cf {
    private static Scanner sc = new Scanner(System.in);

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

    private static int min(int[] a) {
        int min = Integer.MAX_VALUE;
        for (int i : a) {
            min = min > i ? i : min;
        }
        return min;
    }

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

    private static int max(int[] a) {
        int max = Integer.MIN_VALUE;
        for (int i : a) {
            max = max < i ? i : max;
        }
        return max;
    }

    private static void in(int[] a) {
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
        }
    }

    private static void out(int[] a) {
        for (int i : a) {
            System.out.print(i + " ");
        }
        System.out.println();
    }

    private static String dop(int a){
        String s="";
        for(int i=0;i<5-String.valueOf(a).length();i++){
            s+='0';
        }
        s+=a;
        return s;
    }

    public static void main(String[] args) {
        String s = sc.next();
        int a = Integer.parseInt(s.charAt(0) + "" + s.charAt(2) + "" +
                s.charAt(4) + "" + s.charAt(3) + "" + s.charAt(1));
        long ans=a;
        for (int i = 0; i < 4; i++) {
            ans *= a;
            ans = ans % 100000;
        }
        System.out.println(dop(ans));
    }
}


import java.util.Scanner;
public class Main{
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    // ab c de
    int a = n/10000;
    int b = n/1000 - a*10;
    int c = (n%1000)/100;
    int d = (n%100)/10;
    int e = n%10;
    int a1 = a;
    int b1 = c;
    int c1 = e;
    int d1 = d;
    int e1 = b;
    int n1 =a1*10000 + b1*1000 + c1*100 + d1*10 + e1;
    long z2 = (1L*n1*n1)%100000;
    long z3 = (z2*n1)%100000;
    long z4 = (z3*n1)%100000;
    long z5 = (z4*n1)%100000;
    for (int k=1;z5*k<10000;k*10){
        System.out.println(0);
    }
    System.out.println(z5);
  }
}


import java.util.Scanner;
public class Main{
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    // ab c de
    int a = n/10000;
    int b = n/1000 - a*10;
    int c = (n%1000)/100;
    int d = (n%100)/10;
    int e = n%10;
    int a1 = a;
    int b1 = c;
    int c1 = e;
    int d1 = d;
    int e1 = b;
    int n1 =a1*10000 + b1*1000 + c1*100 + d1*10 + e1;
    long z2 = (1L*n1*n1)%100000;
    long z3 = (z2*n1)%100000;
    long z4 = (z3*n1)%100000;
    long z5 = (z4*n1)%100000;
    if (z5==0){
      System.out.println(00000);
    }else{
      for (int k=1;z5*k<10000;k*10){
          System.out.println(0);
      }
    }
    System.out.println(z5);
  }
}


import java.util.Scanner;
public class Code{
   public static void main(String[] args){
      Scanner scan = new Scanner(System.in);
      int n = scan.nextInt();
      int d1 = n / 10000;
      int d2 = n / 1000 % 10;
      int d3 = n / 100 % 10;
      int d4 = n / 10 % 10;
      int d5 = n % 10
      long p = d1*10000+d3*1000+d5*100+d4*10+d2;
      final int c = 100000;
      int r = (int)(p * p % c * p % c * p % c * p % c);
      int rd1 = r / 10000;
      int rd2 = r / 1000 % 10;
      int rd3 = r / 100 % 10;
      int rd4 = r / 10 % 10;
      int rd5 = r % 10;
      System.out.println("" + rd1 + rd2 + rd3 + rd4 + rd5);
   }
}


import java.util.*;
public class Solution
{
    Scanner sc=new Scanner(System.in);
    int[] coins={1,5,10,20,100};
    int amount=sc.nextInt();
    long[][] dp=new long[coins.length][amount+1];
   // Arrays.fill(dp,amount+1);
    for(int j=0;j<=amount;j++)
    {
        for(int i=0;i<coins.length;i++)
        {
            if(coins[i]<=j)
            {
                dp[i][j]=Math.min(dp[i-1][j],dp[i][j-coins[i]])+1;
            }
            else
            {
                break;
            }
        }
    }
    System.out.println(dp[coins.length-1][amount]>amount ? -1 : dp[coins.length-1][amount])

}


import java.util.*;
import java.io.*;
public class Solution{
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static int[] arr = {100, 20, 10, 5, 1};
    static String next(){
         while(st == null || !st.hasMoreElements()){
             try{
                 st = new StringTokenizer(br.readLine().trim())

             }
             catch(Exception e){
                 e.printStackTrace();
             }
         }
        return st.nextToken();
    }

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

    public static void main(String argh[]){
       long num = 0, count = 0;
       num = nextLong();
       int i = 0;
       while(true){
           if(num > arr[i])
             {
                 count++;
                 num -= arr[i];
             }
           else if(num <= 0)break;
             else i ++;
       }

       System.out.println(count);
    }

}


public class one {
	public static void main(String [] args) throws NumberFormatException{
		Scanner sc = new Scanner(System.in);
		int  t = sc.nextInt();
		if(t == 1) {
			System.out.println("1");
		}
		int arr[] = new int[4];
		arr[0] = 100;
		arr[1] = 20;
		arr[2] = 5;
		arr[3] = 1;
		int num = t,rem = 0;
		int i = 0,count = 0,j = 0;;
		while(num > 0 && i < 4) {
			if(num >= arr[i] && j == 0	) {
				rem = num % arr[i];
				num /= arr[i];
				count += num;
				j++;
			}
			else  if(j > 0  && rem >= arr[i]) {
				num = rem / arr[i];
				rem = rem % arr[i];
				count += num;
			}
			else {
				i++;
			}
		}
		System.out.println(count);
	}
}


import java.util.*;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main{
   public static void main(String args[]) throws Exception
   {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      long n = Long.parseLong(br.readLine().trim().split("\\s+"));
      System.out.println(dp_lottery(n));
   }
   public static long dp_lottery(long n)
   {
      long count=0;
      while(n!=0)
      {
         if(n>=100)
         {
            n=n-100;
            count++;
         }
         else if(n>=20)
         {
            n=n-20;
            count++;
         }
         else if(n>=10)
         {
            n=n-10;
            count++;
         }
         else if(n>=5)
         {
            n=n-5;
            count++;
         }
         else
         {
            n=n-1;
            count++;
         }
      }
      return count;
   }
}


import java.util.Scanner;

public class Code_7luogu三角形CF6A {
	static boolean[] vis = new boolean[4];
	static String str = "";
	static int[] flag = new int[3];
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] res = new int[4];
		for(int i = 0; i < 4; i++) {
			res[i] = scan.nextInt();
		}
		for(int i = 0; i < 4; i++) {
			for(int j = 0; j < 4 && j != i; j++) {
				for(int k = 0; k < 4 && k != i && k != j; k++) {
					if(res[i]+res[j]>res[k]&&res[i]+res[k]>res[j]&&res[k]+res[j]>res[i]) {
						System.out.println("TRIANGLE");
						return ;
					}
				}
			}
		}
		for(int i = 0; i < 4; i++) {
			for(int j = 0; j < 4 && j != i; j++) {
				for(int k = 0; j < 4 && k != i && k != j; k++) {
					if(res[i]+res[j]>=res[k]&&res[i]+res[k]>=res[j]&&res[k]+res[j]>=res[i]) {
						System.out.println("SEGMENT");
						return ;
					}
				}
			}
		}
		System.out.println("IMPOSSIBLE");
//		for(int i = 0; i < 4; i++) {
//			res[i] = scan.nextInt();
//		}
//		for(int i = 0; i < 4; i++) {
//			vis[i] = true;
//			if(flag[0] > 0) {
//				System.out.println("TRIANGLE");
//				System.exit(0);
//			}
//			dfs(i, res);
//			vis[i] = false;
//		}
//		if(flag[0] > 0) {
//			System.out.println("TRIANGLE");
//			System.exit(0);
//		}else if(flag[0] ==0 && flag[1] > 0) {
//			System.out.println("SEGMENT");
//			System.exit(0);
//		}else {
//			System.out.println("IMPOSSIBLE");
//			System.exit(0);
//		}
		scan.close();
	}
}


import java.util.*;
public class Main{
    public static void main(String [] args){
        Scanner sca = new Scanner (System.in);
        int [] a = new int [5];
        int [] pd = new int [5];
        int [] c = new int [3];
        int t=0;
        for(int i=1;i<5;i++){
            a[i] = sca.nextInt();
        }
        dfs(a , 1 , pd , c , o);
        if(t==1){
            System.out.println("TRIANGLE");
        }else if(t==2){
             System.out.println("SEGMENT");
        }else{
              System.out.println("IMPOSSIBLE");
        }
        }
    }
    //结果判断
    //0为第一种情况
    //1,2 , int t){
        //截止条件
    static void dfs(int []a , int index , int []pd , int []c,int o)
        if(index == 4){
            if(c[0]+c[1]>c[2]&&c[1]+c[2]>c[0]&&>c[0]+c[2]>c[1]){
                t=1;
            }else if(c[0]+c[1]>=c[2]&&c[1]+c[2]>=c[0]&&>c[0]+c[2]>=c[1]&&t!=1){
                t=2;
            }
        }

        for(int i=1;i<5;i++){
            int k = a[i];
            if(pd[i]==0){
                pd[i]=1;
                c[o] = k;
                dfs(a,index+1,pd,c,o+1)
                pd[i]=0;
            }
        }
    }
}


import java.util.*;
public class 6A_Triangle{
    public static void main(String args[]){

    }
}


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

public class Main{
    public static void main (String[] args){
        Scanner sc=new Scanner(System.in);
        ArrayList<Integer> a=new ArrayList<>();
        a.add(sc.nextInt());
        a.add(sc.nextInt());
        a.add(sc.nextInt());
        a.add(sc.nextInt());
        Collections.sort(a);
        String res;
        if (a.get(3)>a.get(2)+a.get(1))
        	if (a.get(2)>a.get(1)+a.get(0))
        		System.out.prinlnt("IMPOSSIBLE");
        	else
        		if (a.get(2)==a.get(1)+a.get(0))
        			System.out.println("SEGMENT");
        		else
        			System.out.println("TRIANGLE");
        else
        	if(a.get(3)==a.get(2)+a.get(1))
        		if(a.get(2)>a.get(1)+a.get(0))
        			System.out.println("SEGMENT");
        		else
        			System.out.println("TRIANGLE");
        	else
        		System.out.println("TRIANGLE");

}}


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

public class A {
    public static void main(String[] args) throws Exception {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        String s=br.readLine();
        String t=br.readLine();
        int si=0,ti=0;
        int ma=0,ct=0;
        while(si<s.length()) {
            if((ti<t.length) && (s.charAt(si)==t.charAt(ti))) {
                ma=Math.max(ma,ct);
                ti++;
                ct=0;
            }
            else
                ct++;
            si++;
        }
        pw.println(Math.max(ma,ct));
        br.close();
        pw.close();
    }
}


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

public class A {
    public static void main(String[] args) throws Exception {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        String s=br.readLine();
        String t=br.readLine();
        int si=0,sj=0;
        int ma=0,ct=0;
        while((si<s.length()) && (ti<t.length())) {
            if(s.charAt(si)==t.charAt(ti)) {
                ma=Math.max(ma,ct);
                ti++;
                ct=0;
            }
            else
                ct++;
            si++;
        }
        pw.println(Math.max(ma,ct));
        br.close();
        pw.close();
    }
}