#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int s,sh,sm,g,gh,gm,ng[][2]={{0,5},{0,6},{1,6},{2,6}},t[][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 main(){
	while(cin>>s&&s){
		cin>>sh>>sm>>g>>gh>>gm;
		s--;g--;
		if(s>g)swap(s,g);
		int st=sh*60+sm,gt=gh*60+gm;
		int ok=1;
		rep(i,4)if(s==ng[i][0]&&g==ng[i][1])ok=0;
		if(ok&&(1050<=st&&st<=1170||1050<=gt&&gt<=1170))cout<<(t[s][g]/50+1)/2*50<<endl;
		else cout<<t[s][g]<<endl;
	}
}