#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

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

	int n, m, s, e;
	while (scanf("%d", &n), n)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		s = 60*a + b;
		scanf("%d %d %d", &m, &a, &b);
		e = 60*a + b;
		--n;
		--m;
		if (n > m)
			swap(n, m);

		int d = distance[n][m];
		int c = charge[n][m];
		const int S = 60*17 + 30;
		const int E = 60*19 + 30;
		if (d <= 40 && (S <= s && s <= E || S <= e && e <= E))
			c = (c+50)/100*50;
		printf("%d\n", c);
	}

	return 0;
}