b=[[0,6,10,12,14,27,33],
   [6,0,7,9,12,23,30],
   [13,7,0,5,8,20,27],
   [18,12,5,0,5,17,26],
   [23,17,10,5,0,12,23],
   [43,37,30,25,20,0,10],
   [58,52,45,40,35,15,0]]
while 1:
    d=int(input())
    if d==0:break
    e,f=map(int,input().split())
    t=e*60+f
    a=int(input())
    e,f=map(int,input().split())
    _t=e*60+f
    if d>a:d,a=a,d
    d-=1;a-=1
    print((b[d][a]//2+b[d][a]%2)*50if b[a][d]<=40 and ((17*60+30<=t<=19*60+30)or(17*60+30<=_t<=19*60+30))else b[d][a]*50) 