#include<stdio.h>
int d[7][7]={{0,6,10,12,14,27,33},{6,0,7,9,12,23,30},{10,7,0,5,8,20,27},{12,9,5,0,5,17,26},{14,12,8,5,0,12,23},{27,23,20,17,12,0,10},{33,30,27,26,23,10,0}};
int c[]={0,6,13,18,23,43,58};
int ABS(int a){return a<0?-a:a;}
int main(){
	int a;
	while(scanf("%d",&a),a){
		a--;
		int p,q,r,s,t;
		scanf("%d%d%d%d%d",&p,&q,&r,&s,&t);
		r--;
		int ret=d[a][r];
		if(ABS(c[a]-c[r])<=40){
			if(1050<=p*60+q&&p*60+q<=1170)ret=(ret+1)/2;
			else if(1050<=s*60+t&&s*60+t<=1170)ret=(ret+1)/2;
		}printf("%d\n",ret*50);
	}
}