#include<stdio.h>
#include<math.h>
int main(){
int a,b,c,d,e,f,t1,t2;
scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
t1=b*60+c;
t2=e*60+f;
if(a==d){
printf("Y e s\n");
}
else if(d==(a+1)){
if((t2-t1)<=0)
printf("Y e s\n");
else printf("N o\n");
}
else if(a==7&&d==1){
if((t2-t1)<=0)
printf("Y e s\n");
else printf("N o\n");
}
else printf("N o\n");
return 0;
}