#include <bits/stdc++.h>
using namespace std;
int main() {
  int aa[7][7] = {{0, 300, 500, 600, 700, 1350, 1650},
                  {300, 0, 350, 450, 600, 1150, 1500},
                  {500, 350, 0, 250, 400, 1000, 1350},
                  {600, 450, 250, 0, 250, 850, 1300},
                  {700, 600, 400, 250, 0, 600, 1150},
                  {1350, 1150, 1000, 850, 600, 0, 500},
                  {1650, 1500, 1350, 1300, 1150, 500, 0}};
  int bb[7][7] = {{0, 6, 13, 18, 23, 43, 58}, {6, 0, 7, 12, 17, 37, 52},
                  {13, 7, 0, 5, 10, 30, 45},  {18, 12, 5, 0, 5, 25, 40},
                  {23, 17, 10, 5, 0, 20, 35}, {43, 37, 30, 25, 20, 0, 15},
                  {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;
    cin >> n;
    if (n == 0) break;
    cin >> time00 >> time01;
    cin >> n2;
    cin >> time10 >> time11;
    if (time10 == 19 && time11 <= 30) {
      disc2 = 1;
    } else if (time10 == 18)
      disc2 = 1;
    else if (time10 == 17 && time11 >= 30)
      disc2 = 1;
    if (bb[n2 - 1][n - 1] <= 40 && disc2 == 1) disc = 1;
    mo = aa[n - 1][n2 - 1];
    if (disc == 1) {
      mo = mo / 2;
      disc = 0;
      disc2 = 0;
      if (mo % 50 != 0) mo = (mo - (mo % 50)) + 50;
    }
    cout << mo << endl;
  }
}
