// AOJ 0163
#include <iostream>

using namespace std;

int main(void)
{
	int data[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}};
	int start, end, st[2], et[2];
	while (cin >> start, start){
		cin >> st[0] >> st[1];
		cin >> end >> et[0] >> et[1];
		start--; end--;

		bool f = false;
		if (17 <= st[0] && st[0] <= 19){
			if (st[0] == 18) f = true;
			else if ((st[0] == 17 && 30 <= st[1]) || (st[0] == 19 && 30 >= st[1])){
				f = true;
			}
		}
		if (17 <= et[0] && et[0] <= 19){
			if (et[0] == 18) f = true;
			else if ((et[0] == 17 && 30 <= et[1]) || (et[0] == 19 && 30 >= et[1])){
				f = true;
			}
		}

		if (start < end) swap(start, end);
		int k = data[start][end];
		int ret = data[end][start];
		if (40 < k) f = false;

		ret /= 50.0;
		if (f){
			if (ret % 2) ret++;
			ret /= 2;
		}
		cout << (int)(ret * 50) << endl;
	}

	return 0;
}