import java.lang.Math.sqrt

fun main(args:Array<String>?): Unit {
    val n = readLine()!!.trim().toInt()
    val frames = Array(n){
        val (f, a, t, x, y) = readLine()!!.trim().split(' ').map(String::toInt)
        Frame(f, a, t, Position(x, y))
    }
    val aPass = frames.indices.drop(1).filter{i -> frames[i].team == 0 && frames[i - 1].team == 0 && frames[i].label != frames[i - 1].label}.map{i -> Pair(frames[i].position.norm(frames[i - 1].position), frames[i].time - frames[i - 1].time)}.maxWith(Comparator { o1, o2 ->  if (o1.first == o2.first) o2.second.compareTo(o1.second) else o1.first.compareTo(o2.first)})
    val bPass = frames.indices.drop(1).filter{i -> frames[i].team == 1 && frames[i - 1].team == 1 && frames[i].label != frames[i - 1].label}.map{i -> Pair(frames[i].position.norm(frames[i - 1].position), frames[i].time - frames[i - 1].time)}.maxWith(Comparator { o1, o2 ->  if (o1.first == o2.first) o2.second.compareTo(o1.second) else o1.first.compareTo(o2.first)})
    println(aPass?.let{"%.10f %.10f".format(sqrt(it.first.toDouble()), it.second / 60.0)} ?: "-1 -1")
    println(bPass?.let{"%.10f %.10f".format(sqrt(it.first.toDouble()), it.second / 60.0)} ?: "-1 -1")
}
data class Position(val x: Int, val y: Int) {
    fun norm(that: Position): Int = (this - that).let{(dx, dy) -> dx * dx + dy * dy}
    fun distance(that: Position): Double = sqrt(norm(that).toDouble())
    operator fun minus(that: Position): Position = Position(x - that.x, y - that.y)
}
data class Frame(val time: Int, val label: Int, val team: Int, val position: Position)
