import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int gx = sc.nextInt(); final int gy = sc.nextInt(); final int N = sc.nextInt(); final int F = sc.nextInt(); int[] xs = new int[N]; int[] ys = new int[N]; int[] cs = new int[N]; for(int i = 0; i < N; i++){ final int x = sc.nextInt(); final int y = sc.nextInt(); final int c = sc.nextInt(); xs[i] = x; ys[i] = y; cs[i] = c; } long[][] DP = new long[gy + 1][gx + 1]; for(int y = 0; y <= gy; y++){ for(int x = 0; x <= gx; x++){ DP[y][x] = (x + y) * F; } } /* for(int y = 0; y <= gy; y++){ for(int x = 0; x <= gy; x++){ System.out.print(DP[y][x]); } System.out.println(); } //*/ for(int index = 0; index < N; index++){ for(int y = 0; y <= gy; y++){ final int ny = y + ys[index]; if(ny > gy){ break; } for(int x = 0; x <= gx; x++){ final int nx = x + xs[index]; if(nx > gx){ break; } DP[ny][nx] = Math.min(DP[ny][nx], DP[y][x] + cs[index]); } } } /* for(int y = 0; y <= gy; y++){ for(int x = 0; x <= gx; x++){ System.out.print(DP[y][x] + " "); } System.out.println(); } //*/ System.out.println(DP[gy][gx]); } }