# define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12
template<class T> void debug(T a) { for (auto iiiiiiiiii : a)cout << iiiiiiiii << endl; }
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };

int main()
{
	int n[2];
	while (cin >> n[0]&&n[0])
	{
		int t[2];
		int h, m;
		cin >> h >> m;
		t[0] = h * 60 + m;
		cin >> n[1];
		cin >> h >> m;
		t[1] = h * 60 + m;
		int x[][8] = { {0,0,0,0,0,0,0,0},{0,0,300,500,600,700,1350,1650},{0,0,0,350,450,600,1150,1500},{0,0,0,0,250,400,1000,1350},{0,0,0,0,0,250,850,1300},{0,0,0,0,0,0,600,1150},{0,0,0,0,0,0,0,500} };
		int ans = x[min(n[0], n[1])][max(n[0], n[1])];
		int p = 0;
		if (t[0] <= 17 * 60 + 30 && 17 * 60 + 30 <= t[1])p++;
		if (t[0] <= 19 * 60 + 30 && 19 * 60 + 30 <= t[1])p++;

		int d[] = { 6,7,5,5,20,15 };
		int D = 0;
		if (n[0] > n[1])swap(n[0], n[1]);
		while (n[0] < n[1])
		{
			D += d[n[0]-1];
			n[0]++;
		}
		if (p && D <= 40)
		{
			ans /= 2;
			while (ans % 50)ans++;
		}
		cout << ans << endl;


	}

}