import java.io.*;
import java.util.StringTokenizer;
public class APrank {
	/**
	 * @param args
	 * @throws IOException
	 * @throws InterruptedException
	 */
	public static void main(String[] args) throws IOException, InterruptedException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int []a=new int [n];
		StringTokenizer st = new StringTokenizer(br.readLine());
		for(int i=0;st.hasMoreTokens();i++)
			a[i]=Integer.parseInt(st.nextToken());
		if(a[n-1]==n)
			System.out.println(n-1);
		else
		{
			int len=n;
			int srt=0;
			int end=n;
			int max=0;
			int saver=0;
			int tmp=0;
			while(true)
			{	 max=0;
				boolean flag=true;
				for(int i=srt+1;i<end;i++)
				{
					if(a[i]-a[i-1]!=1)
						{
							flag=false;
						}
					saver=i;
				}
				if(flag)
				{
					max=len-2;
				//	System.out.println(saver);
					if(n>1)
						if(a[saver]==1000)
							max++;
					if(n>1)
						if(a[srt+1]==2)
							max++;
					if(max>tmp)
						tmp=max;

				}
				if(end==n)
				{
					len--;
					srt=0;
					end=len;
					if(len==1)
						break;
				}
				else
				{
					srt++;
					end++;
				}
			}
		System.out.println(tmp>=0?tmp:0);
		}
	}
}


package Demo;

import java.util.Scanner;

public class Test {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);
		String Word = input.next();
		int Length = Word.length();
		int i=0;

		for(i=0;i<Length;i++)
		{
			Character modified = Character.toLowerCase(Word.charAt(i));

			if(modified != 'a' && modified != 'i'&& modified != 'y' && modified != 'o' && modified != 'u' &&modified != 'e')
			{
				System.out.print('.');
				System.out.print(modified);

			}
		}

	}

}


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

public class main{

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

        try{
            String s = br.readLine();

            s = s.toLowerCase();
            StringBuilder sb=new StringBuilder(s);

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

                if(sb.charAt(i) == 'a' || sb.charAt(i) == 'e' || sb.charAt(i) == 'i' || sb.charAt(i) == 'o' || sb.charAt(i) == 'u')
                            sb.delete(i,i);

            }

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

                sb.insert(j,".");

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

        }catch(IOException e){

        }
    }
}


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

public class A {
    private void solve() throws IOException {
        String s = reader.readLine();
        s = s.toLowerCase();
        StringBuilder sb = new StringBuilder(s);
        for (int i = 0; i < sb.length(); i++) {
            if (sb.charAt(i) == 'a' || sb.charAt(i) == 'i' || sb.charAt(i) == 'e' || sb.charAt(i) == 'o' || sb.charAt(i)=='u') {
                sb.deleteCharAt(i);
                i = -1;
            }
        }

        for (int i = 0; i < sb.length(); i++)
            System.out.print("." + sb.charAt(i));
        System.out.println();
    }

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

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

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

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

    long[] readLongArray(int size) throws IOException {
        long[] res = new long[size];
        for (int i = 0; i < size; i++) {
            res[i] = nextLong();
        }
        return res;
    }

    double[] readDoubleArray(int size) throws IOException {
        double[] res = new double[size];
        for (int i = 0; i < size; i++) {
            res[i] = nextDouble();
        }
        return res;
    }

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

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

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

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

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


import java.util.Scanner;

public class StringTask {
	static String vowel = "aioue";

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String bd = sc.nextLine().toLowerCase();
		char[] array = bd.toCharArray();
		StringBuilder ans = new StringBuilder("");

		for (int i = 0; i < array.length; i++) {
			if (!vowel.contains(array[i] + "")) {
				ans.append("." + array[i]);
			}
		}
		System.out.println(ans);
	}
}


/*package whatever //do not write package name here */

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

public class GFG {

	public static void main (String[] args) {
		Scanner s=new Scanner(System.in);
		int l=s.nextInt();
		int r=s.nextInt();
		int a=s.nextInt();
		while(a!=0)
		{
		    if(l<r)
		    {
		      l++;
		      a--;
		    }
		    else if(l==r)
		    {
		        l++;
		        r++;
		        a=a-2;
                        if(a==1)
                          break;
		    }
		    else if(r<l)
		    {
		        r++;
		        a--;
		    }
		}
		if(l==r)
		System.out.print(l+r);
		  else if(r>l)
		System.out.print(2*(l+a));
		  else if(r<l)
		System.out.print(2*(r+a));
	}
}


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

public class Main {

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

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer stk = new StringTokenizer(in.readLine());

        int[] arr = new int[3];
        for (int i = 0; i < 3; i++) {
            arr[i] = Integer.parseInt(stk.nextToken());
        }
        int ans = 0, min = 0;
        min = Math.min(arr[0], arr[1]);

        ans += min * 2;
        arr[0] -= min;
        arr[1] -= min;

        while (arr[2] != 0 || arr[2] != 1) {
            if (arr[0] == 0 && arr[1] == 0) {
                int c = arr[2] / 2;
                ans += c * 2;
                break;
            } else if (arr[0] == 0) {
                min = Integer.min(arr[1], arr[2]);
                ans += min * 2;
                arr[2] -= min;
                arr[1] -= min;
            } else if (arr[1] == 0) {
                min = Integer.min(arr[0], arr[2]);
                ans += min * 2;
                arr[2] -= min;
                arr[0] -= min;
            }
        }
        System.out.println(ans);
    }
}


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

/**
 *
 * @author silver
 */
public class JavaApplication1 {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

        String l[] = in.readLine().split(" ");
        int I = Integer.parseInt(l[0]);
        int D = Integer.parseInt(l[1]);
        int A = Integer.parseInt(l[2]);
        int aux = 0;
        if ((I == 0 || D == 0) && A == 0) {
            out.write("0\n");
            out.flush();
        } else {
            if (I == D) {
                out.write(String.valueOf(2 * (I + A / 2)) + "\n");
                out.flush();
            } else {
                while (I != D || A != 0) {

                    if (I < D) {
                        I++;
                        A--;
                    } else {
                        D++;
                        A--;
                    }
                    if (I <= D) {
                        aux = I;
                    } else {
                        aux = D;
                    }
                }
                if (A == 0) {
                    out.write(String.valueOf(2 * aux)+"\n");
                    out.flush();
                } else {
                    out.write(String.valueOf(2 * (aux + A / 2))+"\n");
                    out.flush();
                }

            }

        }

        in.close();

    }
}


/*package whatever //do not write package name here */

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

public class GFG {

	public static void main (String[] args) {
		Scanner s=new Scanner(System.in);
		int l=s.nextInt();
		int r=s.nextInt();
		int a=s.nextInt();
		while(a!=1)
		{
		    if(l<r)
		    {
		      l++;
		      a--;

		    }
		    else if(l==r)
		    {
		        l++;
		        r++;
		        a=a-2;

		    }
		    else if(r<l)
		    {
		        r++;
		        a--;
		    }
		}
		if(l==r)
		System.out.print(l+r);
		  else if(l<r)
		System.out.print(2*(l+a));
		  else if(r>l)
		System.out.print(2*(r+a));
	}
}


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

