import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
public class D {
	public static void main(String[]args)throws IOException,NumberFormatException{
		BufferedReader bf =new BufferedReader(new InputStreamReader(System.in));
		int n=5;
		String s=bf.readLine();
		String[]sa=s.split(" ");
		Long []arr=new Long[n];
		for(int i=0;i<n;i++){
			arr[i]=Long.parseLong(sa[i]);
		}
		long d=arr[0];
		long k=arr[1];
		long a=arr[2];
		long b=arr[3];
		long t=arr[4];
		long total=Math.min(k, d)*a;
		d-=k;
		if(d>0){
			if(a*k+t<=k*b){
				long r=d/k;
				total+=(a*k+t)*r;
				d%=k;
				total+=Math.min(d*b, t+d*a);
			}else
				total+=d*b;
		}
		System.out.println(total);
	}
}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
//Amjad's method.
public class Main {
    static Map <Character, String> map = new HashMap<Character, String>();
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        map.put('0', "O-|-OOOO");
        map.put('1', "O-|O-OOO");
        map.put('2', "O-|OO-OO");
        map.put('3', "O-|OOO-O");
        map.put('4', "O-|OOOO-");
        map.put('5', "-O|-OOOO");
        map.put('6', "-O|O-OOO");
        map.put('7', "-O|OO-OO");
        map.put('8', "-O|OOO-O");
        map.put('9', "-O|OOOO-");
        String temp = scanner.nextLine();
        for(int i = temp.length() - 1; i >= 0; i --){
            System.out.println(map.get(temp.charAt(i)));
        }
    }
}


import java.io.*;
import java.util.*;
public class D1118_CoffeeAndCourseWork {

	public static void main(String[] args) {
		InputReader in = new InputReader();
		int n = in.nextInt();
		int m = in.nextInt();

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

		Arrays.sort(arr);
		arr = reverseOrder(arr);

		int[] sums = new int[n];
		sums[0] = arr[0];
		for (int i=1; i<n; i++)
			sums[i] = sums[i-1] + arr[i];

		if (m > sums[n-1])
			System.out.println(-1);
		else
			System.out.println(binarySearch(arr, sums, m));
	}

	public static int binarySearch(int[] arr, int[] sums, int m) {
		int l = 1; int r = arr.length;
		while (l != r) {
			if (l+1 == r)
				return isPossible(l, arr, sums, m) ? l : r;
			int mid = (l + r)/2;
			if (isPossible(mid, arr, sums, m))
				r = mid;
			else
				l = mid+1;
		}
		return l;
	}

	public static boolean isPossible(int day, int[] arr, int[] sums, int val) {
		int tot = sums[day-1], numUsed = day, sub = 1, prevUsed = 0;
		while (numUsed < arr.length) {
			prevUsed = numUsed;
			numUsed = Math.min(numUsed + day, arr.length);
			int using = numUsed - prevUsed;
			int pos = binarySearch(sub, arr);
			if (pos >= numUsed)
				tot += sums[numUsed-1] - sums[prevUsed-1] - using*sub;
			else if (pos > prevUsed) {
				int index = prevUsed + (using - (numUsed - pos) - 1);
				tot += (sums[index] - sums[prevUsed-1]) - (using - (numUsed - pos))*sub;
			}
			++sub;
		}
		return tot >= val;
	}

	public static int binarySearch(int T, int[] arr) {
		int l = 0, r = arr.length;
		while (l != r) {
			int mid = (l + r)/2;
			if (arr[mid] <= T)
				r = mid;
			else
				l = mid+1;
		}
		return l;
	}

	public static int[] reverseOrder(int[] arr) {
		int[] newArr = new int[arr.length];
		for (int i=0; i<arr.length; i++)
			newArr[i] = arr[arr.length-1-i];
		return newArr;
	}

	static class InputReader {
		public BufferedReader br;
		public StringTokenizer st;

		public InputReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}

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

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


//package ecr012;
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 F3 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	public static int[] sieveEratosthenes(int n) {
		if (n <= 32) {
			int[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };
			for (int i = 0; i < primes.length; i++) {
				if (n < primes[i]) {
					return Arrays.copyOf(primes, i);
				}
			}
			return primes;
		}

		int u = n + 32;
		double lu = Math.log(u);
		int[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)];
		ret[0] = 2;
		int pos = 1;

		int[] isnp = new int[(n + 1) / 32 / 2 + 1];
		int sup = (n + 1) / 32 / 2 + 1;

