#include<iostream>

using namespace std;

int cost[8][8] = {{},{0,0,300,500,600,700,1350,1650},
		  {0,0,0,350,450,600,1150,1500},
		  {0,0,0,0,250,400,1000,1350},
		  {0,0,0,0,0,250,850,1300},
		  {0,0,0,0,0,0,600,1150},
		  {0,0,0,0,0,0,0,500}};

int dis[8][8] = {{},{0,0,6,13,18,23,43,58},
		 {0,0,0,7,12,17,37,52},
		 {0,0,0,0,5,10,30,45},
		 {0,0,0,0,0,5,25,40},
		 {0,0,0,0,0,0,20,35},
		 {0,0,0,0,0,0,0,15}};

struct T{int ic,h,m;};
T t[2];

bool check(T in){
  if(17 < in.h && in.h < 19) return true;
  if(in.h == 17 && in.m >= 30) return true;
  if(in.h == 19 && in.m <= 30) return true;
 
  return false;
}

int solve(T from, T to){
  int ans = 0;
  bool half = (check(from)||check(to));

  int fi = from.ic,ti = to.ic;

  if(from.ic > to.ic) swap(fi,ti);

  ans = cost[fi][ti];
  
  if(half && dis[fi][ti] <= 40) ans /= 2;

  while((ans%100)%50) ans++;

  return ans;
}

int main(){

  while(cin >> t[0].ic && t[0].ic){
    cin >> t[0].h >> t[0].m;
    cin >> t[1].ic >> t[1].h >> t[1].m;
    cout << solve(t[0],t[1]) << endl;
  }
  
  return 0;
}