public class b1 {
	public static void main(String[] args) throws FileNotFoundException {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = in.nextInt();

		int a[] = new int[n];

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

		Arrays.sort(a);

		long ans = 0;
		long cur = a[n - 1] + 1;

		for (int i = n - 1; i > -1; i--) {
			if (cur > a[i]){
				cur = a[i];
			}
			else{
				cur--;
			}

			ans += cur;
		}

		out.println(ans);
		out.close();
	}
}


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

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

    static class TaskB {
        public void solve(int testNumber, FastInputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }

            Arrays.sort(a);
            long ans = a[n - 1];
            for (int i = n - 2; i >= 0; i--) {
                int min = Math.min(a[i], a[i + 1] - 1);
                ans += min;
                a[i] = min;
            }
            out.println(ans);
        }

    }

    static class FastInputReader {
        static InputStream is;
        static private byte[] buffer;
        static private int lenbuf;
        static private int ptrbuf;

        public FastInputReader(InputStream stream) {
            is = stream;
            buffer = new byte[1024];
            lenbuf = 0;
            ptrbuf = 0;
        }

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

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

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

    }
}


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

public class Main {
	public static void main(String[] args)throws IOException{
		PrintWriter pw = new PrintWriter(System.out);
        InputReader in = new InputReader(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++){
        	a[i] = in.nextInt();
        }

        Arrays.sort(a);
        long sum = a[n-1];
        int last = a[n-1];
        for(int i=n-2;i>=0;i--){
        	while(a[i]>=last){
        		a[i]--;
        	}
        	last = a[i];
        	sum+=a[i];
        	if(last==1){
        		break;
        	}

        }

        pw.println(sum);
        pw.close();
	}

static class InputReader {

		private InputStream stream;
		private byte[] buf = new byte[8192];
		private int curChar;
		private int snumChars;
		private SpaceCharFilter filter;

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

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

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}

			int res = 0;

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

			return res * sgn;
		}

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

			long res = 0;

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

			return res * sgn;
		}

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

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

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


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

/**
 * Created by mohannadhassan on 2/4/16.
 */
public class MakingString {

    public static void main(String [] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] input = br.readLine().split(" ");

        int []array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = Integer.parseInt(input[i]);
        }

        java.util.Arrays.sort(array);

        long total = array[n - 1];
        int max = array[n - 1];

        for (int i = n - 2; i >= 0; i--) {
            int num;
            if (array[i] < max)
                num = array[i];
            else
                num = max - 1;
            total += num;
            max = num;
        }

        System.out.println(total);
    }
}


import java.util.Scanner;

public class coder {

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

		int m = in.nextInt();
		int s = in.nextInt();

		if(s == 0 && m != 1 || s > 9*m){
			System.out.println(-1 + " " + -1);
		}else if(m == 1 && s > 9){
			System.out.println(0 + " "+0);
		}else{
			String min = "";
			String max = "";
			int t = 0;
			int n =s;

			while(s >= 9){
				max = max +'9';
				s -= 9;
				t++;
			}

			if(t < m){
				max += (char)(s%10 + '0');
				t++;
			}

			while(t < m){
				max = max +'0';
				t++;
			}

			t =0;
			s = n;
			while(s >= 9){
				min = '9' + min;
				s -= 9;
				t++;

			}

			if(t < m){
				min = (char)(s%10 + '0') + min;
				t++;
			}

			while(t < m){
				min = '0'+min;
				t++;
			}

			if(min.charAt(0) == '0'){

				int k = 1;
				if(k < m){
					while(k < m && min.charAt(k) == '0'){
						k++;
					}

					String temp = min.substring(1,k);
					String tem2 = min.substring(k+1);

					min = '1' + temp + (char)(min.charAt(k)-1) + tem2;
				}

			}

			System.out.println(min + " " + max);

		}
	}
}


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

public class Solution {

    public static void main(String args[]){

        Scanner scn = new Scanner(System.in);
        int m = scn.nextInt();
        int s = scn.nextInt();

        // long mnum = 0;
        StringBuilder mnum = new StringBuilder();
        int sum = s;
        ArrayList<Integer> list = new ArrayList<>();

        while(sum > 0){
            for(int i = 9 ; i >= 0 ; i--){
                if(sum - i >= 0){
                    list.add(i);
                    sum-= i;
                    break;
                }
            }
        }

        if(list.size() == 0 || list.get(0) == 0){
            if(m == 0){
                System.out.println(0 + " " + 0);
                return;
            }
            else{
                System.out.println(-1 + " " + -1);
                return;
            }
        }

        while(list.size() != m){
            list.add(0);
        }

        for(int i : list){
            // mnum = mnum * 10 + i;
            // System.out.println(i);
            mnum.append(i);
        }
        // long minnum = 0;
        StringBuilder minnum = new StringBuilder();
        if(list.get(list.size() - 1) != 0){
            for(int i = list.size() - 1 ; i >= 0 ; i--){
                // minnum = minnum * 10 + list.get(i);
                minnum.append(list.get(i));
            }
        }else{
            for(int i = list.size() - 1 ; i>= 0 ; i--){
                if(list.get(i) > 0){
                    list.set(i , list.get(i) - 1);
                    break;
                }
            }

            minnum.append(1);
            for(int i = list.size() - 2 ; i >= 0 ; i--){
                // minnum = minnum*10 + list.get(i);
                minnum.append(list.get(i));
            }
        }

        System.out.println(minnum +" " +  mnum);

    }
}


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

public class Solution4 {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int m = in.nextInt(); //length
        int s = in.nextInt(); //sum
        int[] abb = new int[10];
        if(s == 0 && m == 1){
            System.out.println("0 0");
            return;
        }
        else if(s == 0 && m > 1){
            System.out.println("-1 -1");
            return;
        }
        StringBuilder a = new StringBuilder();
        StringBuilder w = new StringBuilder();
        while(s != 0 || a.length() != m){
            if(s >= 9){
                a.append("9");
                s-=9;
                abb[9]++;
                continue;
            }
            else if(s < 9 && s >= 0){
                a.append(s);
                w.append(s);
                abb[s]++;
                s = 0;
                continue;
            }
            else{
                a.append("0");
                w.append("0");
                abb[0]++;
            }
        }
        String largest = a.toString();
        for(int i = 0; i < abb[9]; i++){
            w.append(9);
        }
        System.out.println(w + " " + largest);

    }
}


import java.util.*;
public class GivenLengthAndSumDigit {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int s=sc.nextInt();
        StringBuilder sb1=new StringBuilder();
        StringBuilder sb2=new StringBuilder();

        if((s==0 && n!=1) || 9*n<s)
        {
            System.out.println("-1 -1");
            return;
        }
        while(s>=9)
        {
            if(s>=9)
            {
                sb1.append(9);
                sb2.append(9);
                s-=9;
            }
        }
        sb2.append(s);
        int k=n-sb2.length();
        while(k>0)
        {
            sb2.append(0);
            k--;
        }
        if(n-1==sb1.length())
        {
            sb1.append(s);
        }
        else
            sb1.append(s-1);
        int l=n-sb1.length();
        while(l>1)
            sb1.append(0);
        if(l==1)
        {
            sb1.append(1);
        }
        sb1.reverse();
        System.out.println(sb1+" "+sb2);
    }
}


import java.util.Scanner;

public class B {
	static long n;
	static long a;
	static long b;

	static long mi1 = 1;
	static long mi2 = Long.MAX_VALUE;
	static long []memo;

	static long calc(long i, long j) {
		if (6 * n <= (long) ((long) i * j)) {
			if ((long) i * j < (long) mi1 * mi2) {
				mi1 = i;
				mi2 = j;
			}
			return (long)((long)i * j);
		}
		long option1 = calc(i, j + 1);
		long option2 = calc(i + 1, j);
		return Math.min(option1, option2);

	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextLong();
		a = sc.nextLong();
		b = sc.nextLong();
		System.out.println(calc(a, b));
		System.out.println(mi1 + " " + mi2);

	}

}


package olimpiad.B;

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

/**
 * Created by myduomilia on 12.09.14.
 */
