#include <bits/stdc++.h>
using namespace std;
int main() {
  int sic, sh, sm, eic, eh, em, st, et, S, E, flag, ans;
  int d[8][8];
  d[1][2] = d[2][1] = 300;
  d[1][3] = d[3][1] = 500;
  d[1][4] = d[4][1] = 600;
  d[1][5] = d[5][1] = 700;
  d[1][6] = d[6][1] = 1350;
  d[1][7] = d[7][1] = 1650;
  d[2][3] = d[3][2] = 350;
  d[2][4] = d[4][2] = 450;
  d[2][5] = d[5][2] = 600;
  d[2][6] = d[6][2] = 1150;
  d[2][7] = d[7][2] = 1500;
  d[3][4] = d[4][3] = 250;
  d[3][5] = d[5][3] = 400;
  d[3][6] = d[6][3] = 1000;
  d[3][7] = d[7][3] = 1350;
  d[4][5] = d[5][4] = 250;
  d[4][6] = d[6][4] = 850;
  d[4][7] = d[7][4] = 1300;
  d[5][6] = d[6][5] = 600;
  d[5][7] = d[7][5] = 1150;
  d[6][7] = d[7][6] = 500;
  S = 17 * 3600 + 30 * 360;
  E = 19 * 3600 + 30 * 360;
  while (1) {
    cin >> sic >> sh >> sm >> eic >> eh >> em;
    if (!sic) break;
    st = sh * 3600 + sm * 360;
    et = eh * 3600 + em * 360;
    flag = 0;
    if ((S <= st && st <= E) || (S <= et && et <= E)) flag = 1;
    ans = d[sic][eic];
    if (flag) {
      int cal;
      ans /= 2;
      cal = ans % 100;
      if (cal % 50) {
        ans /= 100;
        ans *= 100;
        if (cal < 50)
          ans += 50;
        else
          ans += 100;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
