#include<stdio.h>
int main(){
int tim[4],i,min,count=0,total=0;
for(i=0;i<4;i++)scanf("%d",&tim[i]);
min=(tim[2]*60+tim[3])-(tim[0]*60+tim[1]);
while(min>=30){
min-=30;
++count;
if(count<=4)total+=30;
else if(count<=8&&count>4)total+=40;
else total+=60;
}
printf("%d\n",total);
return 0;
}