A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.You're given a number. Determine if it is a magic number or not.

The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.

Print "YES" if n is a magic number or print "NO" if it's not.

program canhtoan;
uses sysutils;
var s:string;
procedure main();
var s1,s2,s3:string;
    kt:boolean;
begin
read(s);
s1:='1';s2:='14';s3:='144';
kt:=true;
while kt=true do
  begin
    kt:=false;
    if pos(s3,s)=1 then
       begin
         kt:=true;
         delete(s,1,length(s3));
       end
    else
    if pos(s2,s)=1 then
       begin
         kt:=true;
         delete(s,1,length(s2));
       end
    else
    if pos(s1,s)=1 then
       begin
         kt:=true;
         delete(s,1,length(s1));
       end;
    if s='' then break;
  end;
if kt=true then write('YES') else write('NO');
end;
BEGIN
  main();
END.

Var s:string;
begin
readln(s);
while pos('144',s)<>0 do begin
insert('*',s,pos('144',s));
delete(s,pos('144',s),3);
end;

while pos('14',s)<>0 do begin
insert('*',s,pos('14',s));
delete(s,pos('14',s),2);
end;

while pos('1',s)<>0 do begin
insert('*',s,pos('1',s));
delete(s,pos('1',s),1);
end;

while pos('*',s)<>0 do begin
delete(s,pos('*',s),1);
end;

if s='' then writeln('YES') else writeln('NO');

end.

program Project_A;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  n, i, y: integer;
  a: array [1..11] of byte;
  k: boolean;
begin
  readln(n);
  a[11] := 0;
  while (n <> 0) do
  begin
    inc(a[11]);
    a[a[11]] := n mod 10;
    n := n div 10;
  end;
  for i := 1 to (a[11] div 2) do
  begin
    y := a[i];
    a[i] := a[a[11]-i+1];
    a[a[11]-i+1] := y;
  end;
  k := true;
  y := 1;
  while (y <= a[11]) do
  begin
    if ((a[y] = 1) and (a[y+1] = 4) and (a[y+2] = 4)) then
      inc(y, 3)
    else if ((a[y] = 1) and (a[y+1] = 4)) then
      inc(y, 2)
    else if (a[y] = 1) then
      inc(y)
    else
    begin
      k := false;
      break;
    end;
  end;
  if (k) then
    writeln('YES')
  else
    writeln('NO');
  readln;
  readln;
end.

var s:string; k:byte; ok:boolean;
begin
    readln(s);
    while (pos('144',s)>0) do
    begin
        k:=pos('144',s);
        delete(s,k,3); insert('   ',s,k);
    end;
    while (pos('14',s)>0) do
    begin
        k:=pos('14',s);
        delete(s,k,2); insert('  ',s,k);
    end;
    while (pos('1',s)>0) do
    begin
        k:=pos('1',s);
        delete(s,k,1); insert(' ',s,k);
    end;
    for k:=1 to length(s) do
    if (s[k]=' ') then ok:=true else
    begin
        ok:=false; break;
    end;
    if (ok=true) then writeln('YES') else writeln('NO');
end.

var a:string;
    i,n,s:longint;
begin
   readln(a);
   s:=0;
   for i:=1 to length(a) do
      case s of
         0:if a[i]='1'
           then inc(s)
           else begin
                   writeln('NO');
                   halt(0);
                end;
         1:if a[i]='4'
           then inc(s)
           else if a[i]<>'1'
                then begin
                        writeln('NO');
                        halt(0);
                     end;
         2:if a[i]='4'
           then s:=0
           else if a[i]='1'
                then s:=1
                else begin
                        writeln('NO');
                        halt(0);
                     end;
      end;
   writeln('YES');
end.

const
        fi = '';
        fo = '';
var
        f,g : text;
        s : string;
        i : integer;
procedure solve;
begin
        for i := 1 to length(s) do
                if (s[i] <> '1') and (s[i] <> '4') then
                        begin
                                write(g,'NO');
                                close(f);
                                close(g);
                                halt;
                        end;
        if s[1] <> '1' then
                begin
                        write(g,'NO');
                        exit;
                end;
        if pos('444',s) >0 then
                begin
                        write(g,'NO');
                        exit;
                end;
        write(g,'YES');
end;
begin
        assign(f,fi);
        reset(f);
        assign(g,fo);
        rewrite(g);
        read(f,s);
		solve;
        close(f);
        close(g);
end.

Var
    S: String;

Begin
    Readln(S);
    For Var i := 1 to Length(S) - 2 do
        If (S[i] = '1') and (S[i + 1] = '4') and (S[i + 2] = '4') then Begin
            S[i] := 'a';
            S[i + 1] := 'a';
            S[i + 2] := 'a';
        End;
    For Var i := 1 to Length(S) - 1 do
        If (S[i] = '1') and (S[i + 1] = '4') then Begin
            S[i] := 'a';
            S[i + 1] := 'a';
        End;
    For Var i := 1 to Length(S)  do
        If (S[i] = '1') then
            S[i] := 'a';
    For Var i := 1 to Length(S) do
        If S[i] <> 'a' then Begin
            Write('NO');
            Exit
        End;
    Write('YES')
End.

var a            : string;
    dem , i , n : longint;
begin
    read( a );
    if ( a[1] <>'1') then
    begin
         write( 'NO' ); exit;
    end;
	dem :=0;
        n := length( a );
	for i := 2 to length( a ) do
		begin
		     if ( a[i] <> '1' ) and ( a[i] <> '4') then
		     begin
			  write( 'NO' ); exit;
		     end;
	if ( a[i] = '4' ) then inc(dem)
	else dem :=0;
	if ( dem > 2 )  then
		     begin
			  write( 'NO' );exit;
		     end;
                end;
	write( 'YES' );
end.

program volchis;
var s:string[255];
i:integer;

function z(a,b:string;k:integer):string;
var j:integer;
begin
 j:=1;
 while j<>0 do
  begin
   j:=pos(a,b);
   if j<>0 then
   begin
    delete(b,j,k);
    insert('a',b,j);
    //writeln(b);
   end;
  end;

z:=b;
end;

begin
readln(s);
i:=1;
while i<>0 do
begin
  s:=z('144',s,3);
  s:=z('14',s,2);
  s:=z('1',s,1);
  i:=1;
  while i<>0 do
  begin
   i:=pos('a',s);
   if i<>0 then
   begin
    delete(s,i,1);
    end;
   end;
  end;
  i:=length(s);
  if i=0 then writeln('YES') else writeln ('NO');
end.

var
i,j,k:integer;
s:string;
p:boolean;
begin
 readln(s);
 j:=length(s);i:=1;
  p:=true;
 while (0<>j)and p do
  begin
    if s[1]<>'1' then p:=false
     else
      if s[2]='4' then
         if s[3]='4' then delete(s,1,3)
         else delete(s,1,2)
         else delete(s,1,1);

    j:=length(s);
  end;
  if p then write('YES') else write('NO');
end.

uses math;
var
  a:int64;
  s,d,f,g,h:LONGINT;
begin
  READLN(A);
  WHILE (A<>0) DO
  BEGIN
    IF (A MOD 10=1) THEN A:=A DIV 10 ELSE IF (A MOD 100=14) THEN A:=A DIV 100 ELSE IF (A MOD 1000=144) THEN A:=A DIV 1000 ELSE BEGIN WRITELN('NO');HALT; END;
  end;
  WRITELN('YES');
end.

var
 s,ss:string;
 i,j,k:integer; t:boolean;
begin
 readln(s);ss:=s; t:=true;
 for i:=1 to length(s) do
  if (s[i]<>'1') and (s[i]<>'4') then t:=false;
  if pos('444',s)<>0 then t:=false;
  if t=true then begin
       repeat
        i:=pos('144',s);
        if (i<>0)and(s[i+3]<>'4') then delete(s,i,3);
       until (i=0)or(ss[i+3]='4'); ss:=s;
       repeat
        i:=pos('14',s);
        if (i<>0)and(s[i+2]<>'4') then delete(s,i,2);
       until (i=0)or(ss[i+2]='4');
       repeat
        i:=pos('1',s);
        if i<>0 then delete(s,i,1);
       until i=0;
       if s<>'' then writeln('NO')
       else writeln('YES');
                  end
       else writeln('NO');
end.

var
s:string;
n,i,k,f:longint;
begin
readln(s);
n:=length(s);
k:=0;
for i:=1 to n do begin
  if s[i]='1' then begin
    k:=1;
    f:=0;
  end else begin
     if s[i]='4' then inc(f);
     if (f>2) or ((s[i]='4') and (k=0)) or (s[i]<>'4')
     then begin
        write('NO');
        halt;
     end;
  end;
end;
writeln('YES');
end.

var
s:ansistring;
i,four,one:longint;
bol:boolean;
begin

readln(s);
for i:=1 to length(s) do begin
    if (s[i]<>'1')and(s[i]<>'4') then bol:=true;
end;
if bol then writeln('NO')
else begin
    for i:=1 to length(s) do begin
        if s[i]='1' then begin
            one:=1;
            four:=0;
        end;
        if s[i]='4' then begin
            if one<=0 then bol:=true;
            inc(four);
            if four>2 then bol:=true;
        end;
    end;
if bol then writeln('NO')
else writeln('YES');

end;
end.

var
a,b,c,d,e:integer;
function tl : boolean;
begin
result:=(a mod 10<>1) and (a mod 100<>14) and (a mod 1000<>144);
end;
begin
readln(a);
repeat
    if a mod 10=1 then a:=a div 10;
    if a mod 100=14 then a:=a div 100;
    if a mod 1000=144 then a:=a div 1000;
until (a=0) or (tl=true);
if a=0 then
    writeln('YES')
else
    writeln('NO');
end.

var
  i, l, c:longint;
  s:string;
begin
readln(s);
l:= length(s);
for i:=1 to l do
  begin
  if (i-c=1) and (s[i]='1') then c:=i;
  if (i-c<=2) and (i>1) then if (s[i]='4') and (s[i-1]='1')then c:=i;
  if (i-c<=3) and (i>2) then if (s[i]='4') and (s[i-1]='4') and (s[i-2]='1') then c:=i;
  if (i-c>3) then begin write('NO'); exit; end;
  end;
 if c=l then writeln('YES') else write('NO');
end.

var
  n:string;
  i:longint;
begin
  readln(n);
  if n[1]<>'1' then begin writeln('NO');exit;end;
  for i:=1 to length(n) do if (n[i]<>'1') and (n[i]<>'4') then begin writeln('NO');exit;end;
  for i:=1 to length(n)-2 do if (n[i]='4') and (n[i+1]='4') and (n[i+2]='4') then begin writeln('NO');exit;end;
  writeln('YES');
end.

var s:string;
    i,n,j:longint;
    fl:boolean;
begin
readln(s);
fl:=true;
for i:=1 to length(s) do
 if (s[i]<>'4') and (s[i] <> '1')
  then fl:=false;
if s[1]<>'1' then fl:=false;
if pos('444',s) >0 then fl:=false;
if fl then writeln('YES')
      else writeln('NO');
end.

var
        s: string;
        i: LongInt;

begin
        Read (s);

        i := 1;

        if s[i] <> '1' then begin
                Write ('NO');
                Exit
        end;
                for i := 2 to length (s) do
                        if (s[i] <> '1') and (s[i] <> '4') then begin
                                Write ('NO');
                                Exit
                        end
                        else
                                if Pos ('444', s) > 0 then begin
                                        Write ('NO');
                                        Exit
                                end;
        Write ('YES')
end.

Program _320A;
var
  a : array[1..10] of byte;
  n, i, t : longint;
