import java.io.*; import java.util.*; import java.util.Map.*; public class Main_yukicoder496 { private static Scanner sc; private static Printer pr; private static void solve() { int gx = sc.nextInt(); int gy = sc.nextInt(); int n = sc.nextInt(); int f = sc.nextInt(); int[] x = new int[n]; int[] y = new int[n]; int[] c = new int[n]; for (int i = 0; i < n; i++) { x[i] = sc.nextInt(); y[i] = sc.nextInt(); c[i] = sc.nextInt(); } Map hm = new HashMap<>(); hm.put(enc(x[0], y[0]), c[0]); for (int i = 1; i < n; i++) { List tmp = new ArrayList<>(hm.keySet()); for (int e : tmp) { int xx = e / 1000; int yy = e % 1000; int cc = hm.get(e); int nx = xx + x[i]; int ny = yy + y[i]; int nc = cc + c[i]; if (nx > gx || ny > gy) { continue; } int key = enc(nx, ny); if (!hm.containsKey(key)) { hm.put(key, nc); } else { if (hm.get(key) > nc) { hm.put(key, nc); } } } } int min = (gx + gy) * f; for (Entry e : hm.entrySet()) { int xx = e.getKey() / 1000; int yy = e.getKey() % 1000; int cc = e.getValue(); min = Math.min(min, cc + (gx - xx + gy - yy) * f); } pr.println(min); } private static int enc(int x, int y) { return x * 1000 + y; } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }