#!/usr/bin/python Gx, Gy, N, F = list(map(int, input().split())) crystal = [] for i in range(N): crystal.append(tuple(map(int, input().split()))) crystal = tuple(crystal) dp = [[(i + j) * F for i in range(Gx + 1)] for j in range(Gy + 1)] for i in range(N): cx, cy, cc = crystal[i] for y in range(Gy, -1, -1): for x in range(Gx, -1, -1): if y >= cy and x >= cx: dp[y][x] = min(dp[y][x], dp[y - cy][x - cx] + cc) print (dp[Gy][Gx])