begin
  read(n);
  i := 0;
  while n > 0 do
    begin
      i := i + 1;
      a[i] := n mod 10;
      n := n div 10;
    end;
  n := i;
  t := 0;
  if a[n]<>1
     then t := -1;
  for i := n downto 1 do
    case a[i] of
      1:case t of
          0,1,2: t := 0;
          else t := -1;
        end;
      4:case t of
          0, 1 : t := t + 1;
          else t := -1;
        end;
      else t := -1;
    end;
  if t >2
     then t := -1;
  if t = -1
     then write('NO')
     else write('YES');
end.

var i:longint;
    s,s1,s2,s3:string;
begin
    read(s);
    i:=1;
    while i<=length(s) do
    begin
        s1:=copy(s,i,1);   s2:=copy(s,i,2);    s3:=copy(s,i,3);
        if s3='144' then inc(i,3)
        else if s2='14' then inc(i,2)
        else if s1='1' then inc(i,1)
        else
        begin
            write('NO');
            exit;
        end;
    end;
    write('YES');
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  k,n,m,i,j,g,h:integer;
  s:string;
begin
  readln(s);
  k:=0;
  for i:=1 to length(s) do
    begin
      if (s[i]='1') or (s[i]='4') then
        begin
          if (s[i]='4') then
            begin
              if (s[i-1]<>'1') and (s[i-2]<>'1') then
                begin
                  write('NO');
                  exit;
                end;
            end;
        end
          else
            begin
              write('NO');
              exit;
            end;
    end;
  write('YES');
end.

var
	s : string;
	i,x : longint;

begin
	readln(s);
	x:=0;
	for i:=1 to length(s) do begin
		if(s[i]='1')then x:=2
		else if(s[i]='4') then dec(x)
		else begin
			writeln('NO');
			exit;
		end;
		if(x<0)then begin
			writeln('NO');
			exit;
		end;
	end;
	writeln('YES');
end.

var
 i,j:longint;
 s,t:ansistring;
begin
s:='144`';
readln(t);
j:=1;
for i:=1 to length(t) do
 if s[j]=t[i] then inc(j) else
 if s[1]=t[i] then j:=2 else
  begin
   write('NO');
   halt;
  end;
write('YES');
end.

var n:string;
    l, i, t:byte;
begin
t:= 0; {Defaults}
readln(n);
l:= length(n);
for i:=1 to l do begin
    if(n[i] = '1') then t:= 1
    else if((n[i] = '4') and (t > 0) and (t < 3)) then inc(t, 1)
    else begin
        writeln('NO');
        exit;
    end;
end;
writeln('YES');
end.

var i,c: integer; s: string;
begin
  readln(s);
  for i:=length(s) downto 1 do
  begin
    if s[i]='1' then c:=0
                else if s[i]='4' then if c<2 then inc(c)
                                             else
                                             begin
                                               writeln('NO');
                                               exit
                                             end
                                 else
                                 begin
                                   writeln('NO');
                                   exit
                                 end
  end;
  if c=0 then writeln('YES')
         else writeln('NO')
end.

program project1;

var s : string [11];
  i: byte;

begin
  readln (s);

   i:=pos ('444', s)   ;
   if(i>0) then writeln ('NO') else
     begin

  repeat
    begin
     i:=pos( '144', s);
     delete ( s, i, 3 );
    end;
  until (i=0);
  repeat
    begin
     i:= pos ( '14',s);
     delete (s, i, 2);
    end;
  until ( i=0);
  repeat
    i:= pos ('1', s);
    delete ( s, i, 1);
  until (i=0) ;

  if length(s)=0 then
  writeln ( 'YES') else
    writeln ('NO');

       end  ;

end.

//Uses math,sysutils,strutils;
var
n,q,i,w:longint;
a:array[1..10]of integer;
begin
read(n);
w:=1;
for i:=1 to 10 do
a[i]:=0;
q:=10;
while n>0 do
begin
a[q]:=n mod 10;
n:=n div 10;
q:=q-1;
end;
q:=q+1;
if a[q]<>1
then
w:=0;
if q<9
then
for i:=q to 8 do
if (a[i]=a[i+1]) and (a[i]=4) and (a[i]=a[i+2])
then
w:=0;
if q<10
then
for i:=q+1 to 10 do
if (a[i]<>1) and (a[i]<>4)
then
w:=0;
if w=1
then
write('YES')
else
write('NO');
end.

Var s:String;
i:LongInt;
Begin
     //ReSet (input,'input.txt');
   //  ReWrite (output,'output.txt');
     Readln (s);
     If s[1]='4' then    Begin
          Writeln ('NO');
          Halt (0);
     End;
     For I:=1 to Length (s) do
     If (s[i]<>'1') and (s[i]<>'4')
     then Begin
          Writeln ('NO');
          Halt (0);
     End;
      For I:=1 to Length (s)-2 do
     If (s[i]='4') and (s[i+1]='4') and (s[i+2]='4')
     then Begin
          Writeln ('NO');
          Halt (0);
     End;
     Writeln ('YES');
End.

program bai1;
var s:string;
	i:longint;
BEGIN
    readln(s);
    s:='44'+s;
	for i:=3 to length(s) do if ((s[i]<>'1') and (s[i]<>'4')) or (s[i]='4') and (s[i-1]='4') and (s[i-2]='4')  then
    begin
        writeln('NO');
        exit;
    end;
    writeln('YES');

END.

program name;
var i, n:integer;
s:string;
begin
readln (n);
str (n,s);
repeat
i:=pos ('144',s);
if i<>0 then delete (s,i,3);
insert ('a',s,i);
until i=0;
repeat
i:=pos ('14',s);
if i <>0 then delete (s,i,2);
insert ('a',s,i);
until i=0;
repeat
i:=pos ('1',s);
if i<>0 then delete (s,i,1);
insert ('a',s,1);
until i=0;
repeat
i:=pos ('a',s);
if i<>0 then delete (s,i,1);
until i=0;
if length(s)=0 then writeln ('YES') else writeln ('NO');
end.

var
a:int64;
j,i,k:byte;
b:array[1..10] of byte;
r:boolean;
begin
readln(a);
i:=1;
while a>9 do
 begin
  b[i]:=a mod 10;
  a:=a div 10;
  i:=i+1;
 end;
b[i]:=a;
k:=0;
r:=true;
j:=0;
while j<i do
 begin
  j:=j+1;
  if b[j]=4 then k:=k+1
            else
             begin
              if b[j]=1 then k:=0
                        else r:=false;
             end;
  if k>2 then r:=false;
 end;
if b[i]=4 then r:=false;
if r=true then writeln('YES')
          else writeln('NO');
end.

var st:String;
    kt:boolean;
    t,code,n,i:longint;

begin
     //assign(input,'magic_numbers.inp');
     //reset(input);
     //assign(output,'magic_numbers.out');
     //rewrite(output);
     readln(st);
               while pos('144',st)<>0 do
                    begin
                         t:=pos('144',st);
                         st[t]:='.';st[t+1]:='.';st[t+2]:='.';
                    end;
               while pos('14',st)<>0 do
                    begin
                         t:=pos('14',st);
                         st[t]:='.';st[t+1]:='.';
                    end;
                while pos('1',st)<>0 do
                     begin
                          t:=pos('1',st);
                          st[t]:='.';
                     end;
     for i:=1 to length(st) do
        if st[i]<>'.' then
          begin
               write('NO');
               halt;
          end;
     write('YES');

end.

var s,k:string;
    i,j,l,m:longint;
    b:boolean;
begin
readln(s);
i:=1;
b:=true;

while (b=true) and (i<= length(s)) do
begin
k:=copy(s,i,3);
if k='144' then begin
                 inc(i,3);
                 k:=copy(s,i,3);
                end
          else  begin
                k:=copy(s,i,2);
                if k='14' then inc(i,2)
                         else begin
                              k:=copy(s,i,1);
                              if k='1' then inc(i)
                                     else b:=false;
                               end;
end;            end;
if b=false then write('NO')
            else write('YES');
end.

{$APPTYPE CONSOLE}
Var s:string;
Procedure Rec (i:integer);
Begin
  if i>length(s)
  then begin
         writeln ('YES');
         halt (0);
       end;
  if ((s[i]='1')and(s[i+1]='4'))and(s[i+2]='4')
  then Rec (i+3)
  else if (s[i]='1')and(s[i+1]='4')
       then Rec (i+2)
       else if s[i]='1'
            then Rec (i+1);
end;

begin
  Readln (s);
  Rec (1);
  writeln ('NO');
end.

Var n:Longint;
        s,temp:String;
        ok:boolean;
        i:Longint;
Begin
        Readln(n);
        str(n,s);

        ok:=true;

        for i:=1 to length(s) do
         If (s[i]<>'1') and (s[i]<>'4') then ok:=false;

        For i:=2 to length(s)-1 do
         If (s[i]='4') and (s[i+1]='4') and (s[i-1]<>'1') then ok:=false;

        If (s[1]='4') then ok:=false;
        If (s[2]='4') and (s[1]<>'1') then ok:=false;

        If (ok) then Writeln('YES') Else Writeln('NO');
End.

program one;
var
i, n: integer;
s: string;
begin
readln (n);
str (n, s);
repeat
i:= pos ('144', s);
if i <> 0 then delete (s, i, 3);
insert ('a', s, i);
until i = 0;
repeat
i:= pos ('14', s);
if i<>0 then delete (s, i, 2);
insert ('a', s, i);
until i = 0;
repeat
i:= pos ('1', s);
if i<>0 then delete (s, i, 1);
insert ('a', s, i);
until i = 0;
repeat;
i:= pos ('a', s);
if i<>0 then delete (s, i, 1);
until i=0;
if length (s) = 0
then
writeln ('YES')
else writeln ('NO');
end.

var n:string;
begin
        readln(n);
        while length(n)>0 do
        begin
            if copy(n,1,3)='144' then
            begin
                delete(n,1,3);
                continue;
            end;
            if copy(n,1,2)='14' then
            begin
                delete(n,1,2);
                continue;
            end;
            if copy(n,1,1)='1' then
            begin
                delete(n,1,1);
                continue;
            end;
            break;
        end;
        if n<>'' then writeln('NO') else writeln('YES');
end.

var n,a,k1,k4:longint;
begin
readln(n);
a:=n;
k1:=0;
k4:=0;
while a>0 do
  begin
  if a mod 10=1
     then a:=a div 10
     else if (a mod 10<>1) and (a mod 10<>4)
          then begin writeln('NO'); halt; end
          else begin
               if a mod 100=14 then a:=a div 100
                               else if a mod 1000=144 then a:=a div 1000
                                                     else begin writeln('NO'); halt; end;

               end;
  end;
writeln('YES');
end.

var q,n,k,i:longint;s:string;c:set of char;
begin
readln(s);
if s[1]<>'1' then writeln('NO')else
begin
i:=length(s);
while i<>0 do
begin
if (s[1]<>'1')and(s[1]<>'4')then begin writeln('NO');q:=1;break;end else
 if s[1]='4' then begin
    if k>=2 then begin writeln('NO');q:=1;break;end else begin inc(k);end ;
    end else k:=0;
    dec(i);delete(s,1,1);
    end;

if q<>1 then writeln('YES');
end;
end.

var
i,j,k:integer;
s:string;
p:boolean;
begin
 readln(s);
 j:=length(s);i:=1;
  p:=true;
 while (0<>j)and p do
  begin
    if s[1]<>'1' then p:=false
     else
      if s[2]='4' then
         if s[3]='4' then delete(s,1,3)
         else delete(s,1,2)
         else delete(s,1,1);

    j:=length(s);
  end;
  if p then write('YES') else write('NO');
end.

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  s: String;

Function Cnt: Boolean;
var
  i, j, k: Integer;
  ss, s2: String;
  en: Boolean;