public class Main {
    static class FastReadWriteConsole {

        BufferedReader in;
        StringTokenizer tok;
        PrintWriter out;

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

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

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

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

        public String nextString() throws IOException {
            return readToken();
        }

        public void print(Object obj){
            out.print(obj.toString());
        }

        public void close() throws IOException {
            in.close();
            out.close();
        }

    }

    public static void main(String[] args) throws IOException {
        FastReadWriteConsole console = new FastReadWriteConsole();
        long n = console.nextLong() * 6;
        long a = console.nextLong();
        long b = console.nextLong();
        if(b < a){
            long tmp = b;
            b = a;
            a = tmp;
        }
        if(a >= 78000 && b >= 78000){
            console.print(a * b + "\n");
            console.print(a + " " + b);
        }else {
            long ans = 10L * (long)Integer.MAX_VALUE;
            long ansA = 0;
            long ansB = 0;
            for(long i = a; i < 78000; i++){
                long l = b, r = 10L * (long)Integer.MAX_VALUE;
                while (l < r) {
                    long mid = l + (r - l) / 2;
                    if (mid * i >= n) {
                        r = mid;
                    } else {
                        l = mid + 1;
                    }
                }
                for(long j = l - 5; j < l + 5; j++){
                    if(j * i >= n && j * i <= ans && j >= b && i >= a ){
//                        if(j - b == 0 || i - a == 0 || (j - b == i - a)){
                            ans = j * i;
                            ansA = i;
                            ansB = j;
//                        }
                    }
                }
            }
            console.print(ans + "\n");
            console.print(ansA + " " + ansB);
        }
        console.close();

    }
}


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

public class Main {
  // main
  public static void main(String [] args) throws IOException {
    // makes the reader and writer
    BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

    // read in n,a,b
    StringTokenizer st = new StringTokenizer(f.readLine());
    int n = Integer.parseInt(st.nextToken());
    int a = Integer.parseInt(st.nextToken());
    int b = Integer.parseInt(st.nextToken());

    // area already big enough
    if (a*b>=6*n) {
      out.println((long) a*b);
      out.println(a+" "+b);
    } else {
      boolean aBig = true;
      if (a<b) {
        aBig = false;
        int t = a;
        a = b;
        b = t;
      }
      long min = 1<<60;
      int best = 0;
      for (int i=b;i<=Math.sqrt(6*n);i++) {
        if ((6*n-1)/i+1>=a && min>i*((6*n-1)/i+1)) {
          min = i*((6*n-1)/i+1);
          best = i;
        }
      }
      out.println(min);
      if (aBig) out.println(((6*n-1)/best+1)+" "+best);
      else out.println(best+" "+((6*n-1)/best+1));
    }

    // cleanup
    out.close();
    System.exit(0);
  }
}


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

public class Main {
  // main
  public static void main(String [] args) throws IOException {
    // makes the reader and writer
    BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

    // read in n,a,b
    StringTokenizer st = new StringTokenizer(f.readLine());
    long n = Long.parseLong(st.nextToken());
    long a = Long.parseLong(st.nextToken());
    long b = Long.parseLong(st.nextToken());

    // area already big enough
    if (a*b>=6*n) {
      out.println(a*b);
      out.println(a+" "+b);
    } else {
      boolean aBig = true;
      if (a<b) {
        aBig = false;
        long t = a;
        a = b;
        b = t;
      }
      long min = 1<<30;
      long best = 0;
      for (long i=b;i<=Math.sqrt(6*n)+1;i++) {
        if ((6*n-1)/i+1>=a && min>i*((6*n-1)/i+1)) {
          min = i*((6*n-1)/i+1);
          best = i;
        }
      }
      out.println(min);
      if (aBig) out.println(((6*n-1)/best+1)+" "+best);
      else out.println(best+" "+((6*n-1)/best+1));
    }

    // cleanup
    out.close();
    System.exit(0);
  }
}


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

import static java.lang.Math.*;

public class Solution implements Runnable {

	final String fname = "";

	public void solve() throws Exception {
		int n = nextInt();
		int m = nextInt();
		int count [] = new int [2];
		int ret = max (n , m);
		for (int i = 0; i < n; i++) {
			int start = 1;
			if (i % 2 == 0) start = 0;
			for (int j = 0; j < m; j++) {
				count [start]++;
				start ^= 1;
			}
		}
		ret = max (ret, max(count[0], count[1]));
		out.println(ret);
	}

	/********************************************************************************************/
	/* THERE IS INPUT */

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st;

	long stime=0;

	private String next() throws Exception {
		while (st == null || !st.hasMoreElements())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

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

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

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

	public void run() {
		try {
			//Locale.setDefault(Locale.US);
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));
			//in = new BufferedReader(new FileReader(fname+".in"));
			//out = new PrintWriter(new FileWriter(fname+".out"));
			solve();
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) throws Exception {
		new Thread(null, new Solution(), "", 1 << 25).start();
	}

}


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

public class HelpGeneral { //Round #102 - Help General
	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedInputStream(System.in));

		int numRows = sc.nextInt();
		int numCols = sc.nextInt();

		long horizontal = numCols * (numRows / 4 + 1);
		long vertical = numRows * (numCols / 4 + 1);

		long numRowsHalf = numRows / 2;
		long numColsHalf = numCols / 2;

		long other = (numRows - numRowsHalf) * (numCols - numColsHalf) + numRowsHalf * numColsHalf;

		//System.out.println(horizontal + " " + vertical + " " + other);

		System.out.println(Math.max(Math.max(horizontal, vertical), other));
	}
}


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

public class TaskB {
	void Run() throws IOException {
		int n=ReadInt(), m=ReadInt();
		if(n>=m) {
			int x=n;
			n=m;
			m=x;
		}
		if(n==1) {
			output.println(m);
			return;
		}
		if(n==2) {
			output.println(Math.max(4, m));
			return;
		}
		if(n%2==0 || m%2==0) {
			output.println(n*m/2);
			return;
		}
		output.println(n*m/2+1);
	}

	public static void main(String[] args) throws IOException {
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		Reader reader;
		reader=oj ? new InputStreamReader(System.in) : new FileReader("input.txt");
		input=new BufferedReader(reader);
		Writer writer=new OutputStreamWriter(System.out);
		writer=new BufferedWriter(writer);
		output=new PrintWriter(writer);
		new TaskB().Run();
		output.close();
	}

	static int ReadInt() throws IOException {
		return Integer.parseInt(ReadString());
	}

	static long ReadLong() throws IOException {
		return Long.parseLong(ReadString());
	}

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

	static StringTokenizer tokenizer;
	static BufferedReader input;
	static PrintWriter output;
}


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

import static java.lang.Math.*;

