#include <bits/stdc++.h>
int time(int sh, int sm, int eh, int em) {
  if (17 * 60 + 30 <= ((sh)*60 + (sm)) && ((sh)*60 + (sm)) <= 19 * 60 + 30 ||
      17 * 60 + 30 <= ((eh)*60 + (em)) && ((eh)*60 + (em)) <= 19 * 60 + 30)
    return 1;
  else
    return 0;
}
int dist(int s, int e) {
  int a[7] = {0, 6, 7, 5, 5, 20, 15}, i, d = 0;
  for (i = s; i <= e; ++i) d += a[i];
  if (d <= 40)
    return 1;
  else
    return 0;
}
int main() {
  int sn, sh, sm, en, eh, em, prime;
  int ex[6][7] = {
      {0, 300, 500, 600, 700, 1350, 1650}, {0, 0, 350, 450, 600, 1150, 1500},
      {0, 0, 0, 250, 400, 1000, 1350},     {0, 0, 0, 0, 250, 850, 1300},
      {0, 0, 0, 0, 0, 600, 1150},          {0, 0, 0, 0, 0, 0, 500}};
  while (scanf("%d", &sn) && sn) {
    scanf("%d%d%d%d%d", &sh, &sm, &en, &eh, &em);
    prime =
        ex[((sn) > (en) ? (en) : (sn)) - 1][((sn) > (en) ? (sn) : (en)) - 1];
    if (time(sh, sm, eh, em) && dist(sn, en)) prime /= 2;
    if (prime % 100 > 50)
      prime += 100 - prime % 100;
    else if (prime % 100 > 0 && prime % 100 < 50)
      prime += 50 - prime % 100;
    printf("%d\n", prime);
  }
  return 0;
}