		int[] tprimes = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };
		for (int tp : tprimes) {
			ret[pos++] = tp;
			int[] ptn = new int[tp];
			for (int i = (tp - 3) / 2; i < tp << 5; i += tp)
				ptn[i >> 5] |= 1 << (i & 31);
			for (int j = 0; j < sup; j += tp) {
				for (int i = 0; i < tp && i + j < sup; i++) {
					isnp[j + i] |= ptn[i];
				}
			}
		}

		// 3,5,7
		// 2x+3=n
		int[] magic = { 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21, 17,
				9, 6, 16, 5, 15, 14 };
		int h = n / 2;
		for (int i = 0; i < sup; i++) {
			for (int j = ~isnp[i]; j != 0; j &= j - 1) {
				int pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27];
				int p = 2 * pp + 3;
				if (p > n)
					break;
				ret[pos++] = p;
				if ((long) p * p > n)
					continue;
				for (int q = (p * p - 3) / 2; q <= h; q += p)
					isnp[q >> 5] |= 1 << q;
			}
		}

		return Arrays.copyOf(ret, pos);
	}

	int[] primes = sieveEratosthenes(400000);

	void solve()
	{
		long n = nl();
		long ans = 0;
		if(n <= 10) {
			if(n >= 6)ans++;
			if(n >= 8)ans++;
			if(n >= 10)ans++;
			out.println(ans);
			return;
		}

		MeisselLehmer2 ml = new MeisselLehmer2(n/2);
		for(int i = 0;i < primes.length;i++) {
			long plus = ml.pi(n/primes[i]) - (i+1);
			if(plus <= 0)break;
			ans += plus;
		}

		for(int p : primes) {
			if((long)p*p*p <= n) {
				ans++;
			}else {
				break;
			}
		}
		out.println(ans);
	}

	public static class MeisselLehmer2 {
		int[] primes;
//		int[] cump;
		int[] xcums;
		long[] isp;

		int cachelimit;
//		Map<Long, Long> picache;
//		Map<Long, Long> phicache;
		LongHashCounterL picache;
		LongHashCounterL phicache;
		boolean cachePhi = false;

		int[][] cumps;
//		int[] FP = {2,3,5,7,11,13,17};
		int[] FP = {2,3,5,7,11,13,17,19};
		int M = FP.length;

		int B = 100;
		// 10^14 -> 200
		// 10^14/8 -> 100~200

		public MeisselLehmer2(long n)
		{
			assert n >= 4;
//			picache = new HashMap<>();
//			phicache = new HashMap<>();
			picache = new LongHashCounterL();
			phicache = new LongHashCounterL();

			int s = (int)Math.sqrt(n)*B; // not overflow!
			cachelimit = s;
			this.primes = sieveEratosthenes(s);
			xcums = new int[(s>>>6)+1];
			isp = new long[(s>>>6)+1];
			for(int p : primes)isp[p>>>6] |= 1L<<p;
			for(int i = 0;i < xcums.length-1;i++)xcums[i+1] = xcums[i] + Long.bitCount(isp[i]);

			cumps = new int[M][];
			boolean[] b = {true};
			int len = 1;
			for(int i = 0;i < M;i++){
				len *= FP[i];
				boolean[] c = new boolean[len];
				for(int j = 0;j < FP[i];j++){
					System.arraycopy(b, 0, c, j*b.length, b.length);
				}
				for(int k = 0;k < len;k+=FP[i])c[k] = false;
				cumps[i] = new int[len+1];
				for(int j = 0;j < len;j++)cumps[i][j+1] = cumps[i][j] + (c[j] ? 1 : 0);
				FP[i] = len;
				b = c;
			}
		}

		private long sqrt(long n)
		{
			long i = Math.max(0, (long)Math.sqrt(n)-2);
			while(i*i <= n)i++;
			return i-1;
		}

		private long cbrt(long n)
		{
			long i = Math.max(0, (long)Math.cbrt(n)-2);
			while(i*i*i <= n)i++;
			return i-1;
		}

		public long pi(long x)
		{
			if(x <= cachelimit){
				int ix = (int)x;
				return xcums[ix>>>6] + Long.bitCount(isp[ix>>>6]<<~ix);
//				return cump[(int)x];
			}
			if(picache.containsKey(x))return picache.get(x);

			int A = (int)pi(sqrt(sqrt(x)));
			long ret = A + phi(x, A) - P2(x, A) - P3(x, A) - 1;
			picache.put(x, ret);
			return ret;
		}

		private long phi(long x, int A)
		{
			if(A > 0 && A-1 < M){
				return cumps[A-1][FP[A-1]] * (x/FP[A-1]) + cumps[A-1][(int)(x%FP[A-1]+1)];
			}
			if(A > 0 && x <= (long)primes[A-1]*primes[A-1]){
				return pi(x) - A + 1;
			}
//			long code = x<<13|A;
//			if(phicache.containsKey(code))return phicache.get(code);

			long ret = x;
			for(int i = A-1;i >= 0;i--)ret -= phi(x/primes[i], i);

//			if(cachePhi)phicache.put(code, ret);
			return ret;
		}

		private long P2(long x, int A)
		{
			int B = (int)pi(sqrt(x));
			long ret = 0;
			for(int i = A;i < B;i++){
				ret += pi(x/primes[i]);
			}
			ret -= (long)(B-A)*(B+A-1)/2;
			return ret;
		}

		private long P3(long x, int A)
		{
			int C = (int)pi(cbrt(x));
			long ret = 0;
			for(int i = A;i < C;i++){
				long xi = x/primes[i];
				int B = (int)pi(sqrt(xi));
				for(int j = i;j < B;j++){
					ret += pi(xi/primes[j]) - j;
				}
			}
			return ret;
		}

		public static int[] sieveEratosthenes(int n) {
			if (n <= 32) {
				int[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };
				for (int i = 0; i < primes.length; i++) {
					if (n < primes[i]) {
						return Arrays.copyOf(primes, i);
					}
				}
				return primes;
			}

			int u = n + 32;
			double lu = Math.log(u);
			int[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)];
			ret[0] = 2;
			int pos = 1;

			int[] isnp = new int[(n + 1) / 32 / 2 + 1];
			int sup = (n + 1) / 32 / 2 + 1;

			int[] tprimes = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };
			for (int tp : tprimes) {
				ret[pos++] = tp;
				int[] ptn = new int[tp];
				for (int i = (tp - 3) / 2; i < tp << 5; i += tp)
					ptn[i >> 5] |= 1 << (i & 31);
				for (int j = 0; j < sup; j += tp) {
					for (int i = 0; i < tp && i + j < sup; i++) {
						isnp[j + i] |= ptn[i];
					}
				}
			}

			// 3,5,7
			// 2x+3=n
			int[] magic = { 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21, 17,
					9, 6, 16, 5, 15, 14 };
			int h = n / 2;
			for (int i = 0; i < sup; i++) {
				for (int j = ~isnp[i]; j != 0; j &= j - 1) {
					int pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27];
					int p = 2 * pp + 3;
					if (p > n)
						break;
					ret[pos++] = p;
					if ((long) p * p > n)
						continue;
					for (int q = (p * p - 3) / 2; q <= h; q += p)
						isnp[q >> 5] |= 1 << q;
				}
			}

			return Arrays.copyOf(ret, pos);
		}

		private static class LongHashCounterL {
			public long[] keys;
			public long[] allocated;
			private int scale = 1<<2;
			private int rscale = 1<<1;
			private int mask = scale-1;
			public int size = 0;

			public LongHashCounterL(){
				allocated = new long[scale];
				Arrays.fill(allocated, NG);
				keys = new long[scale];
			}

			// if value is NG, entry is removed. (e.g. 0)
			private static final int NG = 0;

			public boolean containsKey(long x)
			{
				int pos = h(x)&mask;
				while(allocated[pos] != NG){
					if(x == keys[pos])return true;
					pos = pos+1&mask;
				}
				return false;
			}

			public long get(long x)
			{
				int pos = h(x)&mask;
				while(allocated[pos] != NG){
					if(x == keys[pos])return allocated[pos];
					pos = pos+1&mask;
				}
				return NG;
			}

			public long put(long x, long v)
			{
				int pos = h(x)&mask;
				while(allocated[pos] != NG){
					if(x == keys[pos]){
						long oldval = allocated[pos];
						allocated[pos] = v;
						return oldval;
					}
					pos = pos+1&mask;
				}
				if(size == rscale){
					resizeAndPut(x, v);
				}else{
					keys[pos] = x;
					allocated[pos] = v;
				}
				size++;
				return 0;
			}

			public long inc(long x, long v)
			{
				int pos = h(x)&mask;
				while(allocated[pos] != NG){
					if(x == keys[pos]){
						allocated[pos] += v;
						return allocated[pos];
					}
					pos = pos+1&mask;
				}
				if(size == rscale){
					resizeAndPut(x, v);
				}else{
					keys[pos] = x;
					allocated[pos] = v;
				}
				size++;
				return v;
			}

			public boolean remove(long x)
			{
				int pos = h(x)&mask;
				while(allocated[pos] != NG){
					if(x == keys[pos]){
						size--;
						// take last and fill rmpos
						int last = pos;
						pos = pos+1&mask;
						while(allocated[pos] != NG){
							int lh = h(keys[pos])&mask;
							// lh <= last < pos
							if(
									lh <= last && last < pos ||
									pos < lh && lh <= last ||
									last < pos && pos < lh
									){
								keys[last] = keys[pos];
								allocated[last] = allocated[pos];
								last = pos;
							}
							pos = pos+1&mask;
						}
						keys[last] = 0;
						allocated[last] = NG;

						return true;
					}
					pos = pos+1&mask;
				}
				return false;
			}

			private void resizeAndPut(long x, long v)
			{
				int nscale = scale<<1;
				int nrscale = rscale<<1;
				int nmask = nscale-1;
				long[] nallocated = new long[nscale];
				Arrays.fill(nallocated, NG);
				long[] nkeys = new long[nscale];
				for(int i = next(0);i < scale;i = next(i+1)){
					long y = keys[i];
					int pos = h(y)&nmask;
					while(nallocated[pos] != NG)pos = pos+1&nmask;
					nkeys[pos] = y;
					nallocated[pos] = allocated[i];
				}
				{
					int pos = h(x)&nmask;
					while(nallocated[pos] != NG)pos = pos+1&nmask;
					nkeys[pos] = x;
					nallocated[pos] = v;
				}
				allocated = nallocated;
				keys = nkeys;
				scale = nscale;
				rscale = nrscale;
				mask = nmask;
			}

			public int next(int itr)
			{
				while(itr < scale && allocated[itr] == NG)itr++;
				return itr;
			}

			private int h(long x)
			{
				x ^= x>>>33;
				x *= 0xff51afd7ed558ccdL;
				x ^= x>>>33;
				x *= 0xc4ceb9fe1a85ec53L;
				x ^= x>>>33;
				return (int)x;
			}

			@Override
			public String toString()
			{
				StringBuilder sb = new StringBuilder();
				for(int i = next(0);i < scale;i = next(i+1)){
					sb.append(",");
					sb.append(keys[i] + ":" + allocated[i]);
				}
				return sb.length() == 0 ? "" : sb.substring(1);
			}
		}
	}

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

	private byte[] inbuf = new byte[1024];
	public 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.*; public class wizards
{ public static void main(String[] args)
{ Scanner in=new Scanner(System.in);
int n=in.nextInt(),x=in.nextInt(),y=in.nextInt();
System.out.println(result(n,x,y));
}
public static int result(int n, int x,int y)
{ int p=(int)Math.ceil((double)(n*(y/100.0)));
if(p>x)
return (p-x);
else return (0);
}
}


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

public class CF985A {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int total1 = 0;
		int total2 = 0;
		ArrayList<Integer> pieces = new ArrayList<>();
		for(int i=0; i<n/2; i++) pieces.add(sc.nextInt());
		Collections.sort(pieces);
		for(int i=0; i<pieces.size(); i++) {
			int goal = (i+1)*2;
			total1+=Math.abs(pieces.get(i)-(goal-1));
			total2+=Math.abs(pieces.get(i)-goal);
		}
		System.out.println(Math.min(total1, total2));
	}
}


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

public class cf388a {
  static FastIO in = new FastIO(), out = in;

  public static void main(String[] args) {
    int n = in.nextInt();
    int[] v = new int[n];
    for(int i=0; i<n; i++) v[i] = in.nextInt();
    Arrays.sort(v);
    int lo = 1, hi = n;
    while(hi - lo > 2) {
      int mid = (hi+lo)/2;
      if(ok(mid, v)) hi = mid;
      else lo = mid;
    }
    while(!ok(lo, v)) lo++;
    out.println(lo);
    out.close();
  }
  static boolean ok(int x, int[] v) {
    for(int i=0; i<v.length; i++)
      if(v[i] < i/x)
        return false;
    return true;
  }

  static class FastIO extends PrintWriter {
    BufferedReader br;
    StringTokenizer st;

    public FastIO() {
      this(System.in, System.out);
    }

    public FastIO(InputStream in, OutputStream out) {
      super(new BufferedWriter(new OutputStreamWriter(out)));
      br = new BufferedReader(new InputStreamReader(in));
      scanLine();
    }

    public void scanLine() {
      try {
        st = new StringTokenizer(br.readLine().trim());
      } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
      }
    }

    public int numTokens() {
      if (!st.hasMoreTokens()) {
        scanLine();
        return numTokens();
      }
      return st.countTokens();
    }

    public String next() {
      if (!st.hasMoreTokens()) {
        scanLine();
        return next();
      }
      return st.nextToken();
    }

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

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

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


import java.util.*;

public class a243 {

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

        int n = scan.nextInt();
        int s = scan.nextInt();

        int sum = 0;
        int max = 0;
        for (int i=0; i<n; i++){
            int t = scan.nextInt();
            if(t > max) max =t;
            sum += t;
        }
        sum -= max;
        if(sum > s) System.out.println("NO");
        else System.out.println("YES");
        return ;
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        solve();
    }

}


//package educational.round68;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.InputMismatchException;

public class G3 {
	InputStream is;
	PrintWriter out;
//	String INPUT = "42";
	String INPUT = "";

	public static void trnz(long... o)
	{
		for(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+":"+o[i]+" ");
		System.out.println();
	}

	void solve()
	{
		BigInteger n = new BigInteger(ns());
		long ans = 0;
		for(int i = 1;i <= 9;i++){
			for(int j = 1;j <= i;j++){
				if(gcd(i, j) == 1){
					if(i == 1){
						ans += n.mod(BigInteger.valueOf(998244353L)).longValue();
					}else{
						long lans = count(n, i, j);
						if(i != j){
							ans += lans*2;
						}else{
							ans += lans;
						}
//						if(lans > 0)tr(i, j, lans, ans);
					}
				}
			}
		}
		out.println(ans % 998244353);
	}

