#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	const int fare[7][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} };
	const int dist[7] = {0, 6, 13, 18, 23, 43, 58};
	
	int s;
	while(scanf("%d", &s), s){
		int h, m;
		scanf("%d%d", &h, &m);
		
		int t = h*60 + m;
		bool half = 17*60+30 <= t && t <= 19*60+30;
		
		int g;
		scanf("%d%d%d", &g, &h, &m);
		t = h*60 + m;
		half |= 17*60+30 <= t && t <= 19*60+30;
		
		s--; g--;
		half &= dist[max(s, g)] - dist[min(s, g)] <= 40;
		
		int cost = fare[min(s, g)][max(s, g)];
		if(half)
			cost = (cost + 99) / 100 * 50;
		printf("%d\n", cost);
	}
	
	return 0;
}