#include <bits/stdc++.h>
int main() {
  const int d[8][8] = {{0, 0, 0, 0, 0, 0, 0, 0},
                       {0, 0, 300, 500, 600, 700, 1350, 1650},
                       {0, 0, 0, 350, 450, 600, 1150, 1500},
                       {0, 0, 0, 0, 250, 400, 1000, 1350},
                       {0, 0, 0, 0, 0, 250, 850, 1300},
                       {0, 0, 0, 0, 0, 0, 600, 1150},
                       {0, 1, 0, 0, 0, 0, 0, 500},
                       {0, 1, 1, 1, 1, 0, 0, 0}};
  int n, m, ih, it, oh, ot;
  int p = 0;
  while (1) {
    scanf("%d", &n);
    if (!n) break;
    scanf("%d %d %d %d %d", &ih, &it, &m, &oh, &ot);
    if (n > m) {
      p = n;
      n = m;
      m = p;
    }
    p = d[n][m];
    it += 60 * ih;
    ot += 60 * oh;
    if (d[m][n] == 0 && ((17 * 60 + 30 <= it && it <= 19 * 60 + 30) ||
                         17 * 60 + 30 <= ot && ot <= 19 * 60 + 30))
      p /= 2;
    if (p % 50) p += 25;
    printf("%d\n", p);
  }
  return 0;
}