	long count(BigInteger N, int u, int v)
	{
		char[] s = ("0" + N.divide(BigInteger.valueOf(u)).add(BigInteger.ONE).toString()).toCharArray();

		int n = s.length;
		// u:2 v:1
		// u倍したときにt*uを含んでいるか
		// v倍したときにt*vを含んでいるか
		int w = 9/u;
		long[][][][] dp = new long[1<<w][1<<w][10][10]; // valid carry
		long[][][][] ep = new long[1<<w][1<<w][10][10]; // valid carry
		int mod = 998244353;
		ep[0][0][0][0] = 1;

		int[][] va0 = new int[10][10];
		int[][] va1 = new int[10][10];
		int[][] nextc0 = new int[10][10];
		int[][] nextc1 = new int[10][10];
		for(int d = 0;d < 10;d++){
			for(int c0 = 0;c0 <= 9;c0++){
				int v0 = d*u + c0;
				for(int t = 1;t <= w;t++){
					if(t*u == v0%10){
						va0[d][c0] |= 1<<t-1;
					}
				}
				nextc0[d][c0] = v0 / 10;
			}
			for(int c1 = 0;c1 <= 9;c1++){
				int v1 = d*v + c1;
				for(int t = 1;t <= w;t++){
					if(t*v == v1%10){
						va1[d][c1] |= 1<<t-1;
					}
				}
				nextc1[d][c1] = v1 / 10;
			}
		}

		for(int i = n-1;i >= 0;i--){
			long[][][][] ndp = new long[1<<w][1<<w][10][10]; // valid carry
			long[][][][] nep = new long[1<<w][1<<w][10][10]; // valid carry

			for(int j = 0;j < 1<<w;j++){
				for(int k = 0;k < 1<<w;k++){
					for(int l = 0;l < 10;l++){
						for(int m = 0;m < 10;m++){
							int d = s[i]-'0';
							int nj = j|va0[d][l];
							int nk = k|va1[d][m];
							int nl = nextc0[d][l];
							int nm = nextc1[d][m];
							ndp[nj][nk][nl][nm] += dp[j][k][l][m];
							if(ndp[nj][nk][nl][nm] >= mod)ndp[nj][nk][nl][nm] -= mod;
						}
					}
				}
			}

			for(int j = 0;j < 1<<w;j++){
				for(int k = 0;k < 1<<w;k++){
					for(int l = 0;l < 10;l++){
						for(int m = 0;m < 10;m++){
							for(int d = 0;d < 10;d++){
								int nj = j|va0[d][l];
								int nk = k|va1[d][m];
								int nl = nextc0[d][l];
								int nm = nextc1[d][m];
								nep[nj][nk][nl][nm] += ep[j][k][l][m];
								if(nep[nj][nk][nl][nm] >= mod)nep[nj][nk][nl][nm] -= mod;
								if(d < s[i]-'0'){
									ndp[nj][nk][nl][nm] += ep[j][k][l][m];
									if(ndp[nj][nk][nl][nm] >= mod)ndp[nj][nk][nl][nm] -= mod;
								}
							}
						}
					}
				}
			}

			dp = ndp;
			ep = nep;
		}

		long ret = 0;
		for(int i = 0;i < 1<<w;i++){
			for(int j = 0;j < 1<<w;j++){
				if((i&j) != 0){
					ret += dp[i][j][0][0];
				}
			}
		}
		return ret % mod;
	}

	public static int gcd(int a, int b) {
		while (b > 0) {
			int c = a;
			a = b;
			b = c % b;
		}
		return a;
	}

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

	private byte[] inbuf = new byte[1024];
	public 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)); }
}


/*
 * Author Ayub Subhaniya
 * Institute DA-IICT
 */

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

public class Codeforces429D
{

	InputStream in;
	PrintWriter out;

	long MAX=Long.MAX_VALUE;
	void solve()
	{
		long f=nl();
		long T=nl();
		long t0=nl();
		long a1,t1,p1,a2,t2,p2;
		a1=nl();t1=nl();p1=nl();
		a2=nl();t2=nl();p2=nl();

		long max1=f/a1;
		long max2=f/a2;
		long cost=MAX;

		if (t1<t2)
		{
			for (int k1=0;k1<=max1;k1++)
			{
				long sz=f-k1*a1;

				long l=0,r=sz/a2,result=-1,t=a1*k1*t1;
				long td;
				while (l<=r)
				{
					long mid=((l+r)>>1);
					td=a2*mid;
					if (t+td*t2+(sz-td)*t0 <= T)
					{
						result=mid;
						r=mid-1;
					}
					else
					{
						l=mid+1;
					}
				}

				if (t+sz*t2<=T)
					cost=Math.min(cost, k1*p1+((sz+a2-1)/a2)*p2);

				if (result!=-1)
				{
					cost=Math.min(cost, k1*p1+result*p2);
				}

			}

			if (f*t1<=T)
				cost=Math.min(cost, ((f+a1-1)/a1)*p1);
		}
		else
		{
			for (int k2=0;k2<=max2;k2++)
			{
				long sz=f-k2*a2;

				long l=0,r=sz/a1,result=-1,t=a2*k2*t2;
				long td;
				while (l<=r)
				{
					long mid=((l+r)>>1);
					td=a1*mid;
					if (t+td*t1+(sz-td)*t0<=T)
					{
						result=mid;
						r=mid-1;
					}
					else
					{
						l=mid+1;
					}
				}

				if (t+sz*t1<=T)
					cost=Math.min(cost, k2*p2+((sz+a1-1)/a1)*p1);

				if (result!=-1)
				{
					cost=Math.min(cost, k2*p2+result*p1);
				}

			}

			if (f*t2<=T)
				cost=Math.min(cost, ((f+a2-1)/a2)*p2);
		}

		if (cost==MAX)
			out.println(-1);
		else
			out.println(cost);
	}

	void run() throws Exception
	{
		String INPUT = "C:/Users/ayubs/Desktop/input.txt";
		in = oj ? System.in : new FileInputStream(INPUT);
		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 Codeforces429D().run();
	}

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

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

	private boolean inSpaceChar(int c)
	{
		return !(c >= 33 && c <= 126);
	}

	private int skip()
	{
		int b;
		while ((b = readByte()) != -1 && inSpaceChar(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 (!(inSpaceChar(b)))
		{ // when nextLine, (inSpaceChar(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 && !(inSpaceChar(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.Scanner;

public class Process {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int kp = 0;
		int p = 0;
		int zp = 0;
		int k = 0;
		for (int i = 0; i < n; i++) {
			int a = in.nextInt();
			if (p == 0 && a != 0) {
				p = a;
				kp = 1;
			}
			else if (a == p && p != 0) {
				kp++;
			}
			else if (a != p && p != 0 && a != 0) {
				k += min(kp, i - zp - kp);
				zp += kp;
				p = a;
				kp = 1;
			}
			else if (p != 0 && a == 0) {
				k += min(kp, i - zp - kp);
				zp += kp;
				p = kp = 0;
			}
			if (i == n - 1 && a != 0) {
				k += min(kp, i - zp - kp + 1);
			}
		}
		System.out.println(k);
		in.close();
	}

	public static int min(int a, int b) {
		if (a < b) {
			return a;
		}
		else {
			return b;
		}
	}
}


import java.util.*;

public class shashank
{
	public static void main(String args[])
	{
		Scanner scan = new Scanner(System.in);
		int n = Math.abs(scan.nextInt());
		int k = 3 - 2 * (n % 2);

		if(n == 0)
			System.out.println(0);
		else
		{
			while(true)
			{
				if((k + 1) * k >= 2 * n)
				{
					System.out.println(k);
					break;
				}
				else if((k + 1) * (k + 2) >= 2 * n)
				{
					System.out.println(k + 1);
					break;
				}
				k += 4;
			}
		}
	}
}


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

public class Main {
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    static void solve() throws Exception {
        int n = nextInt();
        out.println("+------------------------+");
        if (n >= 1) {
            out.print("|O.");
        } else {
            out.print("|#.");
        }
        for (int i = 2; i <= 11; ++i) {
            if (4 + (i - 2) * 3 < n) {
                out.print("O.");
            } else {
                out.print("#.");
            }
        }
        out.println("|D|)");
        if (n >= 2) {
            out.print("|O.");
        } else {
            out.print("|#.");
        }
        for (int i = 2; i <= 11; ++i) {
            if (4 + (i - 2) * 3 + 1 < n) {
                out.print("O.");
            } else {
                out.print("#.");
            }
        }
        out.println("|.|");
        if (n >= 3) {
            out.print("|O.");
        } else {
            out.print("|#.");
        }
        for (int i = 2; i <= 11; ++i) {
            out.print("..");
        }
        out.println("..|");
        if (n >= 4) {
            out.print("|O.");
        } else {
            out.print("|#.");
        }
        for (int i = 2; i <= 11; ++i) {
            if (4 + (i - 2) * 3 + 2 < n) {
                out.print("O.");
            } else {
                out.print("#.");
            }
        }
        out.println("|.|)");
        out.println("+------------------------+");
    }

    static long sqr(int x) {
        return (long)x * x;
    }

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

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

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

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

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

    static String nextLine() throws IOException {
        tok = new StringTokenizer("");
        return in.readLine();
    }

    static boolean hasNext() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null) {
                return false;
            }
            tok = new StringTokenizer(s);
        }
        return true;
    }

    public static void main(String args[]) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
            //in = new BufferedReader(new FileReader("input.in"));
            //out = new PrintWriter(new FileWriter("output.out"));
            solve();
            in.close();
            out.close();
        } catch (Throwable e) {
            e.printStackTrace();
            java.lang.System.exit(1);
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
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);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            char[][] s = new char[][]{in.next().toCharArray(), in.next().toCharArray()};
            for (char[] c : s) {
                for (int i = 0; i < c.length; i++) {
                    if (c[i] == 'C') {
                        c[i] = 'B';
                    }
                }
            }
            int q = in.nextInt();

