// import org.junit.Test;
import java.util.Scanner;

// import static org.junit.Assert.assertEquals;

public class CF_1223G {
    static Scanner scanner = new Scanner(System.in);
    public static void main(String args[])
    {
         //test();
        long caseNum = 1;
        while (caseNum-- > 0) {
            task();
        }
    }

    private static int maxN = 500000;
    private static int[] a = new int[maxN + 10];
    private static int[] sum = new int[maxN + 10];
    private static int[] input = new int[maxN + 10];

    public static void task() {
        int n = scanner.nextInt();
        // System.out.println(n);
        for (int i = 0; i < n; i++) {
            input[i] = scanner.nextInt();
        }
        // System.out.println("input end");
        solve(n, input);
    }

    public static void clear(int n) {
        for (int i = 1; i <= maxN + 1; i++) {
            a[i] = 0;
            sum[i] = 0;
        }
    }

    private static int maxA;

    public static long solve(int n, int[] input) {
        long maxArea = 0;
        maxA = 0;
        clear(n);
        for (int i = 0; i < n; i++) {
            a[input[i]]++;
            if (input[i] > maxA) {
                maxA = input[i];
            }
        }
        for (int i = 2; i <= maxN + 1; i++) {
            sum[i] = a[i] + sum[i - 1];
        }

        for (int y = 2; y <= maxA; y++) {
            long total = 0;
            for (int step = y; step <= maxA; step += y) {
                total += q(step, min(step + y - 1, maxA) + 1) * (long) (step / y);
            }
            int x = 1;
            int left = 2;
            int right = maxA;
            while (left <= right) {
                int mid = (left + right) / 2;
                if (check(y, mid, total)) {
                    if (mid > x) {
                        x = mid;
                    }
                    left = mid + 1;
                } else {
                    right = mid - 1;
                }
            }
            if (x > 1) {
                if ((long) x * (long) y > maxArea) {
                    maxArea = (long) x * (long) y;
                    /*
                    System.out.println(y + " " + x);
                    System.out.println(maxArea);
                     */
                }
            }
        }
        System.out.println(maxArea);

        return maxArea;
    }

    public static boolean check(int y, int x, long total) {
        if (y == 4) {
           // System.out.println("fcuk");
        }
        boolean ret = check1(y, x, total, x + x, false) || check2(y, x, total);
        //System.out.println(y + " " + x + " " + total + " " + ret);
        return ret;
    }

    public static boolean check1(int y, int x, long total, int need, boolean ignore) {
        // together
        long up = (need - 1) / y + 1;
        long down = need / y;
        int hits = 0;
        if (!ignore) {
            if (need < y) {
                if (q(need, y) > 0) {
                    hits = 1;
                }
            }
        }
        if (hits == 1) {
            return total >= x;
        }
        int toSub = 0;
        int remain = need % y;
        for (int step = max(y, need - remain); step + remain <= maxA; step += y) {
            if (q(step + remain, min(step + y,maxA + 1)) > 0) {
                toSub = 1;
                break;
            }
        }
        if (toSub == 1) {
            return total >= x + down;
        } else {
            if (q(need, maxA + 1) > 0) {
                return total >= x + up;
            } else {
                return false;
            }
        }
    }

    private static int min(int x, int y) {
        if (x < y) {
            return x;
        }
        return y;
    }

    private static int max(int x, int y) {
        if (x > y) {
            return x;
        }
        return y;
    }

    public static boolean check2(int y, int x, long total) {
        // separate
        int need = x;
        int up = (need - 1) / y + 1;
        int down = need / y;
        int hits = 0;
        if (need < y) {
            if (q(need, y) > 0) {
                hits = q(need, y);
            }
            if (hits >= 2) {
                hits = 2;
            }
        }
        if (hits == 2) {
            return total >= x;
        }
        // ?
        if (hits == 1) {
            return check1(y, x, total, x, true);
        }
        if (q(need, maxA + 1) < 2){
            return false;
        }
        if (hits == 0) {
            int toSub = 0;
            int remain = need % y;
            for (int step = max(y, need - remain); step + remain <= maxA; step += y) {
                int h = q(step + remain, min(step + y,maxA + 1));
                toSub += h;
                if (toSub >= 2) {
                    toSub = 2;
                    break;
                }
            }
            if (toSub == 2) {
                return total >= x + down + down;
            }
            if (toSub == 1) {
                return total >= x + down + up;
            }
            if (toSub == 0) {
                return total >= x + up + up;
            }
        }
        // never
        return false;
    }

    public static int q(int begin, int end) {
        if (begin > end) {
            return 0;
        }
        return sum[end - 1] - sum[begin - 1];
    }

    public static void test() {
        int n = 90792;
        int[] input = new int[maxN + 10];
        input[0] = 181565;
        input[1] = 181564;
        for (int i = 2; i < n; i++) {
            input[i] = 60522;
        }
        System.out.println(solve(n, input));
    }

    /*
    @Test
    public void test() {
        int n = 1;
        int[] input = {9};
        assertEquals(4, solve(n, input));
    }

    @Test
    public void test2() {
        String s = "9\n" +
                "9 10 9 18 9 9 9 28 9";
        s = "9\n" +
                "9 10 9 19 9 9 9 28 9";
        Scanner scanner = new Scanner(s);
        int n = scanner.nextInt();
        int [] input = new int[500000 +100];
        for (int i = 0; i < n; i++) {
            input[i] = scanner.nextInt();
        }
        assertEquals(90, solve(n, input));
    }
     */
}


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

    static class TaskC {
        final long infinity = Long.MAX_VALUE / 3;
        FastScanner in;

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            this.in = in;
            long bytesLeft0 = assertedNextInt();
            long timeLeft0 = assertedNextInt();
            long t0 = assertedNextInt();

            long a1 = assertedNextInt();
            long t1 = assertedNextInt();
            long p1 = assertedNextInt();

            long a2 = assertedNextInt();
            long t2 = assertedNextInt();
            long p2 = assertedNextInt();
            long u = solve(bytesLeft0, timeLeft0, t0, a1, t1, p1, a2, t2, p2);
            long v = solve(bytesLeft0, timeLeft0, t0, a2, t2, p2, a1, t1, p1);
            long ans = Math.min(u, v);
            if (ans >= infinity) {
                ans = -1;
            }
            out.println(ans);
        }

        private long solve(long bytesLeft0, long timeLeft0, long t0, long a1, long t1, long p1, long a2, long t2, long p2) {
            final int N = (int) 1e7 + 20;
            long ans = infinity;
            for (int k1 = 0; k1 <= N; k1++) {
                long cost1 = k1 * p1;
                long bytesDownloaded1 = Math.min(bytesLeft0, k1 * a1);
                long time1 = bytesDownloaded1 * t1;
                long bytesLeft1 = bytesLeft0 - bytesDownloaded1;
                long timeLeft1 = timeLeft0 - time1;
                if (timeLeft1 < 0) {
                    continue;
                }
                if (bytesLeft1 == 0) {
                    ans = Math.min(ans, cost1);
                    continue;
                }
                if (t0 * bytesLeft1 <= timeLeft1) {
                    ans = Math.min(ans, cost1);
                    continue;
                }
                if (t0 <= t2) {
                    continue;
                }
                if (bytesLeft1 * t2 > timeLeft1) {
                    continue;
                }
                long bytes0 = (timeLeft1 - bytesLeft1 * t2) / (t0 - t2);
                long bytes2 = bytesLeft1 - bytes0;
                long k2 = (bytes2 + a2 - 1) / a2;

                long cost2 = k2 * p2;
                ans = Math.min(ans, cost1 + cost2);
            }
            return ans;
        }

        private long assertedNextInt() {
            long x = in.nextLong();
            if (x < 1 || x > (int) 1e7) {
                throw new AssertionError();
            }
            return x;
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

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

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

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

    }
}


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

    static class TaskC {
        final long infinity = Long.MAX_VALUE / 3;
        FastScanner in;

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            this.in = in;
            long bytesLeft0 = assertedNextInt();
            long timeLeft0 = assertedNextInt();
            long t0 = assertedNextInt();

            long a1 = assertedNextInt();
            long t1 = assertedNextInt();
            long p1 = assertedNextInt();

            long a2 = assertedNextInt();
            long t2 = assertedNextInt();
            long p2 = assertedNextInt();
            long u = solve(bytesLeft0, timeLeft0, t0, a1, t1, p1, a2, t2, p2);
            long v = solve(bytesLeft0, timeLeft0, t0, a2, t2, p2, a1, t1, p1);
            long ans = Math.min(u, v);
            if (ans >= infinity) {
                ans = -1;
            }
            out.println(ans);
        }

        private long solve(long bytesLeft0, long timeLeft0, long t0, long a1, long t1, long p1, long a2, long t2, long p2) {
            final int N = (int) 1e7 + 20;
            long ans = infinity;
            for (int k1 = 0; k1 <= N; k1++) {
                long cost1 = k1 * p1;
                long bytesDownloaded1 = Math.min(bytesLeft0, k1 * a1);
                long time1 = bytesDownloaded1 * t1;
                long bytesLeft1 = bytesLeft0 - bytesDownloaded1;
                long timeLeft1 = timeLeft0 - time1;
                if (timeLeft1 < 0) {
                    continue;
                }
                if (bytesLeft1 == 0) {
                    ans = Math.min(ans, cost1);
                    continue;
                }
                if (t0 * bytesLeft1 <= timeLeft1) {
                    ans = Math.min(ans, cost1);
                    continue;
                }
                if (t0 <= t2) {
                    continue;
                }
                long bytes2 = (bytesLeft1 * t0 - timeLeft1 + (t0 - t2) - 1) / (t0 - t2);
                long k2 = (bytes2 + a2 - 1) / a2;

                long cost2 = k2 * p2;
                long bytesDownloaded2 = Math.min(bytesLeft1, k2 * a2);
                long time2 = bytesDownloaded2 * t2;
                long bytesLeft2 = bytesLeft1 - bytesDownloaded2;
                long timeLeft2 = timeLeft1 - time2;
                if (timeLeft2 >= 0 && bytesLeft2 * t0 <= timeLeft2) {
                    ans = Math.min(ans, cost1 + cost2);
                }
            }
            return ans;
        }

        private long assertedNextInt() {
            long x = in.nextLong();
            if (x < 1 || x > (int) 1e7) {
                throw new AssertionError();
            }
            return x;
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

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

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

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

    }
}


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

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