public class B implements Runnable{

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException{
        if (ONLINE_JUDGE){
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }else{
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException{
        while(!tok.hasMoreTokens()){
            try{
                tok = new StringTokenizer(in.readLine());
            }catch (Exception e){
                return null;
            }
        }
        return tok.nextToken();
    }

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

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

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

    public static void main(String[] args){
        new Thread(null, new B(), "", 256 * (1L << 20)).start();
    }

    long timeBegin, timeEnd;

    void time(){
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory(){
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10) + " KB");
    }

    void debug(Object... objects){
        if (DEBUG){
            for (Object o: objects){
                System.err.println(o.toString());
            }
        }
    }

    public void run(){
        try{
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().totalMemory();
            init();
            solve();
            out.close();
            time();
            memory();
        }catch (Exception e){
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    boolean DEBUG = false;

    void solve() throws IOException{
        int n = readInt();
        int m = readInt();

        if (n == 1){
            out.print(m);
            return;
        }

        if (m == 1){
            out.print(n);
            return;
        }

        if (n == 2 && m == 2){
            out.print(4);
            return;
        }

        int count = n * m + (n * m) % 2;
        out.print(count / 2);
    }
}


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

public class CF746A {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int m = Integer.parseInt(br.readLine());
		int c = Integer.parseInt(br.readLine());
		int sum = 0;
		int i;
		for (i = 1; i <= n; i++) {
			if(i*2 > m || i*4 > c)
				{
				sum += (i-1)+(i-1)*2+(i-1)*4;
				break;
				}
		}
		System.out.println(sum);
	}
}


import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Scanner;

public class Codeforce {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int sum = 0;
        int target = a;
        boolean hello = false;
        while (target>=1){
            boolean flag = false;
            if(target*4>=c){
                flag = true;
            }
            if(target*2>=b){
                flag = true;
            }
            if(!flag){
                sum+=target+(target*2)+(target*4);
                System.out.println(sum);
                hello = true;
                break;
            }else {
                target--;
            }
        }
       if(!hello){
           System.out.println(0);
       }
    }
}


import java.util.Scanner;

public class MyClass {

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

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if(b >=2 && c >= 4){
            while(b/a!=2 || c/a!=4){
                --a;
                if(a==1){
                    break;
                }
            }
            System.out.println(a+a*2+a*4);
        }
        else{
            System.out.println(0);
        }

    }
}


import java.util.Scanner;

public class JavaApplication41 {

    public static void main(String[] args) {
       Scanner n=new Scanner(System.in);
       int l=n.nextInt();
       int p=n.nextInt();
       int a=n.nextInt(); int num=0;
       int a2;
      while(l!=0){
          if((l*2)>a||(l*4)>p)
            l--;
      }
          if(((l*2)<=a)&&((l*4)<=p))
            num=l+(l*2)+(l*4);
          else
              num=0;

        System.out.println(num);
    }

}


package codechef;
import java.util.*;
public class contest {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int y=s.nextInt();
		int a=s.nextInt();
		int org=a-1;
		while(y>=org) {
			if(y==org) {
				System.out.println("Yes");
				return;
			}
			org=org+2;
		}
		System.out.println("No");
	}

}


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

public class Coba {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        try {
            String masukan = in.readLine();
            String[] tokens = masukan.split(" ");
            int x = Integer.parseInt(tokens[0]);
            int y = Integer.parseInt(tokens[1]);

            if(hitung(x, y, 1, 0)) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } finally {
            in.close();
        }
    }

    public static boolean hitung(int x, int y, int ori, int copy) {
        if(ori == y && copy == x) return true;
        if(ori > y || copy > x) return false;
        if(copy == 0) {
           return hitung(x, y, ori + 1, copy + 1);
        } else {
            return hitung(x, y,  ori + 1, copy + 1) || hitung(x, y, ori, copy + 2);
        }
    }
}


package Stab;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Vector;
public class Test {

	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt(),y=sc.nextInt();
		if(y<1){System.out.println("No");return;}
		int cpd=y-1;
		if(y==1)cpd++;
		if(cpd<=x&&(x-cpd)%2==0)System.out.println("Yes");
		else System.out.println("No");
	}
}


package codeforces.round.pkg461.div.pkg2;

import java.util.*;

public class TaskA {

    public static void main(String[] args) {
       Scanner input = new Scanner(System.in);
       long c= input.nextInt();
       long o = input.nextInt();
       long numC= o-1;

       if(o==0) System.out.println("No");
       else if(numC==c) System.out.println("Yes");
       else if((numC%2==0 && c%2==0) || (numC%2!=0 && c%2!=0) ) System.out.println("Yes");
       else System.out.println("No");

    }

}


import java.util.Scanner;
public class Test{
    public static void main(String args[]){
        Scanner in=new Scanner(System.in);
        int l=in.nextInt();
        int count=0,flag=0,i=0,j;
        String s=in.next();
            for(j=1;j<l;j++){
                if(s.charAt(i)==s.charAt(j)){
                    count++;
                    flag=1;
                    i--;
                }
                if(flag==1){ flag=0;i=--j;}
                i++;
        }
        System.out.println(count);
    }
}


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) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc=new Scanner(System.in);
        int n=Integer.parseInt(sc.nextLine());
        String s=sc.nextLine();
        char[] a=new char[n];
        for(int i=0;i<n;i++){
            a[i]=s.charAt(i);
        }
        int c=0;
        int l=s.length();
        for(int i=0;i<l-1;i++){
            while(a[i]==a[i+1]){
                for(int j=i+1;j<l-1;j++){
                    a[j]=a[j+1];
                }
                c++;
                l--;
            }
        }
        System.out.println(c);
    }
}


import java.util.Scanner;
public class Test{
    public static void main(String args[]){
        Scanner in=new Scanner(System.in);
        int l=in.nextInt();
        int count=0,flag=0,i=0,j;
        String s=in.next();
            for(j=1;j<l;j++){
                if(s.charAt(i)==s.charAt(j)){
                    count++;
                    System.out.println(s.charAt(i));
                    flag=1;
                    i--;
                }
                if(flag==1){ flag=0;i=--j;}
                i++;
        }
        System.out.println(count);
    }
}


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

public class A {

    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        String line = in.next();
        out.println(cal(0, ' ', line));
        out.close();
    }

    static int cal(int index, char last, String data) {
        if (index == data.length()) {
            return 0;
        }
        char c = data.charAt(index);
        int result = 0;
        if (c != last) {
            result = cal(index + 1, c, data);
            int val = cal(index + 1, last, data) + 1;
            result = Math.min(result, val);
        } else {
            result = 1 + cal(index + 1, last, data);
        }
        return result;
    }

    static class Point {

        int x, y;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;

        }
    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    static class FT {

        int[] data;

        FT(int n) {
            data = new int[n];
        }

        void update(int index, int val) {
            // System.out.println("UPDATE INDEX " + index);
            while (index < data.length) {
                data[index] += val;
                index += index & (-index);

                //    System.out.println("NEXT " +index);
            }
        }

        int get(int index) {
            //  System.out.println("GET INDEX " + index);
            int result = 0;
            while (index > 0) {
                result += data[index];
                index -= index & (-index);
                // System.out.println("BACK " + index);
            }
            return result;
        }
    }

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

    static int pow(int a, int b) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        int val = pow(a, b / 2);
        if (b % 2 == 0) {

            return val * val;
        } else {
            return val * val * a;
        }
    }

//    static Point intersect(Point a, Point b, Point c) {
//        double D = cross(a, b);
//        if (D != 0) {
//            return new Point(cross(c, b) / D, cross(a, c) / D);
//        }
//        return null;
//    }
//
//    static Point convert(Point a, double angle) {
//        double x = a.x * cos(angle) - a.y * sin(angle);
//        double y = a.x * sin(angle) + a.y * cos(angle);
//        return new Point(x, y);
//    }
//    static Point minus(Point a, Point b) {
//        return new Point(a.x - b.x, a.y - b.y);
//    }
//
//    static Point add(Point a, Point b) {
//        return new Point(a.x + b.x, a.y + b.y);
//    }
//
//    static double cross(Point a, Point b) {
//        return a.x * b.y - a.y * b.x;
//
//
//    }
//
//    static class Point {
//
//        int x, y;
//
//        Point(int x, int y) {
//            this.x = x;
//            this.y = y;
//        }
//
//        @Override
//        public String toString() {
//            return "Point: " + x + " " + y;
//        }
//    }
    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            //System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            // br = new BufferedReader(new FileReader(new File("input.txt")));
        }

        public String next() {

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

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

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

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

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}


