#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
typedef pair<int,int> P;
bool hangaku(int h,int m){
	if(h == 18){
		return true;
	}else if(h == 17){
		return m >= 30;
	}else if(h == 19){
		return m <= 30;
	}else{
		return false;
	}
}

int main(){
	int s,g;
	int kyori[8] = {0,0,6,13,18,23,43,58};
	map<P,int> price;
	price[P(1,2)] = 300;
	price[P(1,3)] = 500;
	price[P(1,4)] = 600;
	price[P(1,5)] = 700;
	price[P(1,6)] = 1350;
	price[P(1,7)] = 1650;
	price[P(2,3)] = 350;
	price[P(2,4)] = 450;
	price[P(2,5)] = 600;
	price[P(2,6)] = 1150;
	price[P(2,7)] = 1500;
	price[P(3,4)] = 250;
	price[P(3,5)] = 400;
	price[P(3,6)] = 1000;
	price[P(3,7)] = 1350;
	price[P(4,5)] = 250;
	price[P(4,6)] = 850;
	price[P(4,7)] = 1300;
	price[P(5,6)] = 600;
	price[P(5,7)] = 1150;
	price[P(6,7)] = 500;
	while(cin>>s,s){
		int h1,m1,h2,m2;
		cin>>h1>>m1>>g>>h2>>m2;
		if(s > g) swap(s,g);
		int ans = price[P(s,g)];
		if(hangaku(h1,m1) || hangaku(h2,m2)){
			if(kyori[g]-kyori[s] <= 40){
				if(ans % 100){
					ans = (ans+50)/2;
				}else{
					ans /= 2;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}