var
f:array[0..400,0..400]of longint;
x,y,n,a,b,c,d,e,ans:longint;
begin
assign(input,'nasa.in');
assign(output,'nasa.out');
reset(input);
rewrite(output);
read(x,y);
read(n);
for n:=1 to n do
begin
read(a,b,c);
for d:=x-a downto 0 do
for e:=y-b downto 0 do
if (f[d,e]+c>f[d+a,e+b]) then f[d+a,e+b]:=f[d,e]+c;
end;
writeln(f[x,y]);
close(input);close(output);
end.