package com.company;

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

public class Main {

    public static void main(String[] args) throws IOException {
            Scanner in = new Scanner(System.in);
            BigInteger input = in.nextBigInteger();
            in.close();
            BigInteger div7 = input.divide(BigInteger.valueOf(7L));
            BigInteger mod7 = input.mod(BigInteger.valueOf(7L));
            BigInteger minimum = div7.multiply(BigInteger.valueOf(2L));
            BigInteger maximum = BigInteger.valueOf(minimum.longValue());
            if(mod7.equals(BigInteger.ZERO)) {
                System.out.println(minimum+" "+ minimum);
            } else {
                maximum = maximum.add(BigInteger.ONE);

                if (mod7.compareTo(BigInteger.ONE) == 1) {
                    maximum = maximum.add(BigInteger.ONE);
                }
                System.out.println(minimum + " " + maximum);
            }

    }
}


package com.company;

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

public class Main {

    public static void main(String[] args) {
        try {
            Scanner in = new Scanner(System.in);
            BigInteger input = in.nextBigInteger();
            BigInteger div7 = input.divide(BigInteger.valueOf(7L));
            BigInteger mod7 = input.mod(BigInteger.valueOf(7L));
            BigInteger minimum = div7.multiply(BigInteger.valueOf(2L));
            BigInteger maximum = BigInteger.valueOf(minimum.longValue());
            if(mod7.equals(BigInteger.ZERO)) {
                System.out.println(minimum+" "+ minimum);
                return;
            }
            maximum=maximum.add(BigInteger.ONE);

            if(mod7.compareTo(BigInteger.ONE)==1) {
                maximum=maximum.add(BigInteger.ONE);
            }
            System.out.println(minimum+" "+ maximum);
        }catch(Exception e) {
            return;
        }

    }
}


package com.company;

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

public class Lain {

    public static void main(String[] args) throws IOException {
            Scanner in = new Scanner(System.in);
            String inputStr = in.nextLine();
            BigInteger input = new BigInteger("14");
            BigInteger div7 = input.divide(BigInteger.valueOf(7L));
            BigInteger mod7 = input.mod(BigInteger.valueOf(7L));
            BigInteger minimum = div7.multiply(BigInteger.valueOf(2L));
            BigInteger maximum = BigInteger.valueOf(minimum.longValue());
            if(mod7.equals(BigInteger.ZERO)) {
                System.out.println(minimum+" "+ minimum);
            } else {
                maximum = maximum.add(BigInteger.ONE);

                if (mod7.compareTo(BigInteger.ONE) == 1) {
                    maximum = maximum.add(BigInteger.ONE);
                }
                System.out.println(minimum + " " + maximum);
            }
        in.close();

    }
}


package com.company;

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

public class Main {

    public static void main(String[] args) throws IOException {
            Scanner in = new Scanner(System.in);
            String inputStr = in.nextLine();
            System.out.println("|" +inputStr +"|");
            BigInteger input = new BigInteger(inputStr);
            in.close();
            BigInteger div7 = input.divide(BigInteger.valueOf(7L));
            BigInteger mod7 = input.mod(BigInteger.valueOf(7L));
            BigInteger minimum = div7.multiply(BigInteger.valueOf(2L));
            BigInteger maximum = BigInteger.valueOf(minimum.longValue());
            if(mod7.equals(BigInteger.ZERO)) {
                System.out.println(minimum+" "+ minimum);
            } else {
                maximum = maximum.add(BigInteger.ONE);

                if (mod7.compareTo(BigInteger.ONE) == 1) {
                    maximum = maximum.add(BigInteger.ONE);
                }
                System.out.println(minimum + " " + maximum);
            }

    }
}


/*
 * #######	   #######       ###### ######
 * #		   #     #		 #	  #	#	 #
 * #		   #	 # 		 #	  #	#	 #
 * #######     #######	 	 #	  ###    #
 *       #     #	 #		 #			 #
 *       #     #	 #		 #			 #
 * #######     #	 #		 #			 #
 *
 */

import java.util.*;

public class henlo {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		long n = in.nextLong();
		long x = n;
		long k = 0;

		while( n > 0) {

			k++;
			x = x / 2;

		}

		System.out.println(k);

		}

	}


import java.util.Scanner;
import java.lang.Math;
public class Main {

    public static void main(String[] args) {
        Scanner newSc = new Scanner(System.in);
        int n = newSc.nextInt();
        int a = 0, j = 0;
        for(int i = 1; i <= n / 2 ; i += 1)
            if(Math.pow(2, j) == i){
                a += 1;
                j += 1;
            }
        System.out.println(a + 1);
    }
}


import java.util.Scanner;
import java.util.HashSet;
public class Packets
{
       public static void main(String args[])
       {
              Scanner sc=new Scanner(System.in);
              int n=sc.nextInt();
              int ans=0,sum=0,temp=1;
              boolean flag=false;
              while(flag!=true)
              {
                     for(int i=1;i<=n;i++)
                     {
                            for(int j=0;j<temp;j++)
                            {
                                   sum=sum+i;
                                   ans++;
                                   if(sum==n)
                                   {
                                          flag=true;
                                          break;
                                   }
                            }
                            if(flag==true)
                                   break;
                     }
                     if(flag==false)
                            ans=0;
                     temp++;
                     sum=0;
              }
              System.out.println(ans);
       }
}


import java.util.Scanner;
import java.util.HashSet;
public class Packets
{
       public static void main(String args[])
       {
              Scanner sc=new Scanner(System.in);
              long n=sc.nextLong();
              long ans=0,sum=0,temp=1;
              boolean flag=false;
              while(flag!=true)
              {
                     for(int i=1;i<=n;i++)
                     {
                            for(int j=0;j<temp;j++)
                            {
                                   sum=sum+i;
                                   ans++;
                                   if(sum==n)
                                   {
                                          flag=true;
                                          break;
                                   }
                            }
                            if(flag==true)
                                   break;
                     }
                     if(flag==false)
                            ans=0;
                     temp++;
                     sum=0;
              }
              System.out.println(ans);
       }
}


import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;

public class P394ACountingSticks {

    public static void doJob(String line) throws IOException {
        char[] chline = line.toCharArray();
        int sIdx = 0;
        while (chline[++sIdx] != '+');
        int eqIdx = sIdx + 1;
        while (chline[++eqIdx] != '+');

        int l = sIdx;
        int r = eqIdx - l - 1;
        int s = line.length() - eqIdx - 1;

        int diff = Math.abs(l + r - s);
        if (diff == 0) {
            System.out.println(line);
        } else if (diff == 2) {
            if (l + r > s) {
                if (l > r) {
                    print(l - 1, r, s + 1);
                } else {
                    print(l, r - 1, s + 1);
                }
            } else {
                print(l + 1, r, s - 1);
            }
        } else {
            System.out.println("Impossible");
        }

    }

    public static void print(int l, int r, int s) throws IOException {
        OutputStream o = new BufferedOutputStream(System.out);
        for (int i = 0; i < l; i++)
            o.write('|');
        o.write('+');
        for (int i = 0; i < r; i++)
            o.write('|');
        o.write('=');
        for (int i = 0; i < s; i++)
            o.write('|');
        o.write('\n');
        o.flush();
    }

    public static void main(String[] args) throws IOException {
        doJob(readAll(System.in));
    }

    public static String readAll(InputStream stream) throws IOException {
        return new BufferedReader(new InputStreamReader(new BufferedInputStream(stream))).readLine();
    }

