#include <bits/stdc++.h>
using namespace std;
int main() {
  int table[][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}};
  int a = 17 * 60 + 30;
  int b = 19 * 60 + 30;
  for (;;) {
    int ic[2];
    bool half = false;
    for (int i = 0; i < 2; ++i) {
      int h, m;
      cin >> ic[i] >> h >> m;
      if (ic[i] == 0) return 0;
      --ic[i];
      m += h * 60;
      if (a <= m && m <= b) half = true;
    }
    if (table[ic[1]][ic[0]] <= 40) half &= true;
    if (half) {
      int a = table[ic[0]][ic[1]];
      if (a % 100 != 0) a += 50;
      cout << (a / 2) << endl;
    } else {
      cout << table[ic[0]][ic[1]] << endl;
    }
  }
}
