from collections import defaultdict import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) inf = 10**9 gx, gy, n, f = map(int, input().split()) H = gx + 1 W = gy + 1 dp = [inf] * (H * W) dp[0] = 0 for _ in range(n): x, y, c = map(int, input().split()) for i in range(H)[::-1]: for j in range(W)[::-1]: nx = x + i ny = y + j if nx < H and ny < W: to = nx * W + ny dp[to] = min(dp[to], dp[i*W+j] + c) ans = inf for i in range(H): for j in range(W): cost = f * (gx+gy-i-j) ans = min(ans, dp[i*W+j]+cost) print(ans)