begin
  en := true;
  while (length(s) > 0) do
  begin
    If (length(s) >= 3) then begin
      If (s[1] = '1') and (s[2] = '4') and (s[3] = '4') then
        Delete(s,1,3) else
      If (s[1] = '1') and (s[2] = '4') and (s[3] <> '4') then
        Delete(s,1,2) else
      If (s[1] = '1') and (s[2] <> '4') then
        Delete(s,1,1) else begin
      en := false ;
      break;
      end;
    end else
      If (length(s) >= 2) then begin
        If (s[1] = '1') and (s[2] = '4') then
          Delete(s,1,2) else
        If (s[1] = '1') and (s[2] <> '4') then
          Delete(s,1,1) else begin
        en := false;
        break;
        end;
      end
        else
      If (length(s) = 1) and (s[1] = '1') then
        delete(s,1,1)
      else begin
        en := false;
        break;
        end;
  end;
  Cnt := en;
end;

begin
  readln(s);
  If (cnt) then
    writeln('YES')
  else
    writeln('NO');
  readln;
  readln;
end.

var  s:string;
   z,i,p:longint;
 begin
  readln(s);
   repeat
    p:=0;
     inc(z);
    if (s[z]='1')and(s[z+1]='4')and(s[z+2]='4') then begin p:=1; z:=z+2; end;
    if (s[z]='1')and(s[z+1]='4')and(p=0) then begin p:=1; z:=z+1; end;
    if (s[z]='1')and(p=0) then begin p:=1; {inc(z);} end;
    if (p=0)and(z<=length(s)) then begin writeln('NO'); exit; end;
   until(z=length(s));
   writeln('YES');
 end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var  m,nep,i, n,k : integer;
    s, s1,s2,s3,st: ansistring;
    f, g: boolean;
begin
  { TODO -oUser -cConsole Main : Insert code here }
   readln(s);
   s1:='144';
   s2:='14';
   s3:='1';
   f:=true;
   i:=1;
   n:=length(s);
   while i<=n do
   begin
     st:=copy(s, i, 3);
     if st=s1 then  inc(i, 3)
     else
         begin
             st:=copy(s, i, 2);
             if st=s2 then i:=i+2
             else
             begin
                 st:=copy(s, i, 1);
                 if st=s3 then i:=i+1
                 else
                 begin
                   f:=false;
                   break;
                 end;
             end;
         end;
   end;

 if f then writeln('YES') else writeln('NO');
end.

program p17;
var
  a:string[10];
  j,k:longint;
begin
  readln(a);
  if a=''
    then begin writeln('NO');halt; end;
  while pos('144',a)<>0 do
    begin
      k:=pos('144',a);a[k]:='a';a[k+1]:='a';a[k+2]:='a';
    end;
  while pos('14',a)<>0 do
    begin
      k:=pos('14',a);a[k]:='a';a[k+1]:='a';
    end;
  while pos('1',a)<>0 do
    begin
      k:=pos('1',a);a[k]:='a';
    end;
  for j:=1 to length(a) do
    if a[j]<>'a'
      then begin writeln('NO');halt; end;
  writeln('YES');
end.

var     n,i,l:longint;
a:array[1..10000] of longint;
begin
read(n);
i:=0;
l:=0;
while n>0 do begin
if (n div 10=0) and (n mod 10<>0) and (n<>1) then begin
write('NO');
exit;
end;
inc(i);
a[i]:=n mod 10;
n:=n div 10;
if (a[i]<>1) and (a[i]<>4) then begin
write('NO');
exit;
end;
if a[i]=4 then inc(l)
          else l:=0;
if l>2 then begin
write('NO');
exit;
end;
end;
write('YES');
end.

var s:ansistring;
    i:longint;
    ok:boolean;
begin
    readln(s);
    ok:=true;
    if s[1]<>'1' then ok:=false;
    if pos('444',s)>0 then ok:=false;
    for i:=1 to length(s)do
     if not(s[i]in['1','4'])then ok:=false;
    if ok then writeln('YES')else writeln('NO');
end.

var s:string;
 a,b,c,x,y,z,i,j,k,n:longint;
  begin
   readln(s);
   x:=0;
   if s[1]='1' then else begin Write('NO'); halt; end;
    for i:=1 to length(S) do
     begin
       if (s[i]='1') or (s[i]='4') then else begin Write('NO'); halt; end;
      if s[i]='4' then x:=x+1
      else if x>2 then begin Write('NO'); halt; end
       else x:=0;
     end;
   if x>2 then Write('NO') else   Write('YES');
  end.

{$MODE OBJFPC}
var
    s:ansistring;
    i,j,k,dem,n:integer;

begin
    readln(s);
    n:=length(s);
    for i:=1 to length(s) do
        if (s[i]<>'1') and (s[i]<>'4') then
            begin
                writeln('NO');
                halt;
            end;
    if (s[1]='4') then
        begin
            writeln('NO');
            halt;
        end;
    for i:=1 to n-1 do
        if (s[i]='1') and (s[i+1]='4') then
            begin
                dem:=0;
                for j:=i+1 to n do
                    if s[j]='4' then
                        inc(dem) else break;
                if (dem>2) then
                    begin
                        writeln('NO');
                        halt;
                    end;
            end;
    writeln('YES');
end.

var
n,m,q,w,l,r,mid,i,k:longint;
s:string;
a,b:array[1..100000] of longint;
c:array[0..1000, 0..1000] of int64;
begin
    {assign(input,'f.in');
    assign(output,'f.out');
    reset(input);
    rewrite(output); }
    read(s);
    if s[1]='4' then
    begin
        write('NO');
        exit;
    end;
    for i:=1 to length(s) do
    begin
        if (s[i]<>'1') and (s[i]<>'4') then
        begin
            write('NO');
            exit;
        end;
        if (s[i]='4') then inc(k);
        if k=3 then
        begin
            write('NO');
            exit;
        end;
        if s[i]='1' then k:=0;
    end;
    write('YES');
end.

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  s:string;
  b:boolean;
  i,n:integer;
begin
  { TODO -oUser -cConsole Main : Insert code here }
  ReadLn(s);
  b:=true;
  n:=0;
  if s[1]='4' then
    b:=False;
  for i := 1 to length(s) do
    if (s[i]='1') or (s[i]='4') then
    begin
      if s[i]='1' then
        n:=0;
      if s[i]='4' then
        inc(n);
      if n = 3 then
        b:=false;
    end
    else
      b:=False;
  if b then
    WriteLn('YES')
  else
    WriteLn('NO');
end.

program volshebstvo_Viki_RESET;
{$APPTYPE CONSOLE}
uses
  SysUtils;

var
  s: string;
  i, j, n:integer;
begin
  readln(s);
  s := s + '55';
  i := 1;
  while (i <= length(s) - 2) do
  begin
    if (copy(s, i, 3) = '144') then
      inc(i, 3)
    else
    if (copy(s, i, 2) = '14') then
      inc(i, 2)
    else
    if (copy(s, i, 1) = '1') then
      inc(i, 1)
    else
    begin
      writeln('NO');
      readln;
      exit;
    end;
  end;
  writeln('YES');
  readln;
end.

var i,c: integer; s: string;
begin
  readln(s);
  for i:=length(s) downto 1 do
  begin
    if s[i]='1' then c:=0
                else if s[i]='4' then if c<2 then inc(c)
                                             else
                                             begin
                                               writeln('NO');
                                               exit
                                             end
                                 else
                                 begin
                                   writeln('NO');
                                   exit
                                 end
  end;
  if c=0 then writeln('YES')
         else writeln('NO')
end.

var s:string;
    i,j,k,l,r,n,m:longint;
  begin
    readln(s);
    i:=1;
    s:=s+'  ';
    while i<>length(s) do
     begin
         if s[i]=' ' then break;
       if s[i]<>'1' then begin writeln('NO'); halt; end;
       if (s[i+1]='4') and (s[i+2]='4') then inc(i,3) else
       if (s[i+1]='4') then inc(i,2) else
       if (s[i]='1') then inc(i,1);
     end;
    writeln('YES');
  end.

Const
        Finp='';
        Fout='';
Var     f,g:text;
        n,s:longint;
Begin
        Assign(f,finp); Reset(f);
        Assign(g,fout); Rewrite(g);
        Readln(f,n);
        While n<>0 do
                Begin
                        s:=n mod 1000;
                        If s=144 then
                                Begin n:=n div 1000; Continue; End;
                        s:=n mod 100;
                        If s=14 then
                                Begin n:=n div 100; Continue; End;
                        s:=n mod 10;
                        If s=1 then
                                Begin n:=n div 10; Continue; End;
                        Break;
                End;
        If n>0 then Write(g,'NO')
        Else Write(g,'YES');
        Close(f); Close(g);
End.

const fi = 'input.txt';
      fo = 'output.txt';

var s: string;
    n, i: longint;
    ok: boolean;

begin
 readln(s);
 n:=length(s);
 ok:=true;
 for i:=1 to n do
  if (s[i] <> '1') and (s[i] <> '4') then ok:=false;
 if ok then
  begin
   if (pos('444', s) > 0) or (s[1] = '4') then writeln('NO')
   else writeln('YES');
  end
 else writeln('NO');

 close(input); close(output);
end.

var n:string;
begin
        readln(n);
        while length(n)>0 do
        begin
            if copy(n,1,3)='144' then
            begin
                delete(n,1,3);
                continue;
            end;
            if copy(n,1,2)='14' then
            begin
                delete(n,1,2);
                continue;
            end;
            if copy(n,1,1)='1' then
            begin
                delete(n,1,1);
                continue;
            end;
            break;
        end;
        if n<>'' then writeln('NO') else writeln('YES');
end.

uses math;
type mass=array[0..11,1..3] of integer;
var r,l,k:int64;s,s1:string;u:boolean;d,max1,min1,n,res,de:int64;i,z,code:integer;x,j,a,b,c,y:int64;
    m:mass;
begin
 // reset(input,'input.txt');
 // assign(output,'output.txt');
  readln(n);
  str(n,s);
  if s[1]='1'
  then Begin
          m[1,1]:=1;
          if s[2]='4'
          then Begin
                  m[2,2]:=1;
                  if s[3]='4'
                  then m[3,3]:=1;
               end;
       end;
  for i:=2 to length(s) do
      for z:=i downto max(1,i-2) do
         if s[z]<>'0'
         then Begin
            val(copy(s,z,i-z+1),a,code);
            if (a=1) and ((m[z-1,1]=1) or (m[z-1,2]=1) or (m[z-1,3]=1))
            then m[i,1]:=1;
            if (a=14) and ((m[z-1,1]=1) or (m[z-1,2]=1) or (m[z-1,3]=1))
            then m[i,2]:=1;
            if (a=144) and ((m[z-1,1]=1) or (m[z-1,2]=1) or (m[z-1,3]=1))
            then m[i,3]:=1;
         end;
  a:=length(s);
  if (m[a,1]=1) or (m[a,2]=1) or (m[a,3]=1)
  then writeln('YES')
  else writeln('NO');
end.

program N_1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
   s:string;
   i,j,n:integer;
begin
   readln(s);
   i:=1;   n:=0;
   while i<= length(s) do
      begin
         if (copy(s,i,3)='144') then begin n:=1; inc(i,3);end
         else if (copy(s,i,2)='14') then begin n:=1; inc(i,2);end
         else if (copy(s,i,1)='1') then begin n:=1; inc(i);end
         else begin writeln('NO');n:=0; break;end; end;
   if n=1 then writeln('YES');
   readln;

end.

Program MagicNumbers;
uses math;
var s:string;
begin   //assign(input,'320A.inp'); reset(input);
        //assign(output,'320A.out'); rewrite(output);
        readln(s);
        while s<>'' do
        begin   if Pos('144',s)=1 then delete(s,1,3)
                else if Pos('14',s)=1 then delete(s,1,2)
                else if Pos('1',s)=1 then delete(s,1,1)
                else begin
                     writeln('NO'); exit;
                     end;
        end;
        writeln('YES');
        //close(input); close(output);
