Gx,Gy,N,F = map(int,input().split()) L = [] P = [[0,0,0]] for n in range(N): x,y,c = list(map(int,input().split())) if c / (x + y) > F: pass else: pi = len(P) for i,p in enumerate(P): if x + p[0] <= Gx and y + p[1] <= Gy and i < pi: x2 = p[0] + x y2 = p[1] + y c2 = p[2] + c if [x2, y2, c2] not in P: P.append([x2,y2,c2]) m = float("inf") for p in P: x = Gx - p[0] y = Gy - p[1] c = (x + y) * F + p[2] if c < m: m = c print(m)