#include <bits/stdc++.h>
using namespace std;

int main() {
  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}};
      
  int a,b;
  while(cin >> a && a) {
    int x[2],y[2];
    cin >> x[0] >> x[1] >> b >> y[0] >> y[1];
    a--,b--;
    if(a>b) swap(a,b);
    int m1=x[0]*60+x[1],m2=y[0]*60+y[1];
    int c=d[a][b];
    if((m1>=17*60+30&&m1<=19*60+30||m2>=17*60+30&&m2<=19*60+30)&&d[b][a]<=40) {
      c/=2;
      if(c%50) c+=50-c%50;
    }
    cout << c << endl;
  }
  return 0;
}
