#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int vl[6][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 dis[7]={0,6,13,18,23,43,58};
    int t,m,pos1,pos2;
    while(scanf("%d",&pos1),pos1){
        bool flag=false;
        scanf("%d%d",&t,&m);
        t=t*100+m;
        if(t>=1730&&t<=1930)flag=true;
        scanf("%d%d%d",&pos2,&t,&m);
        t=t*100+m;
        if(t>=1730&&t<=1930)flag=true;

        if(pos1>pos2)swap(pos1,pos2);
        pos1--;pos2--;
        int ans=vl[pos1][pos2];
        if(dis[pos2]-dis[pos1]>40)flag=false;

        if(flag){
            if(ans%100){
                ans=(ans-50)/2+50;
            }
            else ans/=2;
        }
        printf("%d\n",ans);
    }
    return 0;
}