#include <iostream>
using namespace std;
int main(){
	int discount[2]={17*60+30,19*60+30};
	int D[7]={0,6,13,18,23,43,58};
	int C[7][7]={
		{0,300,500,600,700,1350,1650},
		{0,0,350,450,600,1150,1500},
		{0,0,0,250,400,1000,1350},
		{0,0,0,0,250,850,1300},
		{0,0,0,0,0,600,1150},
		{0,0,0,0,0,0,500},
	};
	int in,out;
	while(cin>>in,in){
		int h1,m1,h2,m2,fare;
		cin>>h1>>m1;
		cin>>out;
		cin>>h2>>m2;
		int d=D[out-1]-D[in-1];
		int min1=h1*60+m1;
		int min2=h2*60+m2;
		if((discount[0]<=min1&&min1<=discount[1])||(discount[0]<=min2&&min2<=discount[1])&&d<=40) fare=(C[in-1][out-1]/2+25)/50*50;
		else fare=C[in-1][out-1];
		cout<<fare<<endl;
	}
	return 0;
}