#include <map>
#include <cstdio>
main(){std::map<int,int>z={{12,6},{13,10},{14,12},{15,14},{16,27},{17,33},{23,7},{24,9},{25,12},{26,23},{27,30},{34,5},{35,8},{36,20},{37,27},{45,5},{46,17},{47,26},{56,12},{57,23},{67,10}};for(int a,b,h,m,H,M;scanf("%d%d%d%d%d%d",&a,&h,&m,&b,&H,&M)>5;printf("%d\n",(h+H)*50))if(m+=h*60,M+=H*60,h=z[a*10+b],H=0,h<27&&((1050<=m&&m<=1170)||(1050<=M&&M<=1170)))H=(h&1),h/=2;}