program objInst;



type
  TToggle = class(TObject)
  private
    FValue : boolean;
    function getValue: boolean;
  public
    constructor create(aValue: boolean);
    function Activate: TToggle; virtual;
    property Value: boolean read getValue;
  end;

  TNthToggle = class(TToggle)
  private
    FCounter, FCountMax : integer;
  public
    constructor create(aValue: boolean; aMaxCount: integer);
    function Activate: TToggle; override;
    property CountMax: integer read FCountMax write FCountMax;
  end;

constructor TToggle.Create(aValue: boolean);
begin
  FValue:=aValue;
end;

function TToggle.Activate: TToggle;
begin
  FValue:=not FValue;
  result:=self;
end;

function TToggle.getValue: boolean;
begin
  result:=FValue;
end;

constructor TNthToggle.Create(aValue: boolean; aMaxCount: integer);
begin
  inherited create(aValue);
  FCountMax:=aMaxCount;
end;

function TNthToggle.Activate: TToggle;
begin
  inc(FCounter);
  if FCounter>=CountMax then begin
    inherited Activate;
    FCounter:=0;
  end;
  result:=self;
end;

var NUM, code, i: integer;
    o: TToggle;
    o2: TNthToggle;
begin
  NUM :=1;
  if (ParamCount=1) then Val(ParamStr(1),NUM,code);

  o:=TToggle.Create(True);
  for i:=1 to 5 do
    if o.Activate.Value then
      Write('true'#13#10)
    else
      Write('false'#13#10);
  o.Destroy;
  for i:=1 to NUM do begin
    o:=TToggle.Create(True);
    o.Destroy;
  end;
  WriteLn;

  o2:=TNthToggle.Create(True,3);
  for i:=1 to 8 do
    if o2.Activate.Value then
      Write('true'#13#10)
    else
      Write('false'#13#10);
  o2.Destroy;
  for i:=1 to NUM do begin
    o2:=TNthToggle.Create(True,3);
    o2.Destroy;
  end;
  WriteLn;
end.