var cas,xx,n,m,i,j:longint; ans:int64; a,b,c,f:array[0..10010]of int64; procedure swap(var x,y:int64); var z:int64; begin z:=x; x:=y; y:=z; end; function min(x,y:longint):longint; begin if xc[i]*mid do inc(i); while b[j]*mid1j; if lf[j] then f[j]:=f[j-c[i]]+a[i]-j*b[i]; ans:=0; for i:=1 to m do if f[i]>ans then ans:=f[i]; writeln(ans); end; end.