#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a) {
  for (auto i : a) cout << i << endl;
}
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
int main() {
  int n[2];
  while (cin >> n[0] && n[0]) {
    int t[2];
    int h, m;
    cin >> h >> m;
    t[0] = h * 60 + m;
    cin >> n[1];
    cin >> h >> m;
    t[1] = h * 60 + m;
    int x[][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, 0, 0, 0, 0, 0, 0, 500}};
    int ans = x[min(n[0], n[1])][max(n[0], n[1])];
    int p = 0;
    if (t[0] <= 17 * 60 + 30 && 17 * 60 + 30 <= t[1]) p++;
    if (t[0] <= 19 * 60 + 30 && 19 * 60 + 30 <= t[1]) p++;
    if (p == 1) {
      ans /= 2;
      while (ans % 50) ans++;
    }
    cout << ans << endl;
  }
}
