#include<bits/stdc++.h>
using namespace std;

struct Data{
  int f,a,t,x,y;
};

double length(int x,int x2,int y,int y2){
  
  return sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2));
  
}
int main(){
  
  int N;
  
  cin >>N;
  
  Data data[N];
  
  for(int i=0 ; i < N ; i++){
    cin >>data[i].f>>data[i].a>>data[i].t>>data[i].x>>data[i].y;
  }
  
  double len_a=-1,len_b=-1,f_a=-1,f_b=-1;
  
  for(int i=0 ; i < N-1 ; i++){
    if(data[i].t == data[i+1].t && data[i].a != data[i+1].a){
      if(data[i].t == 0){
        if((len_a < length(data[i].x,data[i+1].x,data[i].y,data[i+1].y)) ||( len_a == length(data[i].x,data[i+1].x,data[i].y,data[i+1].y) && f_a*60 > data[i+1].f-data[i].f)){
          len_a=length(data[i].x,data[i+1].x,data[i].y,data[i+1].y);
          f_a=(double)(data[i+1].f-data[i].f)/60;
        }
      }else{
        if((len_b < length(data[i].x,data[i+1].x,data[i].y,data[i+1].y)) || ( len_b == length(data[i].x,data[i+1].x,data[i].y,data[i+1].y) && f_b*60 > data[i+1].f-data[i].f)){
          len_b=length(data[i].x,data[i+1].x,data[i].y,data[i+1].y);
          f_b=(double)(data[i+1].f-data[i].f)/60;
        }
      }
    }
  }
  
  
  if(len_a < 0){
    cout <<"-1"<<" "<<"-1"<<endl;
  }else{
    printf("%f %f\n",len_a,f_a);
  }
  
  if(len_b < 0){
    cout <<"-1"<<" "<<"-1"<<endl;
  }else{
    printf("%f %f\n",len_b,f_b);
  }
  
  return 0;
}