#include <bits/stdc++.h>
using namespace std;
int main() {
  int s, g, h, m, t, price;
  bool flag;
  int table[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, 0}};
  while (cin >> s && s) {
    flag = false;
    cin >> h >> m;
    t = h * 60 + m;
    if (t >= 17 * 60 + 30 && t <= 19 * 60 + 30) {
      flag = true;
    }
    cin >> g;
    cin >> h >> m;
    t = h * 60 + m;
    if (t >= 17 * 60 + 30 && t <= 19 * 60 + 30) {
      flag = true;
    }
    s--;
    g--;
    if (g > s) swap(s, g);
    price = table[g][s];
    if (flag) {
      price /= 2;
      if (price % 50) {
        price = price - price % 50 + 50;
      }
    }
    cout << price << endl;
  }
}
