#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);
int dist[7][7] = {{},
                  {6},
                  {13, 7},
                  {18, 12, 5},
                  {23, 17, 10, 5},
                  {43, 37, 30, 25, 20},
                  {58, 52, 45, 40, 35, 15}};
int cost[7][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 a, b;
  int s, t;
  int h, m;
  while (cin >> a && a) {
    cin >> h >> m;
    s = h * 60 + m;
    cin >> b >> h >> m;
    t = h * 60 + m;
    a--;
    b--;
    if (a > b) swap(a, b);
    bool f = true;
    if (dist[b][a] > 40) f = false;
    if (f && ((s >= 17 * 60 + 30 && s <= 19 * 60 + 30) ||
              (t >= 17 * 60 + 30 && t <= 19 * 60 + 30))) {
      cout << (cost[a][b] / 100) / 2 * 100 + (cost[a][b] % 100 == 50 ? 50 : 0)
           << endl;
    } else {
      cout << cost[a][b] << endl;
    }
  }
}
