program gen_random;

{$APPTYPE CONSOLE}

uses SysUtils;

const
  MAXK = 100000;

var
  i, k: integer;
  digits : string;
  
begin
	i:=1;
	while (FileExists(IntToStr(i)+'.in')) do inc(i);
	rewrite(output,IntToStr(i)+'.in');
	
  randomize;
  
  if (ParamCount > 0) then digits := ParamStr(1)
  else begin
  	for i:= 0 to 9 do
  		if (random(1000) < 500) then digits := digits + chr(ord('0') + i);
  end;
  
  if (ParamCount > 1) then k := StrToInt(ParamStr(2)) else k := random(MAXK) + 1;
  
  writeln(digits);
  write(k);
  
  sleep(20);
end.