end.

program A189;
var n, e, a, b, c, d:int64;
    i:integer;
begin
  readln(n);
  a:=1;
  b:=0;
  e:=0;
  while(a<n) do
  begin
    a:=a*10;
    b:=b+1;
  end;
  a:=10;
  for i:=1 to b do
  begin
    c:=(n mod a - n mod (a div 10)) div (a div 10);
    if ((c<>1) and (c<>4)) then
    begin
      d:=1;
      break;
    end
    else
    begin
      if c=4 then
      begin
       e:=e+1;
       if e>2 then d:=1;
      end
      else e:=0;
    end;
    a:=a*10;
  end;
  if c=4 then d:=1;
  if d=1 then writeln('NO')
  else writeln('YES');
end.

program project1;

var s : string [11];
  i: byte;

begin
  readln (s);

   i:=pos ('444', s)   ;
   if(i>0) then writeln ('NO') else
     begin

  repeat
    begin
     i:=pos( '144', s);
     delete ( s, i, 3 );
    end;
  until (i=0);
  repeat
    begin
     i:= pos ( '14',s);
     delete (s, i, 2);
    end;
  until ( i=0);
  repeat
    i:= pos ('1', s);
    delete ( s, i, 1);
  until (i=0) ;

  if length(s)=0 then
  writeln ( 'YES') else
    writeln ('NO');

       end  ;

end.

var
a:ansistring;
i:longint;
b:boolean;
begin
        readln(a);
        if (a[1]<>'1') then writeln('NO')
        else
                begin
                b:=true;
                for i := 2 to (length(a)-1) do begin
                        if ((a[i]<>'1') and (a[i]<>'4'))  then b:=false;
                        if (a[i-1]='4') and (a[i]='4') and (a[i+1]='4') then b:=false;
                end;
                if (a[length(a)]<>'1')and(a[length(a)]<>'4') then b:=false;
                if b=true then writeln('YES')
                else writeln('NO');
                end;
        readln;
end.

var
  s,c:string;
  g,e,d,i,j,n,m:int64;
begin
  readln(s); c:=' '*length(s);
  for i:=1 to length(s)-2 do
    if s[i]+s[i+1]+s[i+2]='144' then begin s[i]:=' '; s[i+1]:=' '; s[i+2]:=' '; end;
  for i:=1 to length(s)-1 do
    if s[i]+s[i+1]='14' then begin s[i]:=' '; s[i+1]:=' '; end;
  for i:=1 to length(s) do
    if s[i]='1' then s[i]:=' ';
  if s=c then writeln('YES') else writeln('NO');
end.

var
        n,m,k,l,i,j,max,min,x,y,sum,ans,res,x2,y2,b,h,e : longint;
        a,d : array [0..1000000] of longint;
        p,q : real;
        s : ansistring;

begin
  readln(s);
  if s[1]='4' then
    begin
    writeln('NO');
    exit;
    end;
  for i:=1 to length(s)-2 do
    begin
    if (s[i]='4') and (s[i+1]='4') and (s[i+2]='4') then
      begin
      writeln('NO');
      exit;
      end;
    end;
  for i:=1 to length(s) do
    if (s[i]<>'1') and (s[i]<>'4') then
      begin
      writeln('NO');
      exit;
      end;
  writeln('YES');
  readln; readln;
end.

const   fi = '';
        fo = '';
var     s:string;
        n:longint;
        f,g:text;

procedure openfile;
begin
        assign(f,fi);reset(f);
        assign(g,fo);rewrite(g);
end;
procedure readfile;
begin
        readln(f,s);
end;
procedure process;
var     i,k:longint;
begin
        n:=length(s);
        for i:=1 to n do
                if (s[i]<>'1') and (s[i]<>'4') then
                        begin
                                writeln(g,'NO');
                                exit;
                        end;
        repeat
                k:=pos('4',s);
                if k=0 then
                        begin
                                writeln(g,'YES');
                                exit
                        end;
                if (k=1) then
                        begin
                                writeln(g,'NO');
                                exit;
                        end
                else
                        if s[k-1]='1' then
                        begin
                                if k<>n then
                                        if s[k+1]='4' then k:=k+1;
                                delete(s,1,k);
                        end
                        else begin
                                writeln(g,'NO');
                                exit;
                        end;
        until false;
end;
procedure closefile;
begin
        close(f);
        close(g);
end;
begin
        openfile;
        readfile;
        process;
        closefile;
end.

var s:string;
	i:longint;
function xuly:string;
begin
    if pos('2',s)>0 then exit('NO');
    if pos('3',s)>0 then exit('NO');
    if pos('5',s)>0 then exit('NO');
    if pos('6',s)>0 then exit('NO');
    if pos('7',s)>0 then exit('NO');
    if pos('9',s)>0 then exit('NO');
    if pos('0',s)>0 then exit('NO');
	i:=pos('144',s);
    while i>0 do begin delete(s,i,3); insert('   ',s,i); i:=pos('144',s); end;
	i:= pos('14',s);
    while i>0 do begin delete(s,i,2); insert('  ',s,i); i:= pos('14',s); end;
	i:=pos('1',s);
    while i>0 do begin delete(s,i,1); insert(' ',s,i); i:=pos('1',s); end;
	i:=pos(' ',s);
	while i>0 do begin delete(s,i,1); i:=pos(' ',s); end;
    if s<>'' then exit('NO');
    exit('YES');
end;

begin
    readln(s);
    writeln(xuly);
end.

{$R+ Q+ I+}
{$apptype console}
uses
    sysutils,math;
var
  s,w : string;
  i : integer;
begin
    read(s);
    i := 1;
    while (i <= length(s)) do begin
          w := s[i];
          if (w <> '1') then begin
              write('NO');
              halt;
          end;
          if (i = length(s)) then break;
          if (i < length(s)) then begin
              if (s[i + 1] = '1') then begin
                  i := i + 1;
                  continue;
              end;
              if (s[i + 1] = '4') then begin
                  w := w + s[i + 1];
                  i := i + 2;
              end
              else begin
                    write('NO');
                    halt;
              end;
          end;
          if (i <= length(s)) then begin
              if (s[i] = '1') then begin
                  continue;
              end;
              if (s[i] = '4') then begin
                  w := w + s[i];
                  i := i + 1;
              end
              else begin
                   write('NO');
                    halt;
              end;
          end;
    end;
    write('YES');

end.

program codeforcesa3;
var
    chk:integer;
    Num:string;
    i:byte;
begin
    readln(Num);
    chk:=0;
    if Num[1]<>'1'
        then chk:=-1
        else for i:=1 to length(Num) do begin
            if Num[i]='1'
                then chk:=1
                else if Num[i]='4' then inc(chk);
            if (chk>3) or (Num[i]<>'1') and (Num[i]<>'4') then begin
                chk:=-1;
                break;
            end;
        end;
    if chk=-1
        then writeln('NO')
        else writeln('YES');
end.

var q,n,k,i:longint;s:string;c:set of char;
begin
readln(s);
if s[1]<>'1' then writeln('NO')else
begin
i:=length(s);
while i<>0 do
begin
if (s[1]<>'1')and(s[1]<>'4')then begin writeln('NO');q:=1;break;end else
 if s[1]='4' then begin
    if k>=2 then begin writeln('NO');q:=1;break;end else begin inc(k);end ;
    end else k:=0;
    dec(i);delete(s,1,1);
    end;

if q<>1 then writeln('YES');
end;
end.

{$R+,Q+,I+}
{$apptype console}
Uses SysUtils;
Var
   dp,used:Array[0..300000] of Boolean;
   n:Integer;
   s:String;
Function Solve(i:Integer):Boolean;
Var
   f:Boolean;
Begin
   If used[i] Then Begin
      Solve:=dp[i];
      Exit;
   End;
   used[i]:=true;
   If i=0 Then Begin
      Solve:=true;
      Exit;
   End;
   f:=false;
   If s[i]='1' Then f:=f or Solve(i-1);
   If (i>=2) and (s[i-1]+s[i]='14') Then f:=f or Solve(i-2);
   If (i>=3) and (s[i-2]+s[i-1]+s[i]='144') Then f:=f or Solve(i-3);
   Solve:=f;
End;
Begin
   Read(s);
   n:=length(s);
   If Solve(n) Then Write('YES')
               Else Write('NO');
End.

var
  s, f, a: string;

begin
  readln(s);
  while f = '' do
    if length(s) <> 0 then
    begin
      a := copy(s, 1, 3);
      if a = '111' then
        delete(s, 1, 2)
      else
      if a = '114' then
        delete(s, 1, 1)
      else
      if a = '144' then
        delete(s, 1, 3)
      else
      if a = '141' then
        delete(s, 1, 2)
      else
      if a = '14' then
        delete(s, 1, 2)
      else
      if a = '1' then
        delete(s, 1, 1)
      else
      if a = '11' then
        delete(s, 1, 2)
      else
        f := 'NO';
    end
    else
      f := 'YES';
  write(f);
end.

var
a:int64;
j,i,k:byte;
b:array[1..10] of byte;
r:boolean;
begin
readln(a);
i:=1;
while a>9 do
 begin
  b[i]:=a mod 10;
  a:=a div 10;
  i:=i+1;
 end;
b[i]:=a;
k:=0;
r:=true;
j:=0;
while j<i do
 begin
  j:=j+1;
  if b[j]=4 then k:=k+1
            else
             begin
              if b[j]=1 then k:=0
                        else r:=false;
             end;
  if k>2 then r:=false;
 end;
if b[i]=4 then r:=false;
if r=true then writeln('YES')
          else writeln('NO');
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  k,n,m,i,j,g,h:integer;
  s:string;
begin
  readln(s);
  k:=0;
  for i:=1 to length(s) do
    begin
      if (s[i]='1') or (s[i]='4') then
        begin
          if (s[i]='4') then
            begin
              if (s[i-1]<>'1') and (s[i-2]<>'1') then
                begin
                  write('NO');
                  exit;
                end;
            end;
        end
          else
            begin
              write('NO');
              exit;
            end;
    end;
  write('YES');
end.

Program A320;
Var
    n: LongInt;
    i: integer;
Begin
    readln(n);
    while n > 0 do begin
        if (n mod 1000 <> 144) and (n mod 100 <> 14) and (n mod 10 <> 1) then break;
        n := n div 10;
    end;
    if n = 0 then writeln('YES') else writeln('NO');
End.

var st:String; i,j:longint; flag:boolean;
begin
//ASSIGN(input,'input.txt'); RESET(input);
//ASSIGN(output,'output.txt'); REWRITE(output);
readln(st);
for i:=1 to length(st)-2 do
   if (st[i]='1') and (st[i+1]='4') and (st[i+2]='4') then begin
   st[i]:='z'; st[i+1]:='z'; st[i+2]:='z' end;

for i:=1 to length(st)-1 do
   if (st[i]='1') and (st[i+1]='4') then begin
   st[i]:='z'; st[i+1]:='z' end;

flag:=true;
for i:=1 to length(st) do
   if (st[i]<>'1') and (st[i]<>'z') then flag:=false;
if flag then write('YES')
else write('NO')
end.

var
  i, l, c:longint;
  s:string;
begin
readln(s);
l:= length(s);
for i:=1 to l do
  begin
  if (i-c=1) and (s[i]='1') then c:=i;
  if (i-c<=2) and (i>1) then if (s[i]='4') and (s[i-1]='1')then c:=i;
  if (i-c<=3) and (i>2) then if (s[i]='4') and (s[i-1]='4') and (s[i-2]='1') then c:=i;
  if (i-c>3) then begin write('NO'); exit; end;
  end;
 if c=l then writeln('YES') else write('NO');
