import java.util.Scanner; public class Main { public static void main(String[] args) { solver(); } static void solver() { int INF = Integer.MAX_VALUE / 4; Scanner sc = new Scanner(System.in); int gx = sc.nextInt(); int gy = sc.nextInt(); int n = sc.nextInt(); int f = sc.nextInt(); int[] x = new int[n]; int[] y = new int[n]; int[] c = new int[n]; for (int i = 0; i < n; i++) { x[i] = sc.nextInt(); y[i] = sc.nextInt(); c[i] = sc.nextInt(); } int[][] map = new int[101][101]; for (int i = 0; i <= 100; i++) { for (int j = 0; j <= 100; j++) { map[i][j] = INF; } } map[0][0] = 0; long ans = f * (gx + gy); for (int i = 0; i < n; i++) { if (c[i] < (x[i] + y[i]) * f) { for (int xx = 0; xx <= gx; xx++) { for (int yy = 0; yy <= gy; yy++) { if (map[xx][yy] != INF) { if (xx + x[i] <= gx && yy + y[i] <= gy) { map[xx + x[i]][yy + y[i]] = Math.min(map[xx][yy] + c[i], map[xx + x[i]][yy + y[i]]); ans = Math.min(ans, f * (gx + gy - xx - yy - x[i] - y[i]) + map[xx + x[i]][yy + y[i]]); } } } } } else { continue; } } System.out.println(ans); } }