
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


int table[8][8] =
{
	{-1, 300, 500, 600, 700, 1350, 1650},
	{6, -1, 350, 450, 600, 1150, 1500},
	{13, 7, -1, 250, 400, 1000, 1350},
	{18, 12, 5, -1, 250, 850, 1300},
	{23, 17, 10, 5, -1, 600, 1150},
	{43, 37, 30, 25, 20, -1, 500},
	{58, 52, 45, 40, 35, 15, -1}
};

bool yes(int h, int t)
{
	if(h == 17) return 30 <= t;
	if(h == 18) return true;
	if(h == 19) return t <= 30;
	return false;
}

int main()
{
	int s, t, sh, st, th, tt;
	while(cin >> s && s)
	{
		cin >> sh >> st >> t >> th >> tt;
		int charge = table[s-1][t-1];
		
		if(table[t-1][s-1] <= 40 && (yes(sh, st) || yes(th, tt)))
		{
			charge /= 2;
			cout << charge + (charge % 50 != 0 ? 25 : 0) << endl;
		}
		else
		{
			cout << charge << endl;
		}
	}
}