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

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

        int n = Integer.parseInt(br.readLine());
    int arr[][] = new int[n-2][n-2];
    int num[] = new int[n];
    String s[] = br.readLine().split(" ");
    for(int i=0;i<n;i++)
    {
        num[i] = Integer.parseInt(s[i]);
    }

    ArrayList<Integer> aa = new ArrayList<Integer>();
    for(int j=0;j<n-2;j++)
    {
        int time=0;
        int max=0;
        for(int k=0;k<n-2;k++)
        {
            if(time==0)
            {
                arr[j][k] = num[k+2]-num[k];
                if(arr[j][k]>max)
                {
                    max = arr[j][k];
                }
                time=1;
            }else
            {
                    arr[j][k] = num[k+2]-num[k+1];
                    if(arr[j][k]>max)
                    {
                        max = arr[j][k];
                    }
            }
        }
        aa.add(max);
    }
    int ans = Collections.min(aa);
    System.out.println(ans);

    }

}


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

public class ProblemC {
    InputReader in; PrintWriter out;
    void temp(int m) {
        out.println("m == " + m);
        int[][] a = new int[m + 2][m + 2];
        for (int j = 1; j <= m; j++)
            a[1][j] = 0;
        a[1][m + 1] = 1;
        for (int i = 2; i <= m + 1; i++)
            for (int j = 1; j <= m + 1; j++) {
                if (j == 1)
                    a[i][j] = a[i - 1][j + 1];
                else {
                    if (j == m + 1)
                        a[i][j] = a[i - 1][j - 1];
                    else
                        a[i][j] = (a[i - 1][j - 1] ^ a[i - 1][j + 1]);
                }
            }
//      for (int i = 1; i <= m + 1; i++, out.println())
//          for (int j = 1; j <= m + 1; j++)
//              out.print(a[i][j] + " ");
        int s = 0;
        for (int i = 1; i <= m + 1; i++)
            s += a[m + 1][i];
        out.println("s == " + s);
    }
    long[][] C = new long[41][41];
    long calc(long n, int nt) {
//      out.println("calc " + n + " " + nt);
        if (nt < 0)
            return 0;
        if (n == 0)
            if (nt == 0)
                return 1;
            else
                return 0;
        if (n == 1)
            if (nt <= 1)
                return 1;
            else
                return 0;
        long st2 = 1;
        int k = 0;
        while (st2 <= n + 1) {
            st2 *= 2;
            k++;
        }
        st2 /= 2;
        k--;
//      out.println("c == " + C[k][nt] + " k, nt: " + k + " " + nt);
        return calc(n - st2, nt - 1) + C[k][nt];
    }
    void solve() {
//      int m = 20;
//      for (int i = 0; i <= m; i++)
//          temp(i);
        long n = in.nextLong();
        long t = in.nextLong();
        n++;
        long st2 = 1;
        int k = 0;
        while (st2 < t) {
            k++;
            st2 *= 2;
        }
        if (st2 != t) {
            out.println("0");
            return;
        }
        int nt = k + 1;
        C[0][0] = 1;
        for (int i = 1; i <= 40; i++)
            for (int j = 0; j <= i; j++) {
                if (j == 0)
                    C[i][j] = 1;
                else
                    C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
            }
        long ans = calc(n, nt);
        if (nt == 1)
            ans--;
        out.println(ans);
    }

    ProblemC(){
        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
        try {
            if (oj) {
                in = new InputReader(System.in);
                out = new PrintWriter(System.out);
            }
            else {
                Writer w = new FileWriter("output.txt");
                in = new InputReader(new FileReader("input.txt"));
                out = new PrintWriter(w);
            }
        } catch(Exception e) {
            throw new RuntimeException(e);
        }
        solve();
        out.close();
    }
    public static void main(String[] args){
        new ProblemC();
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

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

    public InputReader(FileReader fr) {
        reader = new BufferedReader(fr);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() {
        return Long.parseLong(next());
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }

}


// 作者：杨成瑞先生
import java.io.*;
import java.util.*;

public class template {

	static class FastScanner {

        static final int DEFAULT_BUFF = 1024, EOF = -1, INT_MIN = 48, INT_MAX = 57;
        static final byte NEG = 45;
        static final int[] ints = new int[58];

        static {
            int value = 0;
            for (int i = 48; i < 58; i++) {
                ints[i] = value++;
            }
        }

        InputStream stream;

        byte[] buff;
        int buffPtr;

        public FastScanner(InputStream stream) {
            this.stream = stream;
            this.buff = new byte[DEFAULT_BUFF];
            this.buffPtr = -1;
        }

        public int nextInt() throws IOException {
            int val = 0;
            int sign = readNonDigits();
            while (isDigit(buff[buffPtr]) && buff[buffPtr] != EOF) {
                val = (val << 3) + (val << 1) + ints[buff[buffPtr]];
                buffPtr++;
                if (buffPtr == buff.length) {
                    updateBuff();
                }
            }
            return val*sign;
        }

        private int readNonDigits() throws IOException {
            if (buffPtr == -1 || buffPtr == buff.length) {
                updateBuff();
            }
            if (buff[buffPtr] == EOF) {
                throw new IOException("End of stream reached");
            }
            int signByte = -1;
            while (!isDigit(buff[buffPtr])) {
                signByte = buff[buffPtr];
                buffPtr++;
                if (buffPtr >= buff.length) {
                    updateBuff();
                }
                if (buff[buffPtr] == EOF) {
                    throw new IOException("End of stream reached");
                }
            }
            if(signByte == NEG) return -1;
            return 1;
        }

        public void close() throws IOException {
            stream.close();
        }

        private boolean isDigit(int b) {
            return b >= INT_MIN && b <= INT_MAX;
        }

        private void updateBuff() throws IOException {
            buffPtr = 0;
            stream.read(buff);
        }
    }

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int[] games = new int[n];
        for(int i=0;i<n;i++) {
            games[i] = Integer.parseInt(n);
        }
        int max = 0;
        for(int i=0;i<=n;i++) {
            int current = 0;
            for(int j=0;j<i;j++) {
                if(games[j] == 0) {
                    current++;
                }
            }
            for(int k=i;k<n;k++) {
                if(games[k] == 1) {
                    current++;
                }
            }
            max = Math.max(max, current);
            System.out.println(max);
        }
	}

}

// 6
// 0 1 0 0 1 0


public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n,k;
        n = in.nextInt();
        k = in.nextInt();
        String s = in.next();
        int [] ascii_array = new int[n];
        for (int i = 0; i < n; i ++) {
            ascii_array[i] = (int) s.charAt(i) - 96;
        }
        Arrays.sort(ascii_array);
        int cur = ascii_array[0];
        List<Integer> ans = new ArrayList<>();
        ans.add(ascii_array[0]);
        int sum = 0;
        for (int i = 1; i < n; i ++) {
            if (ascii_array[i] - cur >= 2) {
                cur = ascii_array[i];
                ans.add(ascii_array[i]);
            }
        }
        if (ans.size() < k) {
            System.out.println(-1);
            return;
        } else {
            for (int i = 0; i < k; i ++) {
                sum += ans.get(i);
            }
        }
        System.out.println(sum);
    }
}


import java.util.*;

