#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;

int l[7]={0,6,13,18,23,43,58};
int co[7][7]={
	0,300,500,600,700,1350,1650,
	300,0,350,450,600,1150,1500,
	500,350,0,250,400,1000,1350,
	600,450,250,0,250,850,1300,
	700,600,400,250,0,600,1150,
	1350,1150,1000,850,600,0,500,
	1650,1500,1350,1300,1150,500,0
};
int main(void){
	int s[2],h[2],m[2];
	int f[2];
	int ans;
	while(1){
		scanf("%d",&s[0]);
		if(s[0]==0)break;
		scanf("%02d%02d",&h[0],&m[0]);
		scanf("%d",&s[1]);
		scanf("%02d%02d",&h[1],&m[1]);
		for(int i=0;i<2;i++){
			if(h[i]<17 || h[i]==17 && m[i]<30)f[i]=0;
			else if(h[i]<19 || h[i]==19 && m[i]<=30)f[i]=1;
			else f[i]=2;
		}
		ans=co[s[0]-1][s[1]-1];
		if((f[0]==1 || f[1]==1) && abs(l[s[1]-1]-l[s[0]-1])<=40)ans=(co[s[0]-1][s[1]-1]+50)/100*50;
		printf("%d\n",ans);
	}
    return 0;
}