gx, gy, n, f = map(int, input().split()) XYC = [] for i in range(n): x, y, c = map(int, input().split()) XYC.append((x, y, c)) INF = 10**18 dp = [[INF]*(gx+1) for i in range(gy+1)] dp[0][0] = 0 for i in range(gy+1): for j in range(gx+1): for di, dj in (1, 0), (0, 1): ni, nj = i+di, j+dj if 0 <= ni <= gy and 0 <= nj <= gx: dp[ni][nj] = min(dp[ni][nj], dp[i][j]+f) for x, y, c in XYC: for i in reversed(range(gy+1)): for j in reversed(range(gx+1)): if 0 <= i+y <= gy and 0 <= j+x <= gx: dp[i+y][j+x] = min(dp[i+y][j+x], dp[i][j]+c) print(dp[gy][gx])