public class MyClass{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        String str1 = s.nextLine();
        String test = "no";
        int v1 = str1.charAt(0);
        int v2 = str2.charAt(1);
        for(int i = 0; i < 5; i++){
            String str2 = s.next();
            int v3 = str2.charAt(0);
            int v4 = str2.charAt(1);
            if(v1 == v3 || v2 == v4){
                test = "Yes";
            }else{
                continue;
            }
        }
        int v5 = test.charAt(0);
        if(v5 == 89){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


import java.util.Scanner;

public class Zadacha {

	public static void main(String[] args) throws java.io.IOException{
		Scanner scan = new Scanner(System.in);
		int code = scan.nextInt();
		int d5 = code%10;
		int	d4 = code%100/10;
		int	d3 = code%1000/100;
		int	d2 = code%10000/1000;
		int	d1 = code/10000;

		int transformed_code = d1*10000 + d3*1000 + d5*100 + d4*10 + d2;
		long result = transformed_code*transformed_code%100000;

		for(int i = 0; i<3; i++) {
			result = result * transformed_code%100000;
		}

		d1 = (int)result/10000;
		d2 = (int)result%10000/1000;
		d3 = (int)result%1000/100;
		d4 = (int)result%100/10;
		d5 = (int)result%10;

		System.out.println(""+d1 + d2 + d3 + d4 + d5);
	}

}


import java.util.Calendar;
import java.util.Scanner;
import java.util.TimeZone;

public class B_CodeforcesWorldFinals {

    /**
     * 0:14
     */

    static final int INF = 100000000;
    public static void main(String[] args) {

//      System.out.println(days2(new int[]{1, 12, 31}));
//      if(true) return;
        Scanner sc = new Scanner(System.in);

        String[] p1;
        p1 = sc.nextLine().split("\\.");
        int DD = Integer.parseInt(p1[0]);
        int MM = Integer.parseInt(p1[1]);
        int YY = Integer.parseInt(p1[2]);

        p1 = sc.nextLine().split("\\.");
        int BD = Integer.parseInt(p1[0]);
        int BM = Integer.parseInt(p1[1]);
        int BY = Integer.parseInt(p1[2]);

        int[][] perm = new int[][]{{BY, BM, BD}, {BY, BD, BM}, {BM, BD, BY}, {BM, BY, BD}, {BD, BY, BM}, {BD, BM, BY}};

        int hd = days2(new int[]{YY, MM, DD});
        if(hd == INF) throw new RuntimeException();
//      System.out.println(hd);
        for (int i = 0; i < 6; i++) {
            int[] p = perm[i];
            if(p[1] == 2 && p[2] == 29){
                p[1] = 3;
                p[2] = 1;
            }
            p[0] += 18;

            int bd = days2(p);
//          System.out.println(bd);

            if(bd <= hd){
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }

    static final int[] mds = new int[]{31,28,31,30,31,30,31,31,30,31,30,31};
    private static int days(int[] p){
        if(! isValid(p)) return INF;

        int ret = 0;

        for (int y = 0; y <= p[0]; y++) {
            for (int m = 1; m <= (y == p[0] ? p[1] : 12); m++) {
                ret += mds[m-1];
                if(y%4 == 0 && m == 2) ret++;
            }
            if(y == p[0]){
                ret += p[2];
            }
        }
        return ret;
    }
    private static int days2(int[] p){

        if(! isValid(p)) return INF;
        int day = calcDay(2000+p[0], p[1], p[2]);

        return day;

    }

    private static int calcDay(int y, int m, int d){
        Calendar cl = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        cl.set(y, m-1, d, 0, 0, 0);
        cl.set(Calendar.MILLISECOND, 0);
        return (int)(cl.getTimeInMillis() / 1000 / 60 / 60 / 24);
    }

    private static boolean isValid(int[] p){
        if(p[0] > 99) return false;
        if(p[1] < 1 || p[1] > 12) return false;
        if(p[2] < 1 || p[2] > mds[p[1]-1]) return false;
        if(p[0]%4!=0 && p[1]==2 && p[2] == 29) return false;
        return true;
    }

}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.InputMismatchException;

/**
 * @author Egor Kulikov (egor@egork.net)
 *         Created on 14.03.2010
 */
public class TaskB implements Runnable {
	private InputReader in;
	private PrintWriter out;

	public static void main(String[] args) {
//		new Thread(new Template()).start();
		new TaskB().run();
	}

	public TaskB() {
//		String id = getClass().getName().toLowerCase();
//		try {
//			System.setIn(new FileInputStream(id + ".in"));
//			System.setOut(new PrintStream(new FileOutputStream(id + ".out")));
//			System.setIn(new FileInputStream("input.txt"));
//			System.setOut(new PrintStream(new FileOutputStream("output.txt")));
//		} catch (FileNotFoundException e) {
//			throw new RuntimeException();
//		}
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);
	}

	public void run() {
//        int numTests = in.readInt();
//        for (int testNumber = 0; testNumber < numTests; testNumber++) {
		process();
//        }
		out.close();
	}

	private void process() {
		String d1 = in.readString();
		String d2 = in.readString();
		String[] d = d2.split("[.]");
		String[] dd = d1.split("[.]");
		int cday = Integer.parseInt(dd[0]);
		int cmonth = Integer.parseInt(dd[1]);
		int cyear = Integer.parseInt(dd[2]);
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (i == j)
					continue;
				int k = 3 - i - j;
				int day = Integer.parseInt(d[i]);
				int month = Integer.parseInt(d[j]);
				int year = Integer.parseInt(d[k]);
				if (month > 12)
					continue;
				if (day > 31)
					continue;
				if (day == 31 && month == 2 || month == 4 || month == 6 || month == 9 || month == 11)
					continue;
				if (day == 30 && month == 2)
					continue;
				if (day == 29 && month == 2 && year % 4 != 0)
					continue;
				if (cyear - year > 18 || cyear - year == 18 && (cmonth > month || cmonth == month && cday >= day)) {
					out.println("YES");
					return;
				}
			}
		}
		out.println("NO");
	}

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

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

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

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

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

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

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

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

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

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

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

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

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


import java.util.*;
import java .io.*;
public class Maths {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        Stack<Integer>stack = new Stack<>();
        stack.push(b);
        while(b != a){
            if((b & 1) == 0) {
                b /= 2;
            }
            else if(b % 10 == 1) {
                b /= 10;
            }
            else{
                System.out.print("NO");
                return;
            }
            stack.push(b);
        }
        System.out.println("YES");
        System.out.println(stack.size());
        StringBuilder sb = new StringBuilder();
        while(!stack.isEmpty()){
            int temp = stack.pop();
            sb.append(temp + " ");
        }
        System.out.print(sb);
    }
}


import java.io.*;
public class Main  {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        int[] t = new int[2];
        t[0] = Integer.parseInt(s.substring(0,2));
        t[1]= Integer.parseInt(s.substring(3,5));
        int ans = 0;
        while(true){
            if(palindrome(s)) {
                break;
            }
            if(t[0]==23 && t[1]==59){
                t[0]=0;
                t[1]=-1;
            }
            if(t[1]+1==60){
                t[0]++;
                t[1]=-1;
            }
            t[1]++;
            ans++;
        }
        System.out.print(ans);
    }
    public static boolean palindrome(String s){
        int j=s.length();
        for(int i=0;i<j/2;i++){
            if(s.charAt(i)!=s.charAt(j-i-1)){
                return false;
            }
        }
        return true;
    }
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner read = new Scanner(System.in);
		String input = new String();
		input = read.nextLine();
		String[] time;
		time = input.split(":");
		int T[] = new int[2], z, k, p, a = 0, b, flag = 0;
		int[] x = new int[2];
		T[0] = Integer.parseInt(time[0]);
		T[1] = Integer.parseInt(time[1]);
		z = 1;
		k = T[0];
		p = k;
		for (int j = 0; j < 2; j++) {
			k = p % 10;
			x[0] += k * Math.pow(10, z);
			p = p / 10;
			z--;
		}

		b = x[0] - T[1];
		while (flag == 0) {

				if (b >= 0) {
					System.out.println(b);
					flag = 1;
				} else {
					if (T[0] == 23) {
						System.out.println(60 - T[1]);
						break;
					}
					if ((T[0] >= 5) && (T[0] < 10))  {
						System.out.println((10 - T[0]) * 60 + 1 - T[1]);
						break;
					} else if ((T[0] >= 15) && (T[0] < 20)) {
						System.out.println((20 - T[0]) * 60 + 2 - T[1]);
						break;
					}
					else {
						if ((T[0] < 5 && T[0] > 0) || (T[0] > 10 && T[0] < 15)) {
							System.out.println(60 - T[1] + x[0] + 10);
							break;
						} else {

						}
					}

				}
			}
		}

}


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

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

    public static void main(String[] args) {
        Scanner in = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        String val = in.next();
        int[] left = new int[n];
        int[] right = new int[n];
        for (int i = 0; i < n; i++) {
            left[i] = val.charAt(i) - '0';
        }
        for (int i = n; i < 2 * n; i++) {
            right[i] = val.charAt(i) - '0';
        }
        Arrays.sort(left);
        Arrays.sort(right);
        if (left[0] != right[0]) {
            boolean found = true;
            if (left[0] > right[0]) {
                for (int i = 1; i < n; i++) {
                    if(left[i] <= right[i]){
                        found = false;
                        break;
                    }
                }
            }else{
                for (int i = 1; i < n; i++) {
                    if(left[i] >= right[i]){
                        found = false;
                        break;
                    }
                }
            }
            if (found) {
                out.println("YES");
            } else {
                out.println("NO");
            }
        } else {
            out.println("NO");
        }

        out.close();
    }

    public static double dist(Point a, Point b) {
        double val = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
        return Math.sqrt(val);
    }

    public static class Point {

        double x, y;

        public Point(double x, double 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;
    }

    public double pow(double a, int b) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        double val = pow(a, b / 2);
        if (b % 2 == 0) {
            return val * val;
        } else {
            return val * val * a;
        }
    }

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

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

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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


import java.util.Scanner;

public class B_80_Depression {
	public static void main(String[] args){
		Scanner input=new Scanner(System.in);
		String s=input.next();
		String s1=s.substring(0, 2);
		String s2=s.substring(3);
		int hour=Integer.parseInt(s1),minute=Integer.parseInt(s2);
		if(hour>=12)
			hour=hour-12;
		double angle1,angle2;
		angle1=(60*hour+minute)/2;
		angle2=(60-minute)*6;
		if(angle2==360)
			angle2=0;
		System.out.println(angle1+" "+angle2);
	}
}


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) {
        MyScanner sc = new MyScanner();
        int n = sc.nextInt();
        String s = sc.next();
        int max = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 2; j <= n; j++) {
                String sub = s.substring(i, i + j);

                if (s.indexOf(sub, i + j) != -1) {
                    max = Math.max(sub.length() - 1, max);
                }
            }
        }

        System.out.println(n - max);
    }

    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

}


