#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int n1,n2;
	int a[7][7]={
		{0,6,13,18,23,43,58},
		{300,0,7,12,17,37,52},
		{500,350,0,5,10,30,45},
		{600,450,250,0,5,25,40},
		{700,600,400,250,0,20,35},
		{1350,1150,1000,850,600,0,15},
		{1650,1500,1350,1300,1150,500}
	};
	while(cin>>n1,n1){
		int m1,s1,m2,s2;
		cin>>m1>>s1;
		cin>>n2;
		cin>>m2>>s2;
		bool f1=false;
		bool f2=false;
		int t1=m1*60+s1;
		int t2=m2*60+s2;
		if(17*60+30<=t1&&t1<=19*60+30) f1=true;
		if(17*60+30<=t2&&t2<=19*60+30) f1=true;
		if(a[min(n1,n2)-1][max(n1,n2)-1]<=40) f2=true;
		if(f1&&f2){
			int ans=a[max(n1,n2)-1][min(n1,n2)-1];
			if(ans%100==0) cout<<ans/2<<endl;
			else{
				ans+=50;
				cout<<ans/2<<endl;
			}
		}
		else{
			cout<<a[max(n1,n2)-1][min(n1,n2)-1]<<endl;
		}
	}
}



}
int main() try{
    mainmain();
}
catch(...){
}