#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<climits>
using namespace std;

int cost[7][7] = {
    {   0,  300,  500,  600,  700, 1350, 1650},
    { 300,    0,  350,  450,  600, 1150, 1500},
    { 500,  350,    0,  250,  400, 1000, 1350},
    { 600,  450,  250,    0,  250,  850, 1300},
    { 700,  600,  400,  250,    0,  600, 1150},
    {1350, 1150, 1000,  850,  600,    0,  500},
    {1650, 1500, 1350, 1300, 1150,  500,    0}
};

int dist[7][7] = {
    { 0,  6, 13, 18, 23, 43, 58},
    { 6,  0,  7, 12, 17, 37, 52},
    {13,  7,  0,  5, 10, 30, 45},
    {18, 12,  5,  0,  5, 25, 40},
    {23, 17, 10,  5,  0, 20, 35},
    {43, 37, 30, 25, 20,  0, 15},
    {58, 52, 45, 40, 35, 15,  0}
};

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

bool IsInTime(int h, int m){
	return ToMinute(17, 30) <= ToMinute(h, m) && ToMinute(h, m) <= ToMinute(19, 30);
}

int ToHalf(int n){
	n /= 2;
	if(n%50) n += 50 - n%50;
	return n;
}

int main(){
	int ic1, ic2, h1, h2, m1, m2;
	while(cin >> ic1, ic1){
		cin >> h1 >> m1 >> ic2 >> h2 >> m2;
		ic1--; ic2--;
		bool is_half = ( IsInTime(h1, m1) || IsInTime(h2, m2) ) && dist[ic1][ic2] <= 40;
		if(is_half) printf("%d\n", ToHalf(cost[ic1][ic2]) );
		else printf("%d\n", cost[ic1][ic2]);
	}
	return 0;
}