import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int gx = sc.nextInt(); int gy = sc.nextInt(); int n = sc.nextInt(); int f = sc.nextInt(); int[][] costs = new int[gx + 1][gy + 1]; for (int i = 0; i <= gx; i++) { for (int j = 0; j <= gy; j++) { costs[i][j] = (i + j) * f; } } for (int i = 0; i < n; i++) { int x = sc.nextInt(); int y = sc.nextInt(); int c = sc.nextInt(); for (int j = gx; j - x >= 0; j--) { for (int k = gy; k - y >= 0; k--) { costs[j][k] = Math.min(costs[j][k], costs[j - x][k - y] + c); } } } System.out.println(costs[gx][gy]); } }