#include #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define FORR(i,a,b) for (int i=(a);i>=(b);i--) #define pb push_back using namespace std; typedef long long ll; typedef pair pii; typedef vector vi; typedef set si; const int inf = 1e9; const int mod = 1e9+7; int x, y, n, f; ll dp[101][101]; main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> x >> y >> n >> f; FOR(i, 0, 101)FOR(j, 0, 101)dp[i][j] = inf; dp[0][0] = 0; FOR(i, 0, n){ int w, h, c; cin >> w >> h >> c; FORR(_x, x - w, 0){ FORR(_y, y - h, 0){ dp[_y + h][_x + w] = min(dp[_y + h][_x + w], dp[_y][_x] + c); } } } ll ans = inf; FOR(i, 0, x + 1){ FOR(j, 0, y + 1){ ans = min(ans, (x - i + y - j) * f + dp[j][i]); } } cout << ans << endl; }