#include<iostream>

using namespace std;

int main()
{
	int dis_lst[]={0,0,6,13,18,23,43,58};
	int prc_lst[7][8]={{},
		{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},
	};

	for(int ic1,h1,m1,ic2,h2,m2;cin>>ic1>>h1>>m1>>ic2>>h2>>m2,ic1;){
		if(ic1>ic2)	swap(ic1,ic2);
		int dis=dis_lst[ic2]-dis_lst[ic1];

		bool harf=false;
		if(dis<=40
		&&((60*17+30<=60*h1+m1 && 60*h1+m1<=60*19+30)
		|| (60*17+30<=60*h2+m2 && 60*h2+m2<=60*19+30)))	harf=true;

		int prc=prc_lst[ic1][ic2];
		if(harf){
			prc/=2;
			if(prc%50>0)	prc+=50-prc%50;
		}

		cout<<prc<<endl;
	}

	return 0;
}