import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int productCount = sc.nextInt(); int[] productIds = new int[productCount]; int[] productCosts = new int[productCount]; for (int i = 0; i < productCount; i++) { productIds[i] = sc.nextInt(); } for (int i = 0; i < productCount; i++) { productCosts[i] = sc.nextInt(); } int totalBudget = sc.nextInt(); int maxFreeItems = 0, maxFreeWorth = 0; for (int i = 0; i < productCount; i++) { int currentCost = productCosts[i]; int maxPurchaseQty = totalBudget / currentCost; if (maxPurchaseQty > 0) { int freeItems = 0; int freeWorth = 0; for (int j = 0; j < productCount; j++) { if (i != j && productIds[i] % productIds[j] == 0) { freeItems += maxPurchaseQty; freeWorth += productCosts[j] * maxPurchaseQty; } } if (freeItems > maxFreeItems || (freeItems == maxFreeItems && freeWorth > maxFreeWorth)) { maxFreeItems = freeItems; maxFreeWorth = freeWorth; } } } System.out.println(maxFreeItems + " " + maxFreeWorth); } }