            int[][][] count = new int[2][][];
            int[][] sufA = new int[2][];
            for (int i = 0; i < 2; i++) {
                count[i] = count(s[i]);
                sufA[i] = sufA(s[i]);
            }
            int[][] info = new int[2][3];
            for (int i = 0; i < q; i++) {
                int l1 = in.nextInt() - 1, r1 = in.nextInt();
                int l2 = in.nextInt() - 1, r2 = in.nextInt();

                info[0][0] = count[0][0][r1] - count[0][0][l1];
                info[0][1] = count[0][1][r1] - count[0][1][l1];
                info[0][2] = Math.min(sufA[0][r1 - 1], r1 - l1);

                info[1][0] = count[1][0][r2] - count[1][0][l2];
                info[1][1] = count[1][1][r2] - count[1][1][l2];
                info[1][2] = Math.min(sufA[1][r2 - 1], r2 - l2);
                out.print(can(info[0], info[1]) ? '1' : '0');
            }
        }

        private boolean can(int[] a, int[] b) {
            a[0] -= a[2];
            b[0] -= b[2];
            if (a[2] < b[2]) {
                return false;
            }
            if (a[2] % 3 == b[2] % 3) {
                if (can2(a, b)) {
                    return true;
                }
            }
            a[2]--;
            a[1] += 2;

            a[0] += a[2] - b[2];
            return can2(a, b);
        }

        private boolean can2(int[] a, int[] b) {
            if (a[0] < 0 || a[1] < 0) {
                return false;
            }
            if (a[1] > b[1]) {
                return false;
            }
            if (a[1] % 2 != b[1] % 2) {
                return false;
            }
            if (b[1] > a[1] && (a[0] + a[1] == 0)) {
                return false;
            }
            return true;
        }

        private int[] sufA(char[] chars) {
            int[] a = new int[chars.length];
            for (int i = 0; i < chars.length; i++) {
                if (chars[i] == 'A') {
                    a[i] = (i == 0 ? 0 : a[i - 1]) + 1;
                } else {
                    a[i] = 0;
                }
            }
            return a;
        }

        private int[][] count(char[] chars) {
            int[][] a = new int[2][chars.length + 1];
            for (int i = 0; i < chars.length; i++) {
                a[0][i + 1] += a[0][i];
                a[1][i + 1] += a[1][i];
                a[chars[i] - 'A'][i + 1]++;
            }
            return a;
        }

    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

    }
}


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

/**
 * Created by Everest on 22.10.2016.
 */
public class B3 {

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

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

        String tmp = br.readLine();
        char c = tmp.charAt(tmp.length()-1);

        int c1 = 0;

        if (c == 'a'){
            c1 = 4;
        }else if(c == 'b'){
            c1 = 5;
        }else if(c == 'c'){
            c1 = 6;
        }else if(c == 'd'){
            c1 = 3;
        }else if(c == 'e'){
            c1 = 2;
        }else if(c == 'f'){
            c1 = 1;
        }

        long n = Long.parseLong(tmp.substring(0, tmp.length()-1));
        long ans = 0;

        if(n % 4 == 0){
            ans = 12*(n/4 - 1) + 6 + n-3 + c1;
        }else if( (n % 4 != 0) && (n % 2 == 0) ){
            ans = 12*(n/4 + 1) - 6 + c1 + n-1;
        }else{
            ans = 12*(n/4) + c1 + (((n+1) % 4 == 0) ? (n-3) : (n-1));
        }

        System.out.println(ans);

    }

}


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

public class B370{

	void solve()
	{
		int x = ni();
		int y = ni();
		int[] t = {y,y,y};
		int cn = 0;
		for(int i=0;!allX(t,x);i++)
		{
			if(i%3==0)
			{
				int rch = t[1]+t[2]-1;
				t[0] = Math.min(rch,x);
			}
			else if(i%3==1)
			{
				int rch = t[0]+t[2]-1;
				t[1] = Math.min(rch,x);
			}
			else
			{
				int rch = t[0]+t[1]-1;
				t[2] = Math.min(rch,x);
			}
			cn++;
		}
		System.out.println(cn);
	}

	boolean allX(int[] a,int k)
	{
		for(int x : a)
			if(x!=k)
				return false;
		return true;
	}

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

	private byte[] bufferArray = new byte[1024];
	private int bufLength = 0;
	private int bufCurrent = 0;
	InputStream inputStream = System.in;

	int nextByte()
	{
		if(bufLength==-1)
			throw new InputMismatchException();
		if(bufCurrent>=bufLength)
		{
			bufCurrent = 0;
			try
			{bufLength = inputStream.read(bufferArray);}
			catch(IOException e)
			{ throw new InputMismatchException();}
			if(bufLength<=0)
				return -1;
		}
		return bufferArray[bufCurrent++];
	}

	boolean isSpaceChar(int x)
	{return (x<33 || x>126);}

	boolean isDigit(int x)
	{return (x>='0' && x<='9');}

	int nextNonSpace()
	{
		int x;
		while((x=nextByte())!=-1 && isSpaceChar(x));
		return x;
	}

	int ni()
	{
		int ans = 0;
		int sign = 1;
		int x = nextNonSpace();
		if(x=='-')
		{
			sign = -1;
			x = nextByte();
		}
		while(!isSpaceChar(x))
		{
			if(isDigit(x))
			{
				ans = ans*10 + x -'0';
				x = nextByte();
			}
			else
				throw new InputMismatchException();
		}
		return sign*ans;
	}

	long nl()
	{
		long ans = 0;
		long sign = 1;
		int x = nextNonSpace();
		if(x=='-')
		{
			sign = -1;
			x = nextByte();
		}
		while(!isSpaceChar(x))
		{
			if(isDigit(x))
			{
				ans = ans*10 + x -'0';
				x = nextByte();
			}
			else
				throw new InputMismatchException();
		}
		return sign*ans;
	}

	String ns()
	{
		StringBuilder sb = new StringBuilder();
		int x = nextNonSpace();
		while(!isSpaceChar(x))
		{
			sb.append((char)x);
			x = nextByte();
		}
		return sb.toString();
	}

	String nL()
	{
		StringBuilder sb = new StringBuilder();
		int x = nextNonSpace();
		while(x==32 || !isSpaceChar(x))
		{
			sb.append((char)x);
			x = nextByte();
		}
		return sb.toString();
	}

	char nc()
	{ return (char)nextNonSpace();}

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

	char[] ca()
	{ return ns().toCharArray();}

	char[] ca(int n)
	{
		char[] ans = new char[n];
		int p =0;
		int x = nextNonSpace();
		while(p<n)
		{
			ans[p++] = (char)x;
			x = nextByte();
		}
		return ans;
	}

	int[] ia(int n)
	{
		int[] ans = new int[n];
		for(int i=0;i<n;i++)
			ans[i]=ni();
		return ans;
	}

	long[] la(int n)
	{
		long[] ans = new long[n];
		for(int i=0;i<n;i++)
			ans[i] = nl();
		return ans;
	}

}


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

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

    private void solve() {
        int x1 = in.nextInt();
        int x2 = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        if (x2 >= x1 + a && x2 <= x1 + b) {
            out.println("FIRST");
            out.println(x2);
            return;
        }
        if (x1 <= x2 && a <= 0 || x1 >= x2 && b >= 0) {
            out.println("DRAW");
            return;
        }
        int mod = Math.abs(x1 - x2) % Math.abs(a + b);
        if (mod >= Math.min(Math.abs(a), Math.abs(b))
                && mod <= Math.max(Math.abs(a), Math.abs(b))) {
            out.println("FIRST");
            out.println((x1 <= x2) ? (x1 + mod) : (x1 - mod));
            return;
        }
        if (mod == 0) {
            out.println("SECOND");
            return;
        }
        out.println("DRAW");
    }

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

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

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

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

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

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

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

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

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

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

        public boolean hasNext() {
            if (st != null && st.hasMoreTokens()) {
                return true;
            }
            try {
                while (br.ready()) {
                    st = new StringTokenizer(br.readLine());
                    if (st != null && st.hasMoreTokens()) {
                        return true;
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return false;
        }
    }
}


/**
 * @author Finn Lidbetter
 */
import java.util.*;
import java.io.*;
import java.awt.geom.*;

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

    String f0 = "What are you doing at the end of the world? Are you busy? Will you save us?";
    // f_i+1= a+f_i+b+f_i+c;
    String a = "What are you doing while sending \"";
    String b = "\"? Are you busy? Will you send \"";
    String c = "\"?";
    long f0Len = f0.length();
    long aLen = a.length();
    long bLen = b.length();
    long cLen = c.length();
    long abcSum = aLen+bLen+cLen;

    int MAXN=100000;
    long[] len = new long[MAXN+1];
    len[0] = f0Len;
    for (int i=1; i<53; i++) {
      len[i] = (2L*len[i-1])+abcSum;
      //System.out.println(len[i]);
    }
    for (int i=53; i<MAXN+1; i++) {
      len[i] = 1_000_000_000_000_000_000L;
    }

    int q = Integer.parseInt(br.readLine());
    for (int i=0; i<q; i++) {
      String[] s = br.readLine().split(" ");
      int n = Integer.parseInt(s[0]);
      long k = Long.parseLong(s[1])-1;
      boolean done = false;
      while (n>0) {
        //System.out.printf("n:%d, k:%d\n",n,k);
        if (k<aLen) {
          sb.append(a.charAt((int)k));
          done = true;
          break;
        } else if (k<aLen+len[n-1]) {
          k -= aLen;
        } else if (k<aLen+len[n-1]+bLen) {
          sb.append(b.charAt((int)(k-aLen-len[n-1])));
          done = true;
          break;
        } else if (k<aLen+len[n-1]+bLen+len[n-1]) {
          k -= (aLen+len[n-1]+bLen);
        } else if (k<aLen+len[n-1]+bLen+len[n-1]+cLen) {
          sb.append(c.charAt((int)(k-aLen-len[n-1]-bLen-len[n-1])));
          done = true;
          break;
        } else {
          sb.append('.');
          done = true;
          break;
        }
        n--;
      }
      if (!done) {
        if (k>=f0.length()) {
          sb.append('.');
        } else {
          sb.append(f0.charAt((int)k));
        }
      }
    }
    System.out.println(sb);
  }
}


