#include <bits/stdc++.h>
const double PI = acos(-1);
const double ESP = 1e-10;
using namespace std;
int h[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}};
int main() {
  int n, m;
  while (cin >> n, n) {
    int a, b;
    int m1, m2;
    cin >> a >> b;
    m1 = a * 100 + b;
    cin >> m;
    cin >> a >> b;
    m2 = a * 100 + b;
    if (n > m) swap(n, m);
    bool han = true;
    if ((1730 < m1 && m2 < 1930) || (m1 < 1730 && 1930 < m2) ||
        (1930 < m1 && m2 < 1730))
      han = false;
    if ((m == 7 && n < 4) || (m == 6 && n == 1)) han = false;
    int ans = h[n - 1][m - 1];
    if (han) ans /= 2;
    ans = (ans + 49) - (ans + 49) % 50;
    cout << ans << endl;
  }
}
