#include <iostream>
using namespace std;

int price[8][8]={
	{0,0,0,0,0,0,0,0},
	{0,0,300,500,600,700,1350,1650},
	{0,300,0,350,450,600,1150,1500},
	{0,500,350,0,250,400,1000,1350},
	{0,600,450,250,0,250,850,1300},
	{0,700,600,400,250,0,600,1150},
	{0,1350,1150,1000,850,600,0,500},
	{0,1650,1500,1350,1300,1150,500,0}
};

int dist[8][8]={
	{0,0,0,0,0,0,0,0},
	{0,0,6,13,18,23,43,58},
	{0,6,0,7,12,17,37,52},
	{0,13,7,0,5,10,30,45},
	{0,18,12,5,0,5,25,40},
	{0,23,17,10,5,0,20,35},
	{0,43,37,30,25,20,0,15},
	{0,58,52,45,40,35,15,0}
};

int calSec(int h,int m){
	return h * 60 + m;
}

int main(void){
	int ts=calSec(17,30),te=calSec(19,30);
	int s,g,st,gt;

	while(cin>>s && s){
		int h,m;
		cin>>h>>m;
		st = calSec(h,m);
		cin>>g>>h>>m;
		gt = calSec(h,m);

		bool flg = false;
		if(dist[s][g]<=40 && (ts<=st && st<=te || ts<=gt && gt<=te)) flg = true;

		int ans = price[s][g];
		if(flg){
			ans /= 2;
			int rem = ans % 50;
			if(rem != 0) ans += 50 - rem;
		}

		cout<<ans<<endl;
	}

	return 0;
}