import static java.util.Arrays.*;
import static java.lang.Math.*;
import static java.math.BigInteger.*;
import java.util.*;
import java.math.*;
import java.io.*;

public class A implements Runnable
{
    String file = "input";

    boolean TEST = false;

    void solve() throws IOException
    {
        String s = next();
        seen = new HashSet<String>();
        permute(s, 0, new StringBuilder(), new boolean[6]);
        out.println(seen.size());
    }

    void permute(String s, int at, StringBuilder sb, boolean[] used)
    {
        if(at == 6)
        {
            process(sb.toString());
            return;
        }

        for(int i = 0; i < 6; i++)
            if(!used[i])
            {
                used[i] = true;
                sb.append(s.charAt(i));
                permute(s, at + 1, sb, used);
                sb.deleteCharAt(sb.length() - 1);
                used[i] = false;
            }
    }
    HashSet<String> seen;
    void process(String s)
    {
        String res = s;
        Cube cube = new Cube(s);
        for(int i = 0; i < 4; i++)
        {
            cube.down();
            for(int j = 0; j < 4; j++)
            {
                cube.left();
                res = min(res, cube.toString());
            }
        }
        cube.left(); cube.down();
        for(int i = 0; i < 4; i++)
        {
            cube.left();
            res = min(res, cube.toString());
        }
        cube.up(); cube.right(); cube.right(); cube.down();
        for(int i = 0; i < 4; i++)
        {
            cube.left();
            res = min(res, cube.toString());
        }
        seen.add(res);
    }
    String min(String a, String b)
    {
        if(a.compareTo(b) < 0) return a;
        return b;
    }

    class Cube
    {
        char[] cs;

        Cube(String s)
        {
            cs = s.toCharArray();
        }

        void left()
        {
            char t = cs[2];
            cs[2] = cs[3];
            cs[3] = cs[4];
            cs[4] = cs[5];
            cs[5] = t;
        }
        void right()
        {
            left(); left(); left();
        }
        void down()
        {
            char t = cs[0];
            cs[0] = cs[5];
            cs[5] = cs[1];
            cs[1] = cs[3];
            cs[3] = t;
        }
        void up()
        {
            down(); down(); down();
        }

        public String toString()
        {
            return new String(cs);
        }
    }

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

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

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

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

    void print(Object... o)
    {
        System.out.println(deepToString(o));
    }

    void gcj(Object o)
    {
        String s = String.valueOf(o);
        out.println("Case #" + test + ": " + s);
        System.out.println("Case #" + test + ": " + s);
    }

    BufferedReader input;
    PrintWriter out;
    StringTokenizer st;
    int test;

    void init() throws IOException
    {
        if(TEST) input = new BufferedReader(new FileReader(file + ".in"));
        else input = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(new BufferedOutputStream(System.out));
    }

    public static void main(String[] args) throws IOException
    {
        new Thread(null, new A(), "", 1 << 20).start();
    }

