#include using namespace std; #define fi first #define se second #define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repl(i,0,n) #define each(itr,v) for(auto itr:v) #define pb(s) push_back(s) #define mp(a,b) make_pair(a,b) #define all(x) (x).begin(),(x).end() #define dbg(x) cout<<#x"="<(x).count() typedef long long ll; typedef unsigned long long ull; typedef pair P; typedef pair PPI; typedef pair PL; typedef pair PPL; #define INF 1e17 #define MAX_N 1000 ll gx,gy,n,f; ll dx[55],dy[55],c[55]; ll dp[333][333]; int main(){ cin.sync_with_stdio(false); cin>>gx>>gy>>n>>f; rep(i,n)cin>>dx[i]>>dy[i]>>c[i]; rep(i,333)rep(j,333)dp[i][j]=INF; dp[0][0]=0; rep(i,111)rep(j,111){ rep(k,n){ minch(dp[i+dy[k]][j+dx[k]],dp[i][j]+c[k]); } minch(dp[i+1][j],dp[i][j]+f); minch(dp[i][j+1],dp[i][j]+f); } cout<