public class C implements Runnable{

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

    private final static Random rnd = new Random();
    private final static String fileName = "";

    private final static long MODULO = 1000 * 1000 * 1000 + 7;

    final int MAX_RND = 10;

    private void solve1() {
        for (int it = 0; it < 10; ++it) {
            int need = rnd.nextInt(10000) + 1;
            long maxTime = rnd.nextInt(10000000) + 1;
            long freeDefaultTime = rnd.nextInt(10) + 1;

            int firstDefaultSize = rnd.nextInt(100) + 1;
            long firstDefaultTime = rnd.nextInt(10) + 1;
            long firstDefaultCost = rnd.nextInt(10) + 1;

            int secondDefaultSize = rnd.nextInt(100) + 1;
            long secondDefaultTime = rnd.nextInt(10) + 1;
            long secondDefaultCost = rnd.nextInt(10) + 1;

            long[] answer = getAnswer(need, maxTime, freeDefaultTime,
                    firstDefaultSize, firstDefaultTime, firstDefaultCost,
                    secondDefaultSize, secondDefaultTime, secondDefaultCost);

            long[] bruteAnswer = getBruteAnswer(need, maxTime, freeDefaultTime,
                    firstDefaultSize, firstDefaultTime, firstDefaultCost,
                    secondDefaultSize, secondDefaultTime, secondDefaultCost);

            if (answer[0] != bruteAnswer[0]) {
                System.err.println("GOTCHA");

                System.err.println(Arrays.toString(answer));
                System.err.println(Arrays.toString(bruteAnswer));
                System.err.println(need + " " + maxTime + " " +firstDefaultTime);
                System.err.println(firstDefaultSize + " " + firstDefaultTime + " " +firstDefaultCost);
                System.err.println(secondDefaultSize + " " + secondDefaultTime + " " +secondDefaultCost);
            }
        }
    }

    private void solve() {
        long need = readInt();
        long maxTime = readInt();
        long freeDefaultTime = readInt();

        long firstDefaultSize = readInt();
        long firstDefaultTime = readInt();
        long firstDefaultCost = readInt();

        long secondDefaultSize = readInt();
        long secondDefaultTime = readInt();
        long secondDefaultCost = readInt();

//        long[] firstTimes = new long[need + 1];
//        long[] firstCosts = new long[need + 1];
//
//        for (int i = 1; i <= need; i += firstDefaultSize) {
//            firstTimes[i] = firstDefaultTime + (i == 1 ? 0 : firstTimes[i - firstDefaultSize]);
//            firstCosts[i] = firstDefaultCost + (i == 1 ? 0 : firstCosts[i - firstDefaultSize]);
//        }
//
//        for (int i = 1; i <= need; ++i) {
//            firstTimes[i] = max(firstTimes[i - 1], firstTimes[i]);
//            firstCosts[i] = max(firstCosts[i - 1], firstCosts[i]);
//        }
//
//        long[] secondTimes = new long[need + 1];
//        long[] secondCosts = new long[need + 1];
//
//        for (int i = 1; i <= need; i += secondDefaultSize) {
//            secondTimes[i] = secondDefaultTime + (i == 1 ? 0 : secondTimes[i - secondDefaultSize]);
//            secondCosts[i] = secondDefaultCost + (i == 1 ? 0 : secondCosts[i - secondDefaultSize]);
//        }
//
//        for (int i = 1; i <= need; ++i) {
//            secondTimes[i] = max(secondTimes[i - 1], secondTimes[i]);
//            secondCosts[i] = max(secondCosts[i - 1], secondCosts[i]);
//        }
//
//        long[] freeTimes = new long[need + 1];
//        for (int i = 1; i <= need; ++i) {
//            freeTimes[i] = freeTimes[i - 1] + freeDefaultTime;
//        }

        long[] answer = getAnswer(need, maxTime, freeDefaultTime,
                firstDefaultSize, firstDefaultTime, firstDefaultCost,
                secondDefaultSize, secondDefaultTime, secondDefaultCost
        );

        out.println(answer[0]);
    }

