#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(){
  int i,j,n,a[8][8];
  a[1][2] = a[2][1] = 300;
  a[2][3] = a[3][2] = 350;
  a[6][7] = a[7][6] = a[1][3] = a[3][1] = 500;
  a[4][5] = a[5][4] = a[3][4] = a[4][3] = 250;
  a[2][4] = a[4][2] = 450;
  a[5][6] = a[6][5] = a[2][5] = a[5][2] =  a[1][4] = a[4][1] = 600;
  a[3][5] = a[5][3] = 400;
  a[5][1] = a[1][5] = 700;
  a[4][6] = a[6][4] = 850;
  a[3][6] = a[6][3] = 1000;
  a[5][7] = a[7][5] = a[2][6] = a[6][2] = 1150;
  a[3][7] = a[7][3] = a[1][6] = a[6][1] = 1350;
  a[4][7] = a[7][4] = 1300;
  a[2][7] = a[7][2] = 1500;
  a[1][7] = a[7][1] = 1650;

  while(1){
    int ic[2],h[2],m[2],t[2],ans,ans2;
    cin >> ic[0];
    if(ic[0] == 0) break;
    cin >> h[0] >> m[0];
    cin >> ic[1];
    cin >> h[1] >> m[1];

    ans = a[ic[0]][ic[1]];
    for(i=0;i<2;i++){
      if(h[i] == 17 && m[i] >= 30 || h[i] == 18 || h[i] == 19 && m[i] <= 30){
	if(ic[0] == 1 && ic[1] == 6 || ic[0] == 6 && ic[1] == 1);
	else if(ic[0] == 1 && ic[1] == 7 || ic[0] == 7 && ic[1] == 1);
	else if(ic[0] == 2 && ic[1] == 7 || ic[0] == 7 && ic[1] == 2);
	else if(ic[0] == 3 && ic[1] == 7 || ic[0] == 7 && ic[1] == 3);
	else{
	ans /= 2;
	ans2 = ans;
	while(ans2 > 50) ans2 -= 50;
	ans += 50 - ans2;
	break;
	}
      }
    }

    cout << ans << endl;

  }
  return 0;
}