#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int table[][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 a = 17 * 60 + 30;
    int b = 19 * 60 + 30;

    for(;;){
        int ic[2];
        bool half = false;
        for(int i=0; i<2; ++i){
            int h, m;
            cin >> ic[i] >> h >> m;
            if(ic[i] == 0)
                return 0;
            -- ic[i];

            m += h * 60;
            if(a <= m && m <= b)
                half = true;
        }
        if(ic[1] < ic[0])
            swap(ic[0], ic[1]);

        if(table[ic[1]][ic[0]] > 40)
            half = false;

        int ret = table[ic[0]][ic[1]];
        if(half){
            if(ret % 100 != 0)
                ret += 50;
            ret /= 2;
        }
        cout << ret << endl;
    }
}