end.

var
i,ii : integer;
n : ansistring;
x : char;
begin
    read(n);
    if n[1] = '4' then
        begin
            write('NO');
                exit;
        end;
    for i := 1 to length(n) do
        begin
            if n[i] = '4' then
            begin
                for ii := i to i + 2 do
                    if ii  <= length(n) then
                    begin
                        if n[ii] = '4' then
                             begin
                                if ii = (i + 2) then
                                    begin
                                        write('NO');
                                        EXIT;
                                    end;
                             end;
                        if n[ii] = '1' then
                            break
                    end;
            end;
            if ( n[i] <> '4') and ( n[i] <> '1') then
                begin
                    write('NO');
                    exit;
                end;
        end;
    write('YES');
end.

program name;
var
i:integer;
n:integer;
s:string;
begin
readln(n);
str(n,s);
repeat
i:=pos( '144' , s);
if i<>0 then delete (s,i,3);
insert ('a',s,i);
insert('a',s,i);
until i=0;
repeat
i:=pos( '14' , s);
if i<>0 then delete (s,i,2);
insert ('a',s,i);
insert ('a',s,i);
until i=0;
repeat
i:=pos( '1' , s);
if i<>0 then ( delete (s,i,1) );
insert ('a',s,i);
until i=0;
repeat
i:=pos( 'a' , s);
if i<>0 then ( delete (s,i,1) );
until i=0;
if length(s) = 0 then writeln ( 'YES' ) else writeln ( 'NO' );
end.

program abc;
var
i:integer;
n:integer;
s:string;
begin
readln (n);
str (n,s);
repeat
i:=pos ('144',s);
if i <> 0 then delete (s,i,3);
insert ('a',s,i);
until i = 0;
repeat
i:=pos ('14',s);
if i <> 0 then delete (s,i,2);
insert ('a',s,i);
until i=0;
repeat
i:=pos ('1',s);
if i <> 0 then delete (s,i,1);
insert ('a',s,i);
until i=0;
repeat
i:=pos ('a',s);
if i <> 0 then delete (s,i,1);
until i=0;
if length(s) = 0 then writeln ('yes') else writeln ('no');
end.

VAR S:string;
    I:byte;
BEGIN
readln(s);
if s[1] <> '1' then
    write('NO')
else
    begin
    for i:=2 to length(s)-1 do
        begin
        if  (s[i]<>'1') and (s[i] <>'4') then
            begin
            write('NO');
            BREAK;
            end
        else
            if (s[i]=s[i+1]) and (s[i]=s[i-1]) and (s[i]='4') then
                begin
                write('NO');
                break;
                end;
        end;
    write('YES');
    end;
end.

var n:string;
begin
        readln(n);
        while pos('144',n)>0 do delete(n,pos('144',n),3);
        while pos('14',n)>0 do delete(n,pos('14',n),2);
        while pos('1',n)>0 do delete(n,pos('1',n),1);
        if n<>'' then writeln('NO') else writeln('YES');
end.

var
  i, l, c:longint;
  s:string;
begin
readln(s);
l:= length(s);
for i:=1 to l do
  begin
  if s[i]='1' then c:=i;
  if (i-c<=1) and (i>1) then if (s[i]='4') and (s[i-1]='1')then c:=i;
  if (i-c<=2) and (i>2) then if (s[i]='4') and (s[i-1]='4') and (s[i-2]='1') then c:=i;
  if (i-c>2) then begin write('NO'); exit; end;
  end;
 if c=l then writeln('YES') else write('NO');
end.

var a:string;
        i :byte;

begin
        read(a);
        i:= 1;
        for i := 1 to length(a) do
        begin
                if ((a[i] <> '1') and (a[i] <> '4')) or (a[1] = '4') then
                begin
                        write('no');
                        exit;
                end;

                if (a[i] = '4')and (a[i+1]='4') and(a[i+2] = '4' ) then
                        begin
                        write('no');
                        exit;
                        end;
        end;
        write('yes');
end.

var
s:string;
a,b,c,i:longint;
begin
readln(s);
for i:=1 to length (s) do
begin
a:=pos('144',s);
delete(s,a,3);
end;
for i:=1 to length (s) do
begin
c:=pos('14',s);
delete(s,c,3);
end;
for i:=1 to length (s) do
begin
b:=pos('1',s);
delete(s,b,3);
end;
if length(s)=0 then
writeln('YES')
else
writeln('NO')
end.

{$MODE OBJFPC}
var
    s:ansistring;
    i,j,k,dem,n:integer;

begin
    readln(s);
    n:=length(s);
    for i:=1 to length(s) do
        if (s[i]<>'1') and (s[i]<>'4') then
            begin
                writeln('NO');
                halt;
            end;
    for i:=1 to n-1 do
        if (s[i]='1') and (s[i+1]='4') then
            begin
                dem:=0;
                for j:=i+1 to n do
                    if s[j]='4' then
                        inc(dem) else break;
                if (dem>2) then
                    begin
                        writeln('NO');
                        halt;
                    end;
            end;
    writeln('YES');
end.

var st,t:String;
    kt:boolean;

begin
     //assign(input,'magic_numbers.inp');
     //reset(input);
     //assign(output,'magic_numbers.out');
     //rewrite(output);
     readln(st);
               while pos('144',st)<>0 do
                    delete(st,pos('144',st),3);
               while pos('14',st)<>0 do
                    delete(st,pos('14',st),2);
                while pos('1',st)<>0 do
                    delete(st,pos('1',st),1);
     if st='' then
       write('YES')
     else write('NO');

end.

var n, i : longint;
    S : string[10];
    ok : boolean;
begin
     readln(n);
     str(n,S);
     ok := true;
     If pos('2',S) <> 0 then ok := false;
     If pos('3',S) <> 0 then ok := false;
     If pos('444',S) <> 0 then ok := false;
     If pos('5',S) <> 0 then ok := false;
     If pos('6',S) <> 0 then ok := false;
     If pos('7',S) <> 0 then ok := false;
     If pos('8',S) <> 0 then ok := false;
     If pos('9',S) <> 0 then ok := false;
     If ok then writeln('YES')
     else writeln('NO');
end.

var s:string;
 a,b,c,x,y,z,i,j,k,n:longint;
  begin
   readln(s);
   x:=0;
   if s[1]='1' then else begin Write('NO'); halt; end;
    for i:=1 to length(S) do
     begin
       if (s[i]='1') or (s[i]='4') then else begin Write('NO'); halt; end;
      if s[i]='4' then x:=x+1
      else if x>2 then begin Write('NO'); halt; end
       else x:=0;
     end;
     Write('YES');
  end.

Var s:string; i,k:longint;
begin
readln(s);
i:=1;
for i:=1 to length(s) do
if (pos('144',s)<>0) then begin delete(s,pos('144',s),3); k:=k+1;  end;
for i:=1 to length(s) do
if (pos('14',s)<>0) then begin delete(s,pos('14',s),2); k:=k+1;  end;
for i:=1 to length(s) do
if (pos('1',s)<>0) then begin delete(s,pos('1',s),1); k:=k+1;  end;

if s='' then writeln('YES') else writeln('NO')
end.

program zad_A;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  n, num : integer;
begin
  readln(n);
  while(n > 0) do begin
    num := n mod 10;
    if (num = 1) then
      n := n div 10
    else if (num = 4) then begin
      n := n div 10;
      num := num mod 10;
      if(num = 1) then
        n := n div 10
      else if (num = 4) then begin
        n := n div 10;
        if(n mod 10  = 1) then
          n := n div 10
        else begin
          n := 1;
          break;
        end;
      end else begin
        n := 1;
        break;
      end;
    end else
      break;
  end;

  if(n = 0) then
    writeln('YES')
  else
    writeln('NO');

  readln(n);
end.

program zad_A;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  n, num : integer;
begin
  readln(n);
  while(n > 0) do begin
    num := n mod 10;
    if (num = 1) then
      n := n div 10
    else if (num = 4) then begin
      n := n div 10;
      num := num mod 10;
      if(num = 1) then
        n := n div 10
      else if (num = 4) then begin
        n := n div 10;
        if(n mod 10  = 1) then
          n := n div 10
        else
          break;
      end else
        break;
    end else
      break;
  end;

  if(n = 0) then
    writeln('YES')
  else
    writeln('NO');

  readln(n);
end.

{$mode objfpc}
var
  s: string;
begin
  readln(s);
  while pos('1',s) <> 0 do delete(s,pos('1',s),1);
  while pos('14',s) <> 0 do delete(s,pos('14',s),2);
  while pos('144',s) <> 0 do delete(s,pos('144',s),3);
  if s = '' then writeln('YES') else writeln('NO');
end.

var
	s : string;
	a : array[1..3]of string;
	i : longint;

begin
	readln(s);
	a[1]:='144';
	a[2]:='14';
	a[3]:='1';
	for i:= 1 to 3 do begin
		while(pos(a[i],s)>0)do begin
			delete(s,pos(a[i],s),length(a[i]));
		end;
	end;
	if(length(s)=0)then writeln('YES')
	else writeln('NO');
end.

var a: string;
	dem,i,n: longint;
begin
	read(a);
	if a[1] <>'1' then
    begin
    write('NO');
	exit;
    end;
	dem:=0;
	for i:= 2 to length(a) do
		begin
			if (a[i] <> '1') or ( a[i] <> '4') then
				begin
					write('NO');
					exit;
				end;
			if a[i] = '4' then inc(dem)
			else dem:=0;
			if dem > 2 then
				begin
					write('NO');
					exit;
				end;
        end;
	write('YES');
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
  var
 s : string;

begin
readln (s);
while (pos ('144' , s) <> 0) do delete (s , pos ('144' , s) , 3);
while (pos ('14' , s) <> 0) do delete (s , pos ('14' , s) , 2);
while (pos ('1' , s) <> 0) do delete (s , pos ('1' , s) , 1);
if (length (s) <> 0) then writeln ('NO')
else writeln ('YES');
readln;
readln;
end.

program bai1;
var s:string;
	i:longint;
BEGIN
    readln(s);
    s:='44'+s;
	for i:=3 to length(s) do if (s[i]='4') and (s[i-1]='4') and (s[i-2]='4')  then
    begin
        writeln('NO');
        exit;
    end;
    writeln('YES');

END.

program q;
var n,i,j :integer;
s: string;
begin
readln (n);
str (n,s);
repeat
i:=pos('144',s);
if i<> 0 then delete (s,i,3)
until i=0;
repeat
i:=pos('14',s);
if i<>0 then delete (s,i,2)
until i=0;
repeat
i:=pos('1',s);
if i<>0 then delete (s,i,1)
until i=0;
if length (s)=0 then writeln ('YES') else writeln('NO');
end.

var s : string;
        i : byte;
begin
        i := 0;
        read(s);
        if s[1] ='4' then begin write('NO') ;  exit; end;
        for i:= 1 to length(s) do
                begin
                        if( s[i] <> '4') and (s[i] <> '1') then
                                begin
                                        write('NO');
                                        exit;
                                end;
                end;
        if length(s) > 3 then
        for i:= 1 to length(s)-3 do
                        if (s[i] = '4') and (s[i+1]='4') and
                           (s[i+2] = '4') then
                                begin
                                        write('NO');
                                        exit;
                                end;
        write('YES');
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var  m,nep,i, n,k : integer;
    s, s1,s2,s3,st: ansistring;
    f, g: boolean;
begin
  { TODO -oUser -cConsole Main : Insert code here }
   readln(s);
   s1:='144';
   s2:='14';
   s3:='1';
   f:=true;
   i:=1;
   n:=length(s);
   while i<n do
   begin
     st:=copy(s, i, 3);
     if st=s1 then  inc(i, 3)
     else
         begin
             st:=copy(s, i, 2);
             if st=s2 then i:=i+2
             else
             begin
                 st:=copy(s, i, 1);
                 if st=s3 then i:=i+1
                 else
                 begin
                   f:=false;
                   break;
                 end;
             end;
         end;
   end;

 if f then writeln('YES') else writeln('NO');
