#include <bits/stdc++.h>
using namespace std;
int main() {
  int start, finish;
  while (cin >> start, start) {
    int time[2][2];
    for (int i = 0; i < 2; i++) cin >> time[0][i];
    cin >> finish;
    for (int i = 0; i < 2; i++) cin >> time[1][i];
    int num = 0, distance[] = {6, 7, 5, 5, 20, 15},
        money[6][6] = {{300, 500, 600, 700, 1350, 1650},
                       {350, 450, 600, 1150, 1500},
                       {250, 400, 1000, 1350},
                       {250, 850, 1300},
                       {600, 1150},
                       {500}};
    for (int i = start - 1; i < finish; i++) num += distance[i];
    bool kawa = 0;
    for (int i = 0; i < 2 && !kawa && num < 41; i++)
      if (time[i][0] == 18 || time[i][0] == 17 && time[i][1] > 29 ||
          time[i][0] == 19 && time[i][1] < 31)
        kawa = 1;
    num = money[start - 1][finish - start - 1];
    if (kawa) {
      num /= 2;
      if (num % 50 != 0) num += 50 - num % 100;
    }
    cout << num << endl;
  }
}
