import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

void main(){
    int[] l = [0, 0, 6, 13, 18, 23, 43, 58];
    auto c = [
        [1,2]: 300, [1,3]: 500, [1,4]: 600, [1,5]: 700, [1,6]: 1350, [1,7]: 1650,
        [2,3]: 350, [2,4]: 450, [2,5]: 600, [2,6]: 1150, [2,7]: 1500,
        [3,4]: 250, [3,5]: 400, [3,6]: 1000, [3,7]: 1350,
        [4,5]: 250, [4,6]: 850, [4,7]: 1300,
        [5,6]: 600, [5,7]: 1150,
        [6,7]: 500
    ];
    while(true) {
        auto d = readInt();
        if(d == 0) {
            return;
        }
        int hd, md;
        readlnTo(hd, md);
        md += hd*60;
        auto a = readInt();
        int ha, ma;
        readlnTo(ha, ma);
        ma += ha*60;

        if(a < d) {
            swap(a, d);
        }
        if((17*60+30 <= md && md <= 19*60+30) || (17*60+30 <= ma && ma <= 19*60+30)) {
            if(l[a]-l[d] <= 40) {
                auto ans = c[[d,a]]/2;
                if(ans%50 != 0) {
                    ans = ans / 50 * 50 + 50;
                }
                writeln(ans);
            } else {
                writeln(c[[d,a]]);
            }
        } else {
            writeln(c[[d,a]]);
        }
    }
}