#include <bits/stdc++.h>
using namespace std;
int main() {
  int start, startt[2], end, endt[2];
  while (1) {
    cin >> start;
    if (start == 0) break;
    cin >> startt[0] >> startt[1];
    cin >> end >> endt[0] >> endt[1];
    int ans;
    if (start == 1) {
      if (end == 2)
        ans = 300;
      else if (end == 3)
        ans = 500;
      else if (end == 4)
        ans = 600;
      else if (end == 5)
        ans = 700;
      else if (end == 6)
        ans = 1350;
      else if (end == 7)
        ans = 1650;
    } else if (start == 2) {
      if (end == 3)
        ans = 350;
      else if (end == 4)
        ans = 450;
      else if (end == 5)
        ans = 600;
      else if (end == 6)
        ans = 1150;
      else if (end == 7)
        ans == 1500;
    } else if (start == 3) {
      if (end == 4)
        ans = 250;
      else if (end == 5)
        ans = 400;
      else if (end == 6)
        ans = 1000;
      else if (end == 7)
        ans = 1350;
    } else if (start == 4) {
      if (end == 5)
        ans = 250;
      else if (end == 6)
        ans = 850;
      else if (end == 7)
        ans = 1300;
    } else if (start == 5) {
      if (end == 6)
        ans = 600;
      else if (end == 7)
        ans = 1150;
    } else if (start == 6) {
      if (end == 7) ans = 500;
    }
    if (((startt[0] * 60 + startt[1]) >= (17 * 60 + 30) &&
         (startt[0] * 60 + startt[1]) <= (19 * 60 + 30)) ||
        ((endt[0] * 60 + endt[1]) >= (17 * 60 + 30) &&
         (endt[0] * 60 + endt[1]) <= (19 * 60 + 30))) {
      if ((start == 1 && end == 6) || (end == 7 && (start > 0 && start < 5))) {
        cout << ans << endl;
      } else {
        int reans = ans / 2;
        int alt = reans % 50;
        if (alt > 0) {
          reans += (50 - alt);
        }
        cout << reans << endl;
      }
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}
