#include <iostream>
using namespace std;

int table[ 8 ][ 8 ] = {
	{ 0, 0, 0, 0, 0, 0, 0, 0 },
	{ 0, 0, 300, 500, 600, 700, 1350, 1650 },
	{ 0, 6, 0, 350, 450, 600, 1150, 1500 },
	{ 0, 13, 7, 0, 250, 400, 1000, 1350 },
	{ 0, 18, 12, 5, 0, 250, 850, 1300 },
	{ 0, 23, 17, 10, 5, 0, 600, 1150 },
	{ 0, 43, 37, 30, 25, 20, 0, 500 },
	{ 0, 58, 52, 45, 40, 35, 15, 0 }
};

int main()
{
	int s, e;
	int sh, sm, eh, em;
	while( cin >> s && s ){
		cin >> sh >> sm;
		cin >> e;
		cin >> eh >> em;

		int st = sh * 100 + sm;
		int et = eh * 100 + em;
		if( s > e ){
			int t = s;
			s = e;
			e = t;
		}
		int cost = table[ s ][ e ];
		if( ( ( st >= 1730 && st <= 1930 ) || ( et >= 1730 && et <= 1930 ) )
			&& ( table[ e ][ s ] <= 40 ) ){
			cost = static_cast<int>( ( ( cost / 100.0 ) + 0.9 ) ) * 50;
		}

		cout << cost << endl;
	}

	return 0;
}