public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int a1 = Integer.parseInt(br.readLine());
        int a2 = Integer.parseInt(br.readLine());
        int k1 = Integer.parseInt(br.readLine());
        int k2 = Integer.parseInt(br.readLine());
        int n = Integer.parseInt(br.readLine());

        int curr_a1 = a1;
        int curr_a2 = a2;
        int curr_cards = 0;
        int max = 0;
        for(int c = 0; c < n; c++) {
            curr_cards++;

            if (k1 <= k2) {
                if (curr_cards >= k1 && curr_a1 > 0) {
                    max++;
                    curr_cards = 0;
                    curr_a1--;
                } else if (curr_cards >= k2 && curr_a2 > 0) {
                    max++;
                    curr_cards = 0;
                    curr_a2--;
                }
            } else {
                if (curr_cards >= k2 && curr_a2 > 0) {
                    max++;
                    curr_cards = 0;
                    curr_a2--;
                } else if (curr_cards >= k1 && curr_a1 > 0) {
                    max++;
                    curr_cards = 0;
                    curr_a1--;
                }
            }
        }

        curr_a1 = a1;
        curr_a2 = a2;
        curr_cards = 0;
        int min = 0;
        boolean full1 = (k1 == 1), full2 = (k2 == 1);
        for(int c = 0; c < n; c++) {
            curr_cards++;

            if (full1 && full2) {
                if (curr_a1 > 0) {
                    min++;
                    curr_a1--;
                } else if (curr_a2 > 0) {
                    min++;
                    curr_a2--;
                }
            }

            if (!full1) {
                if (curr_cards + 1 > (k1 - 1) * a1) {
                    full1 = true;
                    curr_cards = 0;
                }
            } else if (!full2) {
                if (curr_cards + 1 > (k2 - 1) * a2) {
                    full2 = true;
                    curr_cards = 0;
                }
            }
        }

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


package solution;

import java.util.*;

public class Solution {

    public static void main(String[] args) {

      Scanner sc = new Scanner(System.in);
      int n,a,b;
      int pieces,ans,r;
      ArrayList<Integer> rP= new ArrayList<Integer>();
      n=sc.nextInt();
      a=sc.nextInt();
      b=sc.nextInt();
      ans=1;
      r=0;
      pieces=n/a;
      if(pieces>=4)
      {
          rP.add(n-(a*4));
      }else if(pieces==3)
      {
          ans++;
          rP.add(n-a);
          rP.add(n-(a*3));
      }else if(pieces==2)
      {
          ans++;
          rP.add(n-(a*2));
          rP.add(n-(a*2));
      }else
      {
          ans+=3;
          rP.add(n-a);
          rP.add(n-a);
          rP.add(n-a);
          rP.add(n-a);
      }
        for (Integer i : rP) {
            if(i/b>0)r+=i/b;
        }
        if(r<2)
        {
            if(n>(b*(2-r)))ans++;
            else ans+=2;
        }
        System.out.println(ans);
    }
}


import java.util.Scanner;

public class pineapple {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int t = scan.nextInt(), s = scan.nextInt(), x = scan.nextInt();
		boolean[] times = new boolean[1000000000];
		times[t] = true;

		for(int i = 0; i < x; i+=2) {
			times[t+s] = times[t+s+1] = true;
			t += s;
		}

		if(times[x]) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

		scan.close();
	}

}


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

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * 6
 * 1 0
 * 0 0
 * 0 0
 * 1 1
 * 0 1
 * 1 1
 *
 * @author pttrung
 */
public class B {

    public static long mod = 1000000007;
    public static long[][][] dp;
 static int[] x = {0, 0, 1, -1, 1, -1, 1, -1};
        static int[] y = {1, -1, 0, 0, 1, -1, -1, 1};
    public static void main(String[] args) throws FileNotFoundException {
        PrintWriter out;

        Scanner in = new Scanner();
        //out = new PrintWriter(new FileOutputStream(new File("output.txt")));
        out = new PrintWriter(System.out);
        int[][] r = new int[2][2];
        int[] wk = new int[2];
        int[] bk = new int[2];
        for (int i = 0; i < 2; i++) {
            String line = in.next();
            r[i][0] = line.charAt(0) - 'a';
            r[i][1] = line.charAt(1) - '1';
        }
        String a = in.next();
        wk[0] = a.charAt(0) - 'a';
        wk[1] = a.charAt(1) - '1';
        a = in.next();
        bk[0] = a.charAt(0) - 'a';
        bk[1] = a.charAt(1) - '1';

        int[][] map = new int[8][8];
        map[r[0][0]][r[0][1]] = -1;
        map[r[1][0]][r[1][1]] = -1;
        map[wk[0]][wk[1]] = -1;
        update(r[0][0], r[0][1], map);
        update(r[1][0], r[1][1], map);
        updateK(wk[0], wk[1], map);
        if (map[bk[0]][bk[1]] != 1) {
            out.println("OTHER");
        } else {
            boolean found = false;
            for(int k = 0; k < x.length; k++){
                int i = x[k] + bk[0];
                int j = y[k] + bk[1];
                if(map[i][j] != 1){
                    found = true;
                    break;
                }
            }
            if(!found){
                out.println("CHECKMATE");
            }else{
                out.println("OTHER");
            }
        }

        out.close();
    }

    public static void updateK(int a, int b, int[][] map) {

        for (int k = 0; k < x.length; k++) {
            int i = a + x[k];
            int j = b + y[k];
            if (i >= 0 && i < 8 && j >= 0 && j < 8) {
                if (map[i][j] == 0) {
                    map[i][j] = 1;
                }
            }
        }
    }

    public static void update(int a, int b, int[][] map) {
        for (int i = b + 1; i < 8; i++) {
            if (map[a][i] == 0) {
                map[a][i] = 1;
            } else {
                break;
            }
        }
        for (int i = b - 1; i >= 0; i--) {
            if (map[a][i] == 0) {
                map[a][i] = 1;
            } else {
                break;
            }
        }
        for (int i = a + 1; i < 8; i++) {
            if (map[i][b] == 0) {
                map[i][b] = 1;
            } else {
                break;
            }
        }
        for (int i = a - 1; i >= 0; i--) {
            if (map[i][b] == 0) {
                map[i][b] = 1;
            } else {
                break;
            }
        }

    }

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

    public static Line getLine(Point a, Point b) {
        int c = (a.x - b.x);
        int d = (a.y - b.y);
        if (c == 0) {
            return new Line(1, 0, -a.x);
        } else if (d == 0) {
            return new Line(0, 1, -a.y);
        } else {
            double rate = (double) (-d) / c;

            double other = ((double) rate * a.x) + a.y;
            //System.out.println(a + "|" + b + ": " + rate + " " + other);
            return new Line(rate, 1, -other);
        }
    }

    public static class Line {

        double a, b, c;

        public Line(double a, double b, double c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }

        @Override
        public int hashCode() {
            int hash = 7;
            hash = 47 * hash + (int) (Double.doubleToLongBits(this.a) ^ (Double.doubleToLongBits(this.a) >>> 32));
            hash = 47 * hash + (int) (Double.doubleToLongBits(this.b) ^ (Double.doubleToLongBits(this.b) >>> 32));
            hash = 47 * hash + (int) (Double.doubleToLongBits(this.c) ^ (Double.doubleToLongBits(this.c) >>> 32));
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Line other = (Line) obj;
            if (Double.doubleToLongBits(this.a) != Double.doubleToLongBits(other.a)) {
                return false;
            }
            if (Double.doubleToLongBits(this.b) != Double.doubleToLongBits(other.b)) {
                return false;
            }
            if (Double.doubleToLongBits(this.c) != Double.doubleToLongBits(other.c)) {
                return false;
            }
            return true;
        }

        @Override
        public String toString() {
            return a + " " + b + " " + c;
        }
    }

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

    public static double dist(Point a, Point b) {
        double val = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
        return Math.sqrt(val);
    }

    public static class Point {

        int x, y;

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

        @Override
        public String toString() {
            return x + " " + 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;
    }

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

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

    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("output.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();
            }
        }
    }
}


