import java.util.ArrayList; import java.util.Scanner; public class WarpCrystal { 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(); ArrayList cx = new ArrayList<>(); ArrayList cy = new ArrayList<>(); ArrayList cc = new ArrayList<>(); for(int i = 0;i < N;i++){ int x = s.nextInt(),y = s.nextInt(),c = s.nextInt(); if(c < (x+y)*F){ cx.add(x); cy.add(y); cc.add(c); } } s.close(); int[][] mas = new int[Gx+1][Gy+1]; for(int i =0;i <= Gx;i++){ for(int j = 0;j <= Gy;j++){ mas[i][j] = (i + j) * F; } } for(int i = 0;i < cx.size();i++){ for(int j = Gx;j >= 0;j--){ for(int k = Gy;k >= 0;k--){ if(j - cx.get(i) >= 0 && k -cy.get(i) >= 0){ mas[j][k] = Math.min(mas[j][k], mas[j-cx.get(i)][k-cy.get(i)]+cc.get(i)); } } } } System.out.println(mas[Gx][Gy]); } }