    long[] getAnswer(long need, long maxTime, long freeDefaultTime,
                     long firstDefaultSize,long firstDefaultTime,long firstDefaultCost,
                     long secondDefaultSize,long secondDefaultTime,long secondDefaultCost) {
        long answer = Long.MAX_VALUE;
        long firstOptimal = 0, secondOptimal = 0;

        for (long firstCount = 0, firstSize = 0, firstTime = 0, firstCost = 0; ;
             ++firstCount, firstSize += firstDefaultSize,
            firstCost += firstDefaultCost,
                     firstTime += firstDefaultTime * firstDefaultSize) {

            if (firstSize >= need) {
                firstSize = need;
                firstTime = firstDefaultTime * firstSize;
            }

            long canUseTime = maxTime - firstTime;
            long needUseSize = need - firstSize;
            if (canUseTime >= 0) {
                if (freeDefaultTime <= secondDefaultTime) {
                    long freeTime = freeDefaultTime * needUseSize;
                    if (freeTime + firstTime <= maxTime) {
                        if (answer > firstCost) {
                            answer = firstCost;
                            firstOptimal = firstCount;
                            secondOptimal = 0;
                        }
                    }
                } else {
                    long lowerSideCount = needUseSize / secondDefaultSize;
                    long lowerSecondSize = secondDefaultSize * lowerSideCount;
                    long lowerFreeSize = needUseSize - lowerSecondSize;

                    long lowerSecondTime = lowerSecondSize * secondDefaultTime;
                    long lowerFreeTime = lowerFreeSize * freeDefaultTime;

                    if (lowerSecondTime + lowerFreeTime <= canUseTime) {

                        if (answer > firstCost + lowerSideCount * secondDefaultCost) {
                            answer = firstCost + lowerSideCount * secondDefaultCost;
                            firstOptimal = firstCount;
                            secondOptimal = lowerSideCount;
                        }
                    }

                    long upperSideCount = needUseSize / secondDefaultSize;
                    if (needUseSize % secondDefaultSize != 0) ++upperSideCount;
                    long upperSecondSize = min(needUseSize, secondDefaultSize * upperSideCount);
                    long upperFreeSize = needUseSize - upperSecondSize;

                    long upperSecondTime = upperSecondSize * secondDefaultTime;
                    long upperFreeTime = upperFreeSize * freeDefaultTime;

                    if (upperSecondTime + upperFreeTime <= canUseTime) {
                        if (answer > firstCost + upperSideCount * secondDefaultCost) {
                            answer = firstCost + upperSideCount * secondDefaultCost;
                            firstOptimal = firstCount;
                            secondOptimal = upperSideCount;
                        }

                        long exactNumerator = ((needUseSize * freeDefaultTime - canUseTime));
                        long exactDenominator = (freeDefaultTime - secondDefaultTime) * secondDefaultSize;

                        long exactSideCount = exactNumerator / exactDenominator;
                        if (exactNumerator < 0) exactSideCount = 0;
                        else if (exactNumerator % exactDenominator != 0) {
                            exactSideCount++;
                        }
                        if (exactSideCount >= 0) {
                            long exactSecondSize = min(needUseSize, secondDefaultSize * exactSideCount);
                            long exactFreeSize = needUseSize - exactSecondSize;

                            long exactSecondTime = exactSecondSize * secondDefaultTime;
                            long exactFreeTime = exactFreeSize * freeDefaultTime;

                            if (exactSecondTime + exactFreeTime <= canUseTime) {

                                if (answer > firstCost + exactSideCount * secondDefaultCost) {
                                    answer = firstCost + exactSideCount * secondDefaultCost;
                                    firstOptimal = firstCount;
                                    secondOptimal = exactSideCount;
                                }
                            }
                        }
                    }

                }
            }

            if (firstSize >= need) break;
        }

        for (long secondCount = 0, secondSize = 0, secondCost = 0, secondTime = 0; ;
             ++secondCount, secondSize += secondDefaultSize,
                     secondCost += secondDefaultCost,
                     secondTime += secondDefaultTime * secondDefaultSize) {

            if (secondSize >= need) {
                secondSize = need;
                secondTime = secondDefaultTime * secondSize;
            }

            long canUseTime = maxTime - secondTime;
            long needUseSize = need - secondSize;
            if (canUseTime >= 0) {
                if (freeDefaultTime <= firstDefaultTime) {
                    long freeTime = freeDefaultTime * needUseSize;
                    if (freeTime + secondTime <= maxTime) {
                        if (answer > secondCost) {
                            answer = secondCost;
                            secondOptimal = secondCount;
                            firstOptimal = 0;
                        }
                    }
                } else {
                    long lowerSideCount = needUseSize / firstDefaultSize;
                    long lowerfirstSize = firstDefaultSize * lowerSideCount;
                    long lowerFreeSize = needUseSize - lowerfirstSize;

                    long lowerfirstTime = lowerfirstSize * firstDefaultTime;
                    long lowerFreeTime = lowerFreeSize * freeDefaultTime;

                    if (lowerfirstTime + lowerFreeTime <= canUseTime) {

                        if (answer > secondCost + lowerSideCount * firstDefaultCost) {
                            answer = secondCost + lowerSideCount * firstDefaultCost;
                            secondOptimal = secondCount;
                            firstOptimal = lowerSideCount;
                        }
                    }

                    long upperSideCount = needUseSize / firstDefaultSize;
                    if (needUseSize % firstDefaultSize != 0) ++upperSideCount;
                    long upperfirstSize = min(needUseSize, firstDefaultSize * upperSideCount);
                    long upperFreeSize = needUseSize - upperfirstSize;

                    long upperfirstTime = upperfirstSize * firstDefaultTime;
                    long upperFreeTime = upperFreeSize * freeDefaultTime;

                    if (upperfirstTime + upperFreeTime <= canUseTime) {
                        if (answer > secondCost + upperSideCount * firstDefaultCost) {
                            answer = secondCost + upperSideCount * firstDefaultCost;
                            secondOptimal = secondCount;
                            firstOptimal = upperSideCount;
                        }

                        long exactNumerator = ((needUseSize * freeDefaultTime - canUseTime));
                        long exactDenominator = (freeDefaultTime - firstDefaultTime) * firstDefaultSize;

                        long exactSideCount = exactNumerator / exactDenominator;
                        if (exactNumerator < 0) exactSideCount = 0;
                        else if (exactNumerator % exactDenominator != 0) {
                            exactSideCount++;
                        }
                        if (exactSideCount >= 0) {
                            long exactfirstSize = min(needUseSize, firstDefaultSize * exactSideCount);
                            long exactFreeSize = needUseSize - exactfirstSize;

                            long exactfirstTime = exactfirstSize * firstDefaultTime;
                            long exactFreeTime = exactFreeSize * freeDefaultTime;

                            if (exactfirstTime + exactFreeTime <= canUseTime) {

                                if (answer > secondCost + exactSideCount * firstDefaultCost) {
                                    answer = secondCost + exactSideCount * firstDefaultCost;
                                    secondOptimal = secondCount;
                                    firstOptimal = exactSideCount;
                                }
                            }
                        }
                    }

                }
            }

            if (secondSize >= need) break;
        }

        if (answer == Long.MAX_VALUE) {
            answer = -1;
        }

        return new long[] { answer, firstOptimal, secondOptimal };
    }

    long[] getBruteAnswer(int need, long maxTime, long freeDefaultTime,
                        int firstDefaultSize,long firstDefaultTime,long firstDefaultCost,
                        int secondDefaultSize,long secondDefaultTime,long secondDefaultCost) {
        long answer = Long.MAX_VALUE;
        long firstOptimal = 0, secondOptimal = 0;

        for (int firstCount = 0; ; ++firstCount) {
            int firstSize = min(need, firstCount * firstDefaultSize);
            if (firstSize >= need) firstSize = need;

            long firstTime = firstSize * firstDefaultTime;
            long firstCost = firstCount * firstDefaultCost;

            int needUseSize = (need - firstSize);
            for (int secondCount = 0; ; ++secondCount) {
                int secondSize = min(needUseSize, secondCount * secondDefaultSize);
                if (secondSize >= needUseSize) secondSize = needUseSize;

                long secondTime = secondSize * secondDefaultTime;
                long secondCost = secondCount * secondDefaultCost;

                int freeSize = needUseSize - secondSize;
                long freeTime = freeSize * freeDefaultTime;

                if (firstTime + secondTime + freeTime <= maxTime) {
                    if (answer > firstCost + secondCost) {
                        answer = firstCost + secondCost;
                        firstOptimal = firstCount;
                        secondOptimal = secondCount;
                    }
                }

                if (secondSize >= needUseSize) break;
            }

            if (firstSize >= need) break;
        }

        if (answer == Long.MAX_VALUE) {
            answer = -1;
        }

        return new long[] { answer, firstOptimal, secondOptimal };
    }

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

    private static long add(long a, long b) { return (a + b) % MODULO; }
    private static long subtract(long a, long b) { return add(a, MODULO - b) % MODULO; }
    private static long mult(long a, long b) { return (a * b) % MODULO; }

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

    private final static boolean FIRST_INPUT_STRING = false;
    private final static boolean MULTIPLE_TESTS = false;
    private final boolean ONLINE_JUDGE = !new File("input.txt").exists();
//    private final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    private final static int MAX_STACK_SIZE = 128;

    private final static boolean OPTIMIZE_READ_NUMBERS = false;

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

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

            init();

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

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

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

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

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

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

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

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

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

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

    private long timeBegin;

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

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

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

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

    private String delim = " ";

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

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

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

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

    private final char NOT_A_SYMBOL = '\0';

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

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

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

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

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