end.

  var s:ansistring;
      i,n,k:longint;

BEGIN

 readln(s); i:=1; n:=length(s);
 if s[1]<>'1' then begin writeln('NO'); halt; end;
   while i<=n do
     begin
       if (s[i]<>'1')and(s[i]<>'4') then begin writeln('NO'); halt; end;
       if s[i]='4' then
         begin
          k:=0;
            while (i<=n)and(s[i]='4') do begin inc(k); inc(i); end;
          if k>2 then begin writeln('NO'); halt; end;
         end;
       inc(i);
     end;

 writeln('YES');

END.

var s:string;
    i,n,j:longint;
    fl:boolean;
begin
readln(s);
fl:=true;
for i:=1 to length(s) do
 if (s[i]<>'4') and (s[i] <> '1')
  then fl:=false;
if pos('444',s) >0 then fl:=false;
if fl then writeln('YES')
      else writeln('NO');
end.

var
  i, l, c:longint;
  s:string;
begin
readln(s);
l:= length(s);
for i:=1 to l do
  begin
  if (c=0) and (s[i]='1') then c:=i;
  if (i-c<=1) and (i>1) then if (s[i]='4') and (s[i-1]='1')then c:=i;
  if (i-c<=2) and (i>2) then if (s[i]='4') and (s[i-1]='4') and (s[i-2]='1') then c:=i;
  if (i-c>2) then begin write('NO'); exit; end;
  end;
 if c=l then writeln('YES') else write('NO');
end.

var i:longint;
    s,s1,s2,s3:string;
begin
    read(s);
    while i<=length(s) do
    begin
        s1:=copy(s,i,1);   s2:=copy(s,i,2);    s3:=copy(s,i,3);
        if s3='144' then inc(i,3)
        else if s2='14' then inc(i,2)
        else if s1='1' then inc(i,1)
        else
        begin
            write('NO');
            exit;
        end;
    end;
    write('YES');
end.

var
 s:string;
 i,j,k:integer; t:boolean;
begin
 readln(s); t:=true;
 for i:=1 to length(s) do
  if (s[i]<>'1') and (s[i]<>'4') then t:=false;
  if t=true then begin
       repeat
        i:=pos('144',s);
        if (i<>0)and(s[i+3]<>'4') then delete(s,i,3);
       until (i=0)or(s[i+3]='4');
       repeat
        i:=pos('14',s);
        if (i<>0)and(s[i+2]<>'4') then delete(s,i,2);
       until (i=0)or(s[i+2]='4');
       repeat
        i:=pos('1',s);
        if i<>0 then delete(s,i,1);
       until i=0;
       if s<>'' then writeln('NO')
       else writeln('YES');
                  end
       else writeln('NO');
end.

{$o-}
program abc;
var
  s:string;
  i,n:longint;

procedure f1;
begin
  assign(input,'input.txt');
  assign(output,'output.txt');
  reset(input);
  rewrite(output);
end;

procedure f2;
begin
  close(input);
  close(output);
end;

begin
  read(s);
  if s[1] = '4' then
    write('NO')
  else begin
    i:=1;
    n:=length(s);
    while (i <= n) and ((s[i] = '1') or (s[i] = '4')) do
      inc(i);
    if i > n then
      write('YES')
    else
      write('NO');
  end;
end.

var s:string;
 a,b,c,x,y,z,i,j,k,n:longint;
  begin
   readln(s);
   x:=0;
   if s[1]='1' then else begin Write('NO'); halt; end;
    for i:=1 to length(S) do
     begin
       if (s[i]='1') or (s[i]='4') then else begin Write('NO'); halt; end;
      if s[i]='4' then x:=x+1
      else if x>2 then begin Write('NO'); halt; end
       else x:=0;
     end;
     Write('YES');
  end.

VAR S:string;
    I:byte;
    kt : boolean = true;
BEGIN
readln(s);
if s[1] <> '1' then
    write('NO')
else
    begin
    for i:=2 to length(s)-1 do
        begin
        if  (s[i]<>'1') and (s[i] <>'4') then
            begin
            write('NO');
            kt := FALSE;
            BREAK;
            end
        else
            if (s[i]=s[i+1]) and (s[i]=s[i-1]) and (s[i]='4') then
                begin
                write('NO');
                KT := FALSE;
                break;
                end;
        end;
        IF KT THEN
    write('YES');
    end;
end.

var
c:array [1..1000000] of char;
s:string;
i,l,k:integer;
begin
read(s);
l:=length(s);
for i:=1 to l do
c[i]:=s[i];
c[l+1]:='0';
for i:=1 to l+1 do
    begin
if (c[i]='1') and (c[i+1]='1') and (c[i+2]='4') then
begin
c[i]:='0';
c[i+1]:='0';
c[i+2]:='0';
end;
if (c[i]='1') and (c[i+1]='4') then
begin
c[i]:='0';
c[i+1]:='0';
end;
    end;
for i:=1 to l do
if (c[i]='1') then
c[i]:='0';
for i:=1 to l do
if (c[i]<>'0') then
k:=k+1;
if (k=0) then
write('YES');
if (k>0) then
write('NO')
end.

Program A320;
Var
    n: LongInt;
    i: integer;
Begin
    readln(n);
    while n > 0 do begin
        if (n mod 1000 <> 144) or (n mod 100 <> 14) or (n mod 10 <> 4) then break;
        n := n div 10;
    end;
    if n = 0 then writeln('YES') else writeln('NO');
End.

var
        a : string;
procedure xuli;
var
        i , dem : longint;
begin
        read( a );
        dem := 0;
        for i := 1 to length( a ) do
                begin
                        if dem >= 3 then
                        begin
                                write( 'NO' );
                                exit;
                        end;
                        if ( a[ i ] <> '1' ) and ( a[ i ] <> '4' ) then
                                begin
                                        write( 'NO' );
                                        exit;
                                end;
                        if a[ i ] = '4' then
                                begin
                                        if a[ i - 1 ] <> '1' then
                                        begin
                                                write( 'NO' ) ;
                                                exit;
                                        end
                                        else
                                                inc( dem );
                                end;
                end;
        write( 'YES');
end;
begin
        xuli;
end.

var a: string;
	dem,i,n: longint;
begin
	read(a);
	if a[1] <>'1' then
    begin
    write('NO');
	exit;
    end;
	dem:=0;
	for i:= 2 to n do
		begin
			if (a[i] <> '1') or ( a[i] <> '4') then
				begin
					write('NO');
					exit;
				end;
			if a[i] = '4' then inc(dem)
			else dem:=0;
			if dem > 2 then
				begin
					write('NO');
					exit;
				end;
        end;
	write('YES');
end.

var s:ansistring;
    ok:boolean;
    i:longint;
begin
    readln(s);
    for i:=1 to length(s)do
     delete(s,pos('144',s),3);
    for i:=1 to length(s)do
     delete(s,pos('14',s),2);
    for i:=1 to length(s)do
     delete(s,pos('1',s),1);
    if length(s)>0 then writeln('NO')else writeln('YES');
end.

var     n,i,l : longint;
        s : string;

function kt(q : string) : boolean;
 begin
        kt := true;
        if q[1] <> '1' then exit(false);
        for i := 2 to l-1 do
                if (q[i] <> '1') and (q[i] <> '4') then exit(false) else
                if (q[i] = '4') and (q[i-1] = '4') and (q[i+1] = '4') then exit(false);
 end;

begin
        readln(n);
        str(n,s);
        l := length(s);
        if not(kt(s)) then writeln('NO')
        else writeln('YES');
end.

  var s:ansistring;
      i,n,k:longint;

BEGIN

 readln(s); i:=1; n:=length(s);
   while i<=n do
     begin
       if (s[i]<>'1')and(s[i]<>'4') then begin writeln('NO'); halt; end;
       if s[i]='4' then
         begin
          k:=0;
            while (i<=n)and(s[i]='4') do begin inc(k); inc(i); end;
          if k>2 then begin writeln('NO'); halt; end;
         end;
       inc(i);
     end;

 writeln('YES');

END.

program volchis;
var s:string[255];
i,j:integer;
begin
readln(s);
i:=1;
while i<>0 do
begin
 while i<>0 do
  begin
   i:=pos('144',s);
   if i<>0 then
   begin
    delete(s,i,3);
    insert('a',s,i);
   end;
  end;
  i:=1;
  //writeln(s,' 1');
  while i<>0 do
  begin
   i:=pos('14',s);
   if i<>0 then
   begin
    insert('a',s,i);
    delete(s,i,2);
    end;
   end;
   i:=1;
   //writeln(s,' 2');
  while i<>0 do
  begin
   i:=pos('1',s);
   if i<>0 then
   begin
    delete(s,i,1);
    insert('a',s,i);
    end;
   end;
   i:=1;
  //writeln(s,' 3');
  while i<>0 do
  begin
   i:=pos('a',s);
   if i<>0 then
   begin
    delete(s,i,1);
    end;
   end;
  end;
  i:=length(s);
  if i=0 then writeln('YES') else writeln ('NO');
end.

var ans,f1:integer;
n:string;
begin
read(n);
if n[1]='4' then
    ans:=-1;
for f1:=1 to length(n) do
    begin
        if (n[f1]<>'1')and(n[f1]<>'4') then
            ans:=-1;
        if (f1>1)and(n[f1]='4')and(n[f1-1]<>'1') then
            ans:=-1;
    end;
if ans=-1 then
    write('NO')
        else
            write('YES');
end.

var
     S:String;
     F:Boolean;
     i,Kol:Longint;
begin
     Readln(S);
     F:=True;
     for i:=1 to Length(S) do
begin
     if (S[i]<>'4') and (S[i]<>'1') then begin
                                              F:=False;
                                              Break;
                                          end;
     if S[i]='4' then Inc(Kol)
                 else Kol:=0;
     if Kol>=3 then begin
                         F:=False;
                         Break;
                     end;
 end;
     if F then Writeln('YES')
          else Writeln('NO');
 end.

program yan;
  var s:string[11]; i,j,x,y:byte;
begin
  read(s);
  if s[1]<>'1' then begin write('NO'); exit; end;
  for i:=1 to length(s) do
    if (s[i]<>'1')and(s[i]<>'4') then
      begin write('NO'); exit; end;
  for i:=1 to length(s)-1 do
    if (s[i]='4')and(s[i+1]='4') then
      begin write('NO'); exit; end;
  write('YES');
end.

var s:string;
    n,i:longint;

begin
  {  assign(input,'bai1.inp');
    reset(input);
    assign(output,'bai1.out');
    rewrite(output); }
    readln(s);
    n:=length(S);
    i:=1;
    while i<=n do
      if copy(s,i,3)='114' then i:=i+3
        else if copy(s,i,2)='14' then i:=i+2
        else if copy(s,i,1)='1' then inc(i)
        else
          begin
                writeln('NO');
                halt;
          end;
    writeln('YES');
end.

var s:string;
    i,n,j:longint;
    fl:boolean;
begin
readln(s);
fl:=true;
for i:=1 to length(s) do
 if (s[i]<>'4') and (s[i] <> '1')
  then fl:=false;
if pos('444',s) >0 then fl:=false;
if fl then writeln('YES')
      else writeln('NO');
end.

Program _320A;
var
  a : array[1..10] of byte;
  n, i, t : longint;
