# frame, ?????????, ????????? x, y

def distance(x, y, x2, y2)
  Math.sqrt( ( (x - x2) ** 2 + (y - y2) ** 2 ) )
end

def result_sort(pass)
  pass.sort!{|a, b|
    if a[:distance] != b[:distance]
      b[:distance] <=> a[:distance]
    else
      a[:time] <=> b[:time]
    end
  }
end

def solve(data)
  pass = {0.0 => [], 1.0 => []}
  (0 .. data.length - 2).each{|i|
    if data[i][2] == data[i + 1][2] && data[i][1] != data[i + 1][1]
      pass[ data[i][2] ].push({
        :team     => data[i][2],
        :time     => ( data[i + 1][0] - data[i][0] ) * (1.0 / 60.0),
        :distance => distance(data[i][3], data[i][4], data[i + 1][3], data[i + 1][4]),
      })
    end
  }
  result_sort pass[0.0]
  result_sort pass[1.0]
  pass
end

def main
  n = gets.to_i
  data = (0 .. n - 1).map{|n|
    STDIN.gets.split(" ").map{|x| x.to_f }
  }
  result = solve(data)
  puts result[0.0].empty? ? "-1 -1" : "#{ result[0.0][0][:distance] } #{ result[0.0][0][:time] }"
  puts result[1.0].empty? ? "-1 -1" : "#{ result[1.0][0][:distance] } #{ result[1.0][0][:time] }"
end

main