h={12=>6,13=>10,14=>12,15=>14,16=>27,17=>33,23=>7,24=>9,25=>12,26=>23,27=>30,34=>5,35=>8,36=>20,37=>27,45=>5,46=>17,47=>26,56=>12,57=>23,67=>10}
while(a=gets.to_i)>0
	x,y=gets.split.map(&:to_i)
	y+=x*60
	b=gets.to_i
	x,z=gets.split.map(&:to_i)
	z+=x*60
	c=h[a*10+b]
	c/=2.0 if c<27&&((1050<=y&&y<=1170)||(1050<=z&&z<=1170))
	p c.ceil*50
end