highway_kyori = [0,6,13,18,23,43,58]
highway_price1 = [300,500,600,700,1350,1650]
highway_price2 = [350,450,600,1150,1500]
highway_price3 = [250,400,1000,1350]
highway_price4 = [250,850,1300]
highway_price5 = [600,1150]
highway_price6 = [500]
highway_price = [highway_price1,highway_price2,highway_price3,highway_price4,highway_price5,highway_price6]

id1 = gets.to_i
until id1 == 0
    discount = 0
    time1 = gets.split(" ").map{|k| k.to_i }
    time1[0] *= 60
    all_time1 = time1[0] + time1[1]
    id2 = gets.to_i
    time2 = gets.split(" ").map{|k| k.to_i }
    time2[0] *= 60
    all_time2 = time2[0] + time2[1]
    if all_time1 >= 1050 && all_time1 <= 1170 &&  (highway_kyori[id2-1] - highway_kyori[id1-1]) <= 40
        discount = 1
    elsif all_time2 >= 1050 && all_time2 <= 1170 &&  (highway_kyori[id2-1] - highway_kyori[id1-1]) <= 40
        discount = 1
    end

    if discount == 0
        aa = highway_price[id1-1]
        ans = aa[id2-id1-1]
        puts ans
    elsif discount == 1
        aa = highway_price[id1-1]
        ans1 = aa[id2-id1-1] / 2
        ans2 = ans1.to_s.split("")
        if ans2[-1] == "5"
            ans1 += 25
        end
        ans = ans1
        puts ans
    end
    id1 = gets.to_i
end