    public static void test(String str) throws IOException {
        doJob(readAll(new ByteArrayInputStream(str.getBytes())));
    }

}


package implementation;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Scanner;
import java.lang.Math;

public class A394CountingSticks {
    static String solve(int a, int b, int c)
    {
        double sum = a + b;
        double dif = Math.floor((c - sum)/2);
        String as = new String(new char[a]).replace("\0", "|");
        String bs = new String(new char[(int)(b + dif)]).replace("\0", "|");
        String cs = new String(new char[(int)(c - dif)]).replace("\0", "|");

        return as + '+' + bs + '=' + cs;
    }
    public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
        String equation = s.next();
        int[] abc = new int[3];
        int temp1 = 102, temp2 = 102;
        for (int i = 0; i < equation.length(); i++)
        {
            abc[0]++;
            if (equation.charAt(i) == '+')
                temp1 = i;
            else if (equation.charAt(i) == '=')
                temp2 = i;
            if (i > temp1 && i < temp2)
                abc[1]++;
            else if (i > temp2)
                abc[2]++;
        }
        abc[0] = abc[0] - abc[1] - abc[2] - 2;

        String str = solve(abc[0], abc[1], abc[2]);
        System.out.println(str);
    }
}


import java.util.Scanner;

public class countingSticks{

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String stickEquation=sc.nextLine();
        String[] Parts=stickEquation.split("=");
        if(Parts[0].length() - 1 == Parts[1].length() ){
            System.out.print(stickEquation);
            System.exit(0);
        }
        if(Parts[0].length() +1 != Parts[1].length() || Parts[0].length()>200){
            System.out.print("Impossible");
            System.exit(0);
        }
        String[] Variables=Parts[0].split("+");
        if(Variables[0].length()<100){
            Variables[0]="|"+Variables[0];
        }else{
            Variables[1]="|"+Variables[1];
        }
        Parts[1]=Parts[1].substring(1);
        System.out.print(Variables[0]+"+"+Variables[1]+"="+Parts[1]);

    }
}


import java.util.Scanner;

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

        String x = input.nextLine();
        int a = 0,b = 0,c = 0;
        for (int i = 0; i < x.length(); i++) {
            if(x.charAt(i) == '|'){
                a++;
            }else if(x.charAt(i) == '+'){
                b = a;
            }else if(x.charAt(i) == '='){
                c = a-b;
            }
        }

        a = a -b -c;

        while(a != b + c){
            if(a < b+c){
                a++;
                b--;
            }else{
                a--;
                b++;
            }
        }

        if(a != b + c){
            System.out.println("Impossible");
        }else if(a == b+c){
            for (int i = 0; i <= a+b+c +1; i++) {
                if(i < b)
                System.out.print("|");
                else if(i == b)
                System.out.print("+");
                else if(i<=b+c)
                System.out.print("|");
                else if(i == b + c + 1)
                System.out.print("=");
                else if(i > b+c)
                System.out.print("|");
            }
        }

    }
}


import java.util.*;
public class flowers{
public static void main(String[] args) {
	Scanner s=new Scanner(System.in);
	int n=s.nextInt();
	int a[]=new int[12];
	int m=-1;
	for(int i=0;i<12;i++){
		a[i]=s.nextInt();
	}
    int ans=0;
    if(n>0){
    	while(n>0){
    		int max=0;
    		for (int i=0;i<12;i++) {
    			if (max<a[i]) {
    				max=a[i];
    				m=i;
    			}
    		}
    		n-=max;
    		a[m]=0;
    		ans++;
    	}
    }

    System.out.println(ans);

}

}


import java.util.Scanner;

public class Businesstrip {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in) ;
		while (sc.hasNext())
		{
			int n = sc.nextInt() ;
			int[] arr = new int[12] ;
			boolean[] bol = new boolean[12] ;
			int counter = 0 ;
			int index = 0 ;
			int max = 0 ;
			for (int i = 0; i < arr.length; i++) {
				arr[i] = sc.nextInt() ;
			}

			while (n > 0) {
				max = 0 ;
				for (int i = 0; i < 12; i++) {
					if (arr[i] > max && !bol[i]) {max = arr[i] ; index = i ;}

				}
				//System.out.println("index : "+arr[index]);
				bol[index] = true ;
				n -= max ;
				counter ++ ;
			}
			System.out.println(counter);
		}
	}

}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Vector;

/**
 *
 * @author Mohammad
 */