import java.util.*;
public class coins {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
/*
int table[][]=new int[n][m+1];
for(int i=1;i<=n;i++)
{

	for(int j=0;j<=m;j++)
	{
		if(j==0)
		table[i-1][j]=0;

		if(i==1)
			table[i-1][j]=j;
		else if(j<i)
			table[i-1][j]=table[i-2][j];
		else if(j>=i)

			table[i-1][j]=Math.min(table[i-2][j],table[i-1][j-i]+1);

	}

}
*/
long table[]=new long[m+1];
table[0]=0;
for(int i=1;i<=m;i++)
	table[i]=Integer.MAX_VALUE;
for(int i=1;i<=m;i++)
{
	for(int j=1;j<=n;j++)
	{
		if(j<=i)
		{
			table[i]=Math.min(table[i-j]+1,table[i]);
		}
	}
}
System.out.println(table[m]);

//System.out.println(find(n,m));
	}
	public static int find(int n,int rem)
	{
		if(rem==0)
			return 0;
		int min=Integer.MAX_VALUE;
		for(int i=1;i<=n;i++)
		{if(i<=rem)

		{
			int sr=find(n,rem-i)+1;
		min=Math.min(sr,min);
		}
		}
		return min;
	}

}


//package com.turtle.bone;

import java.util.Scanner;

public class AK740 {

	public static Scanner cin = new Scanner(System.in);

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		while(cin.hasNext()){
			int n=cin.nextInt();
			long arr[]=new long[3];
			for(int i=0;i<3;i++){
				arr[i]=cin.nextInt();
			}
			long res=1000000000;
			for(int i=0;i<4;i++){
				for(int j=0;j<4;j++){
					for(int k=0;k<4;k++){
						int tmp1=n+i+2*j+3*k;
						long tmp2=arr[0]*i+arr[1]*j+arr[k];
						if(tmp1%4==0){
							if(tmp2<res){
								res=tmp2;
							}
						}
					}

				}
			}
		}

	}

}


import java.util.*;
public class a {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int[] arr = new int[n];
    for (int i = 0; i  < n; i++)
        arr[i] = in.nextInt();
        Arrays.sort(arr);
        int a =-1. b = -1, c = -1;
        for (int i = 0; i < n;i++) {
            if (a == arr[i] ||  a== -1) a = arr[i];
            else if (b == arr[i] ||  b== -1) b = arr[i];
            else if (c == arr[i] ||  c== -1) c = arr[i];
            else {
                System.out.println(-1);
                return;
            }

        }
        if (c == -1 || c - b != b - a) System.out.println(-1);
        else System.out.println(b-a);
    }
}


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

public class CF {

	int MAX = (int) 1e6;
	int[] MAX_DIGIT = new int[MAX + 1];
	long[][][] ans1 = new long[2][10][MAX + 1]; // (cnt; res)

	void precalc() {
		for (int i = 0; i <= MAX; i++)
			MAX_DIGIT[i] = Math.max(i % 10, MAX_DIGIT[i / 10]);
		for (int maxDigit = 1; maxDigit < 10; maxDigit++) {
			Arrays.fill(ans1[0][maxDigit], Long.MAX_VALUE);
			for (int val = 0; val <= MAX; val++) {
				int nextVal = val - Math.max(maxDigit, MAX_DIGIT[val]);
				if (nextVal < 0) {
					ans1[0][maxDigit][val] = 1;
					ans1[1][maxDigit][val] = nextVal;
				} else {
					ans1[0][maxDigit][val] = 1 + ans1[0][maxDigit][nextVal];
					ans1[1][maxDigit][val] = ans1[1][maxDigit][nextVal];
				}
			}
		}
	}

	long getAns2(int xx) {
		int[] ans = new int[xx + 1];
		Arrays.fill(ans, Integer.MAX_VALUE / 2);
		ans[0] = 0;
		for (int i = 1; i <= xx; i++) {
			String s = Integer.toString(i);
			for (int x = 0; x < s.length(); x++) {
				int z = s.charAt(x) - '0';
				ans[i] = Math.min(ans[i], 1 + ans[i - z]);
			}
		}
		return ans[xx];
	}

	long getAns(int h1, int h2) {
		long res = 0;
		while (h1 > 0) {
			res += ans1[0][MAX_DIGIT[h1]][h2];
			h2 = (int) ans1[1][MAX_DIGIT[h1]][h2];
			h1--;
			if (h2 < 0)
				h2 += MAX;
		}
		while (h2 > 0) {
			res++;
			h2 -= MAX_DIGIT[h2];
		}
		return res;
	}

	void realSolve() {
		// long st = System.currentTimeMillis();
		precalc();
		// System.err.println(System.currentTimeMillis() - st);
		// for (int x = 0 * (int) (1e6) - 0; x <= 1e7; x++) {
		// System.err.println(x);
		// long x = (long) 1e12;
		long x = in.nextLong();
		// long x = in.nextLong();
		long h1 = x / 1000000;
		long h2 = x % 1000000;
		long v1 = getAns((int) h1, (int) h2);
		// long v2 = getAns2((int) x);
		// long v2 = 0;
		// if (v1 != v2) {
		// System.err.println(x + " " + v1 + " " + v2);
		out.println(v1);
		// throw new AssertionError(x + " " + v1 + " " + v2);
		// }

		// out.println(getAns((int) h1, (int) h2) + " " + getAns2((int) x));
		// }
	}

	private class InputReader {
		StringTokenizer st;
		BufferedReader br;

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

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

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

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

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

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

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

	InputReader in;
	PrintWriter out;

