#include <bits/stdc++.h>
using namespace std;
int cost[8][8] = {{},
                  {0, 0, 300, 500, 600, 700, 1350, 1650},
                  {0, 6, 0, 350, 450, 600, 1150, 1500},
                  {0, 13, 7, 0, 250, 450, 1000, 1350},
                  {0, 18, 12, 5, 0, 250, 850, 1300},
                  {0, 23, 17, 10, 5, 0, 600, 1150},
                  {0, 43, 37, 30, 25, 20, 0, 500},
                  {0, 58, 52, 45, 40, 35, 15, 0}};
int l, lh, lm, a, ah, am;
int main() {
  while (true) {
    cin >> l;
    if (!l) return 0;
    cin >> lh >> lm;
    lm += lh * 100;
    cin >> a;
    cin >> ah >> am;
    am += ah * 100;
    if (cost[max(l, a)][min(l, a)] > 40)
      cout << cost[min(l, a)][max(l, a)] << endl;
    else if ((lm >= 1730 && lm <= 1930) || (am >= 1730 && am <= 1930)) {
      bool flag = false;
      if ((cost[min(l, a)][max(l, a)] / 2) % 50) flag = true;
      int ans = cost[min(l, a)][max(l, a)] / 2 -
                ((cost[min(l, a)][max(l, a)] / 2) % 50);
      if (flag) ans += 50;
      cout << ans << endl;
    } else
      cout << cost[min(l, a)][max(l, a)] << endl;
  }
}
