def half(x): return x/100*50+[0,50][x%100>0]
def In(): return map(int, raw_input().split())
def t(h,m): return 1050<=h*60+m<=1170

toll = {}
P=[6,10,12,14,27,33,7,9,12,23,30,5,8,20,27,5,17,26,12,23,10]
c=0
for i in range(0,6):
  for j in range(i+1,7):
    toll[(i,j)] = toll[(j,i)] =P[c]*50
    c += 1
D=[0, 6, 13, 18, 23, 43, 58]

while 1:
  i1 = input()-1
  if i1<0: break
  h1, m1 = In()
  i2 = input()-1
  h2, m2 = In()
  cost = toll[(i1,i2)]
  if (t(h1, m1) or t(h2,m2)) and abs(D[i1]-D[i2])<=40: cost = half(cost)
  print cost