#include <bits/stdc++.h>
using namespace std;
int main() {
  int start, goal, start_h, start_m, goal_h, goal_m, ans;
  int dist[7] = {0, 6, 13, 18, 23, 43, 58}, toll[8][8];
  toll[1][2] = 300, toll[1][3] = 500, toll[1][4] = 600, toll[1][5] = 700,
  toll[1][6] = 1350, toll[1][7] = 1650;
  toll[2][3] = 350, toll[2][4] = 450, toll[2][5] = 600, toll[2][6] = 1150,
  toll[2][7] = 1500;
  toll[3][4] = 250, toll[3][5] = 400, toll[3][6] = 1000, toll[3][7] = 1350;
  toll[4][5] = 250, toll[4][6] = 850, toll[4][7] = 1300;
  toll[5][6] = 600, toll[5][7] = 1150;
  toll[6][7] = 500;
  while (true) {
    scanf("%d", &start);
    if (start == 0) break;
    scanf("%d %d", &start_h, &start_m);
    scanf("%d", &goal);
    scanf("%d %d", &goal_h, &goal_m);
    if (start > goal) swap(start, goal);
    ans = toll[start][goal];
    if (dist[goal] - dist[start] <= 40) {
      if ((start_h * 60 + start_m) >= 17 * 60 + 30 ||
          (goal_h * 60 + goal_m) <= 19 * 60 + 30) {
        ans /= 2;
        if (ans % 50 > 0) {
          ans -= (ans % 50);
          ans += 50;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
