gx,gy,N,F = map(int,input().split()) x = [0 for i in range(N)] y = [0 for i in range(N)] c = [0 for i in range(N)] for i in range(N): x[i],y[i],c[i] = map(int,input().split()) INF = 10**9+7 dp = [[INF for j in range(100+1)]for i in range(100+1)] dp[0][0] = 0 for i in range(0,100+1): for j in range(0,100+1): if dp[i][j] == INF: continue for k in range(N): if i+x[k] <= 100 and j+y[k] <= 100: dp[i+x[k]][j+y[k]] = min(dp[i+x[k]][j+y[k]],dp[i][j]+c[k]) if i+1 <= 100: dp[i+1][j] = min(dp[i+1][j],dp[i][j]+F) if j+1 <= 100: dp[i][j+1] = min(dp[i][j+1],dp[i][j]+F) print(dp[gx][gy])