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