    public void run()
    {
        try
        {
            init();
            if(TEST)
            {
                int runs = nextInt();
                for(int i = 0; i < runs; i++) solve();
            }
            else solve();
            out.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
            System.exit(1);
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class TaskC {
    public static void main(String[] arg) {

        final FastScanner in = new FastScanner(System.in);
        final PrintWriter out = new PrintWriter(System.out);
        final long n = in.nextInt();
        final long mod = in.nextInt();
        final long [] fact = new long[(int)n+1];
        fact[0]=1;
        for(int i=1;i<=n;i++) {
            fact[i]=fact[i-1]*i%mod;
        }
        long result = 0;
        for(int i=1;i<=n;i++){
            result+=((n-i+1)*fact[i]%mod)*(fact[(int)n-i+1]%mod);
            result %= mod;
        }
        out.printf("%d%n", result);
        out.close();
        in.close();
    }

    private static class Solution {

        private long permutations(final int n, int[] elements) {
            Map<Long, Integer> countMap = new TreeMap<>();
            int[] indexes = new int[n];
            for (int i = 0; i < n; i++) {
                indexes[i] = 0;
            }
            long result =count(n, elements);
            countMap.computeIfAbsent(result,l->1);
            int i = 0;
            while (i < n) {
                if (indexes[i] < i) {
                    swap(elements, i % 2 == 0 ? 0 : indexes[i], i);
                    long cnt = count(n, elements);
                    countMap.computeIfPresent(cnt,(k,v)->v+1);
                    countMap.computeIfAbsent(cnt,l->1);
                    result+=cnt;
                    indexes[i]++;
                    i = 0;
                } else {
                    indexes[i] = 0;
                    i++;
                }
            }
            System.out.printf(" %d %d %d %n",n,
                    factorial(n,1_000_000_009),result);
            return result;
        }

        private long count(final int n,final int [] a){
            long result =0;
            for(int  l=0;l<n;l++){
                int max  = a[l];
                int min =  a[l];
                for(int r=l;r<n;r++){
                    max = Math.max(a[r],max);
                    min = Math.min(a[r],min);
                    if(max-min==r-l){
                        result++;
                    }
                }
            }
            return result;
        }

        private long factorial(final int n,final int m) {
            if(n==1) return 1;
            if(n==2) return 2;
            long fact =2;
            long a = 1;
            long b = 2;
            int i =3;
            while(i<=n){
                fact = fact*i%m;
                i++;
            }
            return fact;
        }

        private void printArray(int []elements){
          System.out.println(Arrays.toString(elements));
        }

        private void swap(int [] input, int a, int b) {
            int tmp = input[a];
            input[a] = input[b];
            input[b] = tmp;
        }
    }

    private static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

        int[] readIntArr(int n) {
            int[] result = new int[n];
            for (int i = 0; i < n; i++) {
                result[i] = Integer.parseInt(next());
            }
            return result;
        }

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

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

    }
}


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

public class B {
	String s = null;

	String[] ss = null;
	int[][] sn = null;
	public void run() throws Exception{

		BufferedReader br = null;
		File file = new File("input.txt");
		if(file.exists()){
			br = new BufferedReader(new FileReader("input.txt"));
		}
		else{
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		s = br.readLine();
		int n = Integer.parseInt(s);
		long[] in = new long[n];
		s = br.readLine();
		ss = s.split(" ");
		for(int i = 0; i < n; i++){
			in[i] = Long.parseLong(ss[i]);
		}
		Arrays.sort(in);

		boolean f = true;
		for(int i = 0; i < in.length-1; i++){
			if(in[i] != in[i+1]){
				if(in[i] * 2 > in[i+1]){
					f = false;
					break;
				}
			}
		}

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

	}

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		B t = new B();
		t.run();

	}

}


//Created by Aminul on 11/17/2020.

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

import static java.lang.Math.*;

public class CF1447F1 {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = in.nextInt();
        int[] arr = new int[n + 1];
        int[] freq = new int[101];
        int mostFreq = 0;
        for (int i = 1; i <= n; i++) {
            arr[i] = in.nextInt();
            freq[arr[i]]++;
            if (freq[arr[i]] > freq[mostFreq]) {
                mostFreq = arr[i];
            }
        }

        int res = 0;
        for (int i = 1; i <= 100; i++) {
            if (i != mostFreq) {
                int tmp = maxSumArrayWithZeroSum(n, mostFreq, i, arr);
                res = max(res, tmp);
            }
        }

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

    static int maxSumArrayWithZeroSum(int n, int x, int y, int[] arr) {
        int offset = n + 5;
        int[] idx = new int[offset + offset + 10];
        int invalid = -n - n - n;
        Arrays.fill(idx, invalid);
        int sum = 0, res = 0;
        idx[offset + sum] = 0;
        for (int i = 1; i <= n; i++) {
            if (arr[i] == x) sum++;
            else if (arr[i] == y) sum--;
            if (idx[offset + sum] != invalid) res = max(res, i - idx[offset + sum]);
            else idx[offset + sum] = i;
        }
        return res;
    }

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


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class StoryOfCountry {
	public static void main(String[] args) {
		FS in = new FS();
		int N = in.nextInt();
		TreeSet<Rec> hEnd = HE();
		TreeSet<Rec> hStart = HS();
		TreeSet<Rec> vEnd = VE();
		TreeSet<Rec> vStart = VS();
		for(int i = 0; i < N; i++) {
			Rec r = new Rec(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), i);
			hEnd.add(r); hStart.add(r); vEnd.add(r); vStart.add(r);
		}
		System.out.println(solve(0, hEnd, hStart, vEnd, vStart) ? "YES":"NO");
	}

	/* State:
	 *  0 -> can be either vertical or horizontal
	 *  1 -> has to be vertical split
	 *  2 -> has to be horizontal split
	 */
	static boolean solve(int state, TreeSet<Rec> he, TreeSet<Rec> hs, TreeSet<Rec> ve, TreeSet<Rec> vs) {
		if(he.size() <= 2) return true; // Always possible with just 2 things

		TreeSet<Rec> lhe = HE();
		TreeSet<Rec> lhs = HS();
		TreeSet<Rec> lve = VE();
		TreeSet<Rec> lvs = VS();

		TreeSet<Rec> rhe = HE();
		TreeSet<Rec> rhs = HS();
		TreeSet<Rec> rve = VE();
		TreeSet<Rec> rvs = VS();

		TreeSet<Rec> lhe2 = HE();
		TreeSet<Rec> lhs2 = HS();
		TreeSet<Rec> lve2 = VE();
		TreeSet<Rec> lvs2 = VS();

		TreeSet<Rec> rhe2 = HE();
		TreeSet<Rec> rhs2 = HS();
		TreeSet<Rec> rve2 = VE();
		TreeSet<Rec> rvs2 = VS();

		Rec lR = null;
		Rec lRS = null;
		int maxLRS = -1;
		Rec rR = null;
		Rec rRS = null;
		int minRRS = 2131231231;

		Rec lR2 = null;
		Rec lRS2 = null;
		int maxLRS2 = -1;
		Rec rR2 = null;
		Rec rRS2 = null;
		int minRRS2 = 2131231231;

		while((state != 2 && (lR == null || rR == null || lR.x2 < rR.x1)) || (state != 1 && (lR2 == null || rR2 == null || lR2.y2 < rR2.y1))) {
			//do left side
			if(state != 2 && (lR == null || rR == null || lR.x2 < rR.x1)) {
				lR = (lR == null ? he.first() : he.higher(lR));
				lhe.add(lR);
				while(true) {
					Rec next = (lRS == null ? hs.first() : hs.higher(lRS));
					if(next == null || next.x1 >= lR.x2) break;
					maxLRS = Math.max(maxLRS, next.x2);
					lRS = next;
				}
				if(lR.x2 >= maxLRS) { //found a working thing
					Rec r;
					while((r = he.higher(lR)) != null && r.x2 == lR.x2){ lhe.add(r); lR = r; }
						for(Rec rr : lhe) {
							he.remove(rr); hs.remove(rr); ve.remove(rr); vs.remove(rr);
							lhs.add(rr); lve.add(rr); lvs.add(rr);
						}
					return solve(2,lhe,lhs,lve,lvs)&&solve(0,he,hs,ve,vs);
				}

				//do right side
				rR = (rR == null ? hs.last() : hs.lower(rR));
				rhe.add(rR);
				while(true) {
					Rec next = (rRS == null ? he.last() : he.lower(rRS));
					if(next == null || next.x2 <= rR.x1) break;
					minRRS = Math.min(minRRS, next.x1);
					rRS = next;
				}
				if(rR.x1 <= minRRS) { //found a working thing
					Rec r;
					while((r = hs.lower(rR)) != null && r.x1 == rR.x1){ rhe.add(r); rR = r; }
						for(Rec rr : rhe) {
							he.remove(rr); hs.remove(rr); ve.remove(rr); vs.remove(rr);
							rhs.add(rr); rve.add(rr); rvs.add(rr);
						}
					return solve(0,he,hs,ve,vs)&&solve(2,rhe,rhs,rve,rvs);
				}
			}

			if(state != 1 && (lR2 == null || rR2 == null || lR2.y2 < rR2.y1)) {
				//do left side2
				lR2 = (lR2 == null ? ve.first() : ve.higher(lR2));
				lhe2.add(lR2);
				while(true) {
					Rec next = (lRS2 == null ? vs.first() : vs.higher(lRS2));
					if(next == null || next.y1 >= lR2.y2) break;
					maxLRS2 = Math.max(maxLRS2, next.y2);
					lRS2 = next;
				}
				if(lR2.y2 >= maxLRS2) { //found a working thing
					Rec r;
					while((r = ve.higher(lR2)) != null && r.y2 == lR2.y2){ lhe2.add(r); lR2 = r; }
						for(Rec rr : lhe2) {
							he.remove(rr); hs.remove(rr); ve.remove(rr); vs.remove(rr);
							lhs2.add(rr); lve2.add(rr); lvs2.add(rr);
						}
					return solve(1,lhe2,lhs2,lve2,lvs2)&&solve(0,he,hs,ve,vs);
				}

				//do right side2
				rR2 = (rR2 == null ? vs.last() : vs.lower(rR2));
				rhe2.add(rR2);
				while(true) {
					Rec next = (rRS2 == null ? ve.last() : ve.lower(rRS2));
					if(next == null || next.y2 <= rR2.y1) break;
					minRRS2 = Math.min(minRRS2, next.y1);
					rRS2 = next;
				}
				if(rR2.y1 <= minRRS2) { //found a working thing
					Rec r;
					while((r = vs.lower(rR2)) != null && r.y1 == rR2.y1){ rhe2.add(r); rR2 = r; }
						for(Rec rr : rhe2) {
							he.remove(rr); hs.remove(rr); ve.remove(rr); vs.remove(rr);
							rhs2.add(rr); rve2.add(rr); rvs2.add(rr);
						}
					return solve(0,he,hs,ve,vs)&&solve(1,rhe2,rhs2,rve2,rvs2);
				}
			}
		}
		return false;
	}

	static TreeSet<Rec> HE() {
		return new TreeSet<Rec>((a,b) -> (a.x2 == b.x2 ? a.id-b.id : a.x2-b.x2));
	}
	static TreeSet<Rec> HS(){
		return new TreeSet<Rec>((a,b) -> (a.x1 == b.x1 ? a.id-b.id : a.x1-b.x1));
	}
	static TreeSet<Rec> VE(){
		return new TreeSet<Rec>((a,b) -> (a.y2 == b.y2 ? a.id-b.id : a.y2-b.y2));
	}
	static TreeSet<Rec> VS(){
		return new TreeSet<Rec>((a,b) -> (a.y1 == b.y1 ? a.id-b.id : a.y1-b.y1));
	}
	static class Rec{
		int x1,y1,x2,y2,id;
		public Rec(int a, int b, int c, int d, int ii) {
			x1=a; y1=b; x2=c; y2=d;
			id=ii;
		}
	}

	static class FS{
		BufferedReader br;
		StringTokenizer st;
		public FS() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while(st == null || !st.hasMoreElements()) {
				try { st = new StringTokenizer(br.readLine());}
				catch(Exception e) { throw null;}
			}
			return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next());}
	}
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        long t = input.nextLong();
        long s = input.nextLong();
        long x = input.nextLong();

        if ((x - t) % s == 0 && (x - t) >= 0) {
            System.out.println("YES");
        } else if ((x - t - 1) % s == 0 && (x - t - 1) != 0 && (x - t - 1) > 0) {
            System.out.println("YES");
        } else {
            System.out.println("No");
        }

    }

}


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

public class CF_574A_BearAndElections {

	static Scanner user_input ;
	static int n ;
	static int m0 ;
	static int m[];
	public static void main(String Args[])
	{
user_input = new Scanner( System.in );
int count=0;
		n=user_input.nextInt();
		m = new int[n-1];
		m0=user_input.nextInt();
		for(int i=0;i<n-1;i++)
		{
			m[i]=user_input.nextInt();
		}

		 Arrays.sort(m);
		while(m0<=m[n-2])
		{
			m[n-2]--;
			m0++;

			count++;
			Arrays.sort(m);
		}
		System.out.println(count);

	}

}


import java.util.Scanner;

public class Main {

