#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int c[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}};
int d[6] = {6,7,5,5,20,15};
int main(){
	int s, t, h1, m1, h2, m2;
	while(cin >> s, s) {
		cin >> h1 >> m1 >> t >> h2 >> m2;
		s--, t--;
		if(s>t) swap(s,t);
		int dist = 0;
		rep(i,7) {
			if(s<=i&&i<t) dist += d[i];
		}
		if(h1*60+m1>=17*60+30 && 19*60+30>=h1*60+m1 ||
		   h2*60+m2>=17*60+30 && 19*60+30>=h2*60+m2) {
			if(dist <= 40) cout << ceil(c[s][t] / 100.0) * 50 << endl;
			else cout << c[s][t] << endl;
		} else cout << c[s][t] << endl;
	}
    return 0;
}