begin
  read(n);
  i := 0;
  while n > 0 do
    begin
      i := i + 1;
      a[i] := n mod 10;
      n := n div 10;
    end;
  n := i;
  t := 0;
  for i := n downto 1 do
    case a[i] of
      1:case t of
          0,1,2: t := 0;
          else t := -1;
        end;
      4:case t of
          0, 1 : t := t + 1;
          else t := -1;
        end;
      else t := -1;
    end;
  if t >2
     then t := -1;
  if t = -1
     then write('NO')
     else write('YES');
end.

program A189;
var n, e, a, b, c, d, i:integer;
begin
  readln(n);
  a:=1;
  b:=0;
  e:=0;
  while(a<n) do
  begin
    a:=a*10;
    b:=b+1;
  end;
  a:=10;
  for i:=1 to b do
  begin
    c:=(n mod a - n mod (a div 10)) div (a div 10);
    if ((c<>1) and (c<>4)) then
    begin
      d:=1;
      break;
    end
    else
    begin
      if c=4 then
      begin
       e:=e+1;
       if e>2 then d:=1;
      end
      else e:=0;
    end;
  end;
  if d=1 then writeln('NO')
  else writeln('YES');
end.

var
        s : string;
        len,i : byte;
        dani : boolean;

begin
        readln(s);
        len := length(s);
        dani := true;
        for i := 1 to len do
          if (s[i]<>'1') and (s[i]<>'4') then begin
              dani := false;
              writeln('NO');
              break;
          end;

        if dani then begin
          if pos('444',s)<>0 then begin
             dani := false;
             writeln('NO');
          end;
        end;

        if s[1]='4' then writeln('NO')
        else if dani then writeln('YES');
end.

var s : string;
        i : byte;
begin
        read(s);
        if s[1] ='4' then begin write('NO') ;  exit; end;
        for i:= 1 to length(s) do
                begin
                        if( s[i] <> '4') and (s[i] <> '1') then
                                begin
                                        write('NO');
                                        exit;
                                end;
                end;
        if length(s) > 3 then
        for i:= 2 to length(s)-3 do
                        if (s[i] = '4') and (s[i+1]='4') and
                           (s[i+2] = '4') then
                                begin
                                        write('NO');
                                        exit;
                                end;
        write('YES');
end.

var
s:string;
b:boolean;
i,j,k,pos1,jarak:integer;

begin
readln(s);
b:=true;
pos1:=-2;
for k:=1 to length(s) do begin
    if (s[k]='1') then pos1:=k
    else if (s[k]='4') then begin
       jarak:=k-pos1;
       if (jarak=1) or (jarak=2) then continue
       else begin
         b:=false;
         break;
       end;
    end
    else begin
        b:=false;
        break;
    end;

    if b then writeln('YES')
    else writeln('NO');
end;

end.

const fi = 'input.txt';
      fo = 'output.txt';

var s: string;
    n, i: longint;
    ok: boolean;

begin
 readln(s);
 n:=length(s);
 ok:=true;
 for i:=1 to n do
  if (s[i] <> '1') and (s[i] <> '4') then ok:=false;
 if ok then
  begin
   if (pos('444', s) > 0) then writeln('NO')
   else writeln('YES');
  end
 else writeln('NO');

 close(input); close(output);
end.

var
	s : string;
	a : array[1..3]of string;
	i : longint;

begin
	readln(s);
	a[1]:='144';
	a[2]:='14';
	a[3]:='1';
	for i:= 1 to 3 do begin
		while(pos(a[i],s)>0)do begin
			delete(s,pos(a[i],s),length(a[i]));
		end;
	end;
	if(length(s)=0)then writeln('YES')
	else writeln('NO');
end.

Var n:Longint;
        s,temp:String;
        ok:boolean;
        i:Longint;
Begin
        Readln(n);
        str(n,s);

        ok:=true;

        for i:=1 to length(s) do
         If (s[i]<>'1') and (s[i]<>'4') then ok:=false;

        For i:=2 to length(s)-1 do
         If (s[i]='4') and (s[i+1]='4') and (s[i-1]<>'1') then ok:=false;

        If (ok) then Writeln('YES') Else Writeln('NO');
End.

var n,a,k1,k4:longint;
begin
readln(n);
a:=n;
k1:=0;
k4:=0;
while a>0 do
  begin
  if (a mod 10=1) or (a mod 10=4)
     then begin
          if a mod 10=1
             then inc(k1)
             else inc(k4);
          a:=a div 10;
          end
     else begin writeln('NO'); halt; end;
  end;
if (k1>0) and (k4=0) then writeln('YES');
if k1=k4 then writeln('YES');
if (k1<>0) and (k4<>0)
  then if (k1 div k4=2) or (k4 div k1=2) then writeln('YES');
end.

var s:string;
    i,k,f:integer;
begin
read(s);
f:=0;
for i:=1 to length(s) do begin
 if s[i]='4' then inc(k)
 else if s[i]='1' then k:=0
 else f:=1;
 if k>=3 then f:=1;
 if f=1 then break;
end;
if f=0 then write('YES') else write('NO');
end.

program project1;

var s : string [11];
  i: byte;

begin
  writeln ( ' enter string ', s );
  readln (s);

  repeat
    begin
     i:=pos( '144', s);
     delete ( s, i, 3 );
    end;
  until (i=0);
  repeat
    begin
     i:= pos ( '14',s);
     delete (s, i, 2);
    end;
  until ( i=0);
  repeat
    i:= pos ('1', s);
    delete ( s, i, 1);
  until (i=0) ;

  if length(s)=0 then
  writeln ( 'YES') else
    writeln ('NO');

end.

var
s:string;
a,b,c,i,d:longint;
begin
readln(s);
for i:=1 to length (s) do
begin
a:=pos('144',s);
delete(s,a,3);
insert(' ',s,a)
end;
for i:=1 to length (s) do
begin
c:=pos('14',s);
delete(s,c,2);
insert(' ',s,c)
end;
for i:=1 to length (s) do
begin
b:=pos('1',s);
delete(s,b,1);
insert(' ',s,b)
end;
begin
d:=pos(' ',s);
delete(s,d,1);
end;
if length(s)=0 then
writeln('YES')
else
writeln('NO')
end.

var
        a : string;
procedure xuli;
var
        i , dem : longint;
begin
        read( a );
        dem := 0;
        for i := 1 to length( a ) do
                begin
                        if dem >= 3 then
                        begin
                                write( 'NO' );
                                exit;
                        end;
                        if ( a[ i ] <> '1' ) and ( a[ i ] <> '4' ) then
                                begin
                                        write( 'NO' );
                                        exit;
                                end;
                        if a[ i ] = '1' then
                                dem := 0;
                        if a[ i ] = '4' then
                                begin
                                        if ( dem = 0 ) and ( a[ i - 1 ] <> '1') then
                                        begin
                                                write( 'NO' ) ;
                                                exit;
                                        end
                                        else
                                                inc( dem );
                                end;
                end;
        write( 'YES');
end;
begin
        xuli;
end.

var n,k,i:longint;s:string;c:set of char;
begin
readln(s);
if s[1]<>'1' then writeln('NO')else
begin
i:=length(s);
while i<>0 do
begin
if (s[1]<>'1')and(s[1]<>'4')then begin writeln('NO');break;end else
 if s[1]='4' then begin
    if k>=2 then begin writeln('NO');break;end else begin inc(k);end ;
    end else k:=0;
    dec(i);delete(s,1,1);
    end;

writeln('YES');
end;
end.

var
n,m,q,w,l,r,mid,i,k:longint;
s:string;
a,b:array[1..100000] of longint;
c:array[0..1000, 0..1000] of int64;
begin
    {assign(input,'f.in');
    assign(output,'f.out');
    reset(input);
    rewrite(output); }
    read(s);
    if s[1]='4' then
    begin
        write('NO');
        exit;
    end;
    for i:=1 to length(s) do
    begin
        if (s[i]<>'1') and (s[i]<>'4') then
        begin
            write('NO');
            exit;
        end;
        if (s[i]='4') then inc(k);
        if k=3 then
        begin
            write('NO');
        end;
        if s[i]='1' then k:=0;
    end;
    write('YES');
end.

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var  m,nep,i, n,k : integer;
    s, s1,s2,s3: ansistring;
    f: boolean;
begin
  { TODO -oUser -cConsole Main : Insert code here }
   readln(s);
   s1:='144';
   s2:='14';

   while pos(s1, s)>0 do delete(s, pos(s1,s), 3);
   while pos(s2, s)>0 do delete(s, pos(s2,s), 2);
   //writeln(s);
   f:=true;
   for i:=1 to length(s) do
     if s[i]<>'1' then
     begin
       f:=false;
       break;
     end;
 if f then writeln('YES') else writeln('NO');
end.

var s:string;
i:longint;
begin
readln(s);
for i:=1 to length(s) do
 if (s[i]='1')or(s[i]='4') then continue else begin writeln('NO');halt;end;
 writeln('YES');
 end.

//Uses math,sysutils,strutils;
var
n,q,i,w:longint;
a:array[1..10]of integer;
begin
read(n);
w:=1;
for i:=1 to 10 do
a[i]:=0;
q:=10;
while n>0 do
begin
a[q]:=n mod 10;
n:=n div 10;
q:=q-1;
end;
q:=q+1;
if a[q]<>1
then
w:=0;
if q>5
then
for i:=q+1 to 8 do
if (a[i]=a[i+1]) and (a[i]=4) and (a[i]=a[i+2])
then
w:=0;
if q<10
then
for i:=q+1 to 10 do
if (a[i]<>1) and (a[i]<>4)
then
w:=0;
if w=1
then
write('YES')
else
write('NO');
end.

var
  i, l, c:longint;
  s:string;
begin
readln(s);
l:= length(s);
for i:=1 to l do
  begin
  if s[i]='1' then c:=i;
  if (i-c<=1) and (i>1) then if (s[i]='4') and (s[i-1]='1')then c:=i;
  if (i-c<=2) and (i>2) then if (s[i]='4') and (s[i-1]='4') and (s[i-2]='1') then c:=i;
  if (i-c>2) then begin write('NO'); exit; end;
  end;
 if c=l then writeln('YES') else write('NO');
end.

var p:longint;
    s:string;

begin

  readln(s);

  while true do
    begin
      p:=pos('144',s);
      if (p>0) then delete(s,p,3)
        else break;
    end;

  while true do
    begin
      p:=pos('14',s);
      if (p>0) then delete(s,p,2)
       else break;
    end;

  while true do
    begin
      p:=pos('1',s);
      if (p>0) then delete(s,p,1)
        else break;
    end;

  if (s='') then writeln('YES')
    else writeln('NO');

end.

program one;
var
i, n: integer;
s: string;
begin
readln (n);
str (n, s);
repeat
i:= pos ('144', s);
if i <> 0 then delete (s, i, 3);
insert ('a', s, i);
until i = 0;
repeat
i:= pos ('14', s);
if i<>0 then delete (s, i, 2);
insert ('a', s, i);
until i = 0;
repeat
i:= pos ('1', s);
if i<>0 then delete (s, i, 1);
insert ('a', s, i);
until i = 0;
if length (s) = 0
then
writeln ('YES')
else writeln ('NO');
end.

VAR S:string;
    I:byte;
BEGIN
readln(s);
if s[1] <> '1' then
    write('NO')
else
    begin
    for i:=2 to length(s)-1 do
        begin
        if  (s[i]<>'1') and (s[i] <>'4') then
            begin
            write('NO');
            BREAK;
            end
        else
            if (s[i]=s[i+1]) and (s[i]=s[i-1]) and (s[i]='4') then
                begin
                write('NO');
                break;
                end;
        end;
    write('YES');
    end;
end.

var s:string;
i:longint;
begin
readln(s);
for i:=2 to length(s) do
  if (s[i]='4')and(s[i-1]='4') then begin writeln('NO');halt;end;
