#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


bool check( int hh, int mm ) {
    if ( hh == 17 ) {
        return mm >= 30;
    } else if ( hh == 19 ) {
        return mm <= 30;
    }
    return hh == 18;
}

const int T[7][7] = {
    { 0, 300, 500, 600, 700, 1350, 1650 },
    { 6, 0, 350, 450, 600, 1150, 1500 },
    { 13, 7, 0, 250, 400, 1000, 1350 },
    { 18, 12, 5, 0, 250, 850, 1300 },
    { 23, 17, 10, 5, 0, 600, 1150 },
    { 43, 37, 30, 25, 20, 0, 500 },
    { 58, 52, 45, 40, 35, 15, 0 }
};

int main() {
    int a, b, h1, m1, h2, m2;
    while ( cin >> a && a ) {
        cin >> h1 >> m1 >> b >> h2 >> m2;
        bool flag = check( h1, m1 ) || check( h2, m2 );
        a --;
        b --;
        int price = T[min(a,b)][max(a,b)];
        int dist = T[max(a,b)][min(a,b)];
        if ( flag && dist <= 40 ) price /= 2;
        if ( price % 50 > 0 ) price += 50;
        price -= price % 50;
        cout << price << endl;
    }
    return 0;
}