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; 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,' ',c[2].cur,' ',c[3].cur,' ',c[4].cur); end; procedure Neco(var s: Integer; var k: Boolean); var i: Integer; begin if not k then 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 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); end; end else if c[2].cur >0 then begin if c[2].state = u then begin konec := true; vypis (1); end else begin 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); end; end else if c[3].cur > 0 then begin if c[3].state = u then begin konec:=true; vypis(1); end else begin 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); end; end else if c[4].cur >0 then begin if c[4].state = u then begin konec := true; vypis (1); end else begin 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); end; end else begin vypis (1); konec:=true; end; end; end; end; begin ReadLn(total, c[1].count, c[2].count, c[3].count, c[4].count); for i:=1 to 4 do begin c[i].cur := 0; c[i].state := n; end; suma := 0; konec := false; Neco (suma, konec); end.