for i:=1 to length(s) do
 if (s[i]='1')or(s[i]='4') then continue else begin writeln('NO');halt;end;
 writeln('YES');
 end.

Var s:String;
i:LongInt;
Begin
     //ReSet (input,'input.txt');
    // ReWrite (output,'output.txt');
     Readln (s);
     For I:=1 to Length (s) do
     If (s[i]<>'1') and (s[i]<>'4')
     then Begin
          Writeln ('NO');
          Halt (0);
     End;
      For I:=1 to Length (s)-2 do
     If (s[i]='4') and (s[i+1]='4') and (s[i+2]='4')
     then Begin
          Writeln ('NO');
          Halt (0);
     End;
     Writeln ('YES');
End.

Program MagicNumbers;
uses math;
var s:string;
begin   //assign(input,'320A.inp'); reset(input);
        //assign(output,'320A.out'); rewrite(output);
        readln(s);
        while Pos('144',s)<>0 do delete(s,Pos('144',s),3);
        while Pos('14',s)<>0 do delete(s,Pos('14',s),2);
        while Pos('1',s)<>0 do delete(s,Pos('1',s),1);
        if s='' then writeln('YES')
        else writeln('NO');
        //close(input); close(output);
end.

var  b:array [0..3]of string;
  s,l:string;
   k,i,p:longint;
 begin
 b[1]:='1';
 b[2]:='14';
 b[3]:='144';
  readln(s);
  l:=s;
   repeat
  p:=0;
  for i:=3 downto 1 do
   begin
    k:=pos(b[i],l);
    if k>0 then begin delete(l,k,i); p:=1; end;
   end;
    if p=0 then begin writeln('NO'); exit; end;
  until(length(l)=0);
  repeat
  p:=0;
  for i:=3 downto 1 do
   begin
    k:=pos(b[i],s);
    if k>0 then begin delete(s,k,i); p:=1;break; end;
   end;
    if p=0 then begin writeln('NO'); exit; end;
  until(length(s)=0);
   if (length(s)=0)or(length(l)=0) then writeln('YES');
 end.

  var s:ansistring;
      i,n,k:longint;

BEGIN

 readln(s); i:=1; n:=length(s);
   while i<=n do
     begin
       if (s[i]<>'1')and(s[i]<>'4') then begin writeln('NO'); halt; end;
       if s[i]='4' then
         begin
          k:=0;
            while (i<=n)and(s[i]='4') do begin inc(k); inc(i); end;
          if k>2 then begin writeln('NO'); halt; end;
         end;
       inc(i);
     end;

 writeln('YES');

END.

var s : string;
        i : byte;
begin
        i := 0;
        read(s);
        if s[1] ='4' then begin write('NO') ;  exit; end;
        for i:= 1 to length(s) do
                begin
                        if( s[i] <> '4') and (s[i] <> '1') then
                                begin
                                        write('NO');
                                        exit;
                                end;
                end;
        if length(s) > 3 then
        for i:= 1 to length(s)-3 do
                        if (s[i] = '4') and (s[i+1]='4') and
                           (s[i+2] = '4') then
                                begin
                                        write('NO');
                                        exit;
                                end;
        write('YES');
end.

  var s:ansistring;
      i,n,k:longint;

BEGIN

 readln(s); i:=1; n:=length(s);
 if s[1]<>'1' then begin writeln('NO'); halt; end;
   while i<=n do
     begin
       if (s[i]<>'1')and(s[i]<>'4') then begin writeln('NO'); halt; end;
       if s[i]='4' then
         begin
          k:=0;
            while (i<=n)and(s[i]='4') do begin inc(k); inc(i); end;
          if k>2 then begin writeln('NO'); halt; end;
         end;
       inc(i);
     end;

 writeln('YES');

END.

var
    n:string;
    i,f:integer;
begin
    readln(n);
    if n[1]='1' then
    begin
        for i:=1 to length(n) do
        begin
            if ((n[i]='1') or (n[i]='4')) then
        begin
            f:=1;
        end
        else
        begin
            writeln('NO') ;
            f:=2;
            break;
        end;
    end;
    if f<>2 then writeln('YES');
    end
    else
            writeln('NO');
end.

program codeforcesa2;
var
    Num:int64;
    Check:set of byte;
    digit, test:integer;
begin
    readln(Num);
    Check:=[1, 14, 144];
    repeat
        test:=1000;
        digit:=Num mod test;
        if not (digit in Check) then begin
            repeat
                test:=test div 10;
                digit:=Num mod test;
                if digit in Check then break;
                if test=10 then begin
                    writeln('NO');
                    exit;
                end;
            until test=10;
        end;
        Num:=Num div test;
    until Num=0;
    writeln('YES');
end.

var s:string;
    i,j,k,l,r,n,m:longint;
  begin
    readln(s);
    i:=1;
    s:=s+'     ';
    while i<>length(s) do
     begin
       if s[i]='4' then begin writeln('NO'); halt; end;
       if s[i]=' ' then break;
       if (s[i+1]='4') and (s[i+2]='4') then inc(i,3) else
       if (s[i+1]='4') then inc(i,2) else inc(i,1);

     end;
    writeln('YES');
  end.

program q;
var a,b,c: integer;
s:string;
begin
readln (a);
str (a,s);
repeat
b:= pos('114',s);
if b <> 0 then delete (s,b,3)
until b=0;
repeat
b:= pos('14',s);
if b <> 0 then delete (s,b,2)
until b=0;
repeat
b:= pos('1',s);
if b <> 0 then delete (s,b,1)
until b=0;
if length (s)=0 then writeln ('YES') else writeln ('NO');
end.

var s:string;
 a,b,c,x,y,z,i,j,k,n:longint;
  begin
   readln(s);
   x:=0;
    for i:=1 to length(S) do
     begin
       if (s[i]='1') or (s[i]='4') then else begin Write('NO'); halt; end;
      if s[i]='4' then x:=x+1
      else if x>2 then begin Write('NO'); halt; end
       else x:=0;
     end;
     Write('YES');
  end.

var
a:int64;
j,i,k:byte;
b:array[1..10] of byte;
r:boolean;
begin
readln(a);
i:=1;
while a>9 do
 begin
  b[i]:=a mod 10;
  a:=a div 10;
  i:=i+1;
 end;
b[i]:=a;
k:=0;
r:=true;
j:=0;
while j<i do
 begin
  j:=j+1;
  if b[j]=4 then k:=k+1
            else
             begin
              if b[j]=1 then k:=0
                        else r:=false;
             end;
  if k>2 then r:=false;
 end;
if r=true then writeln('YES')
          else writeln('NO');
end.

var s,k:string;
    i,j,l,m:longint;
    b:boolean;
begin
readln(s);
i:=1;
b:=true;
k:=copy(s,i,3);
while (b=true) and (i<= length(s)) do
begin
if k='144' then begin
                 inc(i,3);
                 k:=copy(s,i,3);
                end
          else  begin
                k:=copy(s,i,2);
                if k='14' then inc(i,2)
                         else begin
                              k:=copy(s,i,1);
                              if k='1' then inc(i)
                                     else b:=false;
                               end;
end;            end;
if b=false then write('NO')
            else write('YES');
end.

var s:string;i,dem:integer;kt:boolean;
begin
        read(s);dem:=0;kt:=true;
        if s[1] <> '1' then kt:=false;
        if s[1] ='1' then begin
        for i:=1 to length(s) do
        begin
        if s[i]='4' then inc(dem);
        if dem=3 then kt:=false;
        if s[i]='1' then dem:=0;
        end;end;
        if kt=true then write('YES');
        if kt=false then write('NO');
end.

Var s:string; i,k:longint;
begin
readln(s);
i:=1;
for i:=1 to length(s) do
if (pos('144',s)<>0) then begin delete(s,pos('144',s),3); k:=k+1;  end;
for i:=1 to length(s) do
if (pos('14',s)<>0) then begin delete(s,pos('14',s),2); k:=k+1;  end;
for i:=1 to length(s) do
if (pos('1',s)<>0) then begin delete(s,pos('1',s),1); k:=k+1;  end;

if s='' then writeln('YES') else writeln('NO')
end.

var a:string;
        i :byte;

begin
        read(a);
        i:= 1;
        for i := 1 to length(a) do
        begin
                if ((a[i] <> '1') and (a[i] <> '4')) or (a[1] = '4') then
                begin
                        write('No');
                        exit;
                end;

                if (a[i] = '4')and (a[i+1]='4') and(a[i+2] = '4' ) then
                        begin
                        write('NO');
                        exit;
                        end;
        end;
        write('YES');
end.

Program _320A;
var
  a : array[1..10] of byte;
  n, i, t : longint;
begin
  read(n);
  i := 0;
  while n > 0 do
    begin
      i := i + 1;
      a[i] := n mod 10;
      n := n div 10;
    end;
  n := i;
  t := 0;
  for i := n downto 1 do
    case a[i] of
      1:case t of
          0,1,2: t := 0;
          else t := -1;
        end;
      4:case t of
          0, 1 : t := t + 1;
          else t := -1;
        end;
      else t := -1;
    end;
  if t >2
     then t := -1;
  if t = -1
     then write('NO')
     else write('YES');
end.

var s:string; i,f:integer; ans:boolean;

begin
readln(s);
while pos('144',s)>0 do
 begin
  f:=pos('144',s);
  for i:= f to f+2 do s[i]:='x';
 end;
while pos('14',s)>0 do
 begin
  f:=pos('14',s);
  for i:= f to f+3 do s[i]:='x';
 end;
while pos('1',s)>0 do
 begin i:=pos('1',s); s[i]:='x'; end;
ans:=true;
for i:= 1 to length(s) do
 begin
  if s[i]<>'x' then ans:=false;
 end;
if ans then writeln('YES') else writeln('NO');

end.

var s:string;
    i,k4,xx,c:integer;
    x:boolean;
begin
readln(s);
k4:=0;
x:=true;
if s[1]='4' then x:=false else

 for i:=1 to length(s) do
   begin
   val(s[i],xx,c);
   if (xx<>1) and (xx<>4) then begin x:=false; writeln(xx); break end;
   if xx=1 then k4:=0;
   if xx=4 then inc(k4);
   if k4>2 then begin x:=false; break end;
   end;

if x then writeln('YES') else writeln('NO');
end.

var i:longint;
    s,s1,s2,s3:string;
begin
    read(s);
    while i<=length(s) do
    begin
        s1:=copy(s,i,1);   s2:=copy(s,i,2);    s3:=copy(s,i,3);
        if s3='144' then inc(i,3)
        else if s2='14' then inc(i,2)
        else if s1='1' then inc(i,1)
        else
        begin
            write('NO');
            exit;
        end;
    end;
    write('YES');
end.

var ans,f1:integer;
n:string;
begin
read(n);
if n[1]='4' then
    ans:=-1;
for f1:=1 to length(n) do
    begin
        if (n[f1]<>'1')and(n[f1]<>'4') then
            ans:=-1;
        if (f1>1)and(n[f1]='4')and(n[f1-1]<>'1') then
            ans:=-1;
    end;
if ans=-1 then
    write('NO')
        else
            write('YES');
end.

var
i,ii : integer;
n : ansistring;
x : char;
begin
    read(n);
    if n[1] = '4' then
        begin
            write('NO');
                exit;
        end;
    for i := 1 to length(n) do
        begin
            if n[i] = '4' then
            begin
                for ii := i to i + 2 do
                    if ii  <= length(n) then
                    begin
                        if n[ii] = '4' then
                             begin
                                if ii = (i + 2) then
                                    begin
                                        write('NO');
                                        EXIT;
                                    end;
                             end
                    end;
            end;
            if ( n[i] <> '4') and ( n[i] <> '1') then
                begin
                    write('NO');
                    exit;
                end;
        end;
    write('YES');
end.