#include <algorithm>
#include <array>
#include <complex>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
  int N;
  cin >> N;
  double valM1 = -1;
  int valm1 = 10000000;
  double valM2 = -1;
  int valm2 = 10000000;
  int prea = -1;
  int pret = -1;
  int pref = 0;
  int prex, prey;
  for(int i = 0; i < N; ++i) {
    int f, a, t, x, y;
    cin >> f >> a >> t >> x >> y;
    if(pret == t && prea != a){
      double d = (x - prex) * (x - prex) + (y - prey) * (y - prey);
      if(t == 0){
        if(valM1 < d){
          valM1 = d;
          valm1 = f - pref;
        }else if(valM1 == d){
          valm1 = min(valm1, f - pref);
        }
      }else{
        if(valM2 < d){
          valM2 = d;
          valm2 = f - pref;
        }else if(valM2 == d){
          valm2 = min(valm2, f - pref);
        }
      }
    }
    pref = f;
    prea = a;
    pret = t;
    prex = x;
    prey = y;
  }
  if(valM1 == -1){
    printf("%.10f %.10f\n", -1.0, -1.0);
  }else{
    printf("%.10f %.10f\n", sqrt(valM1), (double)valm1 / 60);
  }
  if(valM2 == -1){
    printf("%.10f %.10f\n", -1.0, -1.0);
  }else{
    printf("%.10f %.10f\n", sqrt(valM2), (double)valm2 / 60);
  }

}