#include "bits/stdc++.h" using namespace std; #define print(x) cout< PI; typedef pair V; typedef vector VE; const ll mod = 1000000007; //10^9+7 int dp[102][102]; int main(){ int X,Y,n,f; cin>>X>>Y>>n>>f; int x[52],y[52],c[52]; REP(i,n){ cin>>x[i]>>y[i]>>c[i]; } REP(i,X+1)REP(j,Y+1){ dp[i][j]=(i+j)*f; } REP(k,n){ if(c[k]>(x[k]+y[k])*f)continue; REP(i,X+1)REP(j,Y+1){ dp[i+x[k]][j+y[k]]=min(dp[i+x[k]][j+y[k]],dp[i][j]+c[k]); //print(i+x[i]<<" "<