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[] xArr = new int[n]; int[] yArr = new int[n]; int[] cArr = new int[n]; for (int i = 0; i < n; i++) { xArr[i] = sc.nextInt(); yArr[i] = sc.nextInt(); cArr[i] = sc.nextInt(); } int[][] costs = new int[gx + 1][gy + 1]; for (int[] arr : costs) { Arrays.fill(arr, Integer.MAX_VALUE); } PriorityQueue queue = new PriorityQueue<>(); queue.add(new Path(0, 0, 0)); while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.x][p.y] <= p.value) { continue; } costs[p.x][p.y] = p.value; if (p.x < gx) { queue.add(new Path(p.x + 1, p.y, p.value + f)); } if (p.y < gy) { queue.add(new Path(p.x, p.y + 1, p.value + f)); } for (int i = 0; i < n; i++) { if (p.x + xArr[i] <= gx && p.y + yArr[i] <= gy) { queue.add(new Path(p.x + xArr[i], p.y + yArr[i], p.value + cArr[i])); } } } System.out.println(costs[gx][gy]); } static class Path implements Comparable { int x; int y; int value; public Path(int x, int y, int value) { this.x = x; this.y = y; this.value = value; } public int compareTo(Path another) { return value - another.value; } } }