import std.stdio;
import std.algorithm;

int[8][8] cost;
int[8][8] d;

void main(){
	int a, b, h1, m1, h2, m2, s1, s2, ans;
	cost[1][2..8] = [300, 500, 600, 700, 1350, 1650];
	cost[2][3..8] = [350, 450, 600, 1150, 1500];
	cost[3][4..8] = [250, 400, 1000, 1350];
	cost[4][5..8] = [250, 850, 1300];
	cost[5][6..8] = [600, 1150];
	cost[6][7..8] = [500];
	d[2][1..2] = [6];
	d[3][1..3] = [13, 7];
	d[4][1..4] = [18, 12, 5];
	d[5][1..5] = [23, 17, 10, 5];
	d[6][1..6] = [43, 37, 30, 25, 20];
	d[7][1..7] = [58, 52, 45, 40, 35, 15];
	while (readf("%d\n", &a), a) {
		readf("%d %d\n", &h1, &m1);
		readf("%d\n", &b);
		readf("%d %d\n", &h2, &m2);
		s1 = h1*60+m1;
		s2 = h2*60+m2;
		ans = cost[a][b];
		if (d[b][a] <= 40 && ((s1 >= 17*60+30 && s1 <= 19*60+30) || (s2 >= 17*60+30 && s2 <= 19*60+30))) {
			ans /= 2;
			if (ans%50 != 0) ans = ans/50*50+50;
		}
		writeln(ans);
	}
}