        return field;
    }

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

    private long optimizedReadLong() {
        int sign = 1;
        long result = 0;
        boolean started = false;
        while (true) {
            try {
                int j = in.read();
                if (-1 == j) {
                    if (started) return sign * result;
                    throw new NumberFormatException();
                }

                if (j == '-') {
                    if (started) throw new NumberFormatException();
                    sign = -sign;
                }

                if ('0' <= j && j <= '9') {
                    result = result * 10 + j - '0';
                    started = true;
                } else if (started) {
                    return sign * result;
                }
            } catch (IOException e) {
                throw new RuntimeIOException(e);
            }
        }
    }

    private int readInt() {

        if (!OPTIMIZE_READ_NUMBERS) {
            return Integer.parseInt(readString());
        } else {
            return (int) optimizedReadLong();
        }
    }

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

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

        return array;
    }

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

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

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

        return sortedArray;
    }

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

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

        return array;
    }

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

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

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

        return matrix;
    }

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

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

        return matrix;
    }

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

    private long readLong() {
        if (!OPTIMIZE_READ_NUMBERS) {
            return Long.parseLong(readString());
        } else {
            return optimizedReadLong();
        }
    }

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

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

        return array;
    }

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

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

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

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

        return array;
    }

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

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

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

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

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

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

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

        return array;
    }

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

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

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

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

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

        return graph;
    }

    private static class GraphBuilder {

        final int size;
        final List<Integer>[] edges;

        static GraphBuilder createInstance(int size) {
            List<Integer>[] edges = new List[size];
            for (int v = 0; v < size; ++v) {
                edges[v] = new ArrayList<Integer>();
            }

            return new GraphBuilder(edges);
        }

        private GraphBuilder(List<Integer>[] edges) {
            this.size = edges.length;
            this.edges = edges;
        }

        public void addEdge(int from, int to) {
            addDirectedEdge(from, to);
            addDirectedEdge(to, from);
        }

        public void addDirectedEdge(int from, int to) {
            edges[from].add(to);
        }

        public int[][] build() {
            int[][] graph = new int[size][];
            for (int v = 0; v < size; ++v) {
                List<Integer> vEdges = edges[v];
                graph[v] = castInt(vEdges);
            }

            return graph;
        }
    }

    private final static int ZERO_INDEXATION = 0, ONE_INDEXATION = 1;

    private int[][] readUnweightedGraph(int vertexNumber, int edgesNumber) {
        return readUnweightedGraph(vertexNumber, edgesNumber, ONE_INDEXATION, false);
    }

    private int[][] readUnweightedGraph(int vertexNumber, int edgesNumber,
                                        int indexation, boolean directed
    ) {
        GraphBuilder graphBuilder = GraphBuilder.createInstance(vertexNumber);
        for (int i = 0; i < edgesNumber; ++i) {
            int from = readInt() - indexation;
            int to = readInt() - indexation;

            if (directed) graphBuilder.addDirectedEdge(from, to);
            else graphBuilder.addEdge(from, to);
        }

        return graphBuilder.build();
    }

    private static class Edge {
        int to;
        int w;

        Edge(int to, int w) {
            this.to = to;
            this.w = w;
        }
    }

    private Edge[][] readWeightedGraph(int vertexNumber, int edgesNumber) {
        return readWeightedGraph(vertexNumber, edgesNumber, ONE_INDEXATION, false);
    }

    private Edge[][] readWeightedGraph(int vertexNumber, int edgesNumber,
                                       int indexation, boolean directed) {
        @SuppressWarnings("unchecked")
        List<Edge>[] graph = new List[vertexNumber];
        for (int v = 0; v < vertexNumber; ++v) {
            graph[v] = new ArrayList<Edge>();
        }

        while (edgesNumber --> 0) {
            int from = readInt() - indexation;
            int to = readInt() - indexation;
            int w = readInt();

            graph[from].add(new Edge(to, w));
            if (!directed) graph[to].add(new Edge(from, w));
        }

        Edge[][] graphArrays = new Edge[vertexNumber][];
        for (int v = 0; v < vertexNumber; ++v) {
            graphArrays[v] = graph[v].toArray(new Edge[0]);
        }

        return graphArrays;
    }

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

    private static class IntIndexPair {

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

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

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

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

                return index1 - index2;
            }
        };

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

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

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

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

                return index1 - index2;
            }
        };

        static IntIndexPair[] from(int[] array) {
            IntIndexPair[] iip = new IntIndexPair[array.length];
            for (int i = 0; i < array.length; ++i) {
                iip[i] = new IntIndexPair(array[i], i);
            }

            return iip;
        }

        int value, index;

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

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

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

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

        return array;
    }

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

    private static class OutputWriter extends PrintWriter {

        final int DEFAULT_PRECISION = 12;

        private int precision;
        private String format, formatWithSpace;

        {
            precision = DEFAULT_PRECISION;

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

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

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

        int getPrecision() {
            return precision;
        }

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

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

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

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

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

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

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

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

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

        void printAll(int... array) {
        	for (int value : array) {
        		print(value + " ");
        	}
        }

        void printlnAll(int... array) {
        	printAll(array);
        	println();
        }

        void printAll(long... array) {
        	for (long value : array) {
        		print(value + " ");
        	}
        }

        void printlnAll(long... array) {
        	printAll(array);
        	println();
        }
    }

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

    private static class RuntimeIOException extends RuntimeException {

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

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

    /////////////////////////////////////////////////////////////////////
    //////////////// Some useful constants andTo functions ////////////////
    /////////////////////////////////////////////////////////////////////

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

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

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

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

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

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

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

        return sum;
    }

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

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

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

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

        return new Point(min, max);
    }

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

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

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

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

        return primes;
    }

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

    int[] getDivisors(int value) {
        List<Integer> divisors = new ArrayList<Integer>();
        for (int divisor = 1; divisor * divisor <= value; ++divisor) {
            if (value % divisor == 0) {
                divisors.add(divisor);
                if (divisor * divisor != value) {
                    divisors.add(value / divisor);
                }
            }
        }

        return castInt(divisors);
    }

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

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

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

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

    private interface MultiSet<ValueType> {

        int size();

        void inc(ValueType value);
        boolean dec(ValueType value);

        int count(ValueType value);
    }

    private static abstract class MultiSetImpl
            <ValueType, MapType extends Map<ValueType, Integer>>
            implements MultiSet<ValueType> {

        protected final MapType map;
        protected int size;

        protected MultiSetImpl(MapType map) {
            this.map = map;
            this.size = 0;
        }

        public int size() {
            return size;
        }

        public void inc(ValueType value) {
            int count = count(value);
            map.put(value, count + 1);

            ++size;
        }

        public boolean dec(ValueType value) {
            int count = count(value);
            if (count == 0) return false;

            if (count == 1) map.remove(value);
            else map.put(value, count - 1);

            --size;
            return true;
        }

        public int count(ValueType value) {
            Integer count = map.get(value);
            return (count == null ? 0 : count);
        }
    }

    private static class HashMultiSet<ValueType>
            extends MultiSetImpl<ValueType, Map<ValueType, Integer>> {

        public static <ValueType> MultiSet<ValueType> createMultiSet() {
            Map<ValueType, Integer> map = new HashMap<ValueType, Integer>();
            return new HashMultiSet<ValueType>(map);
        }

        HashMultiSet(Map<ValueType, Integer> map) {
            super(map);
        }
    }

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

    private interface SortedMultiSet<ValueType> extends MultiSet<ValueType> {

        ValueType min();
        ValueType max();

        ValueType pollMin();
        ValueType pollMax();

        ValueType lower(ValueType value);
        ValueType floor(ValueType value);

        ValueType ceiling(ValueType value);
        ValueType higher(ValueType value);
    }

    private static abstract class SortedMultiSetImpl<ValueType>
            extends MultiSetImpl<ValueType, NavigableMap<ValueType, Integer>>
            implements SortedMultiSet<ValueType> {

        SortedMultiSetImpl(NavigableMap<ValueType, Integer> map) {
            super(map);
        }

        @Override
        public ValueType min() {
            return (size == 0 ? null : map.firstKey());
        }

        @Override
        public ValueType max() {
            return (size == 0 ? null : map.lastKey());
        }

        @Override
        public ValueType pollMin() {
            ValueType first = min();
            if (first != null) dec(first);
            return first;
        }

        @Override
        public ValueType pollMax() {
            ValueType last = max();
            dec(last);
            return last;
        }

        @Override
        public ValueType lower(ValueType value) {
            return map.lowerKey(value);
        }

        @Override
        public ValueType floor(ValueType value) {
            return map.floorKey(value);
        }

        @Override
        public ValueType ceiling(ValueType value) {
            return map.ceilingKey(value);
        }

        @Override
        public ValueType higher(ValueType value) {
            return map.higherKey(value);
        }
    }

    private static class TreeMultiSet<ValueType>
            extends SortedMultiSetImpl<ValueType> {

        public static <ValueType> SortedMultiSet<ValueType> createMultiSet() {
            NavigableMap<ValueType, Integer> map = new TreeMap<ValueType, Integer>();
            return new TreeMultiSet<ValueType>(map);
        }

        TreeMultiSet(NavigableMap<ValueType, Integer> map) {
            super(map);
        }
    }

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

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

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

        public IdMap() {
            super();
        }

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

            return id;
        }

        int getId(KeyType key) {
            return get(key);
        }
    }

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

    private static class SortedIdMapper<ValueType extends Comparable<ValueType>> {

        private List<ValueType> values;

        public SortedIdMapper() {
            this.values = new ArrayList<ValueType>();
        }

        void addValue(ValueType value) {
            values.add(value);
        }

        IdMap<ValueType> build() {
            Collections.sort(values);

            IdMap<ValueType> ids = new IdMap<ValueType>();
            List<ValueType> uniqueValues = new ArrayList<ValueType>();

            for (int index = 0; index < values.size(); ++index) {
                ValueType value = values.get(index);
                if (index == 0 || values.get(index - 1).compareTo(value) != 0) {
                    ids.register(value);
                    uniqueValues.add(value);
                }
            }

            values = uniqueValues;

            return ids;
        }
    }

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

    private static int[] castInt(List<Integer> list) {
        int[] array = new int[list.size()];
        for (int i = 0; i < array.length; ++i) {
            array[i] = list.get(i);
        }

        return array;
    }

    private static long[] castLong(List<Long> list) {
        long[] array = new long[list.size()];
        for (int i = 0; i < array.length; ++i) {
            array[i] = list.get(i);
        }

        return array;
    }

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

    /**
     * Generates list with keys 0..<n
     * @param n - exclusive limit of sequence
     */
    private static List<Integer> order(int n) {
        List<Integer> sequence = new ArrayList<Integer>();
        for (int i = 0; i < n; ++i) {
            sequence.add(i);
        }

        return sequence;
    }

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

    interface Rmq {
        int getMin(int left, int right);
        int getMinIndex(int left, int right);
    }

    private static class SparseTable implements Rmq {

        private static final int MAX_BIT = 17;

        int n;
        int[] array;

        SparseTable(int[] array) {
            this.n = array.length;
            this.array = array;
        }

        int[] lengthMaxBits;
        int[][] table;

        int getIndexOfLess(int leftIndex, int rightIndex) {
            return (array[leftIndex] <= array[rightIndex])
                    ? leftIndex
                    : rightIndex;
        }

        SparseTable build() {
            this.lengthMaxBits = new int[n + 1];
            lengthMaxBits[0] = 0;
            for (int i = 1; i <= n; ++i) {
                lengthMaxBits[i] = lengthMaxBits[i - 1];
                int length = (1 << lengthMaxBits[i]);
                if (length + length <= i) ++lengthMaxBits[i];
            }

            this.table = new int[MAX_BIT][n];
            table[0] = castInt(order(n));

            for (int bit = 0; bit < MAX_BIT - 1; ++bit) {
                for (int i = 0, j = (1 << bit); j < n; ++i, ++j) {
                    table[bit + 1][i] = getIndexOfLess(
                            table[bit][i], table[bit][j]
                    );
                }
            }

            return this;
        }

        @Override
        public int getMinIndex(int left, int right) {
            int length = (right - left + 1);

            int bit = lengthMaxBits[length];
            int segmentLength = (1 << bit);

            return getIndexOfLess(
                    table[bit][left], table[bit][right - segmentLength + 1]
            );
        }

        @Override
        public int getMin(int left, int right) {
            return array[getMinIndex(left, right)];
        }
    }

    private static Rmq createRmq(int[] array) {
        return new SparseTable(array).build();
    }

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

    interface Lca {
        Lca build(int root);
        int lca(int a, int b);

        int height(int v);
    }

    private static class LcaRmq implements Lca {

        int n;
        int[][] graph;

        LcaRmq(int[][] graph) {
            this.n = graph.length;
            this.graph = graph;
        }

        int time;

        int[] order;
        int[] heights;
        int[] first;

        Rmq rmq;

        @Override
        public LcaRmq build(int root) {
            this.order = new int[n + n];
            this.heights = new int[n];

            this.first = new int[n];
            Arrays.fill(first, -1);

            this.time = 0;
            dfs(root, 0);

            int[] orderedHeights = new int[n + n];
            for (int i = 0; i < order.length; ++i) {
                orderedHeights[i] = heights[order[i]];
            }

            this.rmq = createRmq(orderedHeights);
            return this;
        }

        void dfs(int from, int height) {
            first[from] = time;
            order[time] = from;
            heights[from] = height;
            ++time;

            for (int to : graph[from]) {
                if (first[to] == -1) {
                    dfs(to, height + 1);

                    order[time] = from;
                    ++time;
                }
            }
        }

        @Override
        public int lca(int a, int b) {
            int aFirst = first[a], bFirst = first[b];
            int left = min(aFirst, bFirst), right = max(aFirst, bFirst);

            int orderIndex = rmq.getMinIndex(left, right);
            return order[orderIndex];
        }

        @Override
        public int height(int v) {
            return heights[v];
        }
    }

    private static class LcaBinary implements Lca {

        private static final int MAX_BIT = 20;

        int n;
        int[][] graph;

        int[] h;
        int[][] parents;

        LcaBinary(int[][] graph) {
            this.n = graph.length;
            this.graph = graph;
        }

        @Override
        public Lca build(int root) {
            this.h = new int[n];

            this.parents = new int[MAX_BIT][n];
            Arrays.fill(parents[0], -1);

            Queue<Integer> queue = new ArrayDeque<Integer>();

            queue.add(root);
            add(root, root);

            while (queue.size() > 0) {
                int from = queue.poll();
                for (int to : graph[from]) {
                    if (parents[0][to] == -1) {
                        add(from, to);
                        queue.add(to);
                    }
                }
            }

            return this;
        }

        void add(int parent, int v) {
            h[v] = h[parent] + 1;
            parents[0][v] = parent;
            for (int bit = 0; bit < MAX_BIT - 1; ++bit) {
                parents[bit + 1][v] = parents[bit][parents[bit][v]];
            }
        }

        @Override
        public int lca(int a, int b) {
            if (h[a] < h[b]) {
                int tmp = a;
                a = b;
                b = tmp;
            }

            int delta = h[a] - h[b];
            for (int bit = MAX_BIT - 1; bit >= 0; --bit) {
                if (delta >= (1 << bit)) {
                    delta -= (1 << bit);
                    a = parents[bit][a];
                }
            }

            if (a == b) return a;

            for (int bit = MAX_BIT - 1; bit >= 0; --bit) {
                int nextA = parents[bit][a], nextB = parents[bit][b];
                if (nextA != nextB) {
                    a = nextA;
                    b = nextB;
                }
            }

            return parents[0][a];
        }

        @Override
        public int height(int v) {
            return h[v];
        }
    }

    private static Lca createLca(int[][] graph, int root) {
        return new LcaRmq(graph).build(root);
    }

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

    private static class BiconnectedGraph {

        int n;
        int[][] graph;

        BiconnectedGraph(int[][] graph) {
            this.n = graph.length;
            this.graph = graph;
        }

        int time;
        int[] tin, up;

        boolean[] used;

        BiconnectedGraph build() {
            calculateTimes();
            condensateComponents();

            return this;
        }

        void calculateTimes() {
            this.tin = new int[n];
            this.up = new int[n];

            this.time = 0;

            this.used = new boolean[n];
            timeDfs(0, -1);
        }

        void timeDfs(int from, int parent) {
            used[from] = true;

            up[from] = tin[from] = time;
            ++time;

            for (int to : graph[from]) {
                if (to == parent) continue;

                if (used[to]) {
                    up[from] = min(up[from], tin[to]);
                } else {
                    timeDfs(to, from);
                    up[from] = min(up[from], up[to]);
                }
            }
        }

        int[] components;
        int[][] componentsGraph;

        int component(int v) { return components[v]; }

        int[][] toGraph() {
            return componentsGraph;
        }

        void condensateComponents() {
            this.components = new int[n];
            Arrays.fill(components, -1);

            for (int v = 0; v < n; ++v) {
                if (components[v] == -1) {
                    componentsDfs(v, v);
                }
            }

            GraphBuilder graphBuilder = GraphBuilder.createInstance(n);

            Set<Point> edges = new HashSet<Point>();
            for (int from = 0; from < n; ++from) {
                int fromComponent = components[from];

                for (int to : graph[from]) {
                    int toComponent = components[to];
                    if (fromComponent == toComponent) continue;

                    Point edge = new Point(fromComponent, toComponent);
                    if (edges.add(edge)) graphBuilder.addDirectedEdge(fromComponent, toComponent);
                }
            }

            this.componentsGraph = graphBuilder.build();
        }

        void componentsDfs(int from, int color) {
            components[from] = color;
            for (int to : graph[from]) {
                if (components[to] != -1) continue;

                if (tin[from] >= up[to] && tin[to] >= up[from]) {
                    componentsDfs(to, color);
                }
            }
        }
    }

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

    private static class VertexBiconnectedGraph {

        static class Edge {
            int to;
            int index;

            Edge(int to, int index) {
                this.to = to;
                this.index = index;
            }
        }

        int n, m;
        List<Edge>[] graph;
        List<Edge> edges;

        VertexBiconnectedGraph(int n) {
            this.n = n;
            this.m = 0;

            this.graph = new List[n];
            for (int v = 0; v < n; ++v) {
                graph[v] = new ArrayList<Edge>();
            }

            this.edges = new ArrayList<Edge>();
        }

        void addEdge(int from, int to) {
            Edge fromToEdge = new Edge(to, m);
            Edge toFromEdge = new Edge(from, m + 1);

            edges.add(fromToEdge);
            edges.add(toFromEdge);

            graph[from].add(fromToEdge);
            graph[to].add(toFromEdge);

            m += 2;
        }

        int time;

        boolean[] used;
        int[] tin, up;
        int[] parents;

        boolean[] isArticulation;

        boolean[] findArticulationPoints() {
            this.isArticulation = new boolean[n];

            this.used = new boolean[n];
            this.parents = new int[n];
            Arrays.fill(parents, -1);

            this.tin = new int[n];
            this.up = new int[n];

            this.time = 0;

            for (int v = 0; v < n; ++v) {
                if (!used[v]) {
                    articulationDfs(v, -1);
                }
            }

            return isArticulation;
        }

        void articulationDfs(int from, int parent) {
            used[from] = true;
            parents[from] = parent;

            ++time;
            up[from] = tin[from] = time;

            int childrenCount = 0;

            for (Edge e : graph[from]) {
                int to = e.to;

                if (to == parent) continue;

                if (used[to]) {
                    up[from] = min(up[from], tin[to]);
                } else {
                    ++childrenCount;

                    articulationDfs(to, from);
                    up[from] = min(up[from], up[to]);
                    if (up[to] >= tin[from] && parent != -1) {
                        isArticulation[from] = true;
                    }
                }
            }

            if (parent == -1 && childrenCount > 1) {
                isArticulation[from] = true;
            }
        }

        int[] edgeColors;
        int maxEdgeColor;

        int[] paintEdges() {
            this.edgeColors = new int[m];
            Arrays.fill(edgeColors, -1);

            this.maxEdgeColor = -1;

            this.used = new boolean[n];

            for (int v = 0; v < n; ++v) {
                if (!used[v]) {
                    ++maxEdgeColor;
                    paintDfs(v, maxEdgeColor, -1);
                }
            }

            return edgeColors;
        }

        void paintEdge(int edgeIndex, int color) {
            if (edgeColors[edgeIndex] != -1) return;

            edgeColors[edgeIndex] = edgeColors[edgeIndex ^ 1] = color;
        }

        void paintDfs(int from, int color, int parent) {
            used[from] = true;

            for (Edge e : graph[from]) {
                int to = e.to;
                if (to == parent) continue;

                if (!used[to]) {
                    if (up[to] >= tin[from]) {
                        int newColor = ++maxEdgeColor;
                        paintEdge(e.index, newColor);
                        paintDfs(to, newColor, from);
                    } else {
                        paintEdge(e.index, color);
                        paintDfs(to, color, from);
                    }
                } else if (up[to] <= tin[from]){
                    paintEdge(e.index, color);
                }
            }
        }

        Set<Integer>[] collectVertexEdgeColors() {
            Set<Integer>[] vertexEdgeColors = new Set[n];
            for (int v = 0; v < n; ++v) {
                vertexEdgeColors[v] = new HashSet<Integer>();
                for (Edge e : graph[v]) {
                    vertexEdgeColors[v].add(edgeColors[e.index]);
                }
            }

            return vertexEdgeColors;
        }

        VertexBiconnectedGraph build() {
            findArticulationPoints();
            paintEdges();
            createComponentsGraph();

            return this;
        }

        int[][] componentsGraph;

        void createComponentsGraph() {
            Set<Integer>[] vertexEdgeColors = collectVertexEdgeColors();

            int edgeColorShift = vertexEdgeColors.length;
            int size = vertexEdgeColors.length + maxEdgeColor + 1;

            GraphBuilder graphBuilder = GraphBuilder.createInstance(size);
            for (int v = 0; v < vertexEdgeColors.length; ++v) {
                for (int edgeColor : vertexEdgeColors[v]) {
                    graphBuilder.addEdge(v, edgeColor + edgeColorShift);
                }
            }

            this.componentsGraph = graphBuilder.build();
        }

        int[][] toGraph() {
            return componentsGraph;
        }
    }

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

    private static class DSU {

        int[] sizes;

        int[] ranks;
        int[] parents;

        static DSU createInstance(int size) {
            int[] sizes = new int[size];
            Arrays.fill(sizes, 1);

            return new DSU(sizes);
        }

        DSU(int[] sizes) {
            this.sizes = sizes;

            int size = sizes.length;

            this.ranks = new int[size];
            Arrays.fill(ranks, 1);

            this.parents = castInt(order(size));
        }

        int get(int v) {
            if (v == parents[v]) return v;
            return parents[v] = get(parents[v]);
        }

        boolean union(int a, int b) {
            a = get(a);
            b = get(b);

            if (a == b) return false;

            if (ranks[a] < ranks[b]) {
                int tmp = a;
                a = b;
                b = tmp;
            }

            parents[b] = a;
            sizes[a] += sizes[b];

            if (ranks[a] == ranks[b]) ++ranks[a];

            return true;
        }
    }

    /////////////////////////////////////////////////////////////////////
}


