# Highway Toll

PRICE_LIST = (
    (0, 0, 0, 0, 0, 0, 0, 0),
    (0, 0, 300, 500, 600, 700, 1350, 1650),
    (0, 6, 0, 350, 450, 600, 1150, 1500),
    (0, 13, 7, 0, 250, 400, 1000, 1350),
    (0, 18, 12, 5, 0, 250, 850, 1300),
    (0, 23, 17, 10, 5, 0, 600, 1150),
    (0, 43, 37, 30, 25, 20, 0, 500),
    (0, 58, 52, 45, 40, 35, 15, 0),
)

while True:
    i = int(raw_input())
    if i == 0:
        break

    it = int(raw_input().strip().replace(' ', ''))
    o = int(raw_input())
    ot = int(raw_input().strip().replace(' ', ''))

    half = False
    price = PRICE_LIST[i][o]
    if (1730 <= it <= 1930 or 1730 <= ot <= 1930) and PRICE_LIST[o][i] <= 40:
        half = True
        price /= 2
        if price % 50:
            price = price - (price % 50) + 50

    print price