#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void){
	int t[8][8];
	int l[8][8];

	t[1][2] = 300; t[1][3] = 500; t[1][4] = 600; t[1][5] = 700; t[1][6] = 1350; t[1][7] = 1650;
	t[2][3] = 350; t[2][4] = 450; t[2][5] = 600; t[2][6] = 1150; t[2][7] = 1500;
	t[3][4] = 250; t[3][5] = 400; t[3][6] = 1000; t[3][7] = 1350;
	t[4][5] = 250; t[4][6] = 850; t[4][7] = 1300;
	t[5][6] = 600; t[5][7] = 1150;
	t[6][7] = 500;

	l[1][2] = 6; l[1][3] = 13; l[1][4] = 18; l[1][5] = 23; l[1][6] = 43; l[1][7] = 58;
	l[2][3] = 7; l[2][4] = 12; l[2][5] = 17; l[2][6] = 37; l[2][7] = 52;
	l[3][4] = 5; l[3][5] = 10; l[3][6] = 30; l[3][7] = 45;
	l[4][5] = 5; l[4][6] = 25; l[4][7] = 40;
	l[5][6] = 20; l[5][7] = 35;
	l[6][7] = 15;

	int in,out,in_t,out_t,t1,t2;

	while(cin >> in && in){
		cin >> t1 >> t2;
		in_t = t1*100+t2;
		cin >> out;
		cin >> t1 >> t2;
		out_t = t1*100+t2;
		if(in > out){
			swap(in,out);
		}
		if(l[in][out] <= 40 && ((1730 <= in_t && in_t <= 1930) || (1730 <= out_t && out_t <= 1930))){
			int tmp = std::ceil((double)(t[in][out] / 2) / 50);
			cout << tmp * 50 << endl;
		}else{
			cout << t[in][out] << endl;
		}
	}
}