    public static String reverseStringWithCharAt(String inputString) {
        int stringLength = inputString.length();
        String result = "";
        for (int i = 0; i < stringLength; i++) {
            result = inputString.charAt(i) + result;
        }
        return result;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        //int num = in.nextInt();
        long x = in.nextLong();
        long y = in.nextLong();
        String X = Long.toBinaryString(x);
        if (X.equals(reverseStringWithCharAt(Long.toBinaryString(Long.parseLong(reverseStringWithCharAt(X), 2))))) {
            String XX = reverseStringWithCharAt(X);
            XX = Long.toBinaryString(Long.parseLong(XX, 2));
            String Y = Long.toBinaryString(y);
            int k = 0;
            for (int i = 0; i < Y.length(); i++) {
                int l = X.length();
                if (i + l <= Y.length()) {
                    if (X.equals(Y.substring(i, i + l))) {
                        k = 1;
                        for (int j = 0; j < i; j++) {
                            if (Y.charAt(j) == '0') {
                                k = 0;
                            }
                        }
                        for (int j = i + l; j < Y.length(); j++) {
                            if (Y.charAt(j) == '0') {
                                k = 0;
                            }
                        }
                    }
                    if (k == 1) {
                        System.out.println("YES");
                        return;
                    }
                }
                l = XX.length();
                if (i + l <= Y.length()) {
                    if (XX.equals(Y.substring(i, i + l))) {
                        k = 1;
                        for (int j = 0; j < i; j++) {
                            if (Y.charAt(j) == '0') {
                                k = 0;
                            }
                        }
                        for (int j = i + l; j < Y.length(); j++) {
                            if (Y.charAt(j) == '0') {
                                k = 0;
                            }
                        }
                    }
                    if (k == 1) {
                        System.out.println("YES");
                        return;
                    }
                }

            }
        } else {
            int l = X.length();
            String Y = Long.toBinaryString(y);
            int i = 0;
            int k = 0;
            if (X.equals(Y)) {
                System.out.println("YES");
                return;
            }
            String oldX = X;
            X += "1";
            X = reverseStringWithCharAt(X);
            X = Long.toBinaryString(Long.parseLong(X, 2));
            String XX = reverseStringWithCharAt(X);
            XX = Long.toBinaryString(Long.parseLong(XX, 2));
            k = 0;
            for (i = 0; i < Y.length(); i++) {
                l = X.length();
                if (i + l <= Y.length()) {
                    if (X.equals(Y.substring(i, i + l))) {
                        k = 1;
                        for (int j = 0; j < i; j++) {
                            if (Y.charAt(j) == '0') {
                                k = 0;
                            }
                        }
                        for (int j = i + l; j < Y.length(); j++) {
                            if (Y.charAt(j) == '0') {
                                k = 0;
                            }
                        }
                    }
                    if (k == 1) {
                        System.out.println("YES");
                        return;
                    }
                }
                l = XX.length();
                if (i + l <= Y.length()) {
                    if (XX.equals(Y.substring(i, i + l))) {
                        k = 1;
                        for (int j = 0; j < i; j++) {
                            if (Y.charAt(j) == '0') {
                                k = 0;
                            }
                        }
                        for (int j = i + l; j < Y.length(); j++) {
                            if (Y.charAt(j) == '0') {
                                k = 0;
                            }
                        }
                    }
                    if (k == 1) {
                        System.out.println("YES");
                        return;
                    }
                }
            }

            X = oldX;
            X = reverseStringWithCharAt(X);
            X = Long.toBinaryString(Long.parseLong(X, 2));
            XX = reverseStringWithCharAt(X);
            XX = Long.toBinaryString(Long.parseLong(XX, 2));
            k = 0;
            for (i = 0; i < Y.length(); i++) {
                l = X.length();
                if (i + l <= Y.length()) {
                    if (X.equals(Y.substring(i, i + l))) {
                        k = 1;
                        for (int j = 0; j < i; j++) {
                            if (Y.charAt(j) == '0') {
                                k = 0;
                            }
                        }
                        for (int j = i + l; j < Y.length(); j++) {
                            if (Y.charAt(j) == '0') {
                                k = 0;
                            }
                        }
                    }
                    if (k == 1) {
                        System.out.println("YES");
                        return;
                    }
                }
                l = XX.length();
                if (i + l <= Y.length()) {
                    if (XX.equals(Y.substring(i, i + l))) {
                        k = 1;
                        for (int j = 0; j < i; j++) {
                            if (Y.charAt(j) == '0') {
                                k = 0;
                            }
                        }
                        for (int j = i + l; j < Y.length(); j++) {
                            if (Y.charAt(j) == '0') {
                                k = 0;
                            }
                        }
                    }
                    if (k == 1) {
                        System.out.println("YES");
                        return;
                    }
                }
            }
        }
        System.out.println("NO");
        return;
    }
}


import java.util.*;

public class CODE {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int T = sc.nextInt();
        int S = sc.nextInt();
        int Q = sc.nextInt();
        int c = 1;
        for (int i = 0; true; i++) {
            if (S >= T) {
                System.out.println(c);
                break;
            }

            int s = S;// store the old value of "s"
            if (i % Q == 0) {
                S += (Q - 1);
            }

            if (i == s) {
                i = 0;
                c++;
            }
        }
    }

}


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

public class JavaApplication7 {
    static int[] winners;
    static int ans;

    public static boolean contains(final int[] array, final int key) {
    for (final int i : array) {
        if (i == key) {
            return true;
        }
    }
    return false;
}

    public static void findwinners(int s)
    {
    int i = (s/50) % 475;
    for (int j = 0; j<25;j++)
    {
        i =(i * 96 + 42) % 475;
        winners[j]=26 + i;
    }
    }

    public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter pw = new PrintWriter(System.out);
    StringTokenizer st = new StringTokenizer(br.readLine());
    int p = Integer.parseInt(st.nextToken());
    int x = Integer.parseInt(st.nextToken());
    int y = Integer.parseInt(st.nextToken());
    winners = new int[25];
    int z = x;
    while(z>=y+50)
    {
        z=z-50;
    }
    //int target;
    findwinners(z);
    while(!contains(winners,p))
    {
        z=z+50;
        findwinners(z);

    }
    //pw.println(z);
    //for(int i=0;i<25;i++){
    //pw.println(winners[i]);}
    if(x>=z) ans=0;
    else ans = (z+50-x)/100;
    pw.println(ans);
    pw.close();
    }

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "khokharnikunj8", 1 << 29);
        thread.start();
        thread.join();
    }

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

    static class CBinarySearch {
        Modular md = new Modular(1000000007);
        Factorial fc = new Factorial(10000, md);

        public int get(int n, int r) {
            return md.mul(fc.fact(n), md.mul(fc.inv(r), fc.inv(n - r)));
        }

        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            int x = in.readInt();
            int pos = in.readInt();
            int low = 0;
            int high = n;
            int smaller = 0;
            int greater = 0;
            while (low < high) {
                int mid = (low + high) >> 1;
                if (pos == mid) {
                    low = mid + 1;
                    continue;
                }
                if (pos < mid) {
                    greater++;
                    high = mid;
                } else {
                    smaller++;
                    low = mid + 1;
                }
            }
            int ans = 1;
            if (x - 1 < smaller || n - x < greater) {
                out.println(0);
                return;
            }
            ans = md.mul(ans, get(x - 1, smaller));
            ans = md.mul(ans, get(n - x, greater));
            ans = md.mul(ans, fc.fact(smaller));
            ans = md.mul(ans, fc.fact(greater));
            int rem = n - 1 - smaller - greater;
            ans = md.mul(ans, fc.fact(rem));
            out.println(ans);

        }

    }

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

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

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

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

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

    }

    static class Modular {
        private final int mod;

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

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

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

        public int getMod() {
            return this.mod;
        }

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

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

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

    }

    static class InverseNumber {
        int[] inv;
        Modular modular;

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

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

        public int inv(int index) {
            return inv[index];
        }

    }

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

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

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

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

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

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

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

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

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

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

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

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

    }

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

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

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

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

        public int readInt() {
            int sign = 1;

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

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

            return val;
        }

    }
}


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

/******************************\
 * The solution is at the top *
 *                            *
 *   Created by : azhar556    *
\******************************/

public class Solution {
    static void solve() {
        int n = ni();
        int m = ni();
        int k = ni();
        int[] s = new int[n];
        int[] b = new int[m];
        int minBuy = Integer.MAX_VALUE;
        int maxSell = 0;
        for (int i = 0; i < n; i++) {
            s[i] = ni();
            if (s[i] < minBuy) minBuy = s[i];
        }
        for (int i = 0; i < m; i++) {
            b[i] = ni();
            if (b[i] > maxSell) maxSell = b[i];
        }
        int res = (k / minBuy) * maxSell + k % minBuy;
        out.println(Math.max(res, k));
    }

    public static void main(String[] args) {
        long time = System.currentTimeMillis();
        int t;// = ni();
        t = 1;
        while (t-- > 0) solve();
        err.println("Time elapsed : " + (System.currentTimeMillis() - time) / 1000F + " s.");
        err.close(); out.close();
    }

    static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    static PrintWriter err = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err)));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer token;

    static String ns() {
        while (token == null || !token.hasMoreTokens()) {
            try {
                token = new StringTokenizer(br.readLine());
            }
            catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return token.nextToken();
    }
    static char nc() {
        return Character.valueOf(ns().charAt(0));
    }
    static int ni() {
        return Integer.parseInt(ns());
    }
    static double nd() {
        return Double.parseDouble(ns());
    }
    static long nl() {
        return Long.parseLong(ns());
    }
}


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

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 class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private final DataInputStream din;
        private final byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

    static long MOD = (long) (1e9 + 7);

    static long powerLL(long x, long n)
    {
        long result = 1;
        while (n > 0)
        {
            if (n % 2 == 1)
            {
                result = result * x % MOD;
            }
            n = n / 2;
            x = x * x % MOD;
        }
        return result;
    }

    static long powerStrings(String sa, String sb)
    {
        long a = 0, b = 0;

        for (int i = 0; i < sa.length(); i++)
        {
            a = (a * 10 + (sa.charAt(i) - '0')) %
                    MOD;
        }

        for (int i = 0; i < sb.length(); i++)
        {
            b = (b * 10 + (sb.charAt(i) - '0')) %
                    (MOD - 1);
        }

        return powerLL(a, b);
    }

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

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

    static int lower_bound(List<Integer> list, int k)
    {
        int s = 0;
        int e = list.size();

        while (s!=e)
        {
            int mid = (s+e)>>1;

            if (list.get(mid)<k) s = mid+1;
            else e = mid;
        }

        if (s == list.size()) return -1;
        return s;
    }

    static int upper_bound(List<Integer> list, int k)
    {
        int s = 0;
        int e = list.size();

        while (s!=e)
        {
            int mid = (s+e)>>1;

            if (list.get(mid)<=k) s = mid+1;
            else e = mid;
        }

        if (s == list.size()) return -1;
        return s;
    }

    static void addEdge(ArrayList<ArrayList<Integer>>graph, int edge1, int edge2)
    {
        graph.get(edge1).add(edge2);
        graph.get(edge2).add(edge1);
    }

    static class Pair<X,Y>
    {
        public final X first;
        public final Y second;

        Pair(X first, Y second)
        {
            this.first = first;
            this.second = second;
        }

        public static <X,Y> Pair <X,Y> of (X a, Y b)
        {
            return new Pair<>(a,b);
        }

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

    static class Comparee
    {
        static void compare(List<Pair<Integer, Integer>> pairs, int m)
        {
            Collections.sort(pairs, new Comparator<Pair<Integer, Integer>>() {
                @Override
                public int compare(Pair<Integer, Integer> p1, Pair<Integer, Integer> p2) {
                    return p1.second - p2.second;
                }
            });
        }
    }

    public static void main(String[] args) throws java.lang.Exception
    {
        try
        {
            //FastReader fr = new FastReader();
            Reader fr = new Reader();

            try(OutputStream out = new BufferedOutputStream(System.out))
            {
                int n = fr.nextInt();
                int m = fr.nextInt();

                List<Pair<Integer,Integer>> pairs = new ArrayList<>();
                Pair<Integer, Integer> p1;

                for (int i=0;i<m;i++)
                {
                    p1 = Pair.of(fr.nextInt(), fr.nextInt());

                    pairs.add(p1);
                }

                //out.write((pairs+"").getBytes());
                Comparee.compare(pairs,m);

                //for (int i=0;i<m;i++) out.write((pairs.get(i).first+" "+pairs.get(i).second+"\n").getBytes());

                long sum = 0;
                int count = 0;

                for (int i=m-1;i>=0;i--)
                {
                    if (pairs.get(i).first<=n-count)
                    {
                        count+=pairs.get(i).first;
                        sum+=(pairs.get(i).first * pairs.get(i).second);
                    }
                    else
                    {
                        int c = n-count;
                        sum+=(c*pairs.get(i).second);
                        count+=c;
                    }

                    if (count == n) break;
                }

                out.write((sum+"").getBytes());

                out.flush();
            }

        }

        catch(Exception e){}
        finally{}
    }
}