	void solve() {
		in = new InputReader(new File("object.in"));
		try {
			out = new PrintWriter(new File("object.out"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

		realSolve();

		out.close();
	}

	void solveIO() {
		in = new InputReader(System.in);
		out = new PrintWriter(System.out);

		realSolve();

		out.close();

	}

	public static void main(String[] args) {
		new CF().solveIO();
	}
}


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

import java.util.*;

public class GFG {
	public static void main (String[] args) {
	    Scanner sc=new Scanner(System.in);
	    long int n=sc.nextInt();
	    long int k=sc.nextInt();
	    int a[]=new int[n];
		for(long int i=0;i<n;i++)
		{
		    a[i]=i+1;
		}
		int count=0;
		for(long int i=0;i<n;i++)
		{
		    for(long int j=n-1;j>i;j--)
		    {

		        int x=a[i]+a[j];
		        if(x==k)
		        {
		            count++;
		            break;
		     }

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


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

public class Main {

	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

	static int[] arr = new int[3];
	static String[] gest = new String[3];
	static boolean tie = true;

	public static void main(String args[]) throws Exception {
		FastReader cin = new FastReader();

		for (int i = 0; i < 3; i++) {
			String s = cin.next();
			gest[i] = s;
			if (s.equals("rock")) {
				arr[0]++;
			}
			if (s.equals("scissors")) {
				arr[1]++;
			}
			if (s.equals("paper")) {
				arr[2]++;
			}
		}

		if (arr[0] == 1 && arr[1] == 2 && arr[3] == 0) {
			if (gest[0].equals("rock")) {
				System.out.println("F");
			}
			if (gest[1].equals("rock")) {
				System.out.println("M");
			}
			if (gest[2].equals("rock")) {
				System.out.print("S");
			}
			tie = false;
		}

		if (arr[0] == 0 && arr[1] == 1 && arr[2] == 2) {
			if (gest[0].equals("scissors")) {
				System.out.println("F");
			}
			if (gest[1].equals("scissors")) {
				System.out.println("M");
			}
			if (gest[2].equals("scissors")) {
				System.out.println("S");
			}
			tie = false;
		}

		if (arr[0] == 2 && arr[1] == 0 && arr[2] == 1) {
			if (gest[0].equals("paper")) {
				System.out.println("F");
			}
			if (gest[1].equals("paper")) {
				System.out.println("M");
			}
			if (gest[2].equals("paper")) {
				System.out.println("S");
			}
			tie = false;
		}

		if (tie) {
			System.out.println("?");
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.math.BigDecimal ;
public class cfvc3
{
    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() );
    }
    public static void main(String [] args) throws IOException
    {
    	init(System.in) ;
    	int a1 = nextInt() ;
    	int b1 = nextInt() ;
    	int a2 = nextInt() ;
    	int b2 = nextInt() ;
    	int a3 = nextInt() ;
    	int b3 = nextInt() ;
    	int al1 = Math.max(a2, b2) ;
    	int al2 = Math.min(a2, b2) ;
    	int bl1 = Math.max(a3, b3) ;
    	int bl2 = Math.min(a3, b3) ;
    	int a = Math.max(a1, b1) ;
    	int b = Math.min(a1, b1) ;
    	if(al1+bl1<=a&&Math.max(al2,bl2)<=b)
    	{
    		System.out.println("YES") ;
    	}
    	else if(al2+bl2<=a&&Math.max(al1,bl1)<=b)
    	{
    		System.out.println("YES") ;
    	}
    	else if(al2+bl2<=b&&Math.max(al1,bl1)<=b)
    	{
    		System.out.println("YES") ;
    	}
    	else if(al1+bl1<=b&&Math.max(al2,bl2)<=a)
    	{
    		System.out.println("YES") ;
    	}
    	else if(al2+bl1<=a&&Math.max(al1,bl2)<=b)
    	{
    		System.out.println("YES") ;
    	}
    	else if(al1+bl2<=a&&Math.max(al2,bl1)<=b)
    	{
    		System.out.println("YES") ;
    	}
    	else if(al2+bl1<=b&&Math.max(al1,bl2)<=a)
    	{
    		System.out.println("YES") ;
    	}
    	else if(al1+bl2<=b&&Math.max(al2,bl1)<=a)
    	{
    		System.out.println("YES") ;
    	}
    	else
    	{
    		System.out.println("NO") ;
    	}
    }
    public static void output() throws IOException
    {
    }
}


import java.awt.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

import static java.lang.Math.max;
import static java.lang.Math.min;

public class EE implements Runnable{

    private final static Random rnd = new Random();

    // SOLUTION!!!
    // HACK ME PLEASE IF YOU CAN!!!
    // PLEASE!!!
    // PLEASE!!!
    // PLEASE!!!

    private static final long INF = Long.MAX_VALUE / 2;

    private static class LongStack {

        private final long[] values;
        private int size;

        LongStack(int size) {
            this.values = new long[size];
            this.size = 0;
        }

        void push(long value) {
            values[size] = value;
            ++size;
        }

        long peek() {
            return (0 == size ? INF : values[size - 1]);
        }

        long poll() {
            --size;
            return values[size];
        }
    }

    private static class MinimumStack {

        private final LongStack stack, stackMin;

        MinimumStack(int size) {
            this.stack = new LongStack(size);
            this.stackMin = new LongStack(size);
        }

        int size() {
            return stack.size;
        }

        long getMin() {
            return stackMin.peek();
        }

        void push(long value) {
            long min = min(getMin(), value);
            stack.push(value);
            stackMin.push(min);
        }

        long poll() {
            stackMin.poll();
            return stack.poll();
        }
    }

    private static class MinimumQueue {

        private final MinimumStack back, front;

        MinimumQueue(int size) {
            this.back = new MinimumStack(size);
            this.front = new MinimumStack(size);
        }

        int size() {
            return back.size() + front.size();
        }

        long getMin() {
            return min(back.getMin(), front.getMin());
        }

        void push(long value) {
            back.push(value);
        }

        void poll() {
            if (front.size() == 0) {
                while (back.size() > 0) {
                    front.push(back.poll());
                }
            }

            front.poll();
        }
    }

    private void solve() {
        int n = readInt();

        long x = readInt();
        long y = readInt();

        long answer = getAnswer(n, x, y);
        out.println(answer);
    }

    private static long getAnswer(int n, long x, long y) {
        long[] dp = new long[(n << 1) + 1];
        Arrays.fill(dp, INF);
        dp[0] = 0;

        MinimumQueue queue = new MinimumQueue(n + 2);

        for (int size = 1; size < dp.length; ++size) {
            long dpResult = dp[size];
            dpResult = min(dpResult, dp[size - 1] + x);

            if (0 == (size & 1)) {
                dpResult = min(dpResult, dp[size >> 1] + y);
            }

            dp[size] = dpResult;
            queue.push(dp[size] + size * x);

            if (1 == (size & 1)) {
                int prevSize = (size + 1) >> 1;
                while (queue.size() > prevSize - 1) {
                    queue.poll();
                }

                dp[prevSize] = min(dp[prevSize], queue.getMin() - prevSize * x);
            }
        }

        return dp[n];
    }

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

    private final static boolean FIRST_INPUT_STRING = false;
    private final static boolean MULTIPLE_TESTS = true;
    private final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    private final static int MAX_STACK_SIZE = 128;

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

    public void run(){
        try{
            timeInit();
            Locale.setDefault(Locale.US);

            init();

            if (ONLINE_JUDGE) {
                solve();
            } else {
                do {
                    try {
                        timeInit();
                        solve();
                        time();

                        out.println();
                    } catch (NumberFormatException e) {
                        break;
                    } catch (NullPointerException e) {
                        if (FIRST_INPUT_STRING) break;
                        else throw e;
                    }
                } while (MULTIPLE_TESTS);
            }

            out.close();
            time();
        }catch (Exception e){
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

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

    private BufferedReader in;
    private OutputWriter out;
    private StringTokenizer tok = new StringTokenizer("");

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

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

    private void init() throws FileNotFoundException{
        Locale.setDefault(Locale.US);

        if (ONLINE_JUDGE){
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new OutputWriter(System.out);
        }else{
            in = new BufferedReader(new FileReader("input.txt"));
            out = new OutputWriter("output.txt");
        }
    }

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

    private long timeBegin;

    private void timeInit() {
        this.timeBegin = System.currentTimeMillis();
    }

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

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

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

    private String delim = " ";

    private String readLine() {
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeIOException(e);
        }
    }

    private String readString() {
        try {
            while(!tok.hasMoreTokens()){
                tok = new StringTokenizer(readLine());
            }

            return tok.nextToken(delim);
        } catch (NullPointerException e) {
            return null;
        }
    }

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

    private final char NOT_A_SYMBOL = '\0';

    private char readChar() {
        try {
            int intValue = in.read();

            if (intValue == -1){
                return NOT_A_SYMBOL;
            }

            return (char) intValue;
        } catch (IOException e) {
            throw new RuntimeIOException(e);
        }
    }

    private char[] readCharArray() {
        return readLine().toCharArray();
    }

    private char[][] readCharField(int rowsCount) {
        char[][] field = new char[rowsCount][];
        for (int row = 0; row < rowsCount; ++row) {
            field[row] = readCharArray();
        }

        return field;
    }

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

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

    private int[] readIntArray(int size) {
        int[] array = new int[size];

        for (int index = 0; index < size; ++index){
            array[index] = readInt();
        }

        return array;
    }

    private int[] readSortedIntArray(int size) {
        Integer[] array = new Integer[size];

        for (int index = 0; index < size; ++index) {
            array[index] = readInt();
        }
        Arrays.sort(array);

        int[] sortedArray = new int[size];
        for (int index = 0; index < size; ++index) {
            sortedArray[index] = array[index];
        }

        return sortedArray;
    }

    private int[] readIntArrayWithDecrease(int size) {
        int[] array = readIntArray(size);

        for (int i = 0; i < size; ++i) {
            array[i]--;
        }

        return array;
    }

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

    private int[][] readIntMatrix(int rowsCount, int columnsCount) {
        int[][] matrix = new int[rowsCount][];

        for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) {
            matrix[rowIndex] = readIntArray(columnsCount);
        }

        return matrix;
    }

    private int[][] readIntMatrixWithDecrease(int rowsCount, int columnsCount) {
        int[][] matrix = new int[rowsCount][];

        for (int rowIndex = 0; rowIndex < rowsCount; ++rowIndex) {
            matrix[rowIndex] = readIntArrayWithDecrease(columnsCount);
        }

        return matrix;
    }

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

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

    private long[] readLongArray(int size) {
        long[] array = new long[size];

        for (int index = 0; index < size; ++index){
            array[index] = readLong();
        }

        return array;
    }

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

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

    private double[] readDoubleArray(int size) {
        double[] array = new double[size];

        for (int index = 0; index < size; ++index){
            array[index] = readDouble();
        }

        return array;
    }

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

    private BigInteger readBigInteger() {
        return new BigInteger(readString());
    }

    private BigDecimal readBigDecimal() {
        return new BigDecimal(readString());
    }

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

    private Point readPoint() {
        int x = readInt();
        int y = readInt();
        return new Point(x, y);
    }

    private Point[] readPointArray(int size) {
        Point[] array = new Point[size];

        for (int index = 0; index < size; ++index){
            array[index] = readPoint();
        }

        return array;
    }

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

    private List<Integer>[] readGraph(int vertexNumber, int edgeNumber) {
        @SuppressWarnings("unchecked")
        List<Integer>[] graph = new List[vertexNumber];

        for (int index = 0; index < vertexNumber; ++index){
            graph[index] = new ArrayList<Integer>();
        }

        while (edgeNumber-- > 0){
            int from = readInt() - 1;
            int to = readInt() - 1;

            graph[from].add(to);
            graph[to].add(from);
        }

        return graph;
    }

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

    private static class IntIndexPair {

        static Comparator<IntIndexPair> increaseComparator = new Comparator<EE.IntIndexPair>() {

            @Override
            public int compare(EE.IntIndexPair indexPair1, EE.IntIndexPair indexPair2) {
                int value1 = indexPair1.value;
                int value2 = indexPair2.value;

                if (value1 != value2) return value1 - value2;

                int index1 = indexPair1.index;
                int index2 = indexPair2.index;

                return index1 - index2;
            }
        };

        static Comparator<IntIndexPair> decreaseComparator = new Comparator<EE.IntIndexPair>() {

            @Override
            public int compare(EE.IntIndexPair indexPair1, EE.IntIndexPair indexPair2) {
                int value1 = indexPair1.value;
                int value2 = indexPair2.value;

                if (value1 != value2) return -(value1 - value2);

                int index1 = indexPair1.index;
                int index2 = indexPair2.index;

                return index1 - index2;
            }
        };

        int value, index;

        IntIndexPair(int value, int index) {
            super();
            this.value = value;
            this.index = index;
        }

        int getRealIndex() {
            return index + 1;
        }
    }

    private IntIndexPair[] readIntIndexArray(int size) {
        IntIndexPair[] array = new IntIndexPair[size];

        for (int index = 0; index < size; ++index) {
            array[index] = new IntIndexPair(readInt(), index);
        }

        return array;
    }

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

    private static class OutputWriter extends PrintWriter {

        final int DEFAULT_PRECISION = 12;

        private int precision;
        private String format, formatWithSpace;

        {
            precision = DEFAULT_PRECISION;

            format = createFormat(precision);
            formatWithSpace = format + " ";
        }

        OutputWriter(OutputStream out) {
            super(out);
        }

        OutputWriter(String fileName) throws FileNotFoundException {
            super(fileName);
        }

        int getPrecision() {
            return precision;
        }

        void setPrecision(int precision) {
            precision = max(0, precision);
            this.precision = precision;

            format = createFormat(precision);
            formatWithSpace = format + " ";
        }

        String createFormat(int precision){
            return "%." + precision + "f";
        }

        @Override
        public void print(double d){
            printf(format, d);
        }

        void printWithSpace(double d){
            printf(formatWithSpace, d);
        }

        void printAll(double...d){
            for (int i = 0; i < d.length - 1; ++i){
                printWithSpace(d[i]);
            }

            print(d[d.length - 1]);
        }

        @Override
        public void println(double d){
            printlnAll(d);
        }

        void printlnAll(double... d){
            printAll(d);
            println();
        }
    }

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

    private static class RuntimeIOException extends RuntimeException {

        /**
         *
         */
        private static final long serialVersionUID = -6463830523020118289L;

        RuntimeIOException(Throwable cause) {
            super(cause);
        }
    }

    /////////////////////////////////////////////////////////////////////
    //////////////// Some useful constants and functions ////////////////
    /////////////////////////////////////////////////////////////////////

    private static final int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    private static final int[][] steps8 = {
            {-1, 0}, {1, 0}, {0, -1}, {0, 1},
            {-1, -1}, {1, 1}, {1, -1}, {-1, 1}
    };

    private static boolean checkCell(int row, int rowsCount, int column, int columnsCount) {
        return checkIndex(row, rowsCount) && checkIndex(column, columnsCount);
    }

    private static boolean checkIndex(int index, int lim){
        return (0 <= index && index < lim);
    }

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

    private static boolean checkBit(int mask, int bit){
        return (mask & (1 << bit)) != 0;
    }

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

    private static long getSum(int[] array) {
        long sum = 0;
        for (int value: array) {
            sum += value;
        }

        return sum;
    }

    private static Point getMinMax(int[] array) {
        int min = array[0];
        int max = array[0];

        for (int index = 0, size = array.length; index < size; ++index, ++index) {
            int value = array[index];

            if (index == size - 1) {
                min = min(min, value);
                max = max(max, value);
            } else {
                int otherValue = array[index + 1];

                if (value <= otherValue) {
                    min = min(min, value);
                    max = max(max, otherValue);
                } else {
                    min = min(min, otherValue);
                    max = max(max, value);
                }
            }
        }

        return new Point(min, max);
    }

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

    private static int[] getPrimes(int n) {
        boolean[] used = new boolean[n];
        used[0] = used[1] = true;

        int size = 0;
        for (int i = 2; i < n; ++i) {
            if (!used[i]) {
                ++size;
                for (int j = 2 * i; j < n; j += i) {
                    used[j] = true;
                }
            }
        }

        int[] primes = new int[size];
        for (int i = 0, cur = 0; i < n; ++i) {
            if (!used[i]) {
                primes[cur++] = i;
            }
        }

        return primes;
    }

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

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

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

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

    private static class IdMap<KeyType> extends HashMap<KeyType, Integer> {

        /**
         *
         */
        private static final long serialVersionUID = -3793737771950984481L;

        public IdMap() {
            super();
        }

        int getId(KeyType key) {
            Integer id = super.get(key);
            if (id == null) {
                super.put(key, id = size());
            }

            return id;
        }
    }
}


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

// http://codeforces.com/contest/452/problem/A
public class Main{

    public static void main(String[] args) throws IOException {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            String input;
            String[] words = {"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"};

            while ((input = reader.readLine()) != null && input.length() > 0) {
                int n = Integer.parseInt(input.trim());
                char[] encryptWord = reader.readLine().trim().toCharArray();

                for (String word : words) {
                    if (word.length() == n) {
                        char[] wordChars = word.toCharArray();
                        boolean found = true;

                        for (int i = 0; i < n; i++) {
                            if (encryptWord[i] != '.' && encryptWord[i] != wordChars[i]) {
                                found = false;
                                break;
                            }
                        }

                        if (found) {
                            System.out.println(word);
                            break;
                        }
                    }
                }
            }
        }
    }
}


import java.io.*;
import java.math.*;
import java.securit
y.KeyStore.Entry;
import java.util.*;

public class mainfile {
    public static void main(String[] args)
    {
        int a, b, c, x, y, z;

        Scanner grape = new Scanner(System.in);
        x = grape.nextInt();
        y = grape.nextInt();
        z = grape.nextInt();
        a = grape.nextInt();
        b = grape.nextInt();
        c = grape.nextInt();

        if(a >= x)
        {
            if(a-x + b >= y)
            {
                if(a + b - x - y + c >= z)
                {
                    System.out.println("YES");
                }
            }
        }
        else
        {
            System.out.println("NO");
        }
    }
}


public class Main {

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
//        BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
//        BufferedReader entrada = new BufferedReader(new InputStreamReader(new FileInputStream("C:\\Users\\felipe.santos\\Documents\\entradas.txt")));
//        Scanner entrada = new Scanner(new FileInputStream("C:\\Users\\felipe.santos\\Documents\\entradas.txt"));///home/felipe/
        Scanner entrada = new Scanner(System.in);
        BufferedWriter saida = new BufferedWriter(new OutputStreamWriter(System.out));
//        BufferedWriter saida = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("C:\\Users\\felipe.santos\\Documents\\saidas.txt")));;

        //left, straight, right, pedestrian
        boolean[][] lights = new boolean[4][4];
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                lights[i][j] = entrada.nextInt() > 0;
            }
        }
        //por linha
        boolean res = false;
        for (int i = 0; i < 4 && !res; i++) {
            //sinal aberto + pedestre passando
            if (lights[i][3]) {
                for (int j = 0; j < 3 && !res; j++) {
                    if (lights[i][j]) {
                        res = true;
                    }
                }
            }
            //quais sinais estão abertos
            if (lights[i][0] && !res) {
                //esquerda
                int idx = ((i - 1) + 4) % 4;
                if (lights[idx][3])
                    res = true;
            }
            if (lights[i][1] && !res) {
                //reto
                int idx = (i + 2) % 4;
                if (lights[idx][3])
                    res = true;
            }
            if (lights[i][2] && !res) {
                //direita
                int idx = (i + 1) % 4;
                if (lights[idx][3])
                    res = true;
            }
        }

        if (res) {
            saida.write("YES");
        } else {
            saida.write("NO");
        }
        saida.write("\n");
        saida.flush();
    }
}


//package round235;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class E2 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni(), m = ni();
		int L = ni(), R = ni(), p = ni();

		long ret = 0;
		if(L == 1){
			ret += (long)n*(m+1)+(long)(n+1)*m;
			ret %= p;
		}

		Arrays.fill(counts, -1);
		long xsum = countx(n, m, 1, (long)R*R);
		Arrays.fill(counts, -1);
		long xsum2 = countx(n, m, 1, (long)L*L-1);
		Arrays.fill(counts, -1);
		long ysum = countx(m, n, 1, (long)R*R);
		Arrays.fill(counts, -1);
		long ysum2 = countx(m, n, 1, (long)L*L-1);
		Arrays.fill(counts, -1);
		long xysum = countxy(n, m, 1, (long)R*R, p);
		Arrays.fill(counts, -1);
		long xysum2 = countxy(n, m, 1, (long)L*L-1, p);
		Arrays.fill(counts, -1);
		long sum = count(n, m, 1, (long)R*R);
		Arrays.fill(counts, -1);
		long sum2 = count(n, m, 1, (long)L*L-1);
//		tr(xsum, xsum2, ysum, ysum2, xysum, xysum2, sum, sum2);
//		if(xsum < 0)throw new RuntimeException("xsum");
//		if(ysum < 0)throw new RuntimeException("ysum");
//		if(xysum < 0)throw new RuntimeException("xysum");
//		if(sum < 0)throw new RuntimeException("sum");

//		tr(ret);
		ret += 2L*((xysum-xysum2)%p-(ysum-ysum2)*(m+1)%p-(xsum-xsum2)*(n+1)%p+(long)(n+1)*(m+1)%p*(sum-sum2)%p);
		out.println((ret%p+p)%p);
//		tr(xsum, ysum, xysum);
	}

	long[] counts = new long[110000];

	long BIG = 8000000000000000000L;

	long count(int n, int m, int d, long R2)
	{
		if(counts[d] >= 0)return counts[d];
		long ret = 0;
		for(long i = 1;i <= m/d;i++){
			double u = ((double)R2/d/d)-i*i;
			if(u < 1)break;
			long x = (long)Math.sqrt(u);
			ret += Math.min(n/d, x);
		}
		for(int i = 2*d;i <= n && i <= m;i += d){
			ret -= count(n, m, i, R2);
		}
		return counts[d] = ret;
	}

	long countx(int n, int m, int d, long R2)
	{
		if(counts[d] >= 0)return counts[d];
		long ret = 0;
		for(long i = 1;i <= m/d;i++){
			double u = ((double)R2/d/d)-i*i;
			if(u < 1)break;
			long x = (long)Math.sqrt(u);
			ret += Math.min(n/d, x) * i;
		}
		for(int i = 2*d, j = 2;i <= n && i <= m;i += d, j++){
			ret -= countx(n, m, i, R2) * j;
		}
		if(ret < 0)throw new RuntimeException();
		return counts[d] = ret;
	}

	long countxy(int n, int m, int d, long R2, int P)
	{
		if(counts[d] >= 0)return counts[d];
		long ret = 0;
		for(long i = 1;i <= m/d;i++){
			double u = ((double)R2/d/d)-i*i;
			if(u < 1)break;
			long x = (long)Math.sqrt(u);
			long y = Math.min(n/d, x);
			ret += y*(y+1)/2 * i;
			if(ret >= BIG)ret %= P;
		}
		for(int i = 2*d, j = 2;i <= n && i <= m;i += d, j++){
			long temp = countxy(n, m, i, R2, P) * j;
			if(temp >= 1000000000000L)temp %= P;
			temp *= j;
			ret -= temp;
			if(ret <= -BIG)ret %= P;
//			ret -= count(n, m, i, R2) * j % P * j % P;
		}
		ret %= P;
		if(ret < 0)ret += P;
		return counts[d] = ret;
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


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

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

class TaskE {
        final int MAX_N = 101_000;
        @SuppressWarnings("uncheked")
        ArrayList<Integer>[] divs = new ArrayList[MAX_N];
        long modulo;

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
                init();
                int n = in.nextInt();
                int m = in.nextInt();
                long L = in.nextInt();
                long R = in.nextInt();
                modulo = in.nextInt();
                long res = 0;
                for (long dx = 1; dx <= n; dx++) {
                        long low = L * L - dx * dx;
                        long high = R * R - dx * dx;
                        if (low < 0)
                                low = 0;
                        if (high < 0)
                                continue;
                        long left = (int)Math.sqrt(low);
                        long right = (int)Math.sqrt(high);
                        while (left > 0 && left * left + dx * dx > L * L)
                                left--;
                        while (left * left + dx * dx <= L * L)
                                left++;
                        left--;
                        while (right > 0 && right * right + dx * dx > R * R)
                                left--;
                        while (right * right + dx * dx <= R * R)
                                right++;
                        right--;
                        if (right <= 0)
                                continue;
                        if (left < 0)
                                left = 0;
                        if (right > m)
                                right = m;
                        if (left > right)
                                continue;
                        long cntR = right - getCount((int)dx, (int)right);
                        long cntL = left - getCount((int)dx, (int)left);
                        long cnt = cntR - cntL;
                        cnt %= modulo;
                        cnt += modulo;
                        cnt %= modulo;
                        long sumR = right * (right + 1) / 2 - getSum((int)dx, (int)right);
                        long sumL = left * (left + 1) / 2 - getSum((int)dx, (int)left);
                        long sum = sumR - sumL;
                        sum = cnt * (m + 1) % modulo - sum;
                        sum %= modulo;
                        sum += modulo;
                        sum %= modulo;
                        res += (2 * sum * (n - dx + 1)) % modulo;
                        res %= modulo;
                }
                if (L <= 1)
                        res += (n + 1) * 1L * m + n * 1L * (m + 1);
                out.println(res % modulo);
        }

        void init() {
                for (int i = 1; i < MAX_N; i++) {
                        divs[i] = new ArrayList<>();
                        divs[i].add(1);
                }
                for (int i = 2; i < MAX_N; i++)
                        for (int j = i; j < MAX_N; j += i)
                                divs[j].add(i);
                for (int i = 1; i < MAX_N; i++)
                        Collections.reverse(divs[i]);
        }

        long getCount(int n, int R) {
                if (n == 1)
                        return 0L;
                if (R <= 1)
                        return 0L;
                int cnt = divs[n].size();
                int[] with = new int[cnt];
                long res = 0;
                for (int i = 0; i < cnt - 1; i++) {
                        int cur = divs[n].get(i);
                        with[i] += R / cur;
                        res += with[i];
                        for (int j = cnt - 1; j >= 0 && divs[n].get(j) < cur; j--)
                                if (cur % divs[n].get(j) == 0)
                                        with[j] -= with[i];
                }
                return res;
        }

        long getSum(int n, int R) {
                if (R <= 1)
                        return 0L;
                if (n == 1)
                        return 0L;
                int cnt = divs[n].size();
                long[] with = new long[cnt];
                long res = 0;
                for (int i = 0; i < cnt - 1; i++) {
                        int cur = divs[n].get(i);
                        with[i] += (R / cur * 1L * (R / cur + 1) / 2) % modulo * cur;
                        with[i] %= modulo;
                        res += with[i];
                        res %= modulo;
                        for (int j = cnt - 1; j >= 0 && divs[n].get(j) < cur; j--)
                                if (cur % divs[n].get(j) == 0) {
                                        with[j] -= with[i];
                                        with[j] %= modulo;
                                        if (with[j] < 0)
                                                with[j] += modulo;
                                }
                }
                return res;
        }
}

class FastScanner {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public FastScanner(InputStream inputStream)  {
                reader = new BufferedReader(new InputStreamReader(inputStream));
        }

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

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

        }


public class Main {
  public static void main (String[] args){
    int a = 0;
    int b = 0;
    int years;
    for(years = 0;;years++){
      a = a*3;
      b = b*2;
      if (a > b){
        years++;
       break;
      }
    }
  }
}


import java.util.*;
public class test {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n==2) System.out.print(2);
        if(n==2) System.out.print(2);
        if(n==2) System.out.print(2);
        System.out.print(x);
    }
}


import java.util.Scanner;

/**
 * Created by mostafa on 9/27/17.
 */
public class TernaryLogic {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = Integer.toString(sc.nextInt(), 3);
        String c = Integer.toString(sc.nextInt(), 3);

