#include <iostream>
#include <vector>

using namespace std;

typedef pair<int, int> P;

int main() {
	vector< vector<P> > data(8, vector<P>(8, P(0, 0)));
	data[1][2] = data[2][1] = P(6, 300);
	data[1][3] = data[3][1] = P(13, 500);
	data[1][4] = data[4][1] = P(18, 600);
	data[1][5] = data[5][1] = P(23, 700);
	data[1][6] = data[6][1] = P(43, 1350);
	data[1][7] = data[7][1] = P(58, 1650);
	data[2][3] = data[3][2] = P(7, 350);
	data[2][4] = data[4][2] = P(12, 450);
	data[2][5] = data[5][2] = P(17, 600);
	data[2][6] = data[6][2] = P(37, 1150);
	data[2][7] = data[7][2] = P(52, 1500);
	data[3][4] = data[4][3] = P(5, 250);
	data[3][5] = data[5][3] = P(10, 400);
	data[3][6] = data[6][3] = P(30, 1000);
	data[3][7] = data[7][3] = P(45, 1350);
	data[4][5] = data[5][4] = P(5, 250);
	data[4][6] = data[6][4] = P(25, 850);
	data[4][7] = data[7][4] = P(40, 1300);
	data[5][6] = data[6][5] = P(20, 600);
	data[5][7] = data[7][5] = P(35, 1150);
	data[6][7] = data[7][6] = P(15, 500);
	int s, g;
	while (cin >> s) {
		if (s == 0) {
			break;
		}
		int sh, sm;
		cin >> sh >> sm;
		int gh, gm;
		cin >> g;
		cin >> gh >> gm;
		int mm = data[s][g].second;
		bool hantei = true;
		if (data[s][g].first <= 40) {
		if (sh == 18) {
			if (mm % 100 == 50) {
				mm += 50;
			}
			mm /= 2;
			hantei = false;
		} else if (sh == 17) {
			if (sm >= 30) {
				if (mm % 100 == 50) {
					mm += 50;
				}
				mm /= 2;
				hantei = false;
			}
		} else if (sh == 19) {
			if (sm <= 30) {
				if (mm % 100 == 50) {
					mm += 50;
				}
				mm /= 2;
				hantei = false;
			}
		}
		if (hantei) {
			if (gh == 18) {
				if (mm % 100 == 50) {
					mm += 50;
				}
				mm /= 2;
			} else if (gh == 17) {
				if (gm >= 30) {
					if (mm % 100 == 50) {
						mm += 50;
					}
					mm /= 2;
				}
			} else if (gh == 19) {
				if (gm <= 30) {
					if (mm % 100 == 50) {
						mm += 50;
					}
					mm /= 2;
				}
			}
		}
		}
		cout << mm << endl;
	}
	return 0;
}