#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a vector make_v(size_t a){return vector(a);} template auto make_v(size_t a,Ts... ts){ return vector(ts...))>(a,make_v(ts...)); } template typename enable_if::value==0>::type fill_v(T &t,const V &v){t=v;} template typename enable_if::value!=0>::type fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); } //INSERT ABOVE HERE signed main(){ Int gx,gy,n,f; cin>>gx>>gy>>n>>f; vector x(n),y(n),c(n); for(Int i=0;i>x[i]>>y[i]>>c[i]; const Int INF = 1e15; auto dp=make_v(200,200); fill_v(dp,INF); dp[0][0]=0; for(Int i=0;i=0;a--) for(Int b=199;b>=0;b--) if(a+y[i]<200&&b+x[i]<200) chmin(dp[a+y[i]][b+x[i]],dp[a][b]+c[i]); Int ans=INF; for(Int i=0;i<=gy;i++) for(Int j=0;j<=gx;j++) chmin(ans,dp[i][j]+(gy-i+gx-j)*f); cout<