passes = [[[-1.0, -1.0]], [[-1.0, -1.0]]]
n = gets.to_i
f1, a1, t1, x1, y1 = gets.chomp.split.map(&:to_i)
(n - 1).times{
    f2, a2, t2, x2, y2 = gets.chomp.split.map(&:to_i)
    passes[t2] << [Math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2), (f2 - f1) / 60.0] if a2 != a1 && t2 == t1
    f1, a1, t1, x1, y1 = f2, a2, t2, x2, y2
}
0.upto(1){|i|
    passes[i].sort_by!{|a, b| [-a, b]}
    puts "#{passes[i][0][0]} #{passes[i][0][1]}"
}
