var w,s,t,w1,t1,s1,a,b,c:longint;
label 146,35;
procedure buxing;
label 10;
begin if (t-t1>=1)and(t1<t) then begin s1:=s1+17;t1:=t1+1;goto 10 end;
if (t-t1>=2)and(t1<t) then begin s1:=s1+34;t1:=t1+2;goto 10 end;
if (t-t1>=3)and(t1<t) then begin s1:=s1+51;t1:=t1+3;goto 10 end;
if (t-t1>=4)and(t1<t) then begin s1:=s1+68;t1:=t1+4;goto 10 end;
10:
end;
begin assign(input,escape.in);
assign(output,escape.out);
reset(input);rewrite(output);
readln(w,s,t);
w1:=w mod 10;t1:=w div 10;s1:=t1*60;
if t1>t then begin s1:=s1-(t1-t)*60;t1:=t;end;
146:
while (t>t1)and(s1<s) do
case w1 of
0,1:if (t-t1>=4)and(s-s1>68) then begin w1:=w1+12-10;t1:=t1+4;s1:=s1+60;goto 146;end
else goto 35;
2,3,4,5:if (t-t1>=3) then begin w1:=w1+8-10;t1:=t1+3;s1:=s1+60;goto 146;end;
6,7,8,9:if t-t1>=2 then begin w1:=w1+4-10;t1:=t1+2;s1:=s1+60;goto 146;end;
else begin 35:buxing;end;
end;
if (s1<s)or(t1>t) then begin writeln(No);write(s1);end;
if (s1>=s)and(t1<=t)then begin writeln(Yes);write(t1);end;
close(input);close(output);
end.
(*^__^*) 嘻嘻…….