#include <iostream>
#define rng(z) (1050 <= z && z <= 1170)
using namespace std;
int a, b, t1, t2, p, q;
int x[7][7] = {
	{0, 300, 500, 600, 700, 1350, 1650},
	{6, 0, 350, 450, 600, 1150, 1500},
	{13, 7, 0, 250, 400, 1000, 1350},
	{18, 12, 5, 0, 250, 850, 1300},
	{23, 17, 10, 5, 0, 600, 1150},
	{43, 37, 30, 25, 20, 0, 500},
	{58, 52, 45, 40, 35, 15, 0}
};
int main() {
	while (cin >> a, a) {
		cin >> p >> q; t1 = p * 60 + q; a--;
		cin >> b >> p >> q; t2 = p * 60 + q; b--;
		if (a > b) swap(a, b);
		int cost = x[a][b], dist = x[b][a];
		if (dist <= 40 && (rng(t1) || rng(t2))) cost /= 2;
		cost = (cost + 49) / 50 * 50;
		cout << cost << endl;
	}
}