#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int cost[8][8]={
{   0,   0,   0,   0,   0,   0,   0,   0},
{   0,   0, 300, 500, 600, 700,1350,1650},
{   0, 300,   0, 350, 450, 600,1150,1500},
{   0, 500, 350,   0, 250, 400,1000,1350},
{   0, 600, 450, 250,   0, 250, 850,1300},
{   0, 700, 600, 400, 250,   0, 600,1150},
{   0,1350,1150,1000, 850, 600,   0, 500},
{   0,1650,1500,1350,1300,1150, 500,   0}
};

int dis[8][8]={
{ 0, 0, 0, 0, 0, 0, 0, 0},
{ 0, 0, 6,13,18,23,43,58},
{ 0, 6, 0, 7,12,17,37,52},
{ 0,13, 7, 0, 5,10,30,45},
{ 0,18,12, 5, 0, 5,25,40},
{ 0,23,17,10, 5, 0,20,35},
{ 0,43,37,30,25,20, 0,15},
{ 0,58,52,45,40,35,15, 0}
};

int main() {
	int n1,n2,h1,h2,m1,m2;
	while(n1=in()){
		cin>>h1>>m1>>n2>>h2>>m2;
		int c=cost[n1][n2];
		int d=dis[n1][n2];
		int time1=h1*60+m1;
		int time2=h2*60+m2;
		if(d<=40&&(17*60+30<=time1&&time1<=19*60+30||17*60+30<=time2&&time2<=19*60+30)){
			c/=2;
			if(c%50){
				c+=50-c%50;
			}
		}
		cout<<c<<endl;
	}
	return 0;
}