using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Contest
{
    class Program
    {
        static int Main(string[] args)
        {
            new Program().Process();

            return 0;
        }

        private CommonInput cin;

        private void Process()
        {
            this.cin = new CommonInput();

            int n;

            int f, a, t, x, y;
            int preF, preA, preX, preY;
            int preTeam = -1;

            preF = preA = preX = preY = 0;

            int tmpDistance, aDistance, bDistance, tmpFrame, aFrame, bFrame;

            tmpDistance = aDistance = bDistance = tmpFrame = aFrame = bFrame = -1;

            n = cin.GetNextToInt();

            for (int i = 0; i < n; i++)
            {
                f = cin.GetNextToInt();
                a = cin.GetNextToInt();
                t = cin.GetNextToInt();
                x = cin.GetNextToInt();
                y = cin.GetNextToInt();

                // ????????????????????¨????????? = ?????????????????????
                // ??????????????¢??¨??????????¨???????????????§????????´??°??????
                if (preTeam == t)
                {
                    tmpDistance = (preX - x) * (preX - x) + (preY - y) * (preY - y);
                    tmpFrame = f - preF;

                    if (t == 0 && preA != a)
                    {
                        // A????????´??°
                        if (tmpDistance > aDistance || (tmpDistance == aDistance && tmpFrame < aFrame))
                        {
                            aDistance = tmpDistance;
                            aFrame = tmpFrame;
                        }
                    }
                    else if(t == 1 && preA != a)
                    {
                        // B????????´??°
                        if (tmpDistance > bDistance || (tmpDistance == bDistance && tmpFrame < bFrame))
                        {
                            bDistance = tmpDistance;
                            bFrame = tmpFrame;
                        }
                    }
                }

                preF = f;
                preA = a;
                preTeam = t;
                preX = x;
                preY = y;
            }

            if (aDistance == -1)
                Console.WriteLine("{0} {1}", aDistance, aFrame);
            else
                Console.WriteLine("{0:f8} {1:f8}", Math.Sqrt(aDistance), aFrame / 60d);

            if (bDistance == -1)
                Console.WriteLine("{0} {1}", bDistance, bFrame);
            else
                Console.WriteLine("{0:f8} {1:f8}", Math.Sqrt(bDistance), bFrame / 60d);

            Console.ReadKey();
        }
    }

    public class CommonInput
    {
        public CommonInput()
        {
            this._s = new string[0];
            this._i = 0;
        }

        public string Line { get; set; }
        private string[] _s;
        private int _i;
        private char[] _sep = { ' ' };

        public void GetLine()
        {
            this._i = 0;
            do
            {
                this.Line = Console.ReadLine();
            } while (this.Line == "");

            if (this.Line != null)
                this._s = this.Line.Split(this._sep, StringSplitOptions.RemoveEmptyEntries);
        }

        public string GetNext()
        {
            if (this._i < this._s.Length)
                return this._s[this._i++];

            this.GetLine();

            return this._s[this._i++];
        }

        public int GetNextToInt()
        {
            return int.Parse(this.GetNext());
        }

        public long GetNextToLong()
        {
            return long.Parse(this.GetNext());
        }

        public double GetNextToDouble()
        {
            return double.Parse(this.GetNext());
        }
    }
}

Measured memory_bytes: 15932