#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int d[7][7]={
  {0,300,500,600,700,1350,1650},
  {6,0,350,450,600,1150,1500},
  {13,7,0,250,400,1000,1350},
  {18,12,5,0,250,850,1300},
  {23,17,10,5,0,600,1150},
  {43,37,30,25,20,0,500},
  {58,52,45,40,35,15,0}
};
int main(){
  int a,b,h1,h2,m1,m2;
  while(cin>>a&&a){
    cin>>h1>>m1>>b>>h2>>m2;
    m1+=h1*100,m2+=h2*100;
    a--,b--;
    if(a>b)swap(a,b);
    int tmp=d[a][b];
    if(d[b][a]<=40&&((1730<=m1&&m1<=1930)||(1730<=m2&&m2<=1930)))tmp/=2;
    if(tmp%50>0)tmp+=50-tmp%50;
    cout<<tmp<<endl;
  }
  return 0;
}