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(); int sx = 0,sy = 0; ArrayList[] crystal = new ArrayList[N]; for(int i = 0;i < N;i++){ crystal[i] = new ArrayList(); crystal[i].add(s.nextInt()); crystal[i].add(s.nextInt()); crystal[i].add(s.nextInt()); } int cost = (Gx + Gy) * F, cost0 = cost; while(sx != Gx || sy != Gy){ //System.out.println(sx + " " + sy); int kn = -1; for(int i = 0;i < N;i++){ int x = crystal[i].get(0); int y = crystal[i].get(1); int c = crystal[i].get(2); if(c != 0){ if(sx + x <= Gx && sy + y <= Gy && cost > cost0 + c - (x+y)*F){ //System.out.print("更新" + x + " " + y + " " + cost); cost += c-(x+y)*F; kn = i; //System.out.println(" " + cost); }else if(c >= (x+y)*F){ crystal[i].set(2, 0); } } } if(kn != -1){ crystal[kn].set(2, 0); sx += crystal[kn].get(0); sy += crystal[kn].get(1); cost0 = cost; }else{ sx = Gx; sy = Gy; } } s.close(); System.out.println(cost); } }