#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int h[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 main(){
  int n,m;
  while(cin>>n,n){
    int a,b;
    int m1,m2;
    cin>>a>>b;
    m1=a*100+b;
    cin>>m;
    cin>>a>>b;
    m2=a*100+b;
    if(n>m)swap(n,m);
    bool han=true;
    if(m2<1730||1950<m1||(m1<1730&&1930<m2))han=false;
    if((m==7&&n<4)||(m==6&&n==1))han=false;
    int ans=h[n-1][m-1];
    if(han)ans/=2;
    ans=(ans+49)-(ans+49)%50;
    cout<<ans<<endl;
  }
}