program methCall;


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;
    value: boolean;
    toggle: TToggle;
    nToggle: TNthToggle;

begin
  value:=false; // just to shut up the compiler
  NUM :=1;
  if (ParamCount=1) then Val(ParamStr(1),NUM,code);

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

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