public class BusinessTrip {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
try{
    int k=Integer.parseInt(input.readLine());
    if(k>=0 && k<=100)

    {

        String m=input.readLine();
        String mm[]=m.split(" ");
int aa[]=new int [m.length()];
        for(int i=0;i<mm.length;i++)
        {
            aa[i]= Integer.valueOf(mm[i]);
        }
        int sum=0;
        int c=0;
        while(sum<k)
        {

            int max=0;
            int index=0;

            for(int i=0;i<aa.length;i++)
                if(aa[i]>max){
                    max=aa[i];
            index=i;}

            if(index!=-1)
            aa[index]=0;
            sum+=max;
            c++;
        }

             System.out.println(c);

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


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

public class A
{
	String line;
	StringTokenizer inputParser;
	BufferedReader is;
	FileInputStream fstream;
	DataInputStream in;
	String FInput="";

	void openInput(String file)
	{

		if(file==null)is = new BufferedReader(new InputStreamReader(System.in));//stdin
		else
		{
			try{

			fstream = new FileInputStream(file);
			in = new DataInputStream(fstream);
			is = new BufferedReader(new InputStreamReader(in));
			}catch(Exception e)
			{
				System.err.println(e);
			}
		}

	}

	void readNextLine()
	{
		try {
			line = is.readLine();
			inputParser = new StringTokenizer(line, " ");
			//System.err.println("Input: " + line);
		} catch (IOException e) {
			System.err.println("Unexpected IO ERROR: " + e);
		}
		catch (NullPointerException e)
		{
			line=null;

		}

	}

	int NextInt()
	{
		String n = inputParser.nextToken();
		int val = Integer.parseInt(n);

		//System.out.println("I read this number: " + val);
		return val;
	}

	long NextLong()
	{
		String n = inputParser.nextToken();
		long val = Long.parseLong(n);

		//System.out.println("I read this number: " + val);
		return val;
	}

	String NextString()
	{
		String n = inputParser.nextToken();
		return n;
	}

	void closeInput()
	{
		try {
			is.close();
		} catch (IOException e) {
			System.err.println("Unexpected IO ERROR: " + e);
		}

	}

	public static void main(String [] argv)
	{
		String filePath=null;
		if(argv.length>0)filePath=argv[0];
		A a = new A(filePath);
	}

	public void readFInput()
	{
		for(;;)
		{
			try
			{
				readNextLine();
				FInput+=line+" ";
			}
			catch(Exception e)
			{
				break;
			}
		}
		inputParser = new StringTokenizer(FInput, " ");
	}

	public A(String inputFile)
	{
		openInput(inputFile);
		int [] p = new int[12];

		readNextLine();
		int k=NextInt();
		readNextLine();
		for(int i=0; i<12; i++)
			p[i]=NextInt();
		Arrays.sort(p);
		int i=11;

		int ret=0;
		while(ret<k&&i>=0)
		{
			ret+=p[i];
			i--;
		}
		if(i<0)System.out.println(-1);
		else System.out.println(11-i);
        closeInput();
	}

}


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

public class D896 {

	long mod;

	long[][] factorial(int n, Long[] prime) {
		int k = prime.length;
		long[][] f = new long[n+1][k+1];
		f[0][0] = 1L;
		for(int i = 1; i <= n; i++) {
			long cur = i;
			for(int j = 0; j <= k; j++) f[i][j] = f[i-1][j];
			for(int j = 0; j < k; j++) {
				while(cur%prime[j] == 0) {
					cur /= prime[j];
					f[i][j+1]++;
				}
			}
			f[i][0] = (f[i][0] * cur) % mod;
		}
		return f;
	}

	Long[] factors(long p){
		LinkedList<Long> f = new LinkedList<Long>();
		long x = 2;
		while(x*x <= p) {
			long y = 0;
			while(p%x == 0) {
				p /= x;
				y++;
			}
			if(y != 0) f.addLast(x);
			x++;
		}
		if(p != 1) f.addLast(p);
		return f.toArray(new Long[0]);
	}

	long[] euclides(long x, long y) {
		if(y == 0) return new long[] {1L,0L};
		if(x == 0) return new long[] {0L,1L};
		long[] res = euclides(y%x, x);
		long a = res[0];
		long b = res[1];
		return new long[] {(b-a*(y/x)), a};
	}

	long inverse(long x) {
		long[] res = euclides(x, mod);
		long a = res[0];
		return ((a%mod)+mod)%mod;
	}

	long modpow(long m, long n) {
		long res = 1%mod;
		while(n > 0){
			if(n % 2 == 1) res = (res*m)%mod;
			m = (m*m)%mod;
			n = n/2;
		}
		return res;
	}

	long[][] facPrime;
	Long[] prime;
	long[] a0;
	long[] al;
	long[] alnext;
	long[] ar;
	long[] arnext;
	int n;
	int l;
	int r;

	private void solve() throws Exception {
		n = nextInt();
		mod = nextInt();
		l = nextInt();
		r = nextInt();

		prime = factors(mod);
		facPrime = factorial(2*n, prime);
		long[] C = new long[2*n+1];

		for(int i = 0; i <= n; i++) {
			long c = (((facPrime[n][0] * inverse(facPrime[i][0])) % mod) * inverse(facPrime[n-i][0])) % mod;
			for(int j = 0; j < prime.length; j++) {
				c = (c * modpow(prime[j], facPrime[n][j+1] - facPrime[i][j+1] - facPrime[n-i][j+1]))%mod;
			}
			C[i] = c;
		}
		a0 = catalan(n,0);
		al = catalan(n,l-1);
		alnext = catalan(n,l);
		ar = catalan(n,r);
		arnext = catalan(n,r+1);

		long[] br = b(r, ar, arnext);
		long[] bl = b(l-1, al, alnext);

		long res = 0;
		for(int i = 0; i <= n; i++) res = (res + (((br[i]-bl[i]+mod)%mod)*C[i])%mod)%mod;

		out.println(res);
	}

	long[] b(int t, long[] at, long[] atnext) {
		long[] res = new long[n+1];
		if(t >= 0) res[0] = 1;
		for(int i = 1; i <= n; i++) {
			res[i] = (2L * res[i-1])%mod;
			res[i] = (res[i] - ((i-t)%2 == 0 ? 0:at[(i+t)/2]) + mod)%mod;
			res[i] = (res[i] + ((i-(t+1))%2 == 0 ? 0:atnext[(i+t+1)/2]) + mod)%mod;
			res[i] = (res[i] - ((i-0)%2 == 0 ? 0: a0[(i+0)/2]) + mod)%mod;
			if(i >= t) {

			}
		}

		return res;
	}

	long[] catalan(int n, int t) {
		long[] res = new long[n+1];
		if(t < 0) return res;
		for(int i = t; i <= n; i++) {
			res[i] = (((facPrime[2*i-t][0] * inverse(facPrime[i+1][0])) % mod) * inverse(facPrime[i-t][0])) % mod;
			for(int j = 0; j < prime.length; j++) {
				res[i]  = (res[i] * modpow(prime[j], facPrime[2*i-t][j+1] - facPrime[i+1][j+1] - facPrime[i-t][j+1]))%mod;
			}
			res[i] = (res[i]*(t+1))%mod;
		}
		return res;
	}

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

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer tokenizer;

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

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

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

	private float nextFloat() throws IOException {
		return Float.parseFloat(nextToken());
	}

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

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


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Random;
import java.util.Map;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.Set;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.util.Map.Entry;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            TaskD solver = new TaskD();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class TaskD {
        public void solve(int testNumber, FastInput in, FastOutput out) {
            int m = in.readInt();
            int p = in.readInt();
            int l = in.readInt();
            int r = in.readInt();

            ExtLucas lucas = new ExtLucas(p, m);

            IntExtCRT crt = new IntExtCRT();

            for (Map.Entry<Integer, LongCombination> entry : lucas) {
                Modular mod = new Modular(entry.getKey());
                LongCombination comb = entry.getValue();
                long ans = 0;
                for (int n = 0; n <= m; n++) {
                    long a = comb.combination(n, DigitUtils.ceilDiv(n + l, 2));
                    long b = comb.combination(n, DigitUtils.floorDiv(n + r, 2) + 1);
                    long c = comb.combination(m, n);

                    long local = mod.subtract(a, b);
                    local = mod.mul(local, c);
                    ans = mod.plus(ans, local);
                }

                crt.add((int) ans, entry.getKey());
            }

            out.println(crt.getValue());
        }

    }

    static class MillerRabin {
        Modular modular;
        Power power;
        Random random = new Random();

        public boolean mr(int n, int s) {
            if (n <= 1) {
                return false;
            }
            if (n == 2) {
                return true;
            }
            if (n % 2 == 0) {
                return false;
            }
            int m = n - 1;
            while (m % 2 == 0) {
                m /= 2;
            }
            modular = new Modular(n);
            power = new Power(modular);
            for (int i = 0; i < s; i++) {
                int x = random.nextInt(n - 2) + 2;
                if (!mr0(x, n, m)) {
                    return false;
                }
            }
            return true;
        }

        private boolean mr0(int x, int n, int m) {
            return test(power.pow(x, m), m, n);
        }

        private boolean test(int y, int exp, int n) {
            int y2 = modular.mul(y, y);
            if (!(exp == n - 1 || test(y2, exp * 2, n))) {
                return false;
            }
            if (exp != n - 1 && y2 != 1) {
                return true;
            }
            if (y != 1 && y != n - 1) {
                return false;
            }
            return true;
        }

    }

    static class Modular {
        int m;

        public int getMod() {
            return m;
        }

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

        public Modular(long m) {
            this.m = (int) m;
            if (this.m != m) {
                throw new IllegalArgumentException();
            }
        }

        public Modular(double m) {
            this.m = (int) m;
            if (this.m != m) {
                throw new IllegalArgumentException();
            }
        }

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

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

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

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

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

        public int subtract(long x, long y) {
            return valueOf(x - y);
        }

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

    }

    static class Factorial {
        int[] fact;
        int[] inv;
        Modular modular;

        public Modular getModular() {
            return modular;
        }

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

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

        public int fact(int n) {
            return fact[n];
        }

        public int invFact(int n) {
            return inv[n];
        }

    }

    static class PrimeCombination implements IntCombination {
        final Factorial factorial;
        final Modular modular;

        public PrimeCombination(Factorial factorial) {
            this.factorial = factorial;
            this.modular = factorial.getModular();
        }

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

        public int combination(int m, int n) {
            if (n > m) {
                return 0;
            }
            return modular.mul(modular.mul(factorial.fact(m), factorial.invFact(n)), factorial.invFact(m - n));
        }

    }

    static class InverseNumber {
        int[] inv;

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

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

    }

    static class PollardRho {
        MillerRabin mr = new MillerRabin();
        Random random = new Random(1);

        public int findFactor(int n) {
            if (mr.mr(n, 5)) {
                return n;
            }
            while (true) {
                int f = rho(n);
                if (f != n) {
                    return f;
                }
            }
        }

        public Map<Integer, Integer> findAllFactors(int n) {
            Map<Integer, Integer> map = new HashMap();
            findAllFactors(map, n);
            return map;
        }

        private void findAllFactors(Map<Integer, Integer> map, int n) {
            if (n == 1) {
                return;
            }
            int f = findFactor(n);
            if (f == n) {
                Integer value = map.get(f);
                if (value == null) {
                    value = 1;
                }
                map.put(f, value * f);
                return;
            }
            findAllFactors(map, f);
            findAllFactors(map, n / f);
        }

        private int rho(int n) {
            if (n % 2 == 0) {
                return 2;
            }
            if (n % 3 == 0) {
                return 3;
            }
            int x = 0, y = x, t, q = 1, c = random.nextInt(n - 1) + 1;
            for (int k = 2; ; k <<= 1, y = x, q = 1) {
                for (int i = 1; i <= k; ++i) {
                    x = DigitUtils.mod((long) x * x + c, n);
                    q = DigitUtils.mod((long) q * Math.abs(x - y), n);
                    if ((i & 127) == 0) {
                        t = GCDs.gcd(q, n);
                        if (t > 1) {
                            return t;
                        }
                    }
                }
                if ((t = GCDs.gcd(q, n)) > 1) {
                    return t;
                }
            }
        }

    }

    static interface LongCombination {
        int combination(long n, long m);

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 20];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static class DigitUtils {
        private DigitUtils() {
        }

        public static int floorDiv(int a, int b) {
            return a < 0 ? -ceilDiv(-a, b) : a / b;
        }

        public static int ceilDiv(int a, int b) {
            if (a < 0) {
                return -floorDiv(-a, b);
            }
            int c = a / b;
            if (c * b < a) {
                return c + 1;
            }
            return c;
        }

        public static int mod(long x, int mod) {
            x %= mod;
            if (x < 0) {
                x += mod;
            }
            return (int) x;
        }

        public static int mod(int x, int mod) {
            x %= mod;
            if (x < 0) {
                x += mod;
            }
            return x;
        }

    }

    static class ExtGCD {
        private long x;
        private long y;
        private long g;

        public long getX() {
            return x;
        }

        public long extgcd(long a, long b) {
            if (a >= b) {
                g = extgcd0(a, b);
            } else {
                g = extgcd0(b, a);
                long tmp = x;
                x = y;
                y = tmp;
            }
            return g;
        }

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

    }

    static class Lucas implements IntCombination, LongCombination {
        private final IntCombination primeCombination;
        private int mod;

        public Lucas(IntCombination primeCombination, int mod) {
            this.primeCombination = primeCombination;
            this.mod = mod;
        }

        public int combination(int m, int n) {
            return combination((long) m, (long) n);
        }

        public int combination(long m, long n) {
            if (n == 0) {
                return 1 % mod;
            }
            return (int) ((long) primeCombination.combination((int) (m % mod), (int) (n % mod)) *
                    combination(m / mod, n / mod) % mod);
        }

    }

    static class ExtLucas implements LongCombination, Iterable<Map.Entry<Integer, LongCombination>> {
        PollardRho pr = new PollardRho();
        Map<Integer, LongCombination> factorialMap = new HashMap();
        int p;

        public Iterator<Map.Entry<Integer, LongCombination>> iterator() {
            return factorialMap.entrySet().iterator();
        }

        public ExtLucas(int p, long m) {
            this.p = p;
            Map<Integer, Integer> factors = pr.findAllFactors(p);
            for (Map.Entry<Integer, Integer> entry : factors.entrySet()) {
                LongCombination combination;
                if (entry.getKey().equals(entry.getValue())) {
                    combination = new Lucas(new PrimeCombination((int) Math.min(m, entry.getKey()), new Modular(entry.getKey())),
                            entry.getKey());
                } else {
                    combination = new ExtLucas.ExtLucasFactorial(entry.getKey(), entry.getValue(), m);
                }
                factorialMap.put(entry.getValue(), combination);
            }
        }

        public int combination(long m, long n) {
            if (m < n) {
                return 0;
            }
            IntExtCRT extCRT = new IntExtCRT();
            for (Map.Entry<Integer, LongCombination> entry : factorialMap.entrySet()) {
                extCRT.add(entry.getValue().combination(m, n), entry.getKey());
            }

//        if (extCRT.r != BigCombination.combination(m, n).mod(BigInteger.valueOf(p)).intValue()) {
//            throw new RuntimeException();
//        }
            return extCRT.getValue();
        }

        public static class ExtLucasFactorial implements LongCombination {
            int exp;
            int fact;
            int p;
            int pc;
            Modular modular;
            Power power;
            ExtGCD extGCD = new ExtGCD();
            int[] g;
            int[] pgc;

            public ExtLucasFactorial(int p, int pc, long m) {
                this.p = p;
                this.pc = pc;
                this.g = new int[(int) (Math.min(pc, m) + 1)];
                modular = new Modular(pc);
                power = new Power(modular);
                g[0] = 1;
                g[1] = 1;
                for (int i = 2; i < g.length; i++) {
                    if (i % p == 0) {
                        g[i] = g[i - 1];
                    } else {
                        g[i] = modular.mul(g[i - 1], i);
                    }
                }

                if (m >= pc) {
                    pgc = new int[(int) m + 1];
                    pgc[0] = 1;
                    for (int i = 1; i <= m; i++) {
                        pgc[i] = modular.mul(pgc[0], g[pc]);
                    }
                }
            }

            private int fact(long m) {
                fact = 1;
                exp = 0;
                while (m > 1) {
                    exp += m / p;
                    if (m >= pc) {
                        fact = modular.mul(fact, pgc[(int) (m / pc)]);
                    }
                    fact = modular.mul(fact, g[(int) (m % pc)]);
                    m /= p;
                }
                return fact;
            }

            public int combination(long m, long n) {
                if (m < n) {
                    return 0;
                }
                int v = fact(m);
                int e = exp;
                extGCD.extgcd(fact(n), pc);
                v = modular.mul(v, modular.valueOf(extGCD.getX()));
                e -= exp;
                extGCD.extgcd(fact(m - n), pc);
                v = modular.mul(v, modular.valueOf(extGCD.getX()));
                e -= exp;
                v = modular.mul(v, power.pow(p, e));
                return v;
            }

        }

    }

    static class IntExtCRT {
        int r;
        int m;
        boolean valid = true;
        static final ExtGCD gcd = new ExtGCD();

        public IntExtCRT() {
            r = 0;
            m = 1;
        }

        public int getValue() {
            return r;
        }

        public boolean add(int r, int m) {
            int m1 = this.m;
            int x1 = this.r;
            int m2 = m;
            int x2 = DigitUtils.mod(r, m);
            int g = (int) gcd.extgcd(m1, m2);
            int a = (int) (gcd.getX() % m2);
            if ((x2 - x1) % g != 0) {
                return valid = false;
            }
            this.m = m1 / g * m2;
            this.r = DigitUtils.mod((long) a * ((x2 - x1) / g) % this.m * m1 % this.m + x1, this.m);
            return true;
        }

        public String toString() {
            return String.format("%d mod %d", r, m);
        }

    }

    static class Power {
        final Modular modular;

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

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

    }

    static interface IntCombination {
        int combination(int m, int n);

    }

    static class GCDs {
        private GCDs() {
        }

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

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

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(int c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(int c) {
            return append(c).println();
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }
}