#include<iostream>
#include<algorithm>
using namespace std;
const int da[] = { 0,0,6,13,18,23,43,58 };
int f(int a, int b, bool c) {
	int p;
	if (a == 1 && b == 2)p = 300;
	else if (a == 1 && b == 3)p = 500;
	else if (a == 1 && b == 4)p = 600;
	else if (a == 1 && b == 5)p = 700;
	else if (a == 1 && b == 6)p = 1350;
	else if (a == 1 && b == 7)p = 1650;
	else if (a == 2 && b == 3)p = 350;
	else if (a == 2 && b == 4)p = 450;
	else if (a == 2 && b == 5)p = 600;
	else if (a == 2 && b == 6)p = 1150;
	else if (a == 2 && b == 7)p = 1500;
	else if (a == 3 && b == 4)p = 250;
	else if (a == 3 && b == 5)p = 400;
	else if (a == 3 && b == 6)p = 1000;
	else if (a == 3 && b == 7)p = 1350;
	else if (a == 4 && b == 5)p = 250;
	else if (a == 4 && b == 6)p = 850;
	else if (a == 4 && b == 7)p = 1300;
	else if (a == 5 && b == 6)p = 600;
	else if (a == 5 && b == 7)p = 1150;
	else if (a == 6 && b == 7)p = 500;
	else p = 114514;
	if (c)p /= 2;
	if (p % 50 != 0)p += 25;
	return p;
}
int main() {
	int a, b, c, d;
	while (cin >> a, a) {
		int h, w; cin >> h >> w;
		b = h * 100 + w;
		cin >> c;
		cin >> h >> w;
		d = h * 100 + w;
		int dis = da[max(a, c)] - da[min(a, c)];
		bool e;
		if (((1730 <= b && b <= 1930) || (1730 <= d && d <= 1930)) && dis <= 40)e = true; else e = false;
		cout << f(min(a, c), max(a, c), e) << endl;
	}
}