Gx, Gy, N, F = map(int, input().split()) XYC = [list(map(int, input().split())) for _ in range(N)] INF = 10 ** 10 dp = [[INF] * (Gy + 1) for _ in range(Gx + 1)] dp[0][0] = 0 ans = (Gx + Gy) * F for x, y, c in XYC: for i in reversed(range(Gx - x + 1)): for j in reversed(range(Gy - y + 1)): if dp[i][j] != INF: if dp[i + x][j + y] > dp[i][j] + c: dp[i + x][j + y] = dp[i][j] + c ans = min(ans, dp[i + x][j + y] + (Gx - i - x + Gy - j - y) * F) print(ans)