#include<iostream>

int toMinute(int h, int m){
	return h * 60 + m;
}

int roundUp(int i){
	if(i % 50){
		return i - (i % 50) + 50;
	}
	return i;
}

//17*60+30 = 1050
//19*60+30 = 1170

int main(){
	int MAX_N = 7;
	int d[MAX_N+1][MAX_N+1], p[MAX_N+1][MAX_N+1];
	d[1][2] = 6;
	d[1][3] = 13;
	d[1][4] = 18;
	d[1][5] = 23;
	d[1][6] = 43;
	d[1][7] = 58;
	d[2][3] = 7;
	d[2][4] = 12;
	d[2][5] = 17;
	d[2][6] = 37;
	d[2][7] = 52;
	d[3][4] = 5;
	d[3][5] = 10;
	d[3][6] = 30;
	d[3][7] = 45;
	d[4][5] = 5;
	d[4][6] = 25;
	d[4][7] = 40;
	d[5][6] = 20;
	d[5][7] = 35;
	d[6][7] = 15;

	p[1][2] = 300;
	p[1][3] = 500;
	p[1][4] = 600;
	p[1][5] = 700;
	p[1][6] = 1350;
	p[1][7] = 1650;
	p[2][3] = 350;
	p[2][4] = 450;
	p[2][5] = 600;
	p[2][6] = 1150;
	p[2][7] = 1500;
	p[3][4] = 250;
	p[3][5] = 400;
	p[3][6] = 1000;
	p[3][7] = 1350;
	p[4][5] = 250;
	p[4][6] = 850;
	p[4][7] = 1300;
	p[5][6] = 600;
	p[5][7] = 1150;
	p[6][7] = 500;

	int a, na, ma;
	while(std::cin >> a >> na >> ma, !std::cin.eof()){
		int b, nb, mb;
		std::cin >> b >> nb >> mb;

		int min_a = toMinute(na, ma),
			min_b = toMinute(nb, mb);

		int big = (a>b)?a:b,
			small = (a<b)?a:b;

		if((1050 <= min_a && min_a <= 1170 ||
				1050 <= min_b && min_b <= 1170) &&
			 d[small][big] <= 40){
			std::cout << roundUp(p[small][big] / 2) << std::endl;
		}else{
			std::cout << p[small][big] << std::endl;
		}
	}
}