#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
typedef pair<double,double> P;

int main(){
  int N;
  P ansA=P(-1,-1),ansB=P(-1,-1);
  int F,A,T,X,Y;
  int f,a,t,x,y;
  cin>>N>>F>>A>>T>>X>>Y;
  for(int i=1;i<N;i++){
    cin>>f>>a>>t>>x>>y;
    if(T==t&&A!=a){
      P d=P( sqrt((X-x)*(X-x)+(Y-y)*(Y-y)) ,F-f);      
      if(t==0)ansA=max(ansA,d);
      else ansB=max(ansB,d);
    }
    F=f;A=a;T=t;X=x;Y=y;
  }
  if(ansA.first<0)printf("-1 -1\n");
  else printf("%.8f %.8f\n",ansA.first,-ansA.second/60.0);
  if(ansB.first<0)printf("-1 -1\n");
  else printf("%.8f %.8f\n",ansB.first,-ansB.second/60.0);
  return 0;
}