gx, gy, n, f = map(int,raw_input().split()) inf = float("inf") dp = [[inf for i in range(gx+1)] for i in range(gy+1)]; dp[0][0] = 0 arr = [map(int,raw_input().split()) for i in range(n)] for tx, ty,cost in arr: for y in range(gy+1): for x in range(gx+1): dx = x + tx; dy = y + ty if dp[y][x] != inf and dx < gx + 1 and dy < gy + 1 : dp[dy][dx] = min(dp[dy][dx], dp[y][x] + cost) for i in range(gy + 1): for j in range(gx + 1): dp[i][j] = min(dp[i][j], (dp[i-1][j] + f) if i-1 > -1 else inf, (dp[i][j-1] + f) if j-1 > -1 else inf) print dp[gy][gx]