import java.util.Scanner; public class WarpCristal { public static void main(String[] args) { Scanner s = new Scanner(System.in); int Gx = s.nextInt(),Gy = s.nextInt(),N = s.nextInt(),F = s.nextInt(); int[][] cost = new int[Gx+1][Gy+1]; int[][] d = new int[Gx+1][Gy+1]; for(int i = 0;i < N;i++){ d[s.nextInt()][s.nextInt()] = s.nextInt(); } s.close(); for(int i = 0;i <= Gx;i++){ for(int j = 0;j <= Gy;j++){ cost[i][j] = (i+j)*F; for(int x = 0;x <= i;x++){ for(int y = 0;y <= j;y++){ if(d[x][y] != 0 && cost[i][j] > cost[i-x][j-y] + d[x][y]){ cost[i][j] = cost[i-x][j-y] + d[x][y]; } } } } } System.out.println(cost[Gx][Gy]); } }