def str_to_ord(s) n = s.size indices = [0] + (0 ... n).filter { |i| s[i] == "1" } a = indices.each_cons(2).map { |l, r| int_to_ord(r - l) } a.sort! a.reverse! a.flatten end def int_to_ord(n, d = 0) if n == 0 return [d] end xs = [] while n > 0 b = 0 while n & 1 == 0 b += 1 n >>= 1 end xs << b n >>= 1 end ys = xs.map { |m| [d + 1] + int_to_ord(m, d + 2) } ys.sort! ys.reverse! [d] + ys.flatten end N = str_to_ord(gets.chomp) M = str_to_ord(gets.chomp) puts ((N <=> M) < 0) ? "Yes" : "No"