char*s,*t;q[],n;main(){for(;~scanf("%s%s",s=q,t=q+5);n=!puts(*t|n?"NO":"YES"))for(;*s;*t%16-n%10||(n=*t&&!t++))n+=*s++%16;}