#include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef pair<int,Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int s,d;
	int score[][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 dist[][7]={{0,6,13,18,23,43,58},
					{0,0,7,12,17,37,52},
				 	{0,0,0,5,10,30,45},
					{0,0,0,0,5,25,40},
				 	{0,0,0,0,0,20,35},
					{0,0,0,0,0,0,15}};
	while(scanf("%d",&s),s){
		int hs,ms;
		scanf("%d%d",&hs,&ms);

		int hd,md;
		scanf("%d",&d);
		scanf("%d%d",&hd,&md);

		s--;d--;
		if(s>d)swap(s,d);

		if(1050 <= hs*60+ms && hs*60+ms <= 1170){
			if(dist[s][d]<=40){
				int ret = score[s][d];
				ret /= 2;
				if(ret%10){
					ret+=25;
				}
				printf("%d\n",ret);
			}
			else{
				printf("%d\n",score[s][d]);
			}
		}
		else if(1050 <= hd*60+md && hd*60+md <= 1170){
			if(dist[s][d]<=40){
				int ret = score[s][d];
				ret /= 2;
				if(ret%10){
					ret+=25;
				}
				printf("%d\n",ret);
			}
			else{
				printf("%d\n",score[s][d]);	
			}
		}
		else{
			printf("%d\n",score[s][d]);
		}
	}
    return 0;
}