{
    ACM ICPC 2003-2004 NEERC

    Problem:    Hypertransmission
    Author:     Nikolay Ignatiev
    Solution:   Dmitry Shtukenberg 
                (N^3 solution; should not pass testing)
}

{$APPTYPE CONSOLE}
{ $DEFINE ALLOWMULTITEST}
{$O-,Q+,R+}

program h_ds;

var N: longint;
    x,y,z,p: array [1..1000] of longint;
    stable: array [1..1000] of integer;

    events: array [0..1000*1000] of record r: longint; f,t: integer end;
    pos_e: array [1..1000] of integer;

    max_r, curr_r: longint;
    tmp_d, max_d: integer;

    i,j,k,l: longint;
    f,t: integer;

function dist( i,j: integer ): longint;
begin
  dist := (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) + (z[i]-z[j])*(z[i]-z[j]);
end;

begin

  read( N );
  for i := 1 to N do read( x[i],y[i],z[i],p[i] );

  for i := 1 to N do begin
    for j := 1 to N do begin
      events[ j + (i-1)*N ].r := dist(i,j);
      events[ j + (i-1)*N ].f := i;
      events[ j + (i-1)*N ].t := j;
    end;

    for j := 1 to N do begin
      for k := (i-1)*N+1 to i*N-1 do begin
        if events[ k ].r > events[ k+1 ].r then begin
          events[ 0 ] := events[ k+1 ];
          events[ k+1 ] := events[ k ];
          events[ k ] := events[ 0 ];
        end;
      end;
    end;
  end;

  (* Merge *)
  for i := 1 to N do pos_e[i] := (i-1)*N+1;
  for i := 1 to N do stable[i] := 0;
  max_d := 0;
  max_r := 0;
  tmp_d := 0;
  curr_r := 0;
  for i := 1 to N*N do begin
    l := 0;
    for j := 1 to N do 
      if (pos_e[j]<=j*N) and ((l=0) or (events[pos_e[l]].r>events[pos_e[j]].r)) then
        l := j;
    if l = 0 then begin writeln ('???'); halt(234); end;

    if curr_r <> events[pos_e[l]].r then begin
      if tmp_d > max_d then begin
        max_r := curr_r;
        max_d := tmp_d;
      end;
    end;

    f := events[pos_e[l]].f;
    t := events[pos_e[l]].t;
    if p[f] <> p[t] then begin
      dec(stable[t]); if stable[t]=-1 then inc(tmp_d);
    end
    else begin
      inc(stable[t]); if stable[t]=0 then dec(tmp_d);
    end;
    curr_r := events[pos_e[l]].r;
    inc(pos_e[l]);
  end;

  if tmp_d > max_d then begin
    max_r := curr_r;
    max_d := tmp_d;
  end;

  writeln( max_d );
  writeln( sqrt(max_r):12:4 );
end.
