{$apptype console}

// (C) Timofey S. Chistyakov 2005

uses
  Types, Math, Classes, SysUtils;

var
  sl: TStringList;

function IsUnique(X, Y: integer; DoAdd: boolean = false): boolean;
var
  s: string;
begin
  s := Format('%d.%d', [X, Y]);
  Result := sl.IndexOf(s) = -1;
  if DoAdd then
    sl.Add(s);
end;

var
  n, dxa: integer;
  x, y, dx, dy: integer;
  xx, yy: array [1..4] of integer;
  i, j, t: integer;
  ok: boolean;
  rx, ry: TIntegerDynArray;
  cnt: integer;
  range: integer;
begin
  RandSeed := StrToInt(ParamStr(1));
  n := StrToInt(ParamStr(2));
  dxa := StrToInt(ParamStr(3));  // амплитуда dx, dy
  range := StrToInt(ParamStr(4)); 

  n := EnsureRange((n div 4) * 4, 4, 2000);
  range := Max(range, 4 * dxa); 

  SetLength(rx, n);
  SetLength(ry, n);

  sl := TStringList.Create;
  sl.Sorted := true;
  cnt := 0;
  for i := 1 to n div 4 do begin
    repeat
      x := RandomRange(-range + 2 * dxa, range - 2 * dxa);
      y := RandomRange(-range + 2 * dxa, range - 2 * dxa);
      repeat
        dx := Random(2 * dxa) - dxa;
        dy := Random(2 * dxa) - dxa;
      until (dx <> 0) or (dy <> 0);

      xx[1] := x;  yy[1] := y;
      xx[2] := xx[1] + dx; yy[2] := yy[1] + dy;
      xx[3] := xx[2] + dy; yy[3] := yy[2] - dx;
      xx[4] := xx[3] - dx; yy[4] := yy[3] - dy;
      ok := true;
      for j := 1 to 4 do
        ok := ok and IsUnique(xx[j], yy[j]);
    until ok;

    for j := 1 to 4 do begin
      rx[cnt] := xx[j];
      ry[cnt] := yy[j];
      IsUnique(xx[j], yy[j], true);
      Inc(cnt);
    end;
  end;

  for i := 0 to n - 1 do begin
    j := i + Random(n - i);
    t := rx[i]; rx[i] := rx[j]; rx[j] := t;
    t := ry[i]; ry[i] := ry[j]; ry[j] := t;
  end;

  Writeln(n);
  for i := 0 to n - 1 do
    WriteLn(rx[i], ' ', ry[i]);
end.
