#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
	
	int c[8][8];
	int d[8][8];
	
	for(int i = 0; i < 8; i++){
		for(int j = 0; j < 8; j++){
			c[i][j] = 0;
			d[i][j] = 0;
		}
	}
	
	c[1][2] = 300;
	d[1][2] = 6;
	c[1][3] = 500;
	c[2][3] = 350;
	d[1][3] = 13;
	d[2][3] = 7;
	c[1][4] = 600;
	c[2][4] = 450;
	c[3][4] = 250;
	d[1][4] = 18;
	d[2][4] = 12;
	d[3][4] = 5;
	c[1][5] = 700;
	c[2][5] = 600;
	c[3][5] = 400;
	c[4][5] = 250;
	d[1][5] = 23;
	d[2][5] = 17;
	d[3][5] = 10;
	d[4][5] = 5;
	c[1][6] = 1350;
	c[2][6] = 1150;
	c[3][6] = 1000;
	c[4][6] = 850;
	c[5][6] = 600;
	d[1][6] = 43;
	d[2][6] = 37;
	d[3][6] = 30;
	d[4][6] = 25;
	d[5][6] = 20;
	c[1][7] = 1650;
	c[2][7] = 1500;
	c[3][7] = 1350;
	c[4][7] = 1300;
	c[5][7] = 1150;
	c[6][7] = 500;
	d[1][7] = 58;
	d[2][7] = 52;
	d[3][7] = 45;
	d[4][7] = 40;
	d[5][7] = 35;
	d[6][7] = 15;
	
	for(int i = 0; i < 8; i++){
		for(int j = 0; j < 8; j++){
			c[i][j] /= 50;;
		}
	}
	
	while(true){
		
		int d1, d2;
		int h, m, time;
		
		bool is_half = false;
		bool is_half2 = false;
		
		cin >> d1;
		
		if(d1 == 0){
			break;
		}
		
		cin >> h >> m;
		
		time = h * 60 + m;
		
		if(time >= 17 * 60 + 30 && time <= 19 * 60 + 30){
			is_half = true;
		}
		
		cin >> d2;
		
		cin >> h >> m;
		
		time = h * 60 + m;
		
		if(time >= 17 * 60 + 30 && time <= 19 * 60 + 30){
			is_half = true;
		}
		
		if(d[d1][d2] <= 40){
			is_half2 = true;
		}
		
		int ans = c[d1][d2];
		
		if(is_half && is_half2){
			ans = (ans + 1) / 2;
		}
		
		cout << ans * 50 << endl;
		
	}
	return 0;
}