#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% import numpy as np # %% Gx, Gy, N, F = map(int, readline().split()) m = map(int, read().split()) XYC = tuple(zip(m, m, m)) # %% INF = 10 ** 16 dp = np.full((Gx + 1, Gy + 1), INF, np.int64) dp[0, 0] = 0 # %% for x, y, c in XYC: np.minimum( dp[x: Gx + 1, y: Gy + 1], dp[0: Gx + 1 - x, 0: Gy + 1 - y] + c, out=dp[x:Gx + 1, y:Gy + 1]) # %% dp += F * (np.arange(Gx + 1)[::-1][:, None] + np.arange(Gy + 1)[::-1][None, :]) answer = dp.min() print(answer)