Gx,Gy,N,F = map(int,input().split()) A = [0]+[list(map(int,input().split())) for _ in range(N)] dp = [[[3*10**5 for _ in range(Gy+1)] for _ in range(Gx+1)] for _ in range(N+1)] for j in range(Gx+1): for k in range(Gy+1): dp[0][j][k] = (j+k)*F for i in range(1,N+1): x,y,c = A[i] for j in range(Gx+1): for k in range(Gy+1): dp[i][j][k] = min((j+k)*F,dp[i-1][j][k]) if j>=x and k>=y: dp[i][j][k] = min(dp[i][j][k],dp[i-1][j-x][k-y]+min(c,(x+y)*F)) print(dp[N][Gx][Gy])