//(()) () (()((()()()())))


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class V {
	public static void main(String[] args) throws IOException {
		 BufferedReader x = new BufferedReader(new InputStreamReader(System.in));
		 int b=Integer.parseInt(x.readLine());
		 int c=Integer.parseInt(x.readLine());
		 int d=Integer.parseInt(x.readLine());
		 System.out.println( (1+((b>d&&c>d)?d:(b<=d&&c>=d)?b:(b<d&&c<d)?b+c-d:c)));
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main
{
    public static void main(String[] args) throws Exception
    {
        int[][] cost = new int[][]
        {
            { 3, 3, 4, 4, 3, 3 },
            { 3, 3, 4, 4, 3, 3 },
            { 2, 2, 3, 3, 2, 2 },
            { 2, 2, 3, 3, 2, 2 },
            { 1, 1, 2, 2, 1, 1 },
            { 1, 1, 2, 2, 1, 1 }
        };
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        char[][] map = new char[6][];
        for (int y = 0; y < 6; y++)
        {
            String line = br.readLine();
            map[y] = line.toCharArray();
        }
        int maxCost = 0, maxY = 0, maxX = 0;
        for (int y = 0; y < 6; y++)
        {
            for (int x = 0, i = 0; x < 8; x++)
            {
                if (map[y][x] == '.')
                {
                    int currCost = cost[y][i];
                    if (currCost > maxCost)
                    {
                        maxCost = currCost;
                        maxY = y;
                        maxX = x;
                    }
                }
                if (map[y][x] != '-')
                    i++;
            }
        }
        map[maxY][maxX] = 'P';
        for (int y = 0; y < 6; y++)
        {
            for (int x = 0; x < 8; x++)
                System.out.print(map[y][x]);
            System.out.println();
        }
    }
}


/*	/ ﾌﾌ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ム
	/ )\⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀  Y
	(⠀⠀| ( ͡° ͜ʖ ͡°）⠀⌒(⠀ ノ
	(⠀ ﾉ⌒ Y ⌒ヽ-く __／
	| _⠀｡ノ| ノ｡ |/
	(⠀ー '_人`ー ﾉ
	⠀|\ ￣ _人'彡ﾉ
	⠀ )\⠀⠀ ｡⠀⠀ /
	⠀⠀(\⠀ #⠀ /
	⠀/⠀⠀⠀/ὣ====================D-
	/⠀⠀⠀/⠀ \ \⠀⠀\
	( (⠀)⠀⠀⠀⠀ ) ).⠀)
	(⠀⠀)⠀⠀⠀⠀⠀( | /
	|⠀ /⠀⠀⠀⠀⠀⠀ | /
	[_] ⠀⠀⠀⠀⠀[___]                     */
// Main Code at the Bottom
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	//Fast IO class
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
        public FastReader() {
        	boolean env=System.getProperty("ONLINE_JUDGE") != null;
        	if(!env) {
        		try {
					br=new BufferedReader(new FileReader("src\\input.txt"));
				} catch (FileNotFoundException e) {
					e.printStackTrace();
				}
        	}
        	else 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 long MOD=1000000000+7;
    //Euclidean Algorithm
    static long gcd(long A,long B){
        if(B==0) return A;
        return gcd(B,A%B);
    }
    //Modular Exponentiation
    static long fastExpo(long x,long n){
        if(n==0) return 1;
        if((n&1)==0) return fastExpo((x*x)%MOD,n/2)%MOD;
        return ((x%MOD)*fastExpo((x*x)%MOD,(n-1)/2))%MOD;
    }
    //Modular Inverse
    static long inverse(long x) {
    	return fastExpo(x,MOD-2);
    }
    //Prime Number Algorithm
    static boolean isPrime(long n){
        if(n<=1) return false;
        if(n<=3) return true;
        if(n%2==0 || n%3==0) return false;
        for(int i=5;i*i<=n;i+=6) if(n%i==0 || n%(i+2)==0) return false;
        return true;
    }
    //Reverse an array
    static void reverse(int arr[],int l,int r){
    	while(l<r) {
    		int tmp=arr[l];
    		arr[l++]=arr[r];
    		arr[r++]=tmp;
    	}
    }
    //Print array
    static void print1d(int arr[]) {
    	out.println(Arrays.toString(arr));
    }
    static void print2d(int arr[][]) {
    	for(int a[]: arr) out.println(Arrays.toString(a));
    }
    // Pair
    static class pair{
    	long x,y;
    	pair(long a,long b){
    		this.x=a;
    		this.y=b;
    	}
    	public boolean equals(Object obj) {
    		if(obj == null || obj.getClass()!= this.getClass()) return false;
            pair p = (pair) obj;
            return (this.x==p.x && this.y==p.y);
        }
    	public int hashCode() {
            return Objects.hash(x,y);
        }
    }
    static FastReader sc=new FastReader();
    static PrintWriter out=new PrintWriter(System.out);
    //Main function(The main code starts from here)
    public static void main (String[] args) throws java.lang.Exception {
    	int test=1;
        while(test-->0) {
        	int n=sc.nextInt(),m=sc.nextInt(),b[]=new int[n];
        	for(int i=0;i<m;i++) {
        		int a=sc.nextInt();
        		for(int j=a-1;j<n;j++) if(b[j]==0) b[j]=a;
        	}
        	for(int i: b) out.print(i+" ");

        }
        out.flush();
        out.close();
    }
}


import java.util.*;

public class C {
	private static Scanner in;

	int n;
	long[] a;
	int[] p;
	int sumP;
	int ans;

	public void run() {
		n = in.nextInt();
		a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextLong();
		}
		Arrays.sort(a);
		p = new int[n];
		sumP = 0;
		for (int i = 0; i < n; i++) {
			long v = a[i];
			for (int t = 2; t * (long) t <= v; t++) {
				while (v % t == 0) {
					v /= t;
					p[i]++;
				}
			}
			if (v > 1) {
				p[i]++;
			}
			if (p[i] > 1) {
				sumP += p[i];
			}
		}
		ans = Integer.MAX_VALUE;
		search(0, 0);
		System.out.println(ans);
	}

	void search(int state, int count) {
		int top = 1;
		if (Integer.bitCount(state) == 2 * n - 1 || n == 1) {
			top = 0;
		}
		ans = Math.min(ans, top + n + sumP - count);
		for (int t = 0; t < n; t++) {
			if (((state >> (2 * t)) & 3) != 0) {
				continue;
			}
			search(state, count, t, 0, a[t], 0);
		}
	}

	void search(int state, int count, int t, int x, long m, int taken) {
		while (x < n && (x == t || ((state >> (2 * x)) & 3) == 3 || m % a[x] != 0)) {
			x++;
		}
		if (x == n) {
			if (taken == 0) {
				return;
			}
			state |= 2 << (2 * t);
			for (int i = 0; i < n; i++) {
				if (((taken >> i) & 1) == 0) {
					continue;
				}
				state |= 3 << (2 * i);
				count += p[i];
			}
			search(state, count);
			return;
		}
		search(state, count, t, x + 1, m, taken);
		search(state, count, t, x + 1, m / a[x], taken | (1 << x));
	}

	public static void main(String[] args) {
		Locale.setDefault(Locale.US);
		in = new Scanner(System.in);
		new C().run();
		in.close();
	}
}
// 8 2 3 4 5 6 7 8 9


import java.util.Scanner;

public class CF306A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] arr = new int[m];
        int div = (int) n/m;
        int left = n%m;
        for (int i = 0; i < m; i++) {
            arr[i] = div;
        }
        int i=m-1;
        while(left>0){
            arr[i]++;
            i--;
            left--;
        }

        for(i=0;i<m;i++)
            System.out.print(arr[i]+" ");
    }
}