import java.util.*; public class Main { static int[] xArr; static int[] yArr; static int[] cArr; static int[][][] dp; static int fee; public static void main (String[] args) { Scanner sc = new Scanner(System.in); int goalX = sc.nextInt(); int goalY = sc.nextInt(); int n = sc.nextInt(); fee = sc.nextInt(); xArr = new int[n]; yArr = new int[n]; cArr = new int[n]; for (int i = 0; i < n; i++) { xArr[i] = sc.nextInt(); yArr[i] = sc.nextInt(); cArr[i] = sc.nextInt(); } dp = new int[n][goalX + 1][goalY + 1]; System.out.println(dfw(n - 1, goalX, goalY)); } static int dfw(int idx, int x, int y) { if (idx < 0) { return (x + y) * fee; } if (dp[idx][x][y] != 0) { return dp[idx][x][y]; } dp[idx][x][y] = dfw(idx - 1, x, y); if (xArr[idx] <= x && yArr[idx] <= y) { dp[idx][x][y] = Math.min(dp[idx][x][y], dfw(idx - 1, x - xArr[idx], y - yArr[idx]) + cArr[idx]); } return dp[idx][x][y]; } }