        a = rev(a); c = rev(c);

        char[] b = new char[Math.max(a.length(), c.length())];
        for(int i = 0; i < Math.max(c.length(), a.length()); i++) {
            if(i >= a.length()) {
                b[i] = c.charAt(i);
                continue;
            }

            if(i >= c.length()) {
                b[i] = (char) ('3' - a.charAt(i) + '0');
                continue;
            }

            int c1 = c.charAt(i) - '0', c2 = a.charAt(i) - '0';
            int bi = (c1 + 3 - c2) % 3;
            b[i] = (char)(bi + '0');
        }

        System.out.println(Integer.parseInt(rev(new String(b)), 3));
    }

    static String rev(String s) {
        return new StringBuilder(s).reverse().toString();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
public class Benches {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader x = new BufferedReader(new InputStreamReader(System.in));
		 int n=Integer.parseInt(x.readLine());
		 int m=Integer.parseInt(x.readLine());
		 List<Integer> b=new ArrayList<>();
		 for(int i=0; i<n; i++) {
			 b.add(Integer.parseInt(x.readLine()));
		 }
		 Collections.sort(b);
		 int max;
		 SortedSet<Integer> b2=new TreeSet<>();
			 max=b.get(b.size()-1)+m;
			 for(int i=0;i<m;i++){
				 b.set(0, (b.get(0)+1));
				 Collections.sort(b);
				 b2.addAll(b);
			 }
		 System.out.println(m<b.get(b.size()-1-b.get(0))?(b.get(b.size()-1)+" "+(b.get(b.size()-1)+m)):b2.last()+" "+max);
		 }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Locale;
import java.util.StringTokenizer;

import static java.util.Arrays.deepToString;

public class D {

	static long get(int ones, int twos) {
		if (ones + twos == 1) {
			return 1;
		}
		if (ones == 0) {
			return fact(twos);
		}
		long ans = get(ones - 1, twos);
		if (ones >= 2) {
			ans += (ones - 1) * get(ones - 2, twos);
		}
		if (twos >= 1) {
			ans += (twos) * get(ones, twos - 1);
		}
		if (ones >= 2 && twos >= 1) {
			long typeSum = 0;
			for (int len = 1; len <= twos; len++) {
				typeSum += special(twos, len) * get(ones - 2, twos - len);
			}
			ans += (ones - 1) * typeSum;
		}
		return ans;
	}

	static long fact(int k) {
		return k <= 1 ? 1 : k * fact(k - 1);
	}

	static long special(int k, int len) {
		long res = 1;
		for (int t = k; t >= k - len + 1; t--) {
			res *= t;
		}
		return res;
	}

	static void solve() {
		int n = nextInt();
		int ones = 0, twos = 0;
		for (int i = 0; i < n; i++) {
			int k = nextInt();
			if (k == 1)
				ones++;
			else
				twos++;
		}
		debug(get(ones, twos));
	}

	public static void main(String[] args) throws Exception {
		reader = new BufferedReader(new InputStreamReader(System.in));
		writer = new PrintWriter(System.out);
		Locale.setDefault(Locale.US);

		setTime();
		solve();
		printTime();
		printMemory();

		writer.close();
	}

	static BufferedReader reader;
	static PrintWriter writer;
	static StringTokenizer tok = new StringTokenizer("");
	static long systemTime;

	static void debug(Object... o) {
		System.err.println(deepToString(o));
	}

	static void setTime() {
		systemTime = System.currentTimeMillis();
	}

	static void printTime() {
		System.err.println("Time consumed: " + (System.currentTimeMillis() - systemTime));
	}

	static void printMemory() {
		System.err.println("Memory consumed: "
				+ (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000 + "kb");
	}

	static String next() {
		while (!tok.hasMoreTokens()) {
			String w = null;
			try {
				w = reader.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			if (w == null)
				return null;
			tok = new StringTokenizer(w);
		}
		return tok.nextToken();
	}

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

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

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

	static BigInteger nextBigInteger() {
		return new BigInteger(next());
	}
}


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

public class A {
	static final long mod = 1000000007;
	public static void main(String[] args) {
		MScanner sc = new MScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt(), ONE = 0, TWO = 0;
		for(int a=0;a<N;a++)if(sc.nextInt()==1)ONE++;else TWO++;
		long[] inv = new long[N];
		inv[0]=inv[1]=1;
		for(int a=2;a<=ONE;a++)
			inv[a]=(inv[a-1]+(a-1)*inv[a-2])%mod;
		long ans = inv[ONE];
		for(int a=0;a<TWO;a++)
			ans = (ans*(TWO+ONE-a))%mod;
		out.println(ans);
		out.close();
	}
	static class MScanner{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public MScanner(){
			stream = System.in;
			//stream = new FileInputStream(new File("dec.in"));

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

		boolean isSpaceChar(int c){
			return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
		}
		boolean isEndline(int c){
			return c=='\n'||c=='\r'||c==-1;
		}
		int nextInt(){
			return Integer.parseInt(next());
		}
		int[] nextInt(int N){
			int[] ret = new int[N];
			for(int a=0;a<N;a++)
				ret[a] = nextInt();
			return ret;
		}
		long nextLong(){
			return Long.parseLong(next());
		}
		long[] nextLong(int N){
			long[] ret = new long[N];
			for(int a=0;a<N;a++)
				ret[a] = nextLong();
			return ret;
		}
		double nextDouble(){
			return Double.parseDouble(next());
		}
		double[] nextDouble(int N){
			double[] ret = new double[N];
			for(int a=0;a<N;a++)
				ret[a] = nextDouble();
			return ret;
		}
		String next(){
			int c = read();
			while(isSpaceChar(c))
				c=read();
			StringBuilder res = new StringBuilder();
			do{
				res.appendCodePoint(c);
				c=read();
			} while(!isSpaceChar(c));
			return res.toString();
		}
		String[] next(int N){
			String[] ret = new String[N];
			for(int a=0;a<N;a++)
				ret[a] = next();
			return ret;
		}
		String nextLine(){
			int c = read();
			while(isEndline(c))
				c=read();
			StringBuilder res = new StringBuilder();
			do{
				res.appendCodePoint(c);
				c = read();
			}while(!isEndline(c));
			return res.toString();
		}
		String[] nextLine(int N){
			String[] ret = new String[N];
			for(int a=0;a<N;a++)
				ret[a] = nextLine();
			return ret;
		}

	}
}


public class missing_vowel {

	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		int c,v0,v,a,l;
		c=sc.nextInt();
		v0=sc.nextInt();
		v=sc.nextInt();
		a=sc.nextInt();
		l=sc.nextInt();
		int count=v0;
		int i=1;
		while(count<c){
			if(l+v0+a*i>v){
				count=count+v-l;
			}else{
				count=count+v0+a*i-l;
			}
			i++;

		}

		System.out.println(i);
	}

}


import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Lotus
 */
public class A224 {
    public static void main (String[] args)
    {
        Scanner input = new Scanner (System.in);
        int s1 = input.nextInt();
        int s2= input.nextInt();
        int s3 =input.nextInt();
        int a1=0;
        int a2=0;
        int a3=0;
        int sum=0;
        int max = Math.max(Math.max(s1, s2), s3);
        for(int i=1 ; i<= max; i++)
        {
            for(int j=1 ; j<=max; j++)
            {
                for(int k=1 ; k<=max ; k++)
                {
                    if((i*j== s1 ) && ( i*k==s2 ) &&( j*k ==s3))
                    {

                        sum = (4*i) +(4*j) + (4*k);
                        break;
                    }
                }
            }
        }
        System.out.println(sum);

    }

}


import java.util.Scanner;
public class A{
    public static void main(String[] arg){
        Scanner read = new Scanner(System.in);
        int yellow = read.nextInt();
        read.nextLine();
        int blue = read.nextInt();
        read.nextLine();
        int red = read.nextInt();

        int max1 = 3*yellow+3;
        int max2 = 3*blue;
        int max3 = 3*red-3;

        System.out.println(Math.max(Math.max(max1,max2),max3));
    }
}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.StringTokenizer;

public class Test {
	static List<Integer> g[];
	static int team[];
	static boolean success = true;
	public static boolean check(int v){
		int a = 0;
		boolean ret = false;
		for(int i = 0; i < g[v].size(); ++i){
			if(team[v] == team[g[v].get(i)]) ++a;
		}
		if(a > 1) return false;
		else return true;

	}
	public static void main(String[] argv) {
		FastScanner scan = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = scan.nextInt();
		int m = scan.nextInt();
		boolean used[] = new boolean[n+1];
		team = new int[n+2];
		g = new ArrayList[n+1];
		for(int i = 0; i < n + 1; ++i){
			g[i] = new ArrayList<Integer>();
		}
		for(int i = 0; i < m; ++i){
			int f = scan.nextInt();
			int t = scan.nextInt();
			g[f].add(t);
			g[t].add(f);
		}

		Queue<Integer> q = new LinkedList();
		for(int i = 1; i <= n; ++i){
			q.add(i);
		}

		while(!q.isEmpty()) {
			int node = q.poll();
			if(!check(node)){
				if(team[node] == 0) team[node] = 1;
				else team[node] = 0;
				for(int i = 0; i < g[node].size(); ++i){
					if(!check(g[node].get(i))){
						q.add(g[node].get(i));
					}
				}
			}
		}

		for(int i = 1; i < n + 1; ++i)
			System.out.print(team[i]);
		out.close();
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner(InputStream is) {
			try {
				br = new BufferedReader(new InputStreamReader(is));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

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

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

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

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


import java.util.Scanner;

public class potion {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		int l,r,x,y,k;
		boolean isGood=false;
		l=in.nextInt();
		r=in.nextInt();
		x=in.nextInt();
		y=in.nextInt();
		k=in.nextInt();
		int[]a = new int[r-l+1];
		int[]b = new int[y-x+1];
		float[]c = new float[(r-l+1)*(y-x+1)];
		a[0]=l;
		b[0]=x;
		for(int i=0;i<r-l;i++) {
			a[i+1]=a[i]+1;
		}
		for(int i=0;i<y-x;i++) {
			b[i+1]=b[i]+1;
		}
		int m=0;
		for(int i=0;i<r-l+1;i++) {
			for(int j=0;j<y-x+1;j++) {
				c[m]=a[i]/b[j];
				if(c[m]==k)
					isGood=true;
				m++;
			}
		}
		if(isGood)
			System.out.print("YES");
		else
			System.out.print("NO");
	}

}


//package CodeforcesRound425;

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

public class SashaAndSticks {

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

	    if (n%k==0) {

		    for (int i = 0; i <=(n%k); i++) {
				n = n-k;
			}
		    System.out.println("YES");
		}
	    else{
	    	System.out.println("NO");
	    }

	    //maximumGcdAndSum(A, B);

	    }
}