#include<iostream>
#include<vector>
using namespace std;

#define MAX 1000000

int main()
{
	int i, j, k;
	vector< vector<int> > distance(8, vector<int>(8));
	vector< vector<int> > fee(8, vector<int>(8));
	fee[1][2] = 200;
	fee[1][3] = 500;
	fee[1][4] = 600;
	fee[1][5] = 700;
	fee[1][6] = 1350;
	fee[1][7] = 1650;
	fee[2][3] = 350;
	fee[2][4] = 450;
	fee[2][5] = 600;
	fee[2][6] = 1150;
	fee[2][7] = 1500;
	fee[3][4] = 250;
	fee[3][5] = 400;
	fee[3][6] = 1000;
	fee[3][7] = 1350;
	fee[4][5] = 250;
	fee[4][6] = 850;
	fee[4][7] = 1300;
	fee[5][6] = 600;
	fee[5][7] = 1150;
	fee[6][7] = 500;
	distance[1][2] = 6;
	distance[1][3] = 13;
	distance[1][4] = 18;
	distance[1][5] = 23;
	distance[1][6] = 42;
	distance[1][7] = 58;
	distance[2][3] = 7;
	distance[2][4] = 12;
	distance[2][5] = 17;
	distance[2][6] = 37;
	distance[2][7] = 52;
	distance[3][4] = 5;
	distance[3][5] = 10;
	distance[3][6] = 30;
	distance[3][7] = 40;
	distance[4][5] = 5;
	distance[4][6] = 25;
	distance[4][7] = 40;
	distance[5][6] = 20;
	distance[5][7] = 35;
	distance[6][7] = 15;

	int s, e, h, m;
	int timeStart = 17*60+30;
	int timeEnd = 19*60+30;
	int r;
	bool f;
	while (cin>>s, s) {
		f = false;
		cin>>h>>m;
		if (timeStart <= h*60+m && h*60+m <= timeEnd) f = true;
		cin>>e>>h>>m;
		if (timeStart <= h*60+m && h*60+m <= timeEnd) f = true;

		if (s>e) {
			s ^= e;
			e ^= s;
			s ^= e;
		}
		r = fee[s][e];
		if (f && distance[s][e]<=40) {
			r /= 2;
			if (r%50) {
				r += 25;
				r /= 50;
				r *= 50;
			}
		}
		cout<<r<<endl;
	}
	return 0;
}