#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
//#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll 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))){
            int ans = cost[a][b];

            cout<<(cost[a][b]/100)/2*100+(cost[a][b]%100==50?50:0)+((cost[a][b]/100)%2==1?50:0)<<endl;
        }
        else{
            cout<<cost[a][b]<<endl;
        }
        //cout<<a<<" "<<b<<endl;
    }
}