type TState = (n, u, d); ct = record count: Integer; cur: Integer; state: TState; end; var c: array [1..4] of ct; total: Integer; suma: Integer; konec: Boolean; i: Integer; supercount:integer; function Hodnota(i: Integer): Integer; begin if i = 1 then Hodnota := 1; if i = 2 then Hodnota := 5; if i = 3 then Hodnota := 10; if i = 4 then Hodnota := 25; end; Procedure vypis (a : integer); begin if a = 1 then writeln ('Charlie cannot buy coffee.') else writeln ('Throw in ',c[1].cur,' cents, ',c[2].cur,' nickels, ',c[3].cur,' dimes, and ',c[4].cur,' quarters.'); end; procedure Neco(var s: Integer; var k: Boolean; var sc:integer); var i: Integer; begin if not k then begin if sc >=maxint -10 then begin konec :=true; vypis (1); end else begin if s total then begin if c[1].cur > 0 then begin if c[1].state = u then begin konec := true; vypis (1); end else begin inc (sc); dec(c[1].cur); c[1].state := d; for i:= 1 to 3 do c[i].state := n; s := s- hodnota(1); neco(s,k,sc); end; end else if c[2].cur >0 then begin if c[2].state = u then begin konec := true; vypis (1); end else begin inc (sc); dec (c[2].cur); c[1].state := n; c[2].state := d; c[3].state := n; c[4].state := n; s:= s - hodnota (2); neco (s,k,sc); end; end else if c[3].cur > 0 then begin if c[3].state = u then begin konec:=true; vypis(1); end else begin inc (sc); dec (c[3].cur); c[1].state := n; c[2].state := n; c[3].state := d; c[4].state := n; s:= s- hodnota(3); neco (s,k,sc); end; end else if c[4].cur >0 then begin if c[4].state = u then begin konec := true; vypis (1); end else begin inc (sc); dec (c[4].cur); for i:= 1 to 3 do c[i].state := n; c[4].state := d; s:= s-hodnota (4); neco (s,k,sc); end; end else begin vypis (1); konec:=true; end; end; end; end; end; begin ReadLn(total, c[1].count, c[2].count, c[3].count, c[4].count); while not((c[1].count=0)and(c[2].count=0)and (c[3].count=0)and(c[4].count=0)) do begin for i:=1 to 4 do begin c[i].cur := 0; c[i].state := n; end; suma := 0; supercount :=0; konec := false; Neco (suma, konec, supercount); ReadLn(total, c[1].count, c[2].count, c[3].count, c[4].count); end; end.