N=input()
M=input()
assert(1<=len(N))
assert(len(N)<=100000)
assert(1<=len(M))
assert(len(M)<=100000)
assert((N=='0')or(N[0]!='0'))
assert((N=='0')or(N[0]!='0'))
assert((M=='0')or(M[0]!='0'))

X=[0,1,5,2,10,6,5,3,9,11,8,7,10,6,5,4,12]
X=[X[i]+1 for i in range(len(X))]
def f(N):
  P=[]
  b=0
  while N:
    if N&1:
      v=X[b]
      P.append(v)
      b=0
    else:
      b+=1
    N>>=1
  P=P[::-1]
  A=[]
  for i in range(len(P)):
    while len(A)>0 and A[-1][0]<P[i]:
      del A[-1]
    if len(A)>0 and A[-1][0]==P[i]:
      A[-1]=(A[-1][0],A[-1][1]+1)
    else:
      A.append((P[i],1))
  return tuple(A)

P=[]
Q=[]
b=0
for i in range(len(N)-1,-1,-1):
  if N[i]=='0':
    b+=1
  else:
    v=f(b)
    P.append(v)
    b=0
P=P[::-1]
b=0
for i in range(len(M)-1,-1,-1):
  if M[i]=='0':
    b+=1
  else:
    v=f(b)
    Q.append(v)
    b=0
Q=Q[::-1]
A=[]
B=[]
for i in range(len(P)):
  v=P[i]
  while len(A)>0:
    if A[-1]<v:
      del A[-1]
    else:
      break
  A.append(v)
for i in range(len(Q)):
  v=Q[i]
  while len(B)>0:
    if B[-1]<v:
      del B[-1]
    else:
      break
  B.append(v)
if A<B:
  print('Yes')
else:
  print('No')