#include <iostream>
#include <vector>
#include <algorithm>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int money[7][7] = {{},{300},{500,350},{600,450,250},{700,600,400,250},{1350,1150,1000,850,600},{1650,1500,1350,1300,1150,500}};
	int dis[7][7] = {{},{6},{13,7},{18,12,5},{23,17,10,5},{43,37,30,25,20},{58,52,45,40,35,15}};

	int sn,sh,sm,gn,gh,gm;
	while(cin >> sn && sn)
	{
		cin >> sh >> sm >> gn >> gh >> gm;

		sn--;
		gn--;
		int s = sh*100 + sm;
		int e = gh*100 + gm;

		if(s < 1730 && 1930 < e)
		{
			cout << money[gn][sn] << endl;		
		}
		else
		{
			int m = money[gn][sn];
			if(dis[gn][sn] <= 40)
			{
				if(m % 100 == 0)
				{
					cout << m/2 << endl;
				}
				else
				{
					cout << (m+50)/2 << endl;
				}
			}
			else
			{
				cout << m << endl;
			}
		}
	}
	return 0;
}