#include #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)n;++i) #define each(a, b) for(auto (a): (b)) #define all(v) (v).begin(),(v).end() #define fi first #define se second #define pb push_back #define show(x) cout <<#x<<" = "<<(x)<P; const int MAX_N = 102; int dp[MAX_N][MAX_N]; int main() { int l,h,n,f; cin >> l >> h >> n >> f; vector x(n),y(n),c(n); rep(i,n){ cin >> x[i] >> y[i] >> c[i]; } rep(i,l+1){ rep(j,h+1){ dp[i][j] = (i+j)*f; } } rep(i,n){ for(int j=l+1;j>=0;j--){ for(int k=h+1;k>=0;k--){ if(j - x[i] >= 0 && k - y[i] >= 0){ dp[j][k] = min(dp[j][k],dp[j-x[i]][k-y[i]] + c[i]); } } } } cout << dp[l][h] << endl; return 0; }