/**
 * BaZ :D
 */
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main
{
    static Reader scan;
    static PrintWriter pw;
    public static void main(String[] args) {
        new Thread(null,null,"BaZ",1<<25)
        {
            public void run()
            {
                try
                {
                    solve();
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                    System.exit(1);
                }
            }
        }.start();
    }
    static void solve() throws IOException
    {
        scan = new Reader();
        pw = new PrintWriter(System.out,true);
        StringBuilder sb = new StringBuilder();
        long f = ni(),T = ni(), t0 = ni();
        long a1 = ni(), t1 = ni(), p1 = ni();
        long a2 = ni(), t2 = ni(), p2 = ni();
        long ans = min(solve(f,T,t0,a1,t1,p1,a2,t2,p2), solve(f,T,t0,a2,t2,p2,a1,t1,p1));
        if(ans==Long.MAX_VALUE) {
            pl(-1);
        }
        else {
            pl(ans);
        }
        pw.flush();
        pw.close();
    }
    static long solve(long f,long T,long t0,long a1,long t1,long p1,long a2,long t2,long p2) {
        long min = Long.MAX_VALUE;
        for(int i=0;;++i) {
            if(a1*i>f) {
                if(T>=t1*f) {
                    min = min(min, i*p1);
                }
                break;
            }
            long amt_2 = calc(f-a1*i, T-1L*a1*i*t1, t0, a2,t2);
            //pl("amt1 : "+i+" amt2 : "+amt_2);
            if(amt_2!=-1) {
                min = min(min, 1L*i*p1 + amt_2*p2);
            }
        }
        return min;
    }
    static long calc(long f, long T, long t0, long a, long t) {
        if(T<0) {
            return -1;
        }
        //pl("f : "+f+" T : "+T+" t0 : "+t0+" a : "+a+" t : "+t);
        if(f<=0 || T>=1L*f*t0)
            return 0;
        //pl("here");
        //int max_no_of_times = (f+a-1)/a;
        if(t0<=t || T<1L*f*t)
            return -1;
        long nu = 1L*f*t0-T;
        long de = 1L*a*(t0-t);
        //pl("nu : "+nu+" de :"+de);
        return (nu+de-1)/de;
    }
    static int ni() throws IOException
    {
        return scan.nextInt();
    }
    static long nl() throws IOException
    {
        return scan.nextLong();
    }
    static double nd() throws IOException
    {
        return scan.nextDouble();
    }
    static void pl()
    {
        pw.println();
    }
    static void p(Object o)
    {
        pw.print(o+" ");
    }
    static void pl(Object o)
    {
        pw.println(o);
    }
    static void psb(StringBuilder sb)
    {
        pw.print(sb);
    }
    static void pa(String arrayName, Object arr[])
    {
        pl(arrayName+" : ");
        for(Object o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, int arr[])
    {
        pl(arrayName+" : ");
        for(int o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, long arr[])
    {
        pl(arrayName+" : ");
        for(long o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, double arr[])
    {
        pl(arrayName+" : ");
        for(double o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, char arr[])
    {
        pl(arrayName+" : ");
        for(char o : arr)
            p(o);
        pl();
    }
    static void pa(String listName, List list)
    {
        pl(listName+" : ");
        for(Object o : list)
            p(o);
        pl();
    }
    static void pa(String arrayName, Object[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(Object o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, int[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(int o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, long[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(long o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, char[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(char o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, double[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(double o : arr[i])
                p(o);
            pl();
        }
    }
    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private 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];
            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();
        }
    }
}


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

    static class TaskC {
        final long infinity = Long.MAX_VALUE / 3;
        FastScanner in;

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            this.in = in;
            long bytesLeft0 = assertedNextInt();
            long timeLeft0 = assertedNextInt();
            long t0 = assertedNextInt();

            long a1 = assertedNextInt();
            long t1 = assertedNextInt();
            long p1 = assertedNextInt();

            long a2 = assertedNextInt();
            long t2 = assertedNextInt();
            long p2 = assertedNextInt();
            long u = solve(bytesLeft0, timeLeft0, t0, a1, t1, p1, a2, t2, p2);
            long v = solve(bytesLeft0, timeLeft0, t0, a2, t2, p2, a1, t1, p1);
            long ans = Math.min(u, v);
            if (ans >= infinity) {
                ans = -1;
            }
            out.println(ans);
        }

        private long solve(long bytesLeft0, long timeLeft0, long t0, long a1, long t1, long p1, long a2, long t2, long p2) {
            final int N = (int) 1e7 + 20;
            long ans = infinity;
            for (int k1 = 0; k1 <= N; k1++) {
                long cost1 = k1 * p1;
                long bytesDownloaded1 = Math.min(bytesLeft0, k1 * a1);
                long time1 = bytesDownloaded1 * t1;
                long bytesLeft1 = bytesLeft0 - bytesDownloaded1;
                long timeLeft1 = timeLeft0 - time1;
                if (timeLeft1 < 0) {
                    continue;
                }
                if (bytesLeft1 == 0) {
                    ans = Math.min(ans, cost1);
                    continue;
                }
                if (t0 * bytesLeft1 <= timeLeft1) {
                    ans = Math.min(ans, cost1);
                    continue;
                }
                if (t0 <= t2) {
                    continue;
                }
                if (bytesLeft1 * t2 > timeLeft1) {
                    continue;
                }
                long bytes0 = Math.min(bytesLeft1, (timeLeft1 - bytesLeft1 * t2) / (t0 - t2));
                long bytes2 = bytesLeft1 - bytes0;
                long k2 = (bytes2 + a2 - 1) / a2;

                long cost2 = k2 * p2;
                ans = Math.min(ans, cost1 + cost2);
            }
            return ans;
        }

        private long assertedNextInt() {
            long x = in.nextLong();
            if (x < 1 || x > (int) 1e7) {
                throw new AssertionError();
            }
            return x;
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

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

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

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

    }
}


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

public class Main {
	private static Scanner in;
	private static PrintWriter out;
	private static final int MOD = (int)1e9 + 7;

	private static int n;
	private static int[] a, degIn;
	private static ArrayList<Integer> s, t;
	private static boolean[] visited;
	private static ArrayList<Integer>[] graph;

	private static boolean isSubset(int a, int b) {
		return (a & b) == a;
	}

	private static boolean isIntersect(int a, int b) {
		return (a & b) != 0;
	}

	// Solve for each weakly connected component (WCC)
	private static int cntOrder(ArrayList<Integer> s, ArrayList<Integer> t) {
		int p = s.size(), m = t.size();

		int[] inMask = new int[m];
		for(int x = 0; x < p; ++x)
			for(int i = 0; i < m; ++i)
				if (t.get(i) % s.get(x) == 0)
					inMask[i] |= 1 << x;

		int[] cnt = new int[1<<p];
		for(int mask = 0; mask < (1<<p); ++mask)
			for(int i = 0; i < m; ++i)
				if (isSubset(inMask[i], mask))
					++cnt[mask];

		int[][] dp = new int[m+1][1<<p];
		for(int i = 0; i < m; ++i)
			dp[1][inMask[i]] += 1;
		for(int k = 1; k < m; ++k) {
			for(int mask = 0; mask < (1<<p); ++mask) {
				for(int i = 0; i < m; ++i)
					if (!isSubset(inMask[i], mask) && isIntersect(inMask[i], mask))
						dp[k+1][mask | inMask[i]] = (int)((dp[k+1][mask | inMask[i]] + dp[k][mask]) % MOD);
				dp[k+1][mask] = (int)((dp[k+1][mask] + (long)dp[k][mask] * (cnt[mask] - k)) % MOD);
			}
		}

		return dp[m][(1<<p)-1];
	}

	private static void dfs(int u) {
		visited[u] = true;
		if (degIn[u] == 0)
			s.add(a[u]);
		else
			t.add(a[u]);

		for(int v: graph[u])
			if (!visited[v])
				dfs(v);
	}

	private static void input() {
		n = in.nextInt();
		a = new int[n];
		for(int u = 0; u < n; ++u)
			a[u] = in.nextInt();
	}

	private static void solve() {
		// Pre-calculate C(n, k)
		int[][] c = new int[n][n];
		for(int i = 0; i < n; ++i) {
			c[i][0] = 1;
			for(int j = 1; j <= i; ++j)
				c[i][j] = (c[i-1][j-1] + c[i-1][j]) % MOD;
		}

		// Building divisibility graph
		degIn = new int[n];
		graph = new ArrayList[n];
		for(int u = 0; u < n; ++u)
			graph[u] = new ArrayList<>();
		for(int u = 0; u < n; ++u) {
			for(int v = 0; v < n; ++v) {
				if (u != v && a[v] % a[u] == 0) {
					graph[u].add(v);
					graph[v].add(u);
					++degIn[v];
				}
			}
		}

		// Solve for each WCC of divisibility graph and combine result
		int ans = 1;
		int curLen = 0;
		visited = new boolean[n];
		for(int u = 0; u < n; ++u) {
			if (!visited[u]) {
				s = new ArrayList<>();
				t = new ArrayList<>();
				dfs(u);

				if (!t.isEmpty()) {
					int sz = t.size() - 1;
					int cnt = cntOrder(s, t);

					// Number of orders for current WCC
					ans = (int)(((long)ans * cnt) % MOD);
					// Number of ways to insert <sz> number to array of <curLen> elements
					ans = (int)(((long)ans * c[curLen + sz][sz]) % MOD);
					curLen += sz;
				}
			}
		}

		out.println(ans);
	}

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

		input();
		solve();

		out.close();
	}
}


import java.io.*;
import java.util.*;
import java.math.*;
public class Solution
{
   BufferedReader in;
   PrintWriter out;
   StringTokenizer ss;

String _token()throws IOException
{
   while (!ss.hasMoreTokens())ss=new StringTokenizer(in.readLine());
   return ss.nextToken();
}
int _int()throws IOException{return Integer.parseInt(_token());}
long _long()throws IOException{return Long.parseLong(_token());}
double _double()throws IOException{return Double.parseDouble(_token());}
void dbg(String s){System.out.println(s);}

BigInteger ad(BigInteger A, BigInteger B){return (A.add(B));}
BigInteger mu(BigInteger A, BigInteger B){return (A.multiply(B));}
BigInteger su(BigInteger A, BigInteger B){return (A.subtract(B));}
BigInteger di(BigInteger A, BigInteger B){return A.divide(B);}
BigInteger mi(BigInteger A){return (BigInteger.ZERO).subtract(A);}
BigInteger sq(BigInteger A){return (A.multiply(A));}
BigInteger va(long a){return BigInteger.valueOf(a);}

BigDecimal val(double a){return BigDecimal.valueOf(a);};
BigDecimal mult(BigDecimal a, BigDecimal b){return a.multiply(b);}
BigDecimal div(BigDecimal a, BigDecimal b){return a.divide(b,30,RoundingMode.CEILING);}
BigDecimal add(BigDecimal a, BigDecimal b){return a.add(b);}
BigDecimal sub(BigDecimal a, BigDecimal b){return a.subtract(b);}

void RUN()throws IOException
{
   in = new BufferedReader(new InputStreamReader(System.in));
   out = new PrintWriter(System.out);
   ss = new StringTokenizer(" ");

//while (in.ready())
//{

   int a = _int();
   int b = _int();
   int n = _int();

   int maxa = (int)1e5+2;
   int maxb = 31;
   int w[][] = new int [maxa+1][maxb+1];

   w[1][maxb]=-1;
   w[maxa][1]=(n-maxa)%2;

   double eps=1e-8;

   for (int sum=maxa+maxb;sum>=0;sum--)
   {
     for (int j=1;j<maxb;j++)
     {
       int i = sum-j;
       if (i<1 || i>=maxa)
         continue;

       if (Math.abs(Math.log(i)*j-Math.log(n))>eps)
       {
         if (Math.log(i)*j>Math.log(n))
           {w[i][j]=0;
            continue;
           }
       }
       else
         if ((va(i).pow(j)).compareTo(va(n))>=0)
         {
           w[i][j]=0;
           continue;
         }

       if (i>1 && j>1)
         {
           if (w[i+1][j]==1 || w[i][j+1]==1)
             {
               w[i][j]=0;
               continue;
             }
          w[i][j]=1;
          continue;
         }
       int cu,cl;
       cu=w[i+1][j];
       cl=w[i][j+1];
       if (cu==1 || cl==1)
       {
         w[i][j]=0;
         continue;
       }
       if (cu==0 && cl==0)
       {
         w[i][j]=1;
         continue;
       }
       w[i][j]=-1;
       continue;
     }
   }

   if (w[a][b]!=-1)
   {
     if (w[a][b]==0)
       out.println("Masha");
     else
       out.println("Stas");
   }
      else
   out.println("Missing");

//}

   out.close();
}

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


import java.util.Scanner;

public class E {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int n = sc.nextInt();
        int sqrt_n = (int) Math.sqrt(n)+1;
        int log_n = (int) (Math.log(n)/Math.log(2))+1;
        if (b > log_n) {
            System.out.println("Missing");
            return;
        }
        if (a > sqrt_n) {
            if ((n-a) % 2==0)
                System.out.println("Masha");
            else
                System.out.println("Stas");
            return;
        }
        int[][]dp = new int[sqrt_n+1][log_n+1];
        if ((n-sqrt_n) % 2==0)
            dp[sqrt_n][1] = 1;
        for (int i = 2; i <= log_n; i++) {
            dp[sqrt_n][i] = 1;
        }
        for (int i = sqrt_n-1; i >= 2; i--) {
            long pow = i;
            int h = 1;
            while (pow < n) {
                pow *= i;
                h++;
            }
            h--;
            for (int j = h+1; j <= log_n; j++) {
                dp[i][j] = 1;
            }
            for (int j = h; j >= 1; j--) {
                if (dp[i+1][j]==0 || dp[i][j+1]==0)
                    dp[i][j] = 1;
            }
        }
        for (int i = log_n; i >= 1; i--) {
            if ((1 << (long)i) >= n)
                dp[1][i] = 2;
            else {
                if (dp[2][i]==1 && dp[1][i+1]==2)
                    dp[1][i] = 2;
                else
                    if (dp[2][i]==0 || dp[1][i+1]==0)
                        dp[1][i] = 1;
            }
        }
        if (dp[a][b]==1)
            System.out.println("Masha");
        else {
            if (dp[a][b]==0)
                System.out.println("Stas");
            else
                System.out.println("Missing");
        }
    }
}


import java.io.*;
import java.util.*;
import java.math.*;
public class Solution
{
   BufferedReader in;
   PrintWriter out;
   StringTokenizer ss;//////////
String _token()throws IOException
{
   while (!ss.hasMoreTokens())ss=new StringTokenizer(in.readLine());
   return ss.nextToken();
}
int _int()throws IOException{return Integer.parseInt(_token());}
long _long()throws IOException{return Long.parseLong(_token());}
double _double()throws IOException{return Double.parseDouble(_token());}
void dbg(String s){System.out.println(s);}

BigInteger ad(BigInteger A, BigInteger B){return (A.add(B));}
BigInteger mu(BigInteger A, BigInteger B){return (A.multiply(B));}
BigInteger su(BigInteger A, BigInteger B){return (A.subtract(B));}
BigInteger di(BigInteger A, BigInteger B){return A.divide(B);}
BigInteger mi(BigInteger A){return (BigInteger.ZERO).subtract(A);}
BigInteger sq(BigInteger A){return (A.multiply(A));}
BigInteger va(long a){return BigInteger.valueOf(a);}

BigDecimal val(double a){return BigDecimal.valueOf(a);};
BigDecimal mult(BigDecimal a, BigDecimal b){return a.multiply(b);}
BigDecimal div(BigDecimal a, BigDecimal b){return a.divide(b,30,RoundingMode.CEILING);}
BigDecimal add(BigDecimal a, BigDecimal b){return a.add(b);}
BigDecimal sub(BigDecimal a, BigDecimal b){return a.subtract(b);}

void RUN()throws IOException
{
   in = new BufferedReader(new InputStreamReader(System.in));
   out = new PrintWriter(System.out);
   ss = new StringTokenizer(" ");

//while (in.ready())
//{

   int a = _int();
   int b = _int();
   int n = _int();

   int maxa = (int)1e5+2;
   int maxb = 31;
   int w[][] = new int [maxa+1][maxb+1];

   w[1][maxb]=-1;
   w[maxa][1]=(n-maxa)%2;

   double eps=1e-8;

   for (int sum=maxa+maxb;sum>=0;sum--)
   {
     for (int j=1;j<maxb;j++)
     {
       int i = sum-j;
       if (i<1 || i>=maxa)
         continue;

       if (Math.abs(Math.log(i)*j-Math.log(n))>eps)
       {
         if (Math.log(i)*j>Math.log(n))
           {w[i][j]=0;
            continue;
           }
       }
       else
         if ((va(i).pow(j)).compareTo(va(n))>=0)
         {
           w[i][j]=0;
           continue;
         }

       if (i>1 && j>1)
         {
           if (w[i+1][j]==1 || w[i][j+1]==1)
             {
               w[i][j]=0;
               continue;
             }
          w[i][j]=1;
          continue;
         }
       int cu,cl;
       cu=w[i+1][j];
       cl=w[i][j+1];
       if (cu==1 || cl==1)
       {
         w[i][j]=0;
         continue;
       }
       if (cu==0 && cl==0)
       {
         w[i][j]=1;
         continue;
       }
       w[i][j]=-1;
       continue;
     }
   }

   if (w[a][b]!=-1)
   {
     if (w[a][b]==0)
       out.println("Masha");
     else
       out.println("Stas");
   }
      else
   out.println("Missing");

//}

   out.close();
}

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