#include <iostream>
#include <memory>
#include <memory.h>
#include <cmath>
#include <fstream>
#include <cmath>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>
#define USE_MATH_DEFINES
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

int table[][7] = {
	{0, 300, 500, 600, 700, 1350, 1650},
	{6, 0, 350, 450, 600, 1150, 1500},
	{13, 7, 0, 250, 400, 1000, 1350},
	{13, 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, 0}
};

int main(){
	int s, t;
	int h1, m1, h2, m2;
	int t1, t2;
	while(cin >> s && s){
		cin >>h1 >> m1;
		cin >> t;
		cin >> h2 >> m2;
		t1 = h1 * 60 + m1;
		t2 = h2 * 60 + m2;
		s--, t--;
		int cost = table[min(s, t)][max(s, t)];
		int dis = table[max(s, t)][min(s, t)];
		if(dis <= 40 && (1050 <= t1 && t1 <= 1170 || 1050 <= t2 && t2 <= 1170)){
			cost = (cost / 2 + 49) / 50 * 50;
		}
		cout << cost << endl;
	}
	return 0;
}