#include<iostream>
#include<cstdio>
#include<algorithm>
#define NN 1000
using namespace std;

int main(){
  int aa[8][8]={{0,1,2,3,4,5,6,7},
		{1,0,300,500,600,700,1350,1650},
		{2,6,0,350,450,600,1150,1500},
		{3,13,7,0,250,400,1000,1350},
		{4,18,12,5,0,250,850,1300},
		{5,23,17,10,5,0,600,1150},
		{6,43,37,30,25,20,0,500},
		{7,58,52,45,40,35,15,0}};
  int i,j,n,time00,time01,time10,time11,n2,disc,mo;
  int disc2;
  while(1){
    disc2=0;
    disc=0; //flag
    cin >> n;
    if(n == 0)break;
    cin >> time00 >> time01;
    cin >> n2;
    cin >> time10 >> time11;

    //  cout << aa[n2][n] << endl;
    // cout << time[1][0] <<" " <<time[1][1] << endl; 
    //if(time10>=17 && (time10 <=19)){
      if(time10 == 19 && time11 <= 30){disc2=1;}
      else if(time10 == 18)disc2=1;
      else if(time10 == 17 && time11>=30)disc2=1;
      // cout << "tes" << endl;
      if(aa[n2][n]<=40 && disc2==1)disc=1; //ツ湘ーツ個渉づーツ鳴楪つスツつオツづつ「ツづェツづ仕iscountツフツδ可グON
      // cout << "tes" << endl;
      //}

    mo=aa[n][n2];
    if(disc == 1){
      mo=mo/2;
      disc=0;
      if(mo%50 !=0)mo=mo+25;
    }
    cout << mo << endl;


    }


}