GX,GY,N,F = map(int,input().split()) DP = [[0] * (GX+1) for i in range(GY+1)] for i in range(N): tx,ty,tc = map(int,input().split()) for y in reversed(range(GY+1)): for x in reversed(range(GX+1)): if DP[y][x]>0 and y+ty<=GY and x+tx<=GX: DP[y+ty][x+tx] = min(DP[y+ty][x+tx],DP[y][x]+tc) if DP[y+ty][x+tx]==0: DP[y+ty][x+tx]=DP[y][x]+tc DP[ty][tx] = min(DP[ty][tx],tc) if DP[ty][tx]==0: DP[ty][tx] = tc ans = (GX+GY)*F for y in range(GY+1): for x in range(GX+1): if DP[y][x] > 0: ans = min(ans,((GY+GX-y-x))*F+DP[y][x]) print(ans)