#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
template <class T>
T RoundOff(T a) {
  return int(a + .5 - (a < 0));
}
template <class T, class C>
void chmax(T& a, C b) {
  if (a < b) a = b;
}
template <class T, class C>
void chmin(T& a, C b) {
  if (b < a) a = b;
}
template <class T, class C>
pair<T, C> mp(T a, C b) {
  return make_pair(a, b);
}
int table[8][8] = {
    {-1, 300, 500, 600, 700, 1350, 1650}, {6, -1, 350, 450, 600, 1150, 1500},
    {13, 7, -1, 250, 400, 1000, 1350},    {18, 12, 5, -1, 250, 850, 1300},
    {23, 17, 10, 5, -1, 600, 1150},       {43, 37, 30, 25, 20, -1, 500},
    {58, 52, 45, 40, 35, 15, -1}};
bool yes(int h, int t) {
  if (h == 17) return 30 <= t;
  if (h == 18) return true;
  if (h == 19) return t <= 30;
  return false;
}
int main() {
  int s, t, sh, st, th, tt;
  while (cin >> s && s) {
    cin >> sh >> st >> t >> th >> tt;
    int charge = table[s - 1][t - 1];
    if (table[t - 1][s - 1] <= 40 && (yes(sh, st) || yes(th, tt))) {
      charge /= 2;
      cout << charge + (charge % 50 != 0 ? 25 : 0) << endl;
    } else {
      cout << charge << endl;
    }
  }
}
