#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<vector<pair<int, int> > > data(
      8, vector<pair<int, int> >(8, pair<int, int>(0, 0)));
  data[1][2] = data[2][1] = pair<int, int>(6, 300);
  data[1][3] = data[3][1] = pair<int, int>(13, 500);
  data[1][4] = data[4][1] = pair<int, int>(18, 600);
  data[1][5] = data[5][1] = pair<int, int>(23, 700);
  data[1][6] = data[6][1] = pair<int, int>(43, 1350);
  data[1][7] = data[7][1] = pair<int, int>(58, 1650);
  data[2][3] = data[3][2] = pair<int, int>(7, 350);
  data[2][4] = data[4][2] = pair<int, int>(12, 450);
  data[2][5] = data[5][2] = pair<int, int>(17, 600);
  data[2][6] = data[6][2] = pair<int, int>(37, 1150);
  data[2][7] = data[7][2] = pair<int, int>(52, 1500);
  data[3][4] = data[4][3] = pair<int, int>(5, 250);
  data[3][5] = data[5][3] = pair<int, int>(10, 400);
  data[3][6] = data[6][3] = pair<int, int>(30, 1000);
  data[3][7] = data[7][3] = pair<int, int>(45, 1350);
  data[4][5] = data[5][4] = pair<int, int>(5, 250);
  data[4][6] = data[6][4] = pair<int, int>(25, 850);
  data[4][7] = data[7][4] = pair<int, int>(40, 1300);
  data[5][6] = data[6][5] = pair<int, int>(20, 600);
  data[5][7] = data[7][5] = pair<int, int>(35, 1150);
  data[6][7] = data[7][6] = pair<int, int>(15, 500);
  int s, g;
  while (cin >> s) {
    if (s == 0) {
      break;
    }
    int sh, sm;
    cin >> sh >> sm;
    int gh, gm;
    cin >> g;
    cin >> gh >> gm;
    int mm = data[s][g].second;
    bool hantei = true;
    if (sh == 18) {
      if (mm % 100 == 50) {
        mm += 50;
      }
      mm /= 2;
      hantei = false;
    } else if (sh == 17) {
      if (sm >= 30) {
        if (mm % 100 == 50) {
          mm += 50;
        }
        mm /= 2;
        hantei = false;
      }
    } else if (sh == 19) {
      if (sm <= 30) {
        if (mm % 100 == 50) {
          mm += 50;
        }
        mm /= 2;
        hantei = false;
      }
    }
    if (hantei) {
      if (gh == 18) {
        if (mm % 100 == 50) {
          mm += 50;
        }
        mm /= 2;
      } else if (gh == 17) {
        if (gm >= 30) {
          if (mm % 100 == 50) {
            mm += 50;
          }
          mm /= 2;
        }
      } else if (gh == 19) {
        if (gm <= 30) {
          if (mm % 100 == 50) {
            mm += 50;
          }
          mm /= 2;
        }
      }
    }
    